anishgirianish commented on code in PR #62343:
URL: https://github.com/apache/airflow/pull/62343#discussion_r2851599684


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py:
##########
@@ -249,6 +256,88 @@ def test_connection(test_body: ConnectionBody) -> 
ConnectionTestResponse:
         os.environ.pop(conn_env_var, None)
 
 
+@connections_router.post(
+    "/test-async",
+    status_code=status.HTTP_202_ACCEPTED,
+    responses=create_openapi_http_exception_doc([status.HTTP_403_FORBIDDEN, 
status.HTTP_404_NOT_FOUND]),
+    dependencies=[Depends(requires_access_connection(method="POST")), 
Depends(action_logging())],
+)
+def test_connection_async(
+    test_body: ConnectionTestRequestBody,
+    session: SessionDep,
+) -> ConnectionTestQueuedResponse:
+    """
+    Queue an async connection test to be executed on a worker.
+
+    The connection must already be saved. Returns a token that can be used
+    to poll for the test result via GET /connections/test-async/{token}.
+    """
+    if conf.get("core", "test_connection", 
fallback="Disabled").lower().strip() != "enabled":
+        raise HTTPException(
+            status.HTTP_403_FORBIDDEN,
+            "Testing connections is disabled in Airflow configuration. "
+            "Contact your deployment admin to enable it.",
+        )
+
+    try:
+        Connection.get_connection_from_secrets(test_body.connection_id)
+    except AirflowNotFoundException:
+        raise HTTPException(
+            status.HTTP_404_NOT_FOUND,
+            f"The Connection with connection_id: `{test_body.connection_id}` 
was not found. "
+            "Connection must be saved before testing.",
+        )
+
+    connection_test = ConnectionTest(connection_id=test_body.connection_id)
+    session.add(connection_test)
+    session.flush()
+
+    callback = connection_test.create_callback()
+    session.add(callback)
+    session.flush()
+
+    connection_test.callback_id = callback.id
+    connection_test.state = ConnectionTestState.QUEUED
+    callback.queue()
+
+    return ConnectionTestQueuedResponse(
+        token=connection_test.token,
+        connection_id=connection_test.connection_id,
+        state=connection_test.state,
+    )
+
+
+@connections_router.get(
+    "/test-async/{token}",

Review Comment:
   renamed thank you



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to