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 2023/01/04 15:26:24 UTC

[GitHub] [airflow] stamixthereal commented on a diff in pull request #28675: MongoHook optimization

stamixthereal commented on code in PR #28675:
URL: https://github.com/apache/airflow/pull/28675#discussion_r1061600064


##########
airflow/providers/mongo/hooks/mongo.py:
##########
@@ -90,15 +84,19 @@ def get_conn(self) -> MongoClient:
             options.update({"ssl_cert_reqs": CERT_NONE})
 
         self.client = MongoClient(self.uri, **options)
-
         return self.client
 
-    def close_conn(self) -> None:
-        """Closes connection"""
-        client = self.client
-        if client is not None:
-            client.close()
-            self.client = None
+    def create_uri(self) -> str:
+        """
+        Create URI string from the given credentials.
+
+        :return: URI string.
+        """
+        srv = self.extras.pop("srv", False)
+        scheme = "mongodb+srv" if srv else "mongodb"
+        creds = f"{self.connection.login}:{self.connection.password}@" if self.connection.login else ""
+        port = f":{self.connection.port}" if self.connection.port else ""
+        return f"{scheme}://{creds}{self.connection.host}{port}/{self.connection.schema}"

Review Comment:
   Absolutely agree with you, @Taragolis! It is generally a good practice to URL encode sensitive information such as login and password, especially when it is included in a URI. This can help prevent potential vulnerabilities caused by parsing the URI in an unexpected way.



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

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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