airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] ashb closed pull request #3721: [AIRFLOW-2875] Escape env vars in tmp config
Date Thu, 01 Nov 2018 21:22:10 GMT
ashb closed pull request #3721: [AIRFLOW-2875] Escape env vars in tmp config
URL: https://github.com/apache/incubator-airflow/pull/3721
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/configuration.py b/airflow/configuration.py
index ed8943ac77..e5a2a000ec 100644
--- a/airflow/configuration.py
+++ b/airflow/configuration.py
@@ -330,7 +330,7 @@ def getsection(self, section):
             _section[key] = val
         return _section
 
-    def as_dict(self, display_source=False, display_sensitive=False):
+    def as_dict(self, display_source=False, display_sensitive=False, escape_env_vars=False):
         """
         Returns the current configuration as an OrderedDict of OrderedDicts.
         :param display_source: If False, the option value is returned. If True,
@@ -378,6 +378,8 @@ def as_dict(self, display_source=False, display_sensitive=False):
             if opt:
                 if not display_sensitive:
                     opt = '< hidden >'
+                if escape_env_vars:
+                    opt = opt.replace('%', '%%')
                 if display_source:
                     opt = (opt, 'bash cmd')
                 cfg.setdefault(section, OrderedDict()).update({key: opt})
diff --git a/airflow/utils/configuration.py b/airflow/utils/configuration.py
index 18a338c23f..6ad43646be 100644
--- a/airflow/utils/configuration.py
+++ b/airflow/utils/configuration.py
@@ -32,7 +32,7 @@ def tmp_configuration_copy():
     settings.
     :return: a path to a temporary file
     """
-    cfg_dict = conf.as_dict(display_sensitive=True)
+    cfg_dict = conf.as_dict(display_sensitive=True, escape_env_vars=True)
     temp_fd, cfg_path = mkstemp()
 
     with os.fdopen(temp_fd, 'w') as temp_file:
diff --git a/run_unit_tests.sh b/run_unit_tests.sh
index 27e4d08af1..dfda2c3dcb 100755
--- a/run_unit_tests.sh
+++ b/run_unit_tests.sh
@@ -26,6 +26,7 @@ export AIRFLOW__CORE__UNIT_TEST_MODE=True
 
 # configuration test
 export AIRFLOW__TESTSECTION__TESTKEY=testvalue
+export AIRFLOW__TESTSECTION__TESTKEYWITHPERCENT=test%with%percent
 
 # use Airflow 2.0-style imports
 export AIRFLOW_USE_NEW_IMPORTS=1
diff --git a/tests/configuration.py b/tests/configuration.py
index ac6f7b7db7..07d817e7d1 100644
--- a/tests/configuration.py
+++ b/tests/configuration.py
@@ -7,9 +7,9 @@
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
-# 
+#
 #   http://www.apache.org/licenses/LICENSE-2.0
-# 
+#
 # Unless required by applicable law or agreed to in writing,
 # software distributed under the License is distributed on an
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -69,6 +69,11 @@ def test_conf_as_dict(self):
         self.assertEqual(
             cfg_dict['testsection']['testkey'], ('testvalue', 'env var'))
 
+        # test escape_env_vars
+        cfg_dict = conf.as_dict(escape_env_vars=True)
+        self.assertEqual(
+            cfg_dict['testsection']['testkeywithpercent'], 'test%%with%%percent')
+
     def test_command_config(self):
         TEST_CONFIG = '''[test]
 key1 = hello


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

Mime
View raw message