Skip to content

Commit

Permalink
Refactor: Simplify code in configuration.py (apache#33160)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro authored and ferruzzi committed Aug 17, 2023
1 parent 010e0dd commit a0b02db
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import datetime
import functools
import io
import itertools as it
import json
import logging
import multiprocessing
Expand Down Expand Up @@ -172,9 +173,8 @@ def retrieve_configuration_description(
from airflow.providers_manager import ProvidersManager

for provider, config in ProvidersManager().provider_configs:
if selected_provider and provider != selected_provider:
continue
base_configuration_description.update(config)
if not selected_provider or provider == selected_provider:
base_configuration_description.update(config)
return base_configuration_description


Expand Down Expand Up @@ -474,13 +474,7 @@ def get_sections_including_defaults(self) -> list[str]:
:return: list of section names
"""
my_own_sections = self.sections()

all_sections_from_defaults = list(self.configuration_description.keys())
for section in my_own_sections:
if section not in all_sections_from_defaults:
all_sections_from_defaults.append(section)
return all_sections_from_defaults
return list(dict.fromkeys(it.chain(self.configuration_description, self.sections())))

def get_options_including_defaults(self, section: str) -> list[str]:
"""
Expand All @@ -491,13 +485,8 @@ def get_options_including_defaults(self, section: str) -> list[str]:
:return: list of option names for the section given
"""
my_own_options = self.options(section) if self.has_section(section) else []
all_options_from_defaults = list(
self.configuration_description.get(section, {}).get("options", {}).keys()
)
for option in my_own_options:
if option not in all_options_from_defaults:
all_options_from_defaults.append(option)
return all_options_from_defaults
all_options_from_defaults = self.configuration_description.get(section, {}).get("options", {})
return list(dict.fromkeys(it.chain(all_options_from_defaults, my_own_options)))

def optionxform(self, optionstr: str) -> str:
"""
Expand Down Expand Up @@ -1544,7 +1533,7 @@ def _include_envs(
continue
if not display_sensitive and env_var != self._env_var_name("core", "unit_test_mode"):
# Don't hide cmd/secret values here
if not env_var.lower().endswith("cmd") and not env_var.lower().endswith("secret"):
if not env_var.lower().endswith(("cmd", "secret")):
if (section, key) in self.sensitive_config_values:
opt = "< hidden >"
elif raw:
Expand Down

0 comments on commit a0b02db

Please sign in to comment.