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 2020/08/10 09:47:20 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #10273: Azure Log Aanalytics Workspace Task Logs Ingestion

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



##########
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:
       Can you check if we can do this with any of these libraries:
   https://pypi.org/project/azure-mgmt-loganalytics/0.7.0/
   https://pypi.org/project/azure-loganalytics/0.1.0/




----------------------------------------------------------------
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:
users@infra.apache.org