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/06/14 21:18:16 UTC

[GitHub] [airflow] ephraimbuddy commented on a change in pull request #9266: add crud endpoint for connections

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



##########
File path: airflow/api_connexion/endpoints/connection_endpoint.py
##########
@@ -47,31 +55,53 @@ def get_connection(connection_id, session):
 
 
 @provide_session
-def get_connections(session):
+def get_connections(session, limit, offset=0):
     """
     Get all connection entries
     """
-    offset = request.args.get(parameters.page_offset, 0)
-    limit = min(int(request.args.get(parameters.page_limit, 100)), 100)
-
+    total_entries = session.query(func.count(Connection.id)).scalar()
     query = session.query(Connection)
-    total_entries = query.count()
-    query = query.offset(offset).limit(limit)
-
-    connections = query.all()
+    connections = query.offset(offset).limit(limit).all()
     return connection_collection_schema.dump(ConnectionCollection(connections=connections,
                                                                   total_entries=total_entries))
 
 
-def patch_connection():
+@provide_session
+def patch_connection(connection_id, session, update_mask=None):
     """
     Update a connection entry
     """
-    raise NotImplementedError("Not implemented yet.")
+    body = request.json
+    connection = session.query(Connection).filter_by(conn_id=connection_id).first()
+    if connection is None:
+        raise NotFound("Connection not found")
+    if update_mask:
+        for field in update_mask:
+            setattr(connection, field, body[field])
+    else:
+        for key in body:
+            setattr(connection, key, body[key])
+    session.add(connection)
+    session.commit()
+    return connection_schema.dump(connection)
 
 
-def post_connection():
+@provide_session
+def post_connection(session):
     """
     Create connection entry
     """
-    raise NotImplementedError("Not implemented yet.")
+    body = request.json
+
+    # connexion handles 404, no need for try/except

Review comment:
       ```suggestion
       # connexion handles 400, no need for try/except
   ```




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