Source code for airflow.providers.amazon.aws.utils.mixins
# Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License."""This module contains different mixin classes for internal use within the Amazon provider... warning:: Only for internal usage, this module and all classes might be changed, renamed or removed in the future without any further notice.:meta: private"""from__future__importannotationsfromfunctoolsimportcache,cached_propertyfromtypingimportAny,Generic,NamedTuple,TypeVarfromtyping_extensionsimportfinalfromairflow.providers.amazon.aws.hooks.base_awsimportAwsGenericHook
[docs]classAwsBaseHookMixin(Generic[AwsHookType]):""" Mixin class for AWS Operators, Sensors, etc. .. warning:: Only for internal usage, this class might be changed, renamed or removed in the future without any further notice. :meta private: """# Should be assigned in child class
[docs]defvalidate_attributes(self):"""Validate class attributes."""ifhasattr(self,"aws_hook_class"):# Validate if ``aws_hook_class`` is properly set.try:ifnotissubclass(self.aws_hook_class,AwsGenericHook):raiseTypeErrorexceptTypeError:# Raise if ``aws_hook_class`` is not a class or not a subclass of Generic/Base AWS HookraiseAttributeError(f"Class attribute '{type(self).__name__}.aws_hook_class' "f"is not a subclass of AwsGenericHook.")fromNoneelse:raiseAttributeError(f"Class attribute '{type(self).__name__}.aws_hook_class' should be set.")
@propertydef_hook_parameters(self)->dict[str,Any]:""" Mapping parameters to build boto3-related hooks. Only required to be overwritten for thick-wrapped Hooks. """return{"aws_conn_id":self.aws_conn_id,"region_name":self.region_name,"verify":self.verify,"config":self.botocore_config,}@cached_property@final
[docs]defhook(self)->AwsHookType:""" Return AWS Provider's hook based on ``aws_hook_class``. This method implementation should be taken as a final for thin-wrapped Hooks around boto3. For thick-wrapped Hooks developer should consider to overwrite ``_hook_parameters`` method instead. """returnself.aws_hook_class(**self._hook_parameters)
@cache
[docs]defaws_template_fields(*template_fields:str)->tuple[str,...]:"""Merge provided template_fields with generic one and return in alphabetical order."""ifnotall(isinstance(tf,str)fortfintemplate_fields):msg=("Expected that all provided arguments are strings, but got "f"{', '.join(map(repr,template_fields))}.")raiseTypeError(msg)returntuple(sorted(list({"aws_conn_id","region_name","verify"}|set(template_fields))))