amoghrajesh commented on code in PR #47946:
URL: https://github.com/apache/airflow/pull/47946#discussion_r2003443243
##########
task-sdk/src/airflow/sdk/definitions/variable.py:
##########
@@ -52,3 +57,38 @@ def get(cls, key: str, default: Any = NOTSET,
deserialize_json: bool = False):
if e.error.error == ErrorType.VARIABLE_NOT_FOUND and default is
not NOTSET:
return default
raise
+
+ @classmethod
+ def get_variable_from_secrets(cls, key: str):
+ """
+ Get Airflow Variable by iterating over all Secret Backends.
+
+ :param key: Variable Key
+ :return: Variable Value
+ """
+ # TODO: check cache first
+ # enabled only if SecretCache.init() has been called first
+ from airflow.sdk.execution_time.supervisor import SECRETS_BACKEND
+
+ var_val = NOTSET
+ # iterate over backends if not in cache (or expired)
+ for secrets_backend in SECRETS_BACKEND:
+ try:
+ var_val = secrets_backend.get_variable(key=key)
+ if var_val is not NOTSET:
+ return var_val
+ except Exception:
+ log.exception(
+ "Unable to retrieve variable from secrets backend (%s). "
+ "Checking subsequent secrets backend.",
+ type(secrets_backend).__name__,
+ )
+
+ if var_val is not NOTSET:
+ raise AirflowNotFoundException(f"The variable with key `{key}`
isn't defined")
+
+ return var_val
+
+ @staticmethod
+ def _convert_variable_to_response(key: str, value: str | None) ->
VariableResponse:
+ return VariableResponse(key=key, value=value)
Review Comment:
I am taking this path ahead and proceeding
--
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]