bharanidharan14 commented on code in PR #28262:
URL: https://github.com/apache/airflow/pull/28262#discussion_r1049291368


##########
airflow/providers/microsoft/azure/hooks/adls.py:
##########
@@ -0,0 +1,221 @@
+# 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
+
+from typing import Any
+
+from azure.core.exceptions import ResourceExistsError, ResourceNotFoundError
+from azure.identity import ClientSecretCredential
+from azure.storage.filedatalake import (
+    DataLakeDirectoryClient,
+    DataLakeFileClient,
+    DataLakeServiceClient,
+    FileSystemClient,
+)
+
+from airflow.hooks.base import BaseHook
+
+
+class AzureDataLakeStorageV2(BaseHook):
+
+    conn_name_attr = "adls_v2_conn_id"
+    default_conn_name = "adls_v2_default"
+    conn_type = "adls_v2"
+    hook_name = "Azure Date Lake Storage"
+
+    @staticmethod
+    def get_connection_form_widgets() -> dict[str, Any]:
+        """Returns connection widgets to add to connection form"""
+        from flask_appbuilder.fieldwidgets import BS3PasswordFieldWidget, 
BS3TextFieldWidget
+        from flask_babel import lazy_gettext
+        from wtforms import PasswordField, StringField
+
+        return {
+            "extra__adls_v2__connection_string": PasswordField(
+                lazy_gettext("Blob Storage Connection String (optional)"), 
widget=BS3PasswordFieldWidget()
+            ),
+            "extra__adls_v2__tenant_id": StringField(
+                lazy_gettext("Tenant Id (Active Directory Auth)"), 
widget=BS3TextFieldWidget()
+            ),
+        }
+
+    @staticmethod
+    def get_ui_field_behaviour() -> dict[str, Any]:
+        """Returns custom field behaviour"""
+        return {
+            "hidden_fields": ["schema", "port"],
+            "relabeling": {
+                "login": "Blob Storage Login (optional)",
+                "password": "Blob Storage Key (optional)",
+                "host": "Account Name (Active Directory Auth)",
+            },
+            "placeholders": {
+                "login": "account name",
+                "password": "secret",
+                "host": "account url",
+                "extra__adls_v2__connection_string": "connection string auth",
+                "extra__adls_v2__tenant_id": "tenant",
+            },
+        }
+
+    def __init__(self, adls_v2_conn_id: str = default_conn_name, public_read: 
bool = False) -> None:
+        super().__init__()
+        self.conn_id = adls_v2_conn_id
+        self.public_read = public_read
+        self.service_client = self.get_conn()
+
+    def get_conn(self) -> DataLakeServiceClient:
+        """Return the DataLakeServiceClient object."""
+        conn = self.get_connection(self.conn_id)
+        extra = conn.extra_dejson or {}
+
+        connection_string = extra.pop(
+            "connection_string", 
extra.pop("extra__adls_v2__connection_string", None)
+        )
+        if connection_string:
+            # connection_string auth takes priority
+            return 
DataLakeServiceClient.from_connection_string(connection_string, **extra)
+
+        tenant = extra.pop("tenant_id", extra.pop("extra__adls_v2__tenant_id", 
None))
+        if tenant:
+            # use Active Directory auth
+            app_id = conn.login
+            app_secret = conn.password
+            token_credential = ClientSecretCredential(tenant, app_id, 
app_secret)
+            return DataLakeServiceClient(
+                account_url=f"https://{conn.login}.dfs.core.windows.net";, 
credential=token_credential, **extra
+            )
+        credential = conn.password

Review Comment:
   @tatiana I am using WASB connection details to connect to ADLS gen2 storage 
account, apart the connection details nothing is similar I think



-- 
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]

Reply via email to