Crowiant commented on code in PR #45931:
URL: https://github.com/apache/airflow/pull/45931#discussion_r3225189568
##########
task-sdk/src/airflow/sdk/configuration.py:
##########
@@ -232,36 +252,92 @@ def initialize_secrets_backends(
Uses SDK's conf instead of Core's conf.
"""
- from airflow.sdk._shared.module_loading import import_string
-
- backend_list = []
- worker_mode = False
# Determine worker mode - if default_backends is not the server default,
it's worker mode
# This is a simplified check; in practice, worker mode is determined by
the caller
- if default_backends != _SERVER_DEFAULT_SECRETS_SEARCH_PATH:
+ from airflow.sdk.configuration import conf
+
+ worker_mode = False
+ search_section = "secrets"
+ environment_variable_args: str | None = (
+ "airflow.secrets.environment_variables.EnvironmentVariablesBackend"
+ )
+ metastore_args: str | None = "airflow.secrets.metastore.MetastoreBackend"
+ execution_args: str | None = None
+
+ if default_backends is not None:
worker_mode = True
+ search_section = "workers"
+ environment_variable_args = (
+ environment_variable_args if environment_variable_args in
default_backends else None
+ )
+ metastore_args = metastore_args if metastore_args in default_backends
else None
+ execution_args = (
+
"airflow.sdk.execution_time.secrets.execution_api.ExecutionAPISecretsBackend"
+ if
"airflow.sdk.execution_time.secrets.execution_api.ExecutionAPISecretsBackend"
+ in default_backends
+ else None
+ )
+
+ backends_map: dict[str, dict[str, Any]] = {
+ "environment_variable": {
+ "callback": get_importable_secret_backend,
+ "args": (environment_variable_args,),
+ },
+ "metastore": {
+ "callback": get_importable_secret_backend,
+ "args": (metastore_args,),
+ },
+ "custom": {
+ "callback": get_custom_secret_backend,
+ "args": (worker_mode,),
+ },
+ "execution_api": {
+ "callback": get_importable_secret_backend,
+ "args": (execution_args,),
+ },
+ }
- custom_secret_backend = get_custom_secret_backend(worker_mode)
+ backends_order = conf.getlist(search_section, "backends_order",
delimiter=",")
- if custom_secret_backend is not None:
- from airflow.sdk.definitions.connection import Connection
+ required_backends = (
+ [Backends.ENVIRONMENT_VARIABLE, Backends.EXECUTION_API]
+ if worker_mode
+ else [Backends.METASTORE, Backends.ENVIRONMENT_VARIABLE]
+ )
- custom_secret_backend._set_connection_class(Connection)
- backend_list.append(custom_secret_backend)
+ if missing_backends := [b.value for b in required_backends if b.value not
in backends_order]:
+ raise AirflowConfigException(
+ f"The configuration option [{search_section}]backends_order is
misconfigured. "
+ f"The following backend types are missing: {missing_backends}",
+ search_section,
Review Comment:
I don't think that it is needed as there were no such check previously
--
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]