Skip to content

Commit

Permalink
Remove use of repeated constant in AirflowConfigParser (#14023)
Browse files Browse the repository at this point in the history
Small refactor that doesn't change any functionality, but does make
future testing/refactoring easier.
  • Loading branch information
ashb committed Feb 2, 2021
1 parent 0fdc03b commit d65376c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ def _create_future_warning(name, section, current_value, new_value, version):
FutureWarning,
)

@staticmethod
def _env_var_name(section, key):
return f'AIRFLOW__{section.upper()}__{key.upper()}'
ENV_VAR_PREFIX = 'AIRFLOW__'

def _env_var_name(self, section: str, key: str) -> str:
return f'{self.ENV_VAR_PREFIX}{section.upper()}__{key.upper()}'

def _get_env_var_option(self, section, key):
# must have format AIRFLOW__{SECTION}__{KEY} (note double underscore)
Expand Down Expand Up @@ -509,7 +510,7 @@ def getsection(self, section: str) -> Optional[Dict[str, Union[str, int, float,
if self.has_section(section):
_section.update(OrderedDict(self.items(section)))

section_prefix = f'AIRFLOW__{section.upper()}__'
section_prefix = self._env_var_name(section, '')
for env_var in sorted(os.environ.keys()):
if env_var.startswith(section_prefix):
key = env_var.replace(section_prefix, '')
Expand Down Expand Up @@ -632,14 +633,14 @@ def _include_commands(self, config_sources, display_sensitive, display_source, r

def _include_envs(self, config_sources, display_sensitive, display_source, raw):
for env_var in [
os_environment for os_environment in os.environ if os_environment.startswith('AIRFLOW__')
os_environment for os_environment in os.environ if os_environment.startswith(self.ENV_VAR_PREFIX)
]:
try:
_, section, key = env_var.split('__', 2)
opt = self._get_env_var_option(section, key)
except ValueError:
continue
if not display_sensitive and env_var != 'AIRFLOW__CORE__UNIT_TEST_MODE':
if not display_sensitive and env_var != self._env_var_name('core', 'unit_test_mode'):
opt = '< hidden >'
elif raw:
opt = opt.replace('%', '%%')
Expand Down

0 comments on commit d65376c

Please sign in to comment.