airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fo...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-48] Parse connection uri querystring
Date Wed, 16 May 2018 08:53:46 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 802cbd9b9 -> b17a99d71


[AIRFLOW-48] Parse connection uri querystring

Closes #3292 from inytar/extras-in-uri


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/b17a99d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/b17a99d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/b17a99d7

Branch: refs/heads/master
Commit: b17a99d714310cd05577a6d1b3b4baa101aec674
Parents: 802cbd9
Author: inytar <pietpiet@fastmail.net>
Authored: Wed May 16 10:53:41 2018 +0200
Committer: Fokko Driesprong <fokkodriesprong@godatadriven.com>
Committed: Wed May 16 10:53:41 2018 +0200

----------------------------------------------------------------------
 airflow/models.py |  4 +++-
 tests/models.py   | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/b17a99d7/airflow/models.py
----------------------------------------------------------------------
diff --git a/airflow/models.py b/airflow/models.py
index 2322860..c9fee0c 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -52,7 +52,7 @@ import hashlib
 
 import uuid
 from datetime import datetime
-from urllib.parse import urlparse, quote
+from urllib.parse import urlparse, quote, parse_qsl
 
 from sqlalchemy import (
     Column, Integer, String, DateTime, Text, Boolean, ForeignKey, PickleType,
@@ -636,6 +636,8 @@ class Connection(Base, LoggingMixin):
         self.login = temp_uri.username
         self.password = temp_uri.password
         self.port = temp_uri.port
+        if temp_uri.query:
+            self.extra = json.dumps(dict(parse_qsl(temp_uri.query)))
 
     def get_password(self):
         if self._password and self.is_encrypted:

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/b17a99d7/tests/models.py
----------------------------------------------------------------------
diff --git a/tests/models.py b/tests/models.py
index c2e54e5..2bf61fe 100644
--- a/tests/models.py
+++ b/tests/models.py
@@ -2326,3 +2326,27 @@ class ConnectionTest(unittest.TestCase):
         mock_get.return_value = 'dGVzdA=='
         test_connection = Connection(extra='testextra')
         self.assertEqual(test_connection.extra, 'testextra')
+
+    def test_connection_from_uri_without_extras(self):
+        uri = 'scheme://user:password@host%2flocation:1234/schema'
+        connection = Connection(uri=uri)
+        self.assertEqual(connection.conn_type, 'scheme')
+        self.assertEqual(connection.host, 'host/location')
+        self.assertEqual(connection.schema, 'schema')
+        self.assertEqual(connection.login, 'user')
+        self.assertEqual(connection.password, 'password')
+        self.assertEqual(connection.port, 1234)
+        self.assertIsNone(connection.extra)
+
+    def test_connection_from_uri_with_extras(self):
+        uri = 'scheme://user:password@host%2flocation:1234/schema?'\
+            'extra1=a%20value&extra2=%2fpath%2f'
+        connection = Connection(uri=uri)
+        self.assertEqual(connection.conn_type, 'scheme')
+        self.assertEqual(connection.host, 'host/location')
+        self.assertEqual(connection.schema, 'schema')
+        self.assertEqual(connection.login, 'user')
+        self.assertEqual(connection.password, 'password')
+        self.assertEqual(connection.port, 1234)
+        self.assertDictEqual(connection.extra_dejson, {'extra1': 'a value',
+                                                       'extra2': '/path/'})


Mime
View raw message