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/18 21:13:04 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #16521: Implement get_uri() in PostgresHook

uranusjr commented on a change in pull request #16521:
URL: https://github.com/apache/airflow/pull/16521#discussion_r654131855



##########
File path: airflow/providers/postgres/hooks/postgres.py
##########
@@ -114,6 +115,25 @@ def get_conn(self) -> connection:
 
         self.conn = psycopg2.connect(**conn_args)
         return self.conn
+    
+    def get_uri(self) -> str:
+        """
+        Extract the URI from the connection.
+
+        :return: the extracted uri.
+        """
+        conn = self.get_connection(getattr(self, self.conn_name_attr))
+        login = ''
+        if conn.login:
+            login = f'{quote_plus(conn.login)}:{quote_plus(conn.password)}@'
+        host = conn.host
+        if conn.port is not None:
+            host += f':{conn.port}'
+        uri = f'{conn.conn_type}://{login}{host}/'
+        schema = self.schema or conn.schema
+        if schema:
+            uri += conn.schema
+        return uri

Review comment:
       `urlunsplit` would save you a lot of trouble :)




-- 
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