ferruzzi commented on code in PR #27823:
URL: https://github.com/apache/airflow/pull/27823#discussion_r1043592808
##########
airflow/providers/amazon/aws/hooks/base_aws.py:
##########
@@ -409,6 +414,92 @@ def __init__(
self._config = config
self._verify = verify
+ @classmethod
+ def _get_provider_version(cls) -> str:
+ """Checks the Providers Manager for the package version."""
+ try:
+ manager = ProvidersManager()
+ hook = manager.hooks[cls.conn_type]
+ if not hook:
+ # This gets caught immediately, but without it MyPy complains
+ # Item "None" of "Optional[HookInfo]" has no attribute
"package_name"
+ # on the following line and static checks fail.
+ raise ValueError(f"Hook info for {cls.conn_type} not found in
the Provider Manager.")
+ provider = manager.providers[hook.package_name]
+ return provider.version
+ except Exception:
+ # Under no condition should an error here ever cause an issue for
the user.
+ return "Unknown"
+
+ @staticmethod
+ def _find_class_name(target_function_name: str) -> str:
+ """
+ Given a frame off the stack, return the name of the class which made
the call.
+ Note: This method may raise a ValueError or an IndexError, but the
calling
+ method is catching and handling those.
+ """
+ stack = inspect.stack()
+ # Find the index of the most recent frame which called the provided
function name.
+ target_frame_index = [frame.function for frame in
stack].index(target_function_name)
+ # Pull that frame off the stack.
+ target_frame = stack[target_frame_index][0]
+ # Get the local variables for that frame.
+ frame_variables = target_frame.f_locals["self"]
+ # Get the class object for that frame.
+ frame_class_object = frame_variables.__class__
+ # Return the name of the class object.
+ return frame_class_object.__name__
+
+ def _get_caller(self, target_function_name: str = "execute") -> str:
+ """Given a function name, walk the stack and return the name of the
class which called it last."""
+ try:
+ caller = self._find_class_name(target_function_name)
+ if caller == "BaseSensorOperator":
+ # If the result is a BaseSensorOperator, then look for
whatever last called "poke".
+ return self._get_caller("poke")
+ return caller
+ except Exception:
+ # Under no condition should an error here ever cause an issue for
the user.
+ return "Unknown"
+
+ @staticmethod
+ def _generate_dag_key() -> str:
+ """
+ The Object Identifier (OID) namespace is used to salt the dag_id value.
+ That salted value is used to generate a SHA-1 hash which, by
definition,
+ can not (reasonably) be reversed. No personal data can be inferred or
+ extracted from the resulting UUID.
+ """
+ try:
+ dag_id = os.environ["AIRFLOW_CTX_DAG_ID"]
+ return str(uuid.uuid5(uuid.NAMESPACE_OID, dag_id))
+ except Exception:
+ # Under no condition should an error here ever cause an issue for
the user.
+ return "00000000-0000-5000-0000-000000000000"
Review Comment:
I'm just running the static checks locally and I'll push the no-regex
version. I actually didn't know about the UUID().version check, that's very
handy. :+1:
--
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]