mik-laj commented on a change in pull request #3684: [AIRFLOW-2840] - add 
update connections cli option
URL: https://github.com/apache/airflow/pull/3684#discussion_r247319535
 
 

 ##########
 File path: airflow/www/api/experimental/endpoints.py
 ##########
 @@ -253,3 +254,70 @@ def delete_pool(name):
         return response
     else:
         return jsonify(pool.to_json())
+
+
[email protected]
+@api_experimental.route('/connections', methods=['GET'])
+@requires_authentication
+def list_connections():
+    """Get all connections."""
+    try:
+        connections = connection_api.list_connections()
+    except AirflowException as err:
+        _log.error(err)
+        response = jsonify(error="{}".format(err))
+        response.status_code = err.status_code
+        return response
+    else:
+        return jsonify([c.to_json() for c in connections])
+
+
[email protected]
+@api_experimental.route('/connections/<string:conn_id>', methods=['DELETE'])
+@requires_authentication
+def delete_connection(conn_id):
+    """Delete pool."""
+    params = request.get_json(force=True)
+    try:
+        msg = connection_api.delete_connection(conn_id=conn_id, **params)
+    except AirflowException as err:
+        _log.error(err)
+        response = jsonify(error="{}".format(err))
+        response.status_code = err.status_code
+        return response
+    else:
+        return jsonify({"success": msg})
+
+
[email protected]
+@api_experimental.route('/connections', methods=['POST'])
+@requires_authentication
+def add_connection():
+    """Delete pool."""
+    params = request.get_json(force=True)
+    try:
+        new_conn = connection_api.add_connection(**params)
+    except AirflowException as err:
+        _log.error(err)
+        response = jsonify(error="{}".format(err))
+        response.status_code = err.status_code
+        return response
+    else:
+        return jsonify(new_conn.to_json())
+
+
[email protected]
+@api_experimental.route('/connections', methods=['PATCH'])
+@requires_authentication
+def update_connection():
+    """Delete pool."""
+    params = request.get_json(force=True)
+    try:
+        new_conn = connection_api.update_connection(**params)
+    except AirflowException as err:
+        _log.error(err)
+        response = jsonify(error="{}".format(err))
+        response.status_code = err.status_code
+        return response
 
 Review comment:
   This code snippet is repeated in any method. Should we think about how to 
avoid repeating this piece of code? Maybe introducing a decorator?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to