Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions tests/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down