You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/08/23 12:46:03 UTC

[GitHub] [airflow] potiuk opened a new pull request #10494: Make configuration.py Pylint compatible

potiuk opened a new pull request #10494:
URL: https://github.com/apache/airflow/pull/10494


   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on a change in pull request #10494: Make configuration.py Pylint compatible

Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #10494:
URL: https://github.com/apache/airflow/pull/10494#discussion_r475908541



##########
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:
       Right




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #10494: Make configuration.py Pylint compatible

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #10494:
URL: https://github.com/apache/airflow/pull/10494#issuecomment-679383209


   Updated. - should be green now.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #10494: Make configuration.py Pylint compatible

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #10494:
URL: https://github.com/apache/airflow/pull/10494#discussion_r475221592



##########
File path: airflow/configuration.py
##########
@@ -878,7 +929,8 @@ def as_dict(*args, **kwargs):   # noqa: D103
     return conf.as_dict(*args, **kwargs)
 
 
-def set(*args, **kwargs):   # noqa: D103
+def set(*args, **kwargs):

Review comment:
       > airflow/configuration.py:932:0: W0622: Redefining built-in 'set' (redefined-builtin)
   
   Still error here.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #10494: Make configuration.py Pylint compatible

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #10494: Make configuration.py Pylint compatible

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [airflow] potiuk merged pull request #10494: Make configuration.py Pylint compatible

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #10494:
URL: https://github.com/apache/airflow/pull/10494


   


----------------------------------------------------------------
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:
users@infra.apache.org