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 2021/05/20 17:21:22 UTC

[GitHub] [airflow] ashb commented on a change in pull request #15795: Ability to test connections from UI or API

ashb commented on a change in pull request #15795:
URL: https://github.com/apache/airflow/pull/15795#discussion_r636308114



##########
File path: airflow/api_connexion/endpoints/connection_endpoint.py
##########
@@ -129,3 +133,21 @@ def post_connection(session):
         session.commit()
         return connection_schema.dump(connection)
     raise AlreadyExists(detail=f"Connection already exist. ID: {conn_id}")
+
+
+@security.requires_access([(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_CONNECTION)])
+def test_connection():
+    """Test a connection"""
+    body = request.json
+    try:
+        data = connection_schema.load(body)
+        dummy_conn_id = get_random_string()
+        data['conn_id'] = dummy_conn_id
+        conn = Connection(**data)
+        conn_env_var = f'AIRFLOW_CONN_{dummy_conn_id.upper()}'
+        os.environ[conn_env_var] = conn.get_uri()

Review comment:
       Why do we need to do this? We've already got the connection object created...




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