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 2018/12/01 14:49:47 UTC

[GitHub] XD-DENG commented on a change in pull request #4232: [AIRFLOW-3390] Add connections to api.

XD-DENG commented on a change in pull request #4232: [AIRFLOW-3390] Add connections to api.
URL: https://github.com/apache/incubator-airflow/pull/4232#discussion_r238065671
 
 

 ##########
 File path: airflow/api/common/experimental/connection.py
 ##########
 @@ -0,0 +1,77 @@
+# -*- 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.
+
+from airflow.exceptions import AirflowBadRequest, ConnectionNotFound
+from airflow.models import Connection
+from airflow.utils.db import provide_session
+
+
+@provide_session
+def get_connection(conn_id, session=None):
+    """Get connection by a given ID."""
+    if not (conn_id and conn_id.strip()):
+        raise AirflowBadRequest("Connection ID shouldn't be empty")
+
+    connection = session.query(Connection).filter_by(conn_id=conn_id).first()
+    if connection is None:
+        raise ConnectionNotFound("Connection '%s' doesn't exist" % conn_id)
+
+    return connection
+
+
+@provide_session
+def get_connections(session=None):
+    """Get all connections."""
+    return session.query(Connection).all()
+
+
+@provide_session
+def create_connection(conn_id, session=None, **kwargs):
 
 Review comment:
   If `conn_id` is `" connection_id"` or `"connection id"` or `"connection_id "`, seems it can not be handled properly. A connection with such an invalid id will be created, which should not happen. 
   
   In your test case, only `''` and `"    "` are covered.
   
   Please let me know if I missed anything. Cheers

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