You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/06/22 16:47:55 UTC

[GitHub] [airflow] natanweinberger commented on a change in pull request #15013: Enable Connection creation from Vault parameters

natanweinberger commented on a change in pull request #15013:
URL: https://github.com/apache/airflow/pull/15013#discussion_r656404549



##########
File path: airflow/providers/hashicorp/secrets/vault.py
##########
@@ -188,12 +204,28 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
         :rtype: str
         :return: The connection uri retrieved from the secret
         """
-        if self.connections_path is None:
+        response = self.get_response(conn_id)
+
+        return response.get("conn_uri") if response else None
+
+    def get_connection(self, conn_id: str) -> Optional[Connection]:
+        """
+        Get connection from Vault as secret. Prioritize conn_uri if exists,
+        if not fall back to normal Connection creation.
+
+        :type conn_id: str
+        :rtype: Connection
+        :return: A Connection object constructed from Vault data
+        """
+        response = self.get_response(conn_id)
+        if response is None:
             return None
-        else:
-            secret_path = self.build_path(self.connections_path, conn_id)
-            response = self.vault_client.get_secret(secret_path=secret_path)
-            return response.get("conn_uri") if response else None
+
+        uri = response.get("conn_uri")
+        if uri:
+            return uri

Review comment:
       This won't return a connection object. I think this should be
   ```python
   if uri:
       return Connection(conn_id, uri=uri)
   
   return Connection(conn_id, **response) 
   # or _create_connection, but constructor handles this logic pretty well now without secrets backend
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org