turbaszek commented on a change in pull request #10494:
URL: https://github.com/apache/airflow/pull/10494#discussion_r475453336
##########
File path: airflow/configuration.py
##########
@@ -540,73 +573,93 @@ def as_dict(
:return: Dictionary, where the key is the name of the section and the
content is
the dictionary with the name of the parameter and its value.
"""
- cfg: Dict[str, Dict[str, str]] = {}
+ config_sources: Dict[str, Dict[str, str]] = {}
configs = [
('default', self.airflow_defaults),
('airflow.cfg', self),
]
- for (source_name, config) in configs:
- for section in config.sections():
- sect = cfg.setdefault(section, OrderedDict())
- for (k, val) in config.items(section=section, raw=raw):
- if display_source:
- val = (val, source_name)
- sect[k] = val
+ self._replace_config_with_display_sources(config_sources, configs,
display_source, raw)
# add env vars and overwrite because they have priority
if include_env:
- for ev in [ev for ev in os.environ if ev.startswith('AIRFLOW__')]:
- try:
- _, section, key = ev.split('__', 2)
- opt = self._get_env_var_option(section, key)
- except ValueError:
- continue
- if not display_sensitive and ev !=
'AIRFLOW__CORE__UNIT_TEST_MODE':
+ self._include_envs(config_sources, display_sensitive,
display_source, raw)
+
+ # add bash commands
+ if include_cmds:
+ self._include_commands(config_sources, display_sensitive,
display_source, raw)
+
+ # add config from secret backends
+ if include_secret:
+ self._include_secrets(config_sources, display_sensitive,
display_source, raw)
+ return config_sources
+
+ def _include_secrets(self, config_sources, display_sensitive,
display_source, raw):
+ for (section, key) in self.sensitive_config_values:
+ opt = self._get_secret_option(section, key)
+ if opt:
+ if not display_sensitive:
opt = '< hidden >'
+ if display_source:
+ opt = (opt, 'secret')
elif raw:
opt = opt.replace('%', '%%')
+ config_sources.setdefault(section, OrderedDict()).update({key:
opt})
+ del config_sources[section][key + '_secret']
Review comment:
```suggestion
if not opt:
continue
if not display_sensitive:
opt = '< hidden >'
if display_source:
opt = (opt, 'secret')
elif raw:
opt = opt.replace('%', '%%')
config_sources.setdefault(section, OrderedDict()).update({key:
opt})
del config_sources[section][key + '_secret']
```
WDYT?
----------------------------------------------------------------
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:
[email protected]