From commits-return-29767-archive-asf-public=cust-asf.ponee.io@airflow.incubator.apache.org Wed Dec 5 21:24:58 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 8279F18067A for ; Wed, 5 Dec 2018 21:24:57 +0100 (CET) Received: (qmail 93231 invoked by uid 500); 5 Dec 2018 20:24:56 -0000 Mailing-List: contact commits-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list commits@airflow.incubator.apache.org Received: (qmail 93222 invoked by uid 99); 5 Dec 2018 20:24:56 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Dec 2018 20:24:56 +0000 From: GitBox To: commits@airflow.apache.org Subject: [GitHub] tmiller-msft commented on a change in pull request #4265: [AIRFLOW-3406] Implement an Azure CosmosDB operator Message-ID: <154404149609.2645.1556481668297277438.gitbox@gitbox.apache.org> Date: Wed, 05 Dec 2018 20:24:56 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit tmiller-msft commented on a change in pull request #4265: [AIRFLOW-3406] Implement an Azure CosmosDB operator URL: https://github.com/apache/incubator-airflow/pull/4265#discussion_r239224502 ########## File path: airflow/contrib/hooks/azure_cosmos_hook.py ########## @@ -0,0 +1,287 @@ +# -*- coding: utf-8 -*- +# +# 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 azure.cosmos.cosmos_client as cosmos_client +from azure.cosmos.errors import HTTPFailure +import uuid + +from airflow.exceptions import AirflowBadRequest +from airflow.hooks.base_hook import BaseHook + + +class AzureCosmosDBHook(BaseHook): + """ + Interacts with Azure CosmosDB. + + login should be the endpoint uri, password should be the master key + optionally, you can use the following extras to default these values + {"database_name": "", "collection_name": "COLLECTION_NAME"}. + + :param azure_cosmos_conn_id: Reference to the Azure CosmosDB connection. + :type azure_cosmos_conn_id: str + """ + + def __init__(self, azure_cosmos_conn_id='azure_cosmos_default'): + self.conn_id = azure_cosmos_conn_id + self.connection = self.get_connection(self.conn_id) + self.extras = self.connection.extra_dejson + + self.endpoint_uri = self.connection.login + self.master_key = self.connection.password + self.default_database_name = self.extras.get('database_name') + self.default_collection_name = self.extras.get('collection_name') + self.cosmos_client = None + + def get_conn(self): + """ + Return a cosmos db client. + """ + if self.cosmos_client is not None: + return self.cosmos_client + + # Initialize the Python Azure Cosmos DB client + self.cosmos_client = cosmos_client.CosmosClient(self.endpoint_uri, {'masterKey': self.master_key}) + + return self.cosmos_client + + def get_database_name(self, database_name=None): Review comment: private, updated to reflect ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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 With regards, Apache Git Services