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


##########
airflow/providers/amazon/aws/fs/s3.py:
##########
@@ -0,0 +1,123 @@
+# 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.
+from __future__ import annotations
+
+import logging
+from functools import partial
+from typing import TYPE_CHECKING, Any, Callable, Dict
+
+import requests
+from botocore import UNSIGNED
+from requests import HTTPError
+
+from airflow.providers.amazon.aws.hooks.base_aws import AwsGenericHook
+
+if TYPE_CHECKING:
+    from botocore.awsrequest import AWSRequest
+    from fsspec import AbstractFileSystem
+
+
+Properties = Dict[str, str]
+
+S3_PROXY_URI = "proxy-uri"
+
+log = logging.getLogger(__name__)
+
+schemes = ["s3", "s3a", "s3n"]
+
+
+class SignError(Exception):
+    """Raises when unable to sign a S3 request."""
+
+
+def get_fs(conn_id: str | None) -> AbstractFileSystem:
+    try:
+        from s3fs import S3FileSystem
+    except ImportError:
+        raise ImportError(
+            "Airflow FS S3 protocol requires the s3fs library, but it is not 
installed as it requires"
+            "aiobotocore. Please install the s3 protocol support library by 
running: "
+            "pip install apache-airflow[s3]"
+        )
+
+    aws: AwsGenericHook = AwsGenericHook(aws_conn_id=conn_id, client_type="s3")
+    session = aws.get_session(deferrable=True)
+    endpoint_url = aws.conn_config.extra_config.get("endpoint_url", None)
+
+    config_kwargs: dict[str, Any] = 
aws.conn_config.extra_config.get("config_kwargs", {})
+    register_events: dict[str, Callable[[Properties], None]] = {}
+
+    if signer := aws.service_config.get("signer", None):

Review Comment:
   Initial idea of service config, store information per AWS service listed in 
boto3, e.g. `s3`, `ec2`, `sts`, `ecr` and other 350+ services
   
   So maybe we could move this parameters inside of `s3` service parameter, for 
example how would looks like some abstract AWS Connection extra:
   
   ```json
   {
     "region_name": "us-east-1",
     "session_kwargs": {
       "profile_name": "default"
     },
     "config_kwargs": {
       "retries": {
         "mode": "standard",
         "max_attempts": 10
       }
     },
     "role_arn": "arn:aws:iam::123456789098:role/role-name",
     "assume_role_method": "assume_role",
     "assume_role_kwargs": {
       "RoleSessionName": "airflow"
     },
     "aws_session_token": "AQoDYXdzEJr...EXAMPLETOKEN",
     "endpoint_url": "http://localhost:4566";,
     "service_config": {
         "s3": {
             "endpoint_url": "https://s3.eu-west-1.amazonaws.com";
             "signer": "S3V4RestSigner",
             "signer_uri": "https://foo.bar";,
             "signer_token": "PLACEHOLDER"
           }
       }
   }
   ```
   
   so we could do something:
   
   ```python
   s3_service_config = aws.service_config
   if signer := s3_service_config.get("signer", None):
       ...
   ```
   
   I think it also would be easy in documentation perspective, just put 
information in separate section into the 
https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/connections/aws.html#per-service-configuration
   
   WDYT?



##########
airflow/providers/amazon/aws/fs/s3.py:
##########
@@ -0,0 +1,123 @@
+# 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.
+from __future__ import annotations
+
+import logging
+from functools import partial
+from typing import TYPE_CHECKING, Any, Callable, Dict
+
+import requests
+from botocore import UNSIGNED
+from requests import HTTPError
+
+from airflow.providers.amazon.aws.hooks.base_aws import AwsGenericHook
+
+if TYPE_CHECKING:
+    from botocore.awsrequest import AWSRequest
+    from fsspec import AbstractFileSystem
+
+
+Properties = Dict[str, str]
+
+S3_PROXY_URI = "proxy-uri"
+
+log = logging.getLogger(__name__)
+
+schemes = ["s3", "s3a", "s3n"]
+
+
+class SignError(Exception):
+    """Raises when unable to sign a S3 request."""
+
+
+def get_fs(conn_id: str | None) -> AbstractFileSystem:
+    try:
+        from s3fs import S3FileSystem
+    except ImportError:
+        raise ImportError(
+            "Airflow FS S3 protocol requires the s3fs library, but it is not 
installed as it requires"
+            "aiobotocore. Please install the s3 protocol support library by 
running: "
+            "pip install apache-airflow[s3]"
+        )
+
+    aws: AwsGenericHook = AwsGenericHook(aws_conn_id=conn_id, client_type="s3")
+    session = aws.get_session(deferrable=True)
+    endpoint_url = aws.conn_config.extra_config.get("endpoint_url", None)
+
+    config_kwargs: dict[str, Any] = 
aws.conn_config.extra_config.get("config_kwargs", {})
+    register_events: dict[str, Callable[[Properties], None]] = {}
+
+    if signer := aws.service_config.get("signer", None):

Review Comment:
   And yeah, AWS Connection in Airflow sooo complicated and have a lot of 
different options (some of them even not documented well)



##########
airflow/providers/amazon/aws/fs/s3.py:
##########
@@ -0,0 +1,123 @@
+# 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.
+from __future__ import annotations
+
+import logging
+from functools import partial
+from typing import TYPE_CHECKING, Any, Callable, Dict
+
+import requests
+from botocore import UNSIGNED
+from requests import HTTPError
+
+from airflow.providers.amazon.aws.hooks.base_aws import AwsGenericHook
+
+if TYPE_CHECKING:
+    from botocore.awsrequest import AWSRequest
+    from fsspec import AbstractFileSystem
+
+
+Properties = Dict[str, str]
+
+S3_PROXY_URI = "proxy-uri"
+
+log = logging.getLogger(__name__)
+
+schemes = ["s3", "s3a", "s3n"]
+
+
+class SignError(Exception):
+    """Raises when unable to sign a S3 request."""
+
+
+def get_fs(conn_id: str | None) -> AbstractFileSystem:
+    try:
+        from s3fs import S3FileSystem
+    except ImportError:
+        raise ImportError(
+            "Airflow FS S3 protocol requires the s3fs library, but it is not 
installed as it requires"
+            "aiobotocore. Please install the s3 protocol support library by 
running: "
+            "pip install apache-airflow[s3]"
+        )
+
+    aws: AwsGenericHook = AwsGenericHook(aws_conn_id=conn_id, client_type="s3")
+    session = aws.get_session(deferrable=True)
+    endpoint_url = aws.conn_config.extra_config.get("endpoint_url", None)

Review Comment:
   ```suggestion
       endpoint_url = 
aws.conn_config.get_service_endpoint_url(service_name="s3")
   ```
   
   This would resolve [AWS Service Endpoint URL 
configuration](https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/connections/aws.html#aws-service-endpoint-url-configuration)
 
   



-- 
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-unsubscr...@airflow.apache.org

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

Reply via email to