airbyte-agent-amazon-ads 0.1.23__py3-none-any.whl → 0.1.25__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -161,6 +161,131 @@ class AirbyteCloudClient:
161
161
  connector_id = connectors[0]["id"]
162
162
  return connector_id
163
163
 
164
+ async def initiate_oauth(
165
+ self,
166
+ definition_id: str,
167
+ external_user_id: str,
168
+ redirect_url: str,
169
+ ) -> str:
170
+ """Initiate a server-side OAuth flow.
171
+
172
+ Starts the OAuth flow for a connector. Returns a consent URL where the
173
+ end user should be redirected to grant access. After completing consent,
174
+ they'll be redirected to your redirect_url with a `server_side_oauth_secret_id`
175
+ query parameter that can be used with `create_source()`.
176
+
177
+ Args:
178
+ definition_id: Connector definition UUID
179
+ external_user_id: Workspace identifier
180
+ redirect_url: URL where users will be redirected after OAuth consent
181
+
182
+ Returns:
183
+ The OAuth consent URL
184
+
185
+ Raises:
186
+ httpx.HTTPStatusError: If the request fails
187
+
188
+ Example:
189
+ consent_url = await client.initiate_oauth(
190
+ definition_id="d8313939-3782-41b0-be29-b3ca20d8dd3a",
191
+ external_user_id="my-workspace",
192
+ redirect_url="https://myapp.com/oauth/callback",
193
+ )
194
+ # Redirect user to: consent_url
195
+ # After consent: https://myapp.com/oauth/callback?server_side_oauth_secret_id=...
196
+ """
197
+ token = await self.get_bearer_token()
198
+ url = f"{self.API_BASE_URL}/api/v1/integrations/connectors/oauth/initiate"
199
+ headers = {"Authorization": f"Bearer {token}"}
200
+ request_body = {
201
+ "external_user_id": external_user_id,
202
+ "definition_id": definition_id,
203
+ "redirect_url": redirect_url,
204
+ }
205
+
206
+ response = await self._http_client.post(url, json=request_body, headers=headers)
207
+ response.raise_for_status()
208
+ return response.json()["consent_url"]
209
+
210
+ async def create_source(
211
+ self,
212
+ name: str,
213
+ connector_definition_id: str,
214
+ external_user_id: str,
215
+ credentials: dict[str, Any] | None = None,
216
+ replication_config: dict[str, Any] | None = None,
217
+ server_side_oauth_secret_id: str | None = None,
218
+ source_template_id: str | None = None,
219
+ ) -> str:
220
+ """Create a new source on Airbyte Cloud.
221
+
222
+ Supports two authentication modes:
223
+ 1. Direct credentials: Provide `credentials` dict
224
+ 2. Server-side OAuth: Provide `server_side_oauth_secret_id` from OAuth flow
225
+
226
+ Args:
227
+ name: Source name
228
+ connector_definition_id: UUID of the connector definition
229
+ external_user_id: User identifier
230
+ credentials: Connector auth config dict. Required unless using OAuth.
231
+ replication_config: Optional replication settings (e.g., start_date for
232
+ connectors with x-airbyte-replication-config). Required for REPLICATION
233
+ mode sources like Intercom.
234
+ server_side_oauth_secret_id: OAuth secret ID from initiate_oauth redirect.
235
+ When provided, credentials are not required.
236
+ source_template_id: Source template ID. Required when organization has
237
+ multiple source templates for this connector type.
238
+
239
+ Returns:
240
+ The created source ID (UUID string)
241
+
242
+ Raises:
243
+ httpx.HTTPStatusError: If creation fails
244
+
245
+ Example:
246
+ # With direct credentials:
247
+ source_id = await client.create_source(
248
+ name="My Intercom Source",
249
+ connector_definition_id="d8313939-3782-41b0-be29-b3ca20d8dd3a",
250
+ external_user_id="my-workspace",
251
+ credentials={"access_token": "..."},
252
+ replication_config={"start_date": "2024-01-01T00:00:00Z"}
253
+ )
254
+
255
+ # With server-side OAuth:
256
+ source_id = await client.create_source(
257
+ name="My Intercom Source",
258
+ connector_definition_id="d8313939-3782-41b0-be29-b3ca20d8dd3a",
259
+ external_user_id="my-workspace",
260
+ server_side_oauth_secret_id="airbyte_oauth_..._secret_...",
261
+ replication_config={"start_date": "2024-01-01T00:00:00Z"}
262
+ )
263
+ """
264
+ token = await self.get_bearer_token()
265
+ url = f"{self.API_BASE_URL}/v1/integrations/connectors"
266
+ headers = {"Authorization": f"Bearer {token}"}
267
+
268
+ request_body: dict[str, Any] = {
269
+ "name": name,
270
+ "definition_id": connector_definition_id,
271
+ "external_user_id": external_user_id,
272
+ }
273
+
274
+ if credentials is not None:
275
+ request_body["credentials"] = credentials
276
+ if replication_config is not None:
277
+ request_body["replication_config"] = replication_config
278
+ if server_side_oauth_secret_id is not None:
279
+ request_body["server_side_oauth_secret_id"] = server_side_oauth_secret_id
280
+ if source_template_id is not None:
281
+ request_body["source_template_id"] = source_template_id
282
+
283
+ response = await self._http_client.post(url, json=request_body, headers=headers)
284
+ response.raise_for_status()
285
+
286
+ data = response.json()
287
+ return data["id"]
288
+
164
289
  async def execute_connector(
165
290
  self,
166
291
  connector_id: str,
@@ -1014,6 +1014,7 @@ def _parse_security_scheme_to_option(scheme_name: str, scheme: Any) -> AuthOptio
1014
1014
  type=single_auth.type,
1015
1015
  config=single_auth.config,
1016
1016
  user_config_spec=single_auth.user_config_spec,
1017
+ untested=getattr(scheme, "x_airbyte_untested", False),
1017
1018
  )
1018
1019
 
1019
1020
 
@@ -19,19 +19,26 @@ class HostedExecutor:
19
19
  instead of directly calling external services. The cloud API handles all
20
20
  connector logic, secrets management, and execution.
21
21
 
