Taragolis commented on code in PR #24246: URL: https://github.com/apache/airflow/pull/24246#discussion_r891002672
########## airflow/providers/amazon/aws/operators/aws_base.py: ########## @@ -0,0 +1,91 @@ +# 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. + +import sys +import warnings +from typing import Generic, Optional, Set, Type, TypeVar + +if sys.version_info >= (3, 8): + from functools import cached_property +else: + from cached_property import cached_property + +from botocore.config import Config + +from airflow import AirflowException +from airflow.models import BaseOperator +from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook + +AwsHookClass = TypeVar("AwsHookClass", bound=AwsBaseHook) + + +class AwsBaseOperator(BaseOperator, Generic[AwsHookClass]): + """Base implementations for amazon-provider operators. + + :param aws_conn_id: aws connection to use + :param region_name: (optional) region name to use in AWS Hook. + Override the region_name in connection (if provided) + :param config: Configuration for botocore client. + (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) + """ + + aws_hook_class: Type[AwsHookClass] + aws_hook_class_fields: Set = { + "aws_conn_id", + "region_name", + "config", + } Review Comment: BTW, I just think about how it would be done better. Every hook based on `AwsBaseHook` could use `aws_conn_id`, `region_name`, `config`. That mean we do not need explicit set this arguments as part of attribute `aws_hook_class_fields` and only set for additional arguments And second part probably `config` is to broad name for operator attribute, and I think better use `botocore_config` or `boto3_config` instead ```python class AwsBaseOperator(BaseOperator, Generic[AwsHookClass]): aws_hook_class: Type[AwsHookClass] aws_hook_class_fields: Optional[Set[str]] = None ... @cached_property def hook(self) -> AwsHookClass: """Create and return an AWS Hook.""" kwargs = {kw: getattr(self, kw) for kw in self.aws_hook_class_fields} return self.aws_hook_class( aws_conn_id=self.aws_conn_id, region_name=self.region_name, config=self.botocore_config, **kwargs ) ``` WDYT @ferruzzi @uranusjr ? -- 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]
