ashb commented on code in PR #57744:
URL: https://github.com/apache/airflow/pull/57744#discussion_r2537360520
##########
airflow-core/src/airflow/configuration.py:
##########
@@ -273,148 +279,14 @@ def
_update_logging_deprecated_template_to_one_from_defaults(self):
default,
)
- def is_template(self, section: str, key) -> bool:
- """
- Return whether the value is templated.
-
- :param section: section of the config
- :param key: key in the section
- :return: True if the value is templated
- """
- if self.configuration_description is None:
- return False
- return _is_template(self.configuration_description, section, key)
-
- def _update_defaults_from_string(self, config_string: str):
- """
- Update the defaults in _default_values based on values in
config_string ("ini" format).
-
- Note that those values are not validated and cannot contain variables
because we are using
- regular config parser to load them. This method is used to test the
config parser in unit tests.
-
- :param config_string: ini-formatted config string
- """
- parser = ConfigParser()
- parser.read_string(config_string)
- for section in parser.sections():
- if section not in self._default_values.sections():
- self._default_values.add_section(section)
- errors = False
- for key, value in parser.items(section):
- if not self.is_template(section, key) and "{" in value:
- errors = True
- log.error(
- "The %s.%s value %s read from string contains
variable. This is not supported",
- section,
- key,
- value,
- )
- self._default_values.set(section, key, value)
- if errors:
- raise AirflowConfigException(
- f"The string config passed as default contains variables. "
- f"This is not supported. String config: {config_string}"
- )
-
- def get_default_value(self, section: str, key: str, fallback: Any = None,
raw=False, **kwargs) -> Any:
- """
- Retrieve default value from default config parser.
-
- This will retrieve the default value from the default config parser.
Optionally a raw, stored
- value can be retrieved by setting skip_interpolation to True. This is
useful for example when
- we want to write the default value to a file, and we don't want the
interpolation to happen
- as it is going to be done later when the config is read.
-
- :param section: section of the config
- :param key: key to use
- :param fallback: fallback value to use
- :param raw: if raw, then interpolation will be reversed
- :param kwargs: other args
- :return:
- """
- value = self._default_values.get(section, key, fallback=fallback,
**kwargs)
- if raw and value is not None:
- return value.replace("%", "%%")
- return value
-
def get_provider_config_fallback_defaults(self, section: str, key: str,
**kwargs) -> Any:
"""Get provider config fallback default values."""
return self._provider_config_fallback_default_values.get(section, key,
fallback=None, **kwargs)
- # These configuration elements can be fetched as the stdout of commands
- # following the "{section}__{name}_cmd" pattern, the idea behind this
- # is to not store password on boxes in text files.
- # These configs can also be fetched from Secrets backend
- # following the "{section}__{name}__secret" pattern
- @functools.cached_property
- def sensitive_config_values(self) -> set[tuple[str, str]]:
- if self.configuration_description is None:
- return set()
- flattened = {
- (s, k): item
- for s, s_c in self.configuration_description.items()
- for k, item in s_c.get("options").items() # type:
ignore[union-attr]
- }
- sensitive = {
- (section.lower(), key.lower())
- for (section, key), v in flattened.items()
- if v.get("sensitive") is True
- }
- depr_option = {self.deprecated_options[x][:-1] for x in sensitive if x
in self.deprecated_options}
- depr_section = {
- (self.deprecated_sections[s][0], k) for s, k in sensitive if s in
self.deprecated_sections
- }
- sensitive.update(depr_section, depr_option)
- return sensitive
-
- # A mapping of (new section, new option) -> (old section, old option,
since_version).
- # When reading new option, the old option will be checked to see if it
exists. If it does a
- # DeprecationWarning will be issued and the old option will be used instead
- deprecated_options: dict[tuple[str, str], tuple[str, str, str]] = {
- ("dag_processor", "refresh_interval"): ("scheduler",
"dag_dir_list_interval", "3.0"),
- ("api", "host"): ("webserver", "web_server_host", "3.0"),
- ("api", "port"): ("webserver", "web_server_port", "3.0"),
- ("api", "workers"): ("webserver", "workers", "3.0"),
- ("api", "worker_timeout"): ("webserver", "web_server_worker_timeout",
"3.0"),
- ("api", "ssl_cert"): ("webserver", "web_server_ssl_cert", "3.0"),
- ("api", "ssl_key"): ("webserver", "web_server_ssl_key", "3.0"),
- ("api", "access_logfile"): ("webserver", "access_logfile", "3.0"),
- ("triggerer", "capacity"): ("triggerer", "default_capacity", "3.0"),
- ("api", "expose_config"): ("webserver", "expose_config", "3.0.1"),
- ("fab", "access_denied_message"): ("webserver",
"access_denied_message", "3.0.2"),
- ("fab", "expose_hostname"): ("webserver", "expose_hostname", "3.0.2"),
- ("fab", "navbar_color"): ("webserver", "navbar_color", "3.0.2"),
- ("fab", "navbar_text_color"): ("webserver", "navbar_text_color",
"3.0.2"),
- ("fab", "navbar_hover_color"): ("webserver", "navbar_hover_color",
"3.0.2"),
- ("fab", "navbar_text_hover_color"): ("webserver",
"navbar_text_hover_color", "3.0.2"),
- ("api", "secret_key"): ("webserver", "secret_key", "3.0.2"),
- ("api", "enable_swagger_ui"): ("webserver", "enable_swagger_ui",
"3.0.2"),
- ("dag_processor", "parsing_pre_import_modules"): ("scheduler",
"parsing_pre_import_modules", "3.0.4"),
- ("api", "grid_view_sorting_order"): ("webserver",
"grid_view_sorting_order", "3.1.0"),
- ("api", "log_fetch_timeout_sec"): ("webserver",
"log_fetch_timeout_sec", "3.1.0"),
- ("api", "hide_paused_dags_by_default"): ("webserver",
"hide_paused_dags_by_default", "3.1.0"),
- ("api", "page_size"): ("webserver", "page_size", "3.1.0"),
- ("api", "default_wrap"): ("webserver", "default_wrap", "3.1.0"),
- ("api", "auto_refresh_interval"): ("webserver",
"auto_refresh_interval", "3.1.0"),
- ("api", "require_confirmation_dag_change"): ("webserver",
"require_confirmation_dag_change", "3.1.0"),
- ("api", "instance_name"): ("webserver", "instance_name", "3.1.0"),
- ("api", "log_config"): ("api", "access_logfile", "3.1.0"),
- }
-
- # A mapping of new section -> (old section, since_version).
- deprecated_sections: dict[str, tuple[str, str]] = {}
-
- # Now build the inverse so we can go from old_section/old_key to
new_section/new_key
- # if someone tries to retrieve it based on old_section/old_key
- @functools.cached_property
- def inversed_deprecated_options(self):
- return {(sec, name): key for key, (sec, name, ver) in
self.deprecated_options.items()}
-
- @functools.cached_property
- def inversed_deprecated_sections(self):
- return {
- old_section: new_section for new_section, (old_section, ver) in
self.deprecated_sections.items()
- }
+ # Deprecated options and sections are now defined in the shared base class.
+ # sensitive_config_values is also provided by the shared base class as a
cached property.
+ # The inversed_deprecated_options and inversed_deprecated_sections are also
+ # provided by the shared base class as cached properties.
Review Comment:
I don't think this comment has any value once this Pr is merged, so lets
remove this
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]