22
- The executor takes an external_user_id and uses the AirbyteCloudClient to:
22
+ The executor uses the AirbyteCloudClient to:
23
23
  1. Authenticate with the Airbyte Platform (bearer token with caching)
24
- 2. Look up the user's connector
24
+ 2. Look up the user's connector (if connector_id not provided)
25
25
  3. Execute the connector operation via the cloud API
26
26
 
27
27
  Implements ExecutorProtocol.
28
28
 
29
29
  Example:
30
- # Create executor with user ID, credentials, and connector definition ID
30
+ # Create executor with explicit connector_id (no lookup needed)
31
+ executor = HostedExecutor(
32
+ airbyte_client_id="client_abc123",
33
+ airbyte_client_secret="secret_xyz789",
34
+ connector_id="existing-source-uuid",
35
+ )
36
+
37
+ # Or create executor with user ID for lookup
31
38
  executor = HostedExecutor(
32
- external_user_id="user-123",
33
39
  airbyte_client_id="client_abc123",
34
40
  airbyte_client_secret="secret_xyz789",
41
+ external_user_id="user-123",
35
42
  connector_definition_id="abc123-def456-ghi789",
36
43
  )
37
44
 
@@ -51,28 +58,48 @@ class HostedExecutor:
51
58
 
52
59
  def __init__(
53
60
  self,
54
- external_user_id: str,
55
61
  airbyte_client_id: str,
56
62
  airbyte_client_secret: str,
57
- connector_definition_id: str,
63
+ connector_id: str | None = None,
64
+ external_user_id: str | None = None,
65
+ connector_definition_id: str | None = None,
58
66
  ):
59
67
  """Initialize hosted executor.
60
68
 
69
+ Either provide connector_id directly OR (external_user_id + connector_definition_id)
70
+ for lookup.
71
+
61
72
  Args:
62
- external_user_id: User identifier in the Airbyte system
63
73
  airbyte_client_id: Airbyte client ID for authentication
64
74
  airbyte_client_secret: Airbyte client secret for authentication
65
- connector_definition_id: Connector definition ID used to look up
66
- the user's connector.
75
+ connector_id: Direct connector/source ID (skips lookup if provided)
76
+ external_user_id: User identifier in the Airbyte system (for lookup)
77
+ connector_definition_id: Connector definition ID (for lookup)
78
+
79
+ Raises:
80
+ ValueError: If neither connector_id nor (external_user_id + connector_definition_id) provided
67
81
 
68
82
  Example:
83
+ # With explicit connector_id (no lookup)
84
+ executor = HostedExecutor(
85
+ airbyte_client_id="client_abc123",
86
+ airbyte_client_secret="secret_xyz789",
87
+ connector_id="existing-source-uuid",
88
+ )
89
+
90
+ # With lookup by user + definition
69
91
  executor = HostedExecutor(
70
- external_user_id="user-123",
71
92
  airbyte_client_id="client_abc123",
72
93
  airbyte_client_secret="secret_xyz789",
94
+ external_user_id="user-123",
73
95
  connector_definition_id="abc123-def456-ghi789",
74
96
  )
75
97
  """
98
+ # Validate: either connector_id OR (external_user_id + connector_definition_id) required
99
+ if not connector_id and not (external_user_id and connector_definition_id):
100
+ raise ValueError("Either connector_id OR (external_user_id + connector_definition_id) must be provided")
101
+
102
+ self._connector_id = connector_id
76
103
  self._external_user_id = external_user_id
77
104
  self._connector_definition_id = connector_definition_id
78
105
 
@@ -86,10 +113,9 @@ class HostedExecutor:
86
113
  """Execute connector via cloud API (ExecutorProtocol implementation).
87
114
 
88
115
  Flow:
89
- 1. Get connector definition id from executor config
90
- 2. Look up the user's connector ID
91
- 3. Execute the connector operation via the cloud API
92
- 4. Parse the response into ExecutionResult
116
+ 1. Use provided connector_id or look up from external_user_id + definition_id
117
+ 2. Execute the connector operation via the cloud API
118
+ 3. Parse the response into ExecutionResult
93
119
 
94
120
  Args:
95
121
  config: Execution configuration (entity, action, params)
@@ -98,7 +124,7 @@ class HostedExecutor:
98
124
  ExecutionResult with success/failure status
99
125
 
100
126
  Raises:
101
- ValueError: If no connector or multiple connectors found for user
127
+ ValueError: If no connector or multiple connectors found for user (when doing lookup)
102
128
  httpx.HTTPStatusError: If API returns 4xx/5xx status code
103
129
  httpx.RequestError: If network request fails
104
130
 
@@ -114,23 +140,26 @@ class HostedExecutor:
114
140
 
115
141
  with tracer.start_as_current_span("airbyte.hosted_executor.execute") as span:
116
142
  # Add span attributes for observability
117
- span.set_attribute("connector.definition_id", self._connector_definition_id)
143
+ if self._connector_definition_id:
144
+ span.set_attribute("connector.definition_id", self._connector_definition_id)
118
145
  span.set_attribute("connector.entity", config.entity)
119
146
  span.set_attribute("connector.action", config.action)
120
- span.set_attribute("user.external_id", self._external_user_id)
147
+ if self._external_user_id:
148
+ span.set_attribute("user.external_id", self._external_user_id)
121
149
  if config.params:
122
150
  # Only add non-sensitive param keys
123
151
  span.set_attribute("connector.param_keys", list(config.params.keys()))
124
152
 
125
153
  try:
126
- # Step 1: Get connector definition id
127
- connector_definition_id = self._connector_definition_id
128
-
129
- # Step 2: Get the connector ID for this user
130
- connector_id = await self._cloud_client.get_connector_id(
131
- external_user_id=self._external_user_id,
132
- connector_definition_id=connector_definition_id,
133
- )
154
+ # Use provided connector_id or look it up
155
+ if self._connector_id:
156
+ connector_id = self._connector_id
157
+ else:
158
+ # Look up connector by external_user_id + definition_id
159
+ connector_id = await self._cloud_client.get_connector_id(
160
+ external_user_id=self._external_user_id, # type: ignore[arg-type]
161
+ connector_definition_id=self._connector_definition_id, # type: ignore[arg-type]
162
+ )
134
163
 
135
164
  span.set_attribute("connector.connector_id", connector_id)
136
165
 
@@ -36,6 +36,7 @@ from ..types import (
36
36
  EndpointDefinition,
37
37
  EntityDefinition,
38
38
  )
39
+ from ..utils import find_matching_auth_options
39
40
 
40
41
  from .models import (
41
42
  ActionNotSupportedError,
@@ -356,8 +357,8 @@ class LocalExecutor:
356
357
  ) -> tuple[AuthOption, dict[str, SecretStr]]:
357
358
  """Infer authentication scheme from provided credentials.
