ashb commented on a change in pull request #15795:
URL: https://github.com/apache/airflow/pull/15795#discussion_r636862851
##########
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}")
+
+
[email protected]_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()
+ status, message = conn.test_connection()
+ del os.environ[conn_env_var]
Review comment:
In case of an exception this env var is not deleted -- we should delete
this in a `finally` block.
--
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:
[email protected]