turbaszek commented on a change in pull request #10494:
URL: https://github.com/apache/airflow/pull/10494#discussion_r475917409



##########
File path: airflow/configuration.py
##########
@@ -540,73 +573,94 @@ 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':
-                    opt = '< hidden >'
-                elif raw:
-                    opt = opt.replace('%', '%%')
-                if display_source:
-                    opt = (opt, 'env var')
-
-                section = section.lower()
-                # if we lower key for kubernetes_environment_variables section,
-                # then we won't be able to set any Airflow environment
-                # variables. Airflow only parse environment variables starts
-                # with AIRFLOW_. Therefore, we need to make it a special case.
-                if section != 'kubernetes_environment_variables':
-                    key = key.lower()
-                cfg.setdefault(section, OrderedDict()).update({key: opt})
+            self._include_envs(config_sources, display_sensitive, 
display_source, raw)
 
         # add bash commands
         if include_cmds:
-            for (section, key) in self.sensitive_config_values:
-                opt = self._get_cmd_option(section, key)
-                if opt:
-                    if not display_sensitive:
-                        opt = '< hidden >'
-                    if display_source:
-                        opt = (opt, 'cmd')
-                    elif raw:
-                        opt = opt.replace('%', '%%')
-                    cfg.setdefault(section, OrderedDict()).update({key: opt})
-                    del cfg[section][key + '_cmd']
+            self._include_commands(config_sources, display_sensitive, 
display_source, raw)
 
         # add config from secret backends
         if include_secret:
-            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('%', '%%')
-                    cfg.setdefault(section, OrderedDict()).update({key: opt})
-                    del cfg[section][key + '_secret']
-
-        return cfg
+            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']
   ```




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


Reply via email to