358
359
 
359
- Matches user credentials against each auth option's required fields
360
- to determine which scheme to use.
360
+ Uses shared utility find_matching_auth_options to match credentials
361
+ against each auth option's required fields.
361
362
 
362
363
  Args:
363
364
  user_credentials: User-provided credentials
@@ -375,16 +376,8 @@ class LocalExecutor:
375
376
  # Get the credential keys provided by the user
376
377
  provided_keys = set(user_credentials.keys())
377
378
 
378
- # Find all options where all required fields are present
379
- matching_options: list[AuthOption] = []
380
- for option in options:
381
- if option.user_config_spec and option.user_config_spec.required:
382
- required_fields = set(option.user_config_spec.required)
383
- if required_fields.issubset(provided_keys):
384
- matching_options.append(option)
385
- elif not option.user_config_spec or not option.user_config_spec.required:
386
- # Option has no required fields - it matches any credentials
387
- matching_options.append(option)
379
+ # Use shared utility to find matching options
380
+ matching_options = find_matching_auth_options(provided_keys, options)
388
381
 
389
382
  # Handle matching results
390
383
  if len(matching_options) == 0:
@@ -199,6 +199,11 @@ class SecurityScheme(BaseModel):
199
199
  alias="x-airbyte-token-extract",
200
200
  description="List of fields to extract from OAuth2 token responses and use as server variables",
201
201
  )
202
+ x_airbyte_untested: bool = Field(
203
+ False,
204
+ alias="x-airbyte-untested",
205
+ description="Mark this auth scheme as untested to skip cassette coverage validation",
206
+ )
202
207
 
203
208
  @field_validator("x_airbyte_token_extract", mode="after")
204
209
  @classmethod
@@ -90,6 +90,10 @@ class AuthOption(BaseModel):
90
90
  None,
91
91
  description="User-facing credential specification from x-airbyte-auth-config",
92
92
  )
93
+ untested: bool = Field(
94
+ False,
95
+ description="Mark this auth scheme as untested to skip cassette coverage validation",
96
+ )
93
97
 
94
98
 
95
99
  class AuthConfig(BaseModel):
@@ -1,7 +1,13 @@
1
1
  """Utility functions for working with connectors."""
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  from collections.abc import AsyncIterator
4
6
  from pathlib import Path
7
+ from typing import TYPE_CHECKING
8
+
9
+ if TYPE_CHECKING:
10
+ from .types import AuthOption
5
11
 
6
12
 
7
13
  async def save_download(
@@ -58,3 +64,64 @@ async def save_download(
58
64
  raise OSError(f"Failed to write file {file_path}: {e}") from e
59
65
 
60
66
  return file_path
67
+
68
+
69
+ def find_matching_auth_options(
70
+ provided_keys: set[str],
71
+ auth_options: list[AuthOption],
72
+ ) -> list[AuthOption]:
73
+ """Find auth options that match the provided credential keys.
74
+
75
+ This is the single source of truth for auth scheme inference logic,
76
+ used by both the executor (at runtime) and validation (for cassettes).
77
+
78
+ Matching logic:
79
+ - An option matches if all its required fields are present in provided_keys
80
+ - Options with no required fields match any credentials
81
+
82
+ Args:
83
+ provided_keys: Set of credential/auth_config keys
84
+ auth_options: List of AuthOption from the connector model
85
+
86
+ Returns:
87
+ List of AuthOption that match the provided keys
88
+ """
89
+ matching_options: list[AuthOption] = []
90
+
91
+ for option in auth_options:
92
+ if option.user_config_spec and option.user_config_spec.required:
93
+ required_fields = set(option.user_config_spec.required)
94
+ if required_fields.issubset(provided_keys):
95
+ matching_options.append(option)
96
+ elif not option.user_config_spec or not option.user_config_spec.required:
97
+ # Option has no required fields - it matches any credentials
98
+ matching_options.append(option)
99
+
100
+ return matching_options
101
+
102
+
103
+ def infer_auth_scheme_name(
104
+ provided_keys: set[str],
105
+ auth_options: list[AuthOption],
106
+ ) -> str | None:
107
+ """Infer the auth scheme name from provided credential keys.
108
+
109
+ Uses find_matching_auth_options to find matches, then returns
110
+ the scheme name only if exactly one option matches.
111
+
112
+ Args:
113
+ provided_keys: Set of credential/auth_config keys
114
+ auth_options: List of AuthOption from the connector model
115
+
116
+ Returns:
117
+ The scheme_name if exactly one match, None otherwise
118
+ """
119
+ if not provided_keys or not auth_options:
120
+ return None
121
+
122
+ matching = find_matching_auth_options(provided_keys, auth_options)
123
+
124
+ if len(matching) == 1:
125
+ return matching[0].scheme_name
126
+
127
+ return None
@@ -21,7 +21,8 @@ from .connector_model_loader import (
21
21
  load_connector_model,
22
22
  )
23
23
  from .testing.spec_loader import load_test_spec
24
- from .types import Action, EndpointDefinition
24
+ from .types import Action, ConnectorModel, EndpointDefinition
25
+ from .utils import infer_auth_scheme_name
25
26
  from .validation_replication import validate_replication_compatibility
26
27
 
27
28
 
@@ -53,6 +54,112 @@ def build_cassette_map(cassettes_dir: Path) -> Dict[Tuple[str, str], List[Path]]
53
54
  return dict(cassette_map)
54
55
 
55
56
 
57
+ def build_auth_scheme_coverage(
58
+ cassettes_dir: Path,
59
+ auth_options: list | None = None,
60
+ ) -> Tuple[Dict[str | None, List[Path]], List[Tuple[Path, set[str]]]]:
61
+ """Build a map of auth_scheme -> list of cassette paths.
62
+
63
+ For multi-auth connectors, infers the auth scheme from the cassette's auth_config
64
+ keys using the same matching logic as the executor.
65
+
66
+ Args:
67
+ cassettes_dir: Directory containing cassette YAML files
68
+ auth_options: List of AuthOption from the connector model (for inference)
69
+
70
+ Returns:
71
+ Tuple of:
72
+ - Dictionary mapping auth_scheme names (or None for single-auth) to cassette paths
73
+ - List of (cassette_path, auth_config_keys) for cassettes that couldn't be matched
74
+ """
75
+ auth_scheme_map: Dict[str | None, List[Path]] = defaultdict(list)
76
+ unmatched_cassettes: List[Tuple[Path, set[str]]] = []
77
+
78
+ if not cassettes_dir.exists() or not cassettes_dir.is_dir():
79
+ return {}, []
80
+
81
+ for cassette_file in cassettes_dir.glob("*.yaml"):
82
+ try:
83
+ spec = load_test_spec(cassette_file, auth_config={})
84
+
85
+ # First, check if auth_scheme is explicitly set in the cassette
86
+ if spec.auth_scheme:
87
+ auth_scheme_map[spec.auth_scheme].append(cassette_file)
88
+ # Otherwise, try to infer from auth_config keys
89
+ elif spec.auth_config and auth_options:
90
+ auth_config_keys = set(spec.auth_config.keys())
91
+ inferred_scheme = infer_auth_scheme_name(auth_config_keys, auth_options)
92
+ if inferred_scheme is not None:
93
+ auth_scheme_map[inferred_scheme].append(cassette_file)
94
+ else:
95
+ # Couldn't infer - track as unmatched
96
+ unmatched_cassettes.append((cassette_file, auth_config_keys))
97
+ else:
98
+ # No auth_scheme and no auth_config - treat as None
99
+ auth_scheme_map[None].append(cassette_file)
100
+ except Exception:
101
+ continue
102
+
103
+ return dict(auth_scheme_map), unmatched_cassettes
104
+
105
+
106
+ def validate_auth_scheme_coverage(
107
+ config: ConnectorModel,
108
+ cassettes_dir: Path,
109
+ ) -> Tuple[bool, List[str], List[str], List[str], List[Tuple[Path, set[str]]]]:
110
+ """Validate that each auth scheme has at least one cassette.
111
+
112
+ For multi-auth connectors, every defined auth scheme must have coverage
113
+ unless marked with x-airbyte-untested: true.
114
+ For single-auth connectors, this check is skipped (existing cassette checks suffice).
115
+
116
+ Args:
117
+ config: Loaded connector model
118
+ cassettes_dir: Directory containing cassette files
119
+
120
+ Returns:
121
+ Tuple of (is_valid, errors, warnings, covered_schemes, unmatched_cassettes)
122
+ """
123
+ errors: List[str] = []
124
+ warnings: List[str] = []
125
+
126
+ # Skip check for single-auth connectors
127
+ if not config.auth.is_multi_auth():
128
+ return True, errors, warnings, [], []
129
+
130
+ # Get all defined auth schemes, separating tested from untested
131
+ options = config.auth.options or []
132
+
133
+ # Build auth scheme coverage from cassettes (pass options for inference)
134
+ auth_scheme_coverage, unmatched_cassettes = build_auth_scheme_coverage(cassettes_dir, options)
135
+ tested_schemes = {opt.scheme_name for opt in options if not opt.untested}
136
+ untested_schemes = {opt.scheme_name for opt in options if opt.untested}
137
+ covered_schemes = {scheme for scheme in auth_scheme_coverage.keys() if scheme is not None}
138
+
139
+ # Find missing tested schemes (errors)
140
+ missing_tested = tested_schemes - covered_schemes
141
+ for scheme in sorted(missing_tested):
142
+ errors.append(
143
+ f"Auth scheme '{scheme}' has no cassette coverage. "
144
+ f"Record at least one cassette using this authentication method, "
145
+ f"or add 'x-airbyte-untested: true' to skip this check."
146
+ )
147
+
148
+ # Warn about untested schemes without coverage
149
+ missing_untested = untested_schemes - covered_schemes
150
+ for scheme in sorted(missing_untested):
151
+ warnings.append(
152
+ f"Auth scheme '{scheme}' is marked as untested (x-airbyte-untested: true) " f"and has no cassette coverage. Validation skipped."
153
+ )
154
+
155
+ # Warn about cassettes that couldn't be matched to any auth scheme
156
+ for cassette_path, auth_config_keys in unmatched_cassettes:
157
+ warnings.append(f"Cassette '{cassette_path.name}' could not be matched to any auth scheme. " f"auth_config keys: {sorted(auth_config_keys)}")
158
+
159
+ is_valid = len(missing_tested) == 0
160
+ return is_valid, errors, warnings, sorted(covered_schemes), unmatched_cassettes
161
+
162
+
56
163
  def validate_response_against_schema(response_body: Any, schema: Dict[str, Any]) -> Tuple[bool, List[str]]:
57
164
  """Validate a response body against a JSON schema.
58
165
 
@@ -588,6 +695,9 @@ def validate_connector_readiness(connector_dir: str | Path) -> Dict[str, Any]:
588
695
  cassettes_dir = connector_path / "tests" / "cassettes"
589
696
  cassette_map = build_cassette_map(cassettes_dir)
590
697
 
698
+ # Validate auth scheme coverage for multi-auth connectors
699
+ auth_valid, auth_errors, auth_warnings, auth_covered_schemes, auth_unmatched_cassettes = validate_auth_scheme_coverage(config, cassettes_dir)
700
+
591
701
  validation_results = []
592
702
  total_operations = 0
593
703
  operations_with_cassettes = 0
@@ -827,8 +937,12 @@ def validate_connector_readiness(connector_dir: str | Path) -> Dict[str, Any]:
827
937
  if replication_result.get("registry_found", False):
828
938
  total_warnings += len(replication_warnings)
829
939
 
830
- # Update success criteria to include replication validation
831
- success = operations_missing_cassettes == 0 and cassettes_invalid == 0 and total_operations > 0 and len(replication_errors) == 0
940
+ # Merge auth scheme validation errors/warnings into totals
941
+ total_errors += len(auth_errors)
942
+ total_warnings += len(auth_warnings)
943
+
944
+ # Update success criteria to include replication and auth scheme validation
945
+ success = operations_missing_cassettes == 0 and cassettes_invalid == 0 and total_operations > 0 and len(replication_errors) == 0 and auth_valid
832
946
 
833
947
  # Check for preferred_for_check on at least one list operation
834
948
  has_preferred_check = False
@@ -849,12 +963,26 @@ def validate_connector_readiness(connector_dir: str | Path) -> Dict[str, Any]:
849
963
  "to enable reliable health checks."
850
964
  )
851
965
 
966
+ # Build auth scheme validation result
967
+ options = config.auth.options or []
968
+ tested_schemes = [opt.scheme_name for opt in options if not opt.untested]
969
+ untested_schemes_list = [opt.scheme_name for opt in options if opt.untested]
970
+ missing_tested = [s for s in tested_schemes if s not in auth_covered_schemes]
971
+
852
972
  return {
853
973
  "success": success,
854
974
  "connector_name": config.name,
855
975
  "connector_path": str(connector_path),
856
976
  "validation_results": validation_results,
857
977
  "replication_validation": replication_result,
978
+ "auth_scheme_validation": {
979
+ "valid": auth_valid,
980
+ "errors": auth_errors,
981
+ "warnings": auth_warnings,
982
+ "covered_schemes": auth_covered_schemes,
983
+ "missing_schemes": missing_tested,
984
+ "untested_schemes": untested_schemes_list,
985
+ },
858
986
  "readiness_warnings": readiness_warnings,
859
987
  "summary": {
860
988
  "total_operations": total_operations,
@@ -30,6 +30,7 @@ from .types import (
30
30
  )
31
31
  if TYPE_CHECKING:
32
32
  from .models import AmazonAdsAuthConfig
33
+
33
34
  # Import response models and envelope models at runtime
34
35
  from .models import (
35
36
  AmazonAdsCheckResult,
@@ -122,6 +123,7 @@ class AmazonAdsConnector:
122
123
  external_user_id: str | None = None,
123
124
  airbyte_client_id: str | None = None,
124
125
  airbyte_client_secret: str | None = None,
126
+ connector_id: str | None = None,
125
127
  on_token_refresh: Any | None = None,
126
128
  region: str | None = None ):
127
129
  """
@@ -129,13 +131,14 @@ class AmazonAdsConnector:
129
131
 
130
132
  Supports both local and hosted execution modes:
131
133
  - Local mode: Provide `auth_config` for direct API calls
132
- - Hosted mode: Provide `external_user_id`, `airbyte_client_id`, and `airbyte_client_secret` for hosted execution
134
+ - Hosted mode: Provide Airbyte credentials with either `connector_id` or `external_user_id`
133
135
 
134
136
  Args:
135
137
  auth_config: Typed authentication configuration (required for local mode)
136
- external_user_id: External user ID (required for hosted mode)
138
+ external_user_id: External user ID (for hosted mode lookup)
137
139
  airbyte_client_id: Airbyte OAuth client ID (required for hosted mode)
138
140
  airbyte_client_secret: Airbyte OAuth client secret (required for hosted mode)
141
+ connector_id: Specific connector/source ID (for hosted mode, skips lookup)
139
142
  on_token_refresh: Optional callback for OAuth2 token refresh persistence.
140
143
  Called with new_tokens dict when tokens are refreshed. Can be sync or async.
141
144
  Example: lambda tokens: save_to_database(tokens) region: The Amazon Ads API endpoint URL based on region:
@@ -146,7 +149,14 @@ class AmazonAdsConnector:
146
149
  Examples:
147
150
  # Local mode (direct API calls)
148
151
  connector = AmazonAdsConnector(auth_config=AmazonAdsAuthConfig(client_id="...", client_secret="...", refresh_token="..."))
149
- # Hosted mode (executed on Airbyte cloud)
152
+ # Hosted mode with explicit connector_id (no lookup needed)
153
+ connector = AmazonAdsConnector(
154
+ airbyte_client_id="client_abc123",
155
+ airbyte_client_secret="secret_xyz789",
156
+ connector_id="existing-source-uuid"
157
+ )
158
+
159
+ # Hosted mode with lookup by external_user_id
150
160
  connector = AmazonAdsConnector(
151
161
  external_user_id="user-123",
152
162
  airbyte_client_id="client_abc123",
@@ -164,21 +174,24 @@ class AmazonAdsConnector:
164
174
  on_token_refresh=save_tokens
165
175
  )
166
176
  """
167
- # Hosted mode: external_user_id, airbyte_client_id, and airbyte_client_secret provided
168
- if external_user_id and airbyte_client_id and airbyte_client_secret:
177
+ # Hosted mode: Airbyte credentials + either connector_id OR external_user_id
178
+ is_hosted = airbyte_client_id and airbyte_client_secret and (connector_id or external_user_id)
179
+
180
+ if is_hosted:
169
181
  from ._vendored.connector_sdk.executor import HostedExecutor
170
182
  self._executor = HostedExecutor(
171
- external_user_id=external_user_id,
172
183
  airbyte_client_id=airbyte_client_id,
173
184
  airbyte_client_secret=airbyte_client_secret,
174
- connector_definition_id=str(AmazonAdsConnectorModel.id),
185
+ connector_id=connector_id,
186
+ external_user_id=external_user_id,
187
+ connector_definition_id=str(AmazonAdsConnectorModel.id) if not connector_id else None,
175
188
  )
176
189
  else:
177
190
  # Local mode: auth_config required
178
191
  if not auth_config:
179
192
  raise ValueError(
180
- "Either provide (external_user_id, airbyte_client_id, airbyte_client_secret) for hosted mode "
181
- "or auth_config for local mode"
193
+ "Either provide Airbyte credentials (airbyte_client_id, airbyte_client_secret) with "
194
+ "connector_id or external_user_id for hosted mode, or auth_config for local mode"
182
195
  )
183
196
 
184
197
  from ._vendored.connector_sdk.executor import LocalExecutor
@@ -478,6 +491,183 @@ class AmazonAdsConnector:
478
491
  )
479
492
  return entity_def.entity_schema if entity_def else None
480
493
 
494
+ @property
495
+ def connector_id(self) -> str | None:
496
+ """Get the connector/source ID (only available in hosted mode).
497
+
498
+ Returns:
499
+ The connector ID if in hosted mode, None if in local mode.
500
+
501
+ Example:
502
+ connector = await AmazonAdsConnector.create_hosted(...)
503
+ print(f"Created connector: {connector.connector_id}")
504
+ """
505
+ if hasattr(self, '_executor') and hasattr(self._executor, '_connector_id'):
506
+ return self._executor._connector_id
507
+ return None
508
+
509
+ # ===== HOSTED MODE FACTORY =====
510
+
511
+ @classmethod
512
+ async def initiate_oauth(
513
+ cls,
514
+ *,
515
+ external_user_id: str,
516
+ redirect_url: str,
517
+ airbyte_client_id: str,
518
+ airbyte_client_secret: str,
519
+ ) -> str:
520
+ """
521
+ Initiate server-side OAuth flow for this connector.
522
+
523
+ Returns a consent URL where the end user should be redirected to grant access.
524
+ After completing consent, they'll be redirected to your redirect_url with a
525
+ `server_side_oauth_secret_id` query parameter that can be used with `create_hosted()`.
526
+
527
+ Args:
528
+ external_user_id: Workspace identifier in Airbyte Cloud
529
+ redirect_url: URL where users will be redirected after OAuth consent
530
+ airbyte_client_id: Airbyte OAuth client ID
531
+ airbyte_client_secret: Airbyte OAuth client secret
532
+
533
+ Returns:
534
+ The OAuth consent URL
535
+
536
+ Example:
537
+ consent_url = await AmazonAdsConnector.initiate_oauth(
538
+ external_user_id="my-workspace",
539
+ redirect_url="https://myapp.com/oauth/callback",
540
+ airbyte_client_id="client_abc",
541
+ airbyte_client_secret="secret_xyz",
542
+ )
543
+ # Redirect user to: consent_url
544
+ # After consent, user arrives at: https://myapp.com/oauth/callback?server_side_oauth_secret_id=...
545
+ """
546
+ from ._vendored.connector_sdk.cloud_utils import AirbyteCloudClient
547
+
548
+ client = AirbyteCloudClient(
549
+ client_id=airbyte_client_id,
550
+ client_secret=airbyte_client_secret,
551
+ )
552
+
553
+ try:
554
+ consent_url = await client.initiate_oauth(
555
+ definition_id=str(AmazonAdsConnectorModel.id),
556
+ external_user_id=external_user_id,
557
+ redirect_url=redirect_url,
558
+ )
559
+ finally:
560
+ await client.close()
561
+
562
+ return consent_url
563
+
564
+ @classmethod
565
+ async def create_hosted(
566
+ cls,
567
+ *,
568
+ external_user_id: str,
569
+ airbyte_client_id: str,
570
+ airbyte_client_secret: str,
571
+ auth_config: "AmazonAdsAuthConfig" | None = None,
572
+ server_side_oauth_secret_id: str | None = None,
573
+ name: str | None = None,
574
+ replication_config: dict[str, Any] | None = None,
575
+ source_template_id: str | None = None,
576
+ ) -> "AmazonAdsConnector":
577
+ """
578
+ Create a new hosted connector on Airbyte Cloud.
579
+
580
+ This factory method:
581
+ 1. Creates a source on Airbyte Cloud with the provided credentials
582
+ 2. Returns a connector configured with the new connector_id
583
+
584
+ Supports two authentication modes:
585
+ 1. Direct credentials: Provide `auth_config` with typed credentials
586
+ 2. Server-side OAuth: Provide `server_side_oauth_secret_id` from OAuth flow
587
+
588
+ Args:
589
+ external_user_id: Workspace identifier in Airbyte Cloud
590
+ airbyte_client_id: Airbyte OAuth client ID
591
+ airbyte_client_secret: Airbyte OAuth client secret
592
+ auth_config: Typed auth config. Required unless using server_side_oauth_secret_id.
593
+ server_side_oauth_secret_id: OAuth secret ID from initiate_oauth redirect.
594
+ When provided, auth_config is not required.
595
+ name: Optional source name (defaults to connector name + external_user_id)
596
+ replication_config: Optional replication settings dict.
597
+ Required for connectors with x-airbyte-replication-config (REPLICATION mode sources).
598
+ source_template_id: Source template ID. Required when organization has
599
+ multiple source templates for this connector type.
600
+
601
+ Returns:
602
+ A AmazonAdsConnector instance configured in hosted mode
603
+
604
+ Raises:
605
+ ValueError: If neither or both auth_config and server_side_oauth_secret_id provided
606
+
607
+ Example:
608
+ # Create a new hosted connector with API key auth
609
+ connector = await AmazonAdsConnector.create_hosted(
610
+ external_user_id="my-workspace",
611
+ airbyte_client_id="client_abc",
612
+ airbyte_client_secret="secret_xyz",
613
+ auth_config=AmazonAdsAuthConfig(client_id="...", client_secret="...", refresh_token="..."),
614
+ )
615
+
616
+ # With server-side OAuth:
617
+ connector = await AmazonAdsConnector.create_hosted(
618
+ external_user_id="my-workspace",
619
+ airbyte_client_id="client_abc",
620
+ airbyte_client_secret="secret_xyz",
621
+ server_side_oauth_secret_id="airbyte_oauth_..._secret_...",
622
+ )
623
+
624
+ # Use the connector
625
+ result = await connector.execute("entity", "list", {})
626
+ """
627
+ # Validate: exactly one of auth_config or server_side_oauth_secret_id required
628
+ if auth_config is None and server_side_oauth_secret_id is None:
629
+ raise ValueError(
630
+ "Either auth_config or server_side_oauth_secret_id must be provided"
631
+ )
632
+ if auth_config is not None and server_side_oauth_secret_id is not None:
633
+ raise ValueError(
634
+ "Cannot provide both auth_config and server_side_oauth_secret_id"
635
+ )
636
+
637
+ from ._vendored.connector_sdk.cloud_utils import AirbyteCloudClient
638
+
639
+ client = AirbyteCloudClient(
640
+ client_id=airbyte_client_id,
641
+ client_secret=airbyte_client_secret,
642
+ )
643
+
644
+ try:
645
+ # Build credentials from auth_config (if provided)
646
+ credentials = auth_config.model_dump(exclude_none=True) if auth_config else None
647
+ replication_config_dict = replication_config.model_dump(exclude_none=True) if replication_config else None
648
+
649
+ # Create source on Airbyte Cloud
650
+ source_name = name or f"{cls.connector_name} - {external_user_id}"
651
+ source_id = await client.create_source(
652
+ name=source_name,
653
+ connector_definition_id=str(AmazonAdsConnectorModel.id),
654
+ external_user_id=external_user_id,
655
+ credentials=credentials,
656
+ replication_config=replication_config_dict,
657
+ server_side_oauth_secret_id=server_side_oauth_secret_id,
658
+ source_template_id=source_template_id,
659
+ )
660
+ finally:
661
+ await client.close()
662
+
663
+ # Return connector configured with the new connector_id
664
+ return cls(
665
+ airbyte_client_id=airbyte_client_id,
666
+ airbyte_client_secret=airbyte_client_secret,
667
+ connector_id=source_id,
668
+ )
669
+
670
+
481
671
 
482
672
 
483
673
  class ProfilesQuery:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: airbyte-agent-amazon-ads
3
- Version: 0.1.23
3
+ Version: 0.1.25
4
4
  Summary: Airbyte Amazon-Ads Connector for AI platforms
5
5
  Project-URL: Homepage, https://github.com/airbytehq/airbyte-agent-connectors
6
6
  Project-URL: Documentation, https://docs.airbyte.com/ai-agents/
@@ -135,7 +135,7 @@ See the official [Amazon-Ads API reference](https://advertising.amazon.com/API/d
135
135
 
136
136
  ## Version information
137
137
 
138
- - **Package version:** 0.1.23
138
+ - **Package version:** 0.1.25
139
139
  - **Connector version:** 1.0.5
140
- - **Generated with Connector SDK commit SHA:** 580ea1221eff062f41b1065a155124c85861cb18
140
+ - **Generated with Connector SDK commit SHA:** 9d9866b0aae8c3494d04d34e193b9bd860bfc1c6
141
141
  - **Changelog:** [View changelog](https://github.com/airbytehq/airbyte-agent-connectors/blob/main/connectors/amazon-ads/CHANGELOG.md)
@@ -1,5 +1,5 @@
1
1
  airbyte_agent_amazon_ads/__init__.py,sha256=MICR9abWiXLcSQ0jd4W7S6xyo2KgwRjOPIZTeHpz67I,1950
2
- airbyte_agent_amazon_ads/connector.py,sha256=lgYzmFTnjjGlMCmDAN-l3FlTYOZDTdOAQ3c7Re5B89g,25456
2
+ airbyte_agent_amazon_ads/connector.py,sha256=9r5mxeos61jzP-tTNJf4UB2h6XCXoMs5T5E7r2xhqFg,33158
3
3
  airbyte_agent_amazon_ads/connector_model.py,sha256=QAxt_l2-RjUBxg2izmclOPTqVrjF9CL70fOkkYcwpTk,98041
4
4
  airbyte_agent_amazon_ads/models.py,sha256=KmYWz46e-8HuQdnuz6FQT99uDKwpcToEc9Xda2M7FL4,9781
5
5
  airbyte_agent_amazon_ads/types.py,sha256=EW-jvOmXyJQqe2ESiDCs7nCIIsFreDCIZBlA6aplxpA,6728
@@ -7,22 +7,22 @@ airbyte_agent_amazon_ads/_vendored/__init__.py,sha256=ILl7AHXMui__swyrjxrh9yRa4d
7
7
  airbyte_agent_amazon_ads/_vendored/connector_sdk/__init__.py,sha256=T5o7roU6NSpH-lCAGZ338sE5dlh4ZU6i6IkeG1zpems,1949
8
8
  airbyte_agent_amazon_ads/_vendored/connector_sdk/auth_strategies.py,sha256=5Sb9moUp623o67Q2wMa8iZldJH08y4gQdoutoO_75Iw,42088
9
9
  airbyte_agent_amazon_ads/_vendored/connector_sdk/auth_template.py,sha256=nju4jqlFC_KI82ILNumNIyiUtRJcy7J94INIZ0QraI4,4454
10
- airbyte_agent_amazon_ads/_vendored/connector_sdk/connector_model_loader.py,sha256=ecm0Cdj1SyhDOpEi2wUzzrJNkgt0wViB0Q-YTrDPsjU,41698
10
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/connector_model_loader.py,sha256=1AAvSvjxM9Nuto6w7D6skN5VXGb4e6na0lMFcFmmVkI,41761
11
11
  airbyte_agent_amazon_ads/_vendored/connector_sdk/constants.py,sha256=AtzOvhDMWbRJgpsQNWl5tkogHD6mWgEY668PgRmgtOY,2737
12
12
  airbyte_agent_amazon_ads/_vendored/connector_sdk/exceptions.py,sha256=ss5MGv9eVPmsbLcLWetuu3sDmvturwfo6Pw3M37Oq5k,481
13
13
  airbyte_agent_amazon_ads/_vendored/connector_sdk/extensions.py,sha256=XWRRoJOOrwUHSKbuQt5DU7CCu8ePzhd_HuP7c_uD77w,21376
14
14
  airbyte_agent_amazon_ads/_vendored/connector_sdk/http_client.py,sha256=09Fclbq4wrg38EM2Yh2kHiykQVXqdAGby024elcEz8E,28027
15
15
  airbyte_agent_amazon_ads/_vendored/connector_sdk/introspection.py,sha256=e9uWn2ofpeehoBbzNgts_bjlKLn8ayA1Y3OpDC3b7ZA,19517
16
16
  airbyte_agent_amazon_ads/_vendored/connector_sdk/secrets.py,sha256=J9ezMu4xNnLW11xY5RCre6DHP7YMKZCqwGJfk7ufHAM,6855
17
- airbyte_agent_amazon_ads/_vendored/connector_sdk/types.py,sha256=sRZ4rRkJXGfqdjfF3qb0kzrw_tu1cn-CmFSZKMMgF7o,9269
18
- airbyte_agent_amazon_ads/_vendored/connector_sdk/utils.py,sha256=G4LUXOC2HzPoND2v4tQW68R9uuPX9NQyCjaGxb7Kpl0,1958
19
- airbyte_agent_amazon_ads/_vendored/connector_sdk/validation.py,sha256=iz1wo5CrHT_yD4elBGM9TSCFAegVmkEZiRKCpjSu7IA,33997
17
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/types.py,sha256=MsWJsQy779r7Mqiqf_gh_4Vs6VDqieoMjLPyWt7qhu8,9412
18
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/utils.py,sha256=UYwYuSLhsDD-4C0dBs7Qy0E0gIcFZXb6VWadJORhQQU,4080
19
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/validation.py,sha256=w5WGnmILkdBslpXhAXhKhE-c8ANBc_OZQxr_fUeAgtc,39666
20
20
  airbyte_agent_amazon_ads/_vendored/connector_sdk/validation_replication.py,sha256=v7F5YWd5m4diIF7_4m4nOkC9crg97vqRUUkt9ka9HZ4,36043
21
21
  airbyte_agent_amazon_ads/_vendored/connector_sdk/cloud_utils/__init__.py,sha256=4799Hv9f2zxDVj1aLyQ8JpTEuFTp_oOZMRz-NZCdBJg,134
22
- airbyte_agent_amazon_ads/_vendored/connector_sdk/cloud_utils/client.py,sha256=YxdRpQr9XjDzih6csSseBVGn9kfMtaqbOCXP0TPuzFY,7189
22
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/cloud_utils/client.py,sha256=e0VLNCmesGGfo2uD0GiICgXsXTeTkh0GYiVgx_e4VEc,12296
23
23
  airbyte_agent_amazon_ads/_vendored/connector_sdk/executor/__init__.py,sha256=EmG9YQNAjSuYCVB4D5VoLm4qpD1KfeiiOf7bpALj8p8,702
24
- airbyte_agent_amazon_ads/_vendored/connector_sdk/executor/hosted_executor.py,sha256=AC5aJtdcMPQfRuam0ZGE4QdhUBu2oGEmNZ6oVQLHTE8,7212
25
- airbyte_agent_amazon_ads/_vendored/connector_sdk/executor/local_executor.py,sha256=l2b0VILgtOlUNyG19J0UkbCa6rJXkU8g1uzLot8BJjQ,77008
24
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/executor/hosted_executor.py,sha256=tv0njAdy-gdHBg4izgcxhEWYbrNiBifEYEca9AWzaL0,8693
25
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/executor/local_executor.py,sha256=RtdTXFzfoJz5Coz9nwQi81Df1402BRgO1Mgd3ZzTkfw,76581
26
26
  airbyte_agent_amazon_ads/_vendored/connector_sdk/executor/models.py,sha256=mUUBnuShKXxVIfsTOhMiI2rn2a-50jJG7SFGKT_P6Jk,6281
27
27
  airbyte_agent_amazon_ads/_vendored/connector_sdk/http/__init__.py,sha256=y8fbzZn-3yV9OxtYz8Dy6FFGI5v6TOqADd1G3xHH3Hw,911
28
28
  airbyte_agent_amazon_ads/_vendored/connector_sdk/http/config.py,sha256=6J7YIIwHC6sRu9i-yKa5XvArwK2KU60rlnmxzDZq3lw,3283
@@ -48,11 +48,11 @@ airbyte_agent_amazon_ads/_vendored/connector_sdk/schema/components.py,sha256=nJI
48
48
  airbyte_agent_amazon_ads/_vendored/connector_sdk/schema/connector.py,sha256=mSZk1wr2YSdRj9tTRsPAuIlCzd_xZLw-Bzl1sMwE0rE,3731
49
49
  airbyte_agent_amazon_ads/_vendored/connector_sdk/schema/extensions.py,sha256=5hgpFHK7fzpzegCkJk882DeIP79bCx_qairKJhvPMZ8,9590
50
50
  airbyte_agent_amazon_ads/_vendored/connector_sdk/schema/operations.py,sha256=St-A75m6sZUZlsoM6WcoPaShYu_X1K19pdyPvJbabOE,6214
51
- airbyte_agent_amazon_ads/_vendored/connector_sdk/schema/security.py,sha256=1CVCavrPdHHyk7B6JtUD75yRS_hWLCemZF1zwGbdqxg,9036
51
+ airbyte_agent_amazon_ads/_vendored/connector_sdk/schema/security.py,sha256=R-21DLnp-ANIRO1Dzqo53TYFJL6lCp0aO8GSuxa_bDI,9225
52
52
  airbyte_agent_amazon_ads/_vendored/connector_sdk/telemetry/__init__.py,sha256=RaLgkBU4dfxn1LC5Y0Q9rr2PJbrwjxvPgBLmq8_WafE,211
53
53
  airbyte_agent_amazon_ads/_vendored/connector_sdk/telemetry/config.py,sha256=tLmQwAFD0kP1WyBGWBS3ysaudN9H3e-3EopKZi6cGKg,885
54
54
  airbyte_agent_amazon_ads/_vendored/connector_sdk/telemetry/events.py,sha256=8Y1NbXiwISX-V_wRofY7PqcwEXD0dLMnntKkY6XFU2s,1328
55
55
  airbyte_agent_amazon_ads/_vendored/connector_sdk/telemetry/tracker.py,sha256=SginFQbHqVUVYG82NnNzG34O-tAQ_wZYjGDcuo0q4Kk,5584
56
- airbyte_agent_amazon_ads-0.1.23.dist-info/METADATA,sha256=vx6N_n2UUPIp2UU7llrnkFlQbKeae4DBW_Xp-C3YeoU,5326
57
- airbyte_agent_amazon_ads-0.1.23.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
58
- airbyte_agent_amazon_ads-0.1.23.dist-info/RECORD,,
56
+ airbyte_agent_amazon_ads-0.1.25.dist-info/METADATA,sha256=mgsYZFR2QZ1zOj3x28WcdeuxnD6HibWamIMoq6vwF3o,5326
57
+ airbyte_agent_amazon_ads-0.1.25.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
58
+ airbyte_agent_amazon_ads-0.1.25.dist-info/RECORD,,