ephraimbuddy commented on a change in pull request #10273:
URL: https://github.com/apache/airflow/pull/10273#discussion_r468176857



##########
File path: airflow/providers/microsoft/azure/hooks/laws.py
##########
@@ -0,0 +1,110 @@
+#
+# 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 integration with Azure LAWS.
+
+"""
+import requests
+import datetime
+import hashlib
+import hmac
+import base64
+from datetime import datetime
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+
+class LawsHook(BaseHook):
+    """
+    Interacts with Azure LAWS through api.
+
+    :param remote_conn_id: Not Used
+    :type remote_conn_id: str
+    :param account_id: Laws Account Id
+    :type account_id: str
+    :param access_key: Access Key
+    :type access_key: str
+    :param table_name: <Table Name>_CL
+    :type table_name: str
+    """
+
+    def __init__(self,remote_conn_id,account_id,access_key,table_name):
+        super().__init__()
+        self.conn_id = remote_conn_id
+        self.account_id = account_id
+        self.access_key = access_key
+        self.table_name = table_name
+
+    def build_signature(self, date, content_length, method, content_type, 
resource):
+        x_headers = 'x-ms-date:' + date
+        string_to_hash = method + "\n" + str(content_length) + "\n" + 
content_type + "\n" + x_headers + "\n" + resource
+        bytes_to_hash = bytes(string_to_hash, encoding="utf-8")
+        decoded_key = base64.b64decode(self.access_key)
+        encoded_hash = base64.b64encode(
+            hmac.new(decoded_key, bytes_to_hash, 
digestmod=hashlib.sha256).digest()
+        ).decode()
+        authorization = "SharedKey {}:{}".format(self.account_id, encoded_hash)
+        return authorization
+

Review comment:
       @kumargauravin , I actually don't think it's ok to provide access key in 
the way you're currently doing it. We have `connection` table to manage 
authentication information. You can take inspiration from the other hooks in 
the Azure package. That's what 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.

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


Reply via email to