Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Simplify code in configuration.py #33160

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1543,7 +1532,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