Skip to content

Commit 8137b0d

Browse files
feat(cli): fall back to Application Default Credentials for secrets commands
Co-Authored-By: AJ Steers <aj@airbyte.io>
1 parent ef8df7b commit 8137b0d

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

airbyte_cdk/cli/airbyte_cdk/_secrets.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,14 @@ def _get_secret_filepath(
414414

415415

416416
def _get_gsm_secrets_client() -> "secretmanager.SecretManagerServiceClient": # type: ignore
417-
"""Get the Google Secret Manager client."""
417+
"""Get the Google Secret Manager client.
418+
419+
If the `GCP_GSM_CREDENTIALS` environment variable is set, the client will be
420+
created using service account credentials from that JSON string. Otherwise, the
421+
client will fall back to Application Default Credentials (ADC), which supports
422+
user credentials from `gcloud auth application-default login`, GCE metadata
423+
server credentials, and other standard GCP authentication methods.
424+
"""
418425
if not secretmanager:
419426
raise ImportError(
420427
"google-cloud-secret-manager package is required for Secret Manager integration. "
@@ -423,17 +430,17 @@ def _get_gsm_secrets_client() -> "secretmanager.SecretManagerServiceClient": #
423430
)
424431

425432
credentials_json = os.environ.get("GCP_GSM_CREDENTIALS")
426-
if not credentials_json:
427-
raise ValueError(
428-
"No Google Cloud credentials found. "
429-
"Please set the `GCP_GSM_CREDENTIALS` environment variable."
433+
if credentials_json:
434+
return cast(
435+
"secretmanager.SecretManagerServiceClient",
436+
secretmanager.SecretManagerServiceClient.from_service_account_info(
437+
json.loads(credentials_json)
438+
),
430439
)
431440

432441
return cast(
433442
"secretmanager.SecretManagerServiceClient",
434-
secretmanager.SecretManagerServiceClient.from_service_account_info(
435-
json.loads(credentials_json)
436-
),
443+
secretmanager.SecretManagerServiceClient(),
437444
)
438445

439446

0 commit comments

Comments
 (0)