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/21 07:58:35 UTC

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

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



##########
File path: airflow/providers/postgres/hooks/postgres.py
##########
@@ -115,6 +116,23 @@ 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}'
+        schema = self.schema or conn.schema or ''
+        uri = urlunsplit((conn.conn_type, f'{login}{host}', schema, '', ''))
+        return uri

Review comment:
       I think that is a better way to implement this.
   I'll work on it.




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