You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/06/07 08:52:07 UTC

[GitHub] [airflow] Taragolis commented on a diff in pull request #24246: Make amazon athena, batch, lambda, and eks operators more consistent

Taragolis commented on code in PR #24246:
URL: https://github.com/apache/airflow/pull/24246#discussion_r890954255


##########
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",
+    }
+
+    def __init__(
+        self,
+        *,
+        aws_conn_id: Optional[str] = "aws_default",
+        region_name: Optional[str] = None,
+        config: Optional[Config] = None,
+        **kwargs,
+    ) -> None:
+        self.aws_conn_id = aws_conn_id
+
+        region = kwargs.pop("region", None)
+        if region:
+            warnings.warn(
+                'Parameter `region` is deprecated. Please use `region_name` instead.',
+                DeprecationWarning,
+                stacklevel=2,
+            )
+            if region_name:
+                raise AirflowException("Either `region_name` or `region` can be provided, not both.")
+            region_name = region
+
+        self.region_name = region_name
+        self.config = config
+
+        # Remove hook fields from keywords arguments
+        for kw in self.aws_hook_class_fields:
+            if kw in kwargs:
+                if not hasattr(self, kw):
+                    setattr(self, kw, kwargs.pop(kw, None))
+                else:
+                    kwargs.pop(kw, None)
+
+        super().__init__(**kwargs)
+
+    @cached_property
+    def hook(self) -> AwsHookClass:
+        """Create and return an AthenaHook."""

Review Comment:
   Whoops copy-paste issue



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org