mit einem Klick
validate-connector-auth
// Generate and run an auth verification test to confirm that collected credentials are valid.
// Generate and run an auth verification test to confirm that collected credentials are valid.
Create a pyproject.toml for a source connector and build it as an independent Python package.
Single step only: audit a completed connector — implementation, testing & simulator validation, artifacts, security smells, cross-doc consistency — and produce a scored markdown review report. Read-mostly; does not modify connector code.
Single step only: implement the connector in Python when the API doc already exists. Do NOT use for full connector creation — use the create-connector agent instead.
Single step only: run the per-source pytest suite, diagnose failures, and fix the connector or simulator until everything passes. Branches on mode={simulate|record}. Do NOT use for full connector creation — use the create-connector agent instead.
Implement test utilities that write test data to the source system and validate end-to-end read cycles.
Set up authentication for a source connector — generate connector spec, collect credentials interactively, and validate auth.
| name | validate-connector-auth |
| description | Generate and run an auth verification test to confirm that collected credentials are valid. |
| disable-model-invocation | true |
Generate and run an authentication verification test for the {{source_name}} connector to confirm that the supplied credentials are valid.
src/databricks/labs/community_connector/sources/{{source_name}}/{{source_name}}_api_doc.mdCONNECTOR_TEST_CONFIG_JSON env var — inline JSON.CONNECTOR_TEST_CONFIG_PATH env var — path to a JSON file.load_config.If no credentials resolve, stop and report that credentials have not been collected yet and ask user to provide.
tests/unit/sources/{{source_name}}/auth_test.py — a passing auth verification testCheck if tests/unit/sources/{{source_name}}/auth_test.py already exists.
Do NOT search for file locations — all paths are known. Do not run Glob/Search to discover files. Credential field names come from connector_spec.yaml (connection_parameters section), not from any specific on-disk config file.
Read src/databricks/labs/community_connector/sources/{{source_name}}/connector_spec.yaml to get the credential field names (connection_parameters), and read the authentication section of src/databricks/labs/community_connector/sources/{{source_name}}/{{source_name}}_api_doc.md to determine:
Generate a Python test file at tests/unit/sources/{{source_name}}/auth_test.py.
This script must:
load_config from tests.unit.sources.test_utils to load credentialsTemplate:
"""
Auth verification test for {SourceName} connector.
Run this script to verify your credentials are correctly configured.
Usage:
# via env var (inline JSON):
CONNECTOR_TEST_CONFIG_JSON='{"token":"..."}' \\
python tests/unit/sources/{source_name}/auth_test.py
# via env var (path to a JSON file at any location):
CONNECTOR_TEST_CONFIG_PATH=~/secrets/{source_name}.json \\
python tests/unit/sources/{source_name}/auth_test.py
"""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..', '..'))
from tests.unit.sources.test_utils import load_config
import requests
def test_auth():
"""Verify supplied credentials are valid by making a simple API call."""
config = load_config() # honors CONNECTOR_TEST_CONFIG_JSON / _PATH env vars
# Build auth headers/params from config — customize based on auth method
# Example for Bearer token:
# headers = {"Authorization": f"Bearer {config['access_token']}"}
# Example for API key:
# headers = {"Authorization": f"Token token={config['api_key']}"}
# Example for Basic auth:
# auth = (config['email'], config['api_token'])
response = requests.get(
"{base_url}{verification_endpoint_path}",
headers=headers, # or auth=auth, etc.
timeout=10
)
if response.status_code == 200:
print(f"Authentication successful! Connected to {SourceName}.")
print(f" Response: {response.json()}")
return True
elif response.status_code == 401:
print(f"Authentication failed: Invalid credentials (HTTP 401).")
print(f" Check the credentials supplied via CONNECTOR_TEST_CONFIG_JSON / "
f"CONNECTOR_TEST_CONFIG_PATH.")
return False
elif response.status_code == 403:
print(f"Authorization failed: Insufficient permissions (HTTP 403).")
print(f" Ensure your credentials have the required scopes/permissions.")
return False
else:
print(f"Unexpected response: HTTP {response.status_code}")
print(f" Body: {response.text}")
return False
if __name__ == "__main__":
success = test_auth()
sys.exit(0 if success else 1)
Customize the template based on:
Run the test using the project virtual environment (Python 3.10+):
source .venv/bin/activate
python tests/unit/sources/{source_name}/auth_test.py
Debug if authentication fails and report the issue clearly.
load_configrequests library unless the source has an official Python SDK that simplifies auth significantlyrefresh_token, client_id, client_secret. The auth test may need to exchange the refresh token for an access token first.subdomain field in config.