airbyte-cdk 6.48.9__py3-none-any.whl → 6.48.10__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.
- airbyte_cdk/cli/airbyte_cdk/_secrets.py +107 -13
- airbyte_cdk/cli/airbyte_cdk/exceptions.py +23 -0
- {airbyte_cdk-6.48.9.dist-info → airbyte_cdk-6.48.10.dist-info}/METADATA +1 -1
- {airbyte_cdk-6.48.9.dist-info → airbyte_cdk-6.48.10.dist-info}/RECORD +8 -7
- {airbyte_cdk-6.48.9.dist-info → airbyte_cdk-6.48.10.dist-info}/LICENSE.txt +0 -0
- {airbyte_cdk-6.48.9.dist-info → airbyte_cdk-6.48.10.dist-info}/LICENSE_SHORT +0 -0
- {airbyte_cdk-6.48.9.dist-info → airbyte_cdk-6.48.10.dist-info}/WHEEL +0 -0
- {airbyte_cdk-6.48.9.dist-info → airbyte_cdk-6.48.10.dist-info}/entry_points.txt +0 -0
@@ -43,6 +43,7 @@ from click import style
|
|
43
43
|
from rich.console import Console
|
44
44
|
from rich.table import Table
|
45
45
|
|
46
|
+
from airbyte_cdk.cli.airbyte_cdk.exceptions import ConnectorSecretWithNoValidVersionsError
|
46
47
|
from airbyte_cdk.utils.connector_paths import (
|
47
48
|
resolve_connector_name,
|
48
49
|
resolve_connector_name_and_directory,
|
@@ -131,24 +132,46 @@ def fetch(
|
|
131
132
|
)
|
132
133
|
# Fetch and write secrets
|
133
134
|
secret_count = 0
|
135
|
+
exceptions = []
|
136
|
+
|
134
137
|
for secret in secrets:
|
135
138
|
secret_file_path = _get_secret_filepath(
|
136
139
|
secrets_dir=secrets_dir,
|
137
140
|
secret=secret,
|
138
141
|
)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
142
|
+
try:
|
143
|
+
_write_secret_file(
|
144
|
+
secret=secret,
|
145
|
+
client=client,
|
146
|
+
file_path=secret_file_path,
|
147
|
+
connector_name=connector_name,
|
148
|
+
gcp_project_id=gcp_project_id,
|
149
|
+
)
|
150
|
+
click.echo(f"Secret written to: {secret_file_path.absolute()!s}", err=True)
|
151
|
+
secret_count += 1
|
152
|
+
except ConnectorSecretWithNoValidVersionsError as e:
|
153
|
+
exceptions.append(e)
|
154
|
+
click.echo(
|
155
|
+
f"Failed to retrieve secret '{e.secret_name}': No enabled version found", err=True
|
156
|
+
)
|
157
|
+
|
158
|
+
if secret_count == 0 and not exceptions:
|
159
|
+
click.echo(
|
160
|
+
f"No secrets found for connector: '{connector_name}'",
|
161
|
+
err=True,
|
143
162
|
)
|
144
|
-
click.echo(f"Secret written to: {secret_file_path.absolute()!s}", err=True)
|
145
|
-
secret_count += 1
|
146
163
|
|
147
|
-
if
|
164
|
+
if exceptions:
|
165
|
+
error_message = f"Failed to retrieve {len(exceptions)} secret(s)"
|
148
166
|
click.echo(
|
149
|
-
|
167
|
+
style(
|
168
|
+
error_message,
|
169
|
+
fg="red",
|
170
|
+
),
|
150
171
|
err=True,
|
151
172
|
)
|
173
|
+
if secret_count == 0:
|
174
|
+
raise exceptions[0]
|
152
175
|
|
153
176
|
if not print_ci_secrets_masks:
|
154
177
|
return
|
@@ -230,9 +253,8 @@ def list_(
|
|
230
253
|
table.add_column("Created", justify="left", style="blue", overflow="fold")
|
231
254
|
for secret in secrets:
|
232
255
|
full_secret_name = secret.name
|
233
|
-
secret_name = full_secret_name
|
234
|
-
|
235
|
-
secret_url = f"https://console.cloud.google.com/security/secret-manager/secret/{secret_name}/versions?hl=en&project={gcp_project_id}"
|
256
|
+
secret_name = _extract_secret_name(full_secret_name)
|
257
|
+
secret_url = _get_secret_url(secret_name, gcp_project_id)
|
236
258
|
table.add_row(
|
237
259
|
f"[link={secret_url}]{secret_name}[/link]",
|
238
260
|
"\n".join([f"{k}={v}" for k, v in secret.labels.items()]),
|
@@ -242,6 +264,43 @@ def list_(
|
|
242
264
|
console.print(table)
|
243
265
|
|
244
266
|
|
267
|
+
def _extract_secret_name(secret_name: str) -> str:
|
268
|
+
"""Extract the secret name from a fully qualified secret path.
|
269
|
+
|
270
|
+
Handles different formats of secret names:
|
271
|
+
- Full path: "projects/project-id/secrets/SECRET_NAME"
|
272
|
+
- Already extracted: "SECRET_NAME"
|
273
|
+
|
274
|
+
Args:
|
275
|
+
secret_name: The secret name or path
|
276
|
+
|
277
|
+
Returns:
|
278
|
+
str: The extracted secret name without project prefix
|
279
|
+
"""
|
280
|
+
if "/secrets/" in secret_name:
|
281
|
+
return secret_name.split("/secrets/")[-1]
|
282
|
+
return secret_name
|
283
|
+
|
284
|
+
|
285
|
+
def _get_secret_url(secret_name: str, gcp_project_id: str) -> str:
|
286
|
+
"""Generate a URL for a secret in the GCP Secret Manager console.
|
287
|
+
|
288
|
+
Note: This URL itself does not contain secrets or sensitive information.
|
289
|
+
The URL itself is only useful for valid logged-in users of the project, and it
|
290
|
+
safe to print this URL in logs.
|
291
|
+
|
292
|
+
Args:
|
293
|
+
secret_name: The name of the secret in GCP.
|
294
|
+
gcp_project_id: The GCP project ID.
|
295
|
+
|
296
|
+
Returns:
|
297
|
+
str: URL to the secret in the GCP console
|
298
|
+
"""
|
299
|
+
# Ensure we have just the secret name without the project prefix
|
300
|
+
secret_name = _extract_secret_name(secret_name)
|
301
|
+
return f"https://console.cloud.google.com/security/secret-manager/secret/{secret_name}/versions?hl=en&project={gcp_project_id}"
|
302
|
+
|
303
|
+
|
245
304
|
def _fetch_secret_handles(
|
246
305
|
connector_name: str,
|
247
306
|
gcp_project_id: str = AIRBYTE_INTERNAL_GCP_PROJECT,
|
@@ -272,9 +331,44 @@ def _write_secret_file(
|
|
272
331
|
secret: "Secret", # type: ignore
|
273
332
|
client: "secretmanager.SecretManagerServiceClient", # type: ignore
|
274
333
|
file_path: Path,
|
334
|
+
connector_name: str,
|
335
|
+
gcp_project_id: str,
|
275
336
|
) -> None:
|
276
|
-
|
277
|
-
|
337
|
+
"""Write the most recent enabled version of a secret to a file.
|
338
|
+
|
339
|
+
Lists all enabled versions of the secret and selects the most recent one.
|
340
|
+
Raises ConnectorSecretWithNoValidVersionsError if no enabled versions are found.
|
341
|
+
|
342
|
+
Args:
|
343
|
+
secret: The secret to write to a file
|
344
|
+
client: The Secret Manager client
|
345
|
+
file_path: The path to write the secret to
|
346
|
+
connector_name: The name of the connector
|
347
|
+
gcp_project_id: The GCP project ID
|
348
|
+
|
349
|
+
Raises:
|
350
|
+
ConnectorSecretWithNoValidVersionsError: If no enabled version is found
|
351
|
+
"""
|
352
|
+
# List all enabled versions of the secret.
|
353
|
+
response = client.list_secret_versions(
|
354
|
+
request={"parent": secret.name, "filter": "state:ENABLED"}
|
355
|
+
)
|
356
|
+
|
357
|
+
# The API returns versions pre-sorted in descending order, with the
|
358
|
+
# 0th item being the latest version.
|
359
|
+
versions = list(response)
|
360
|
+
|
361
|
+
if not versions:
|
362
|
+
secret_name = _extract_secret_name(secret.name)
|
363
|
+
raise ConnectorSecretWithNoValidVersionsError(
|
364
|
+
connector_name=connector_name,
|
365
|
+
secret_name=secret_name,
|
366
|
+
gcp_project_id=gcp_project_id,
|
367
|
+
)
|
368
|
+
|
369
|
+
enabled_version = versions[0]
|
370
|
+
|
371
|
+
response = client.access_secret_version(name=enabled_version.name)
|
278
372
|
file_path.write_text(response.payload.data.decode("UTF-8"))
|
279
373
|
file_path.chmod(0o600) # default to owner read/write only
|
280
374
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.
|
2
|
+
"""Exceptions for the Airbyte CDK CLI."""
|
3
|
+
|
4
|
+
from dataclasses import dataclass
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass(kw_only=True)
|
8
|
+
class ConnectorSecretWithNoValidVersionsError(Exception):
|
9
|
+
"""Error when a connector secret has no valid versions."""
|
10
|
+
|
11
|
+
connector_name: str
|
12
|
+
secret_name: str
|
13
|
+
gcp_project_id: str
|
14
|
+
|
15
|
+
def __str__(self) -> str:
|
16
|
+
"""Return a string representation of the exception."""
|
17
|
+
from airbyte_cdk.cli.airbyte_cdk._secrets import _get_secret_url
|
18
|
+
|
19
|
+
url = _get_secret_url(self.secret_name, self.gcp_project_id)
|
20
|
+
return (
|
21
|
+
f"No valid versions found for secret '{self.secret_name}' in connector '{self.connector_name}'. "
|
22
|
+
f"Please check the following URL for more information:\n- {url}"
|
23
|
+
)
|
@@ -4,8 +4,9 @@ airbyte_cdk/cli/airbyte_cdk/__init__.py,sha256=8IoEcbdYr7CMAh97Xut5__uHH9vV4LKUt
|
|
4
4
|
airbyte_cdk/cli/airbyte_cdk/_connector.py,sha256=drKb_EXJOFX-cSeLwJB8WXE-lesOL0dx2ziWSmW3Jkg,5187
|
5
5
|
airbyte_cdk/cli/airbyte_cdk/_image.py,sha256=AkBEZrRYXEwvhW7hPOPRWeYEZutzi2PIzjpl7_yaE8I,2890
|
6
6
|
airbyte_cdk/cli/airbyte_cdk/_manifest.py,sha256=aFdeeWgek7oXR3YfZPxk7kBZ64Blmsr0dAXN6BVGiIA,482
|
7
|
-
airbyte_cdk/cli/airbyte_cdk/_secrets.py,sha256=
|
7
|
+
airbyte_cdk/cli/airbyte_cdk/_secrets.py,sha256=1IqVz-csoMJoKajSX4DzoWrngswuNHBPkzzchQggAeE,17010
|
8
8
|
airbyte_cdk/cli/airbyte_cdk/_version.py,sha256=ohZNIktLFk91sdzqFW5idaNrZAPX2dIRnz---_fcKOE,352
|
9
|
+
airbyte_cdk/cli/airbyte_cdk/exceptions.py,sha256=bsGmlWN6cXL2jCD1WYAZMqFmK1OLg2xLrcC_60KHSeA,803
|
9
10
|
airbyte_cdk/cli/source_declarative_manifest/__init__.py,sha256=-0ST722Nj65bgRokzpzPkD1NBBW5CytEHFUe38cB86Q,91
|
10
11
|
airbyte_cdk/cli/source_declarative_manifest/_run.py,sha256=9qtbjt-I_stGWzWX6yVUKO_eE-Ga7g-uTuibML9qLBs,8330
|
11
12
|
airbyte_cdk/cli/source_declarative_manifest/spec.json,sha256=Earc1L6ngcdIr514oFQlUoOxdF4RHqtUyStSIAquXdY,554
|
@@ -407,9 +408,9 @@ airbyte_cdk/utils/slice_hasher.py,sha256=EDxgROHDbfG-QKQb59m7h_7crN1tRiawdf5uU7G
|
|
407
408
|
airbyte_cdk/utils/spec_schema_transformations.py,sha256=-5HTuNsnDBAhj-oLeQXwpTGA0HdcjFOf2zTEMUTTg_Y,816
|
408
409
|
airbyte_cdk/utils/stream_status_utils.py,sha256=ZmBoiy5HVbUEHAMrUONxZvxnvfV9CesmQJLDTAIWnWw,1171
|
409
410
|
airbyte_cdk/utils/traced_exception.py,sha256=C8uIBuCL_E4WnBAOPSxBicD06JAldoN9fGsQDp463OY,6292
|
410
|
-
airbyte_cdk-6.48.
|
411
|
-
airbyte_cdk-6.48.
|
412
|
-
airbyte_cdk-6.48.
|
413
|
-
airbyte_cdk-6.48.
|
414
|
-
airbyte_cdk-6.48.
|
415
|
-
airbyte_cdk-6.48.
|
411
|
+
airbyte_cdk-6.48.10.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
|
412
|
+
airbyte_cdk-6.48.10.dist-info/LICENSE_SHORT,sha256=aqF6D1NcESmpn-cqsxBtszTEnHKnlsp8L4x9wAh3Nxg,55
|
413
|
+
airbyte_cdk-6.48.10.dist-info/METADATA,sha256=j6-W6yWj9uT1PuC976m8r6xZy0S1ifMec_7m7qIRLF8,6344
|
414
|
+
airbyte_cdk-6.48.10.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
415
|
+
airbyte_cdk-6.48.10.dist-info/entry_points.txt,sha256=AKWbEkHfpzzk9nF9tqBUaw1MbvTM4mGtEzmZQm0ZWvM,139
|
416
|
+
airbyte_cdk-6.48.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|