Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions airbyte_cdk/cli/airbyte_cdk/_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
logger = logging.getLogger("airbyte-cdk.cli.secrets")

try:
import google.auth.exceptions
from google.cloud import secretmanager_v1 as secretmanager
from google.cloud.secretmanager_v1 import Secret
except ImportError:
# If the package is not installed, we will raise an error in the CLI command.
google = None # type: ignore
secretmanager = None # type: ignore
Secret = None # type: ignore

Expand Down Expand Up @@ -414,7 +416,14 @@ def _get_secret_filepath(


def _get_gsm_secrets_client() -> "secretmanager.SecretManagerServiceClient": # type: ignore
"""Get the Google Secret Manager client."""
"""Get the Google Secret Manager client.

If the `GCP_GSM_CREDENTIALS` environment variable is set, the client will be
created using service account credentials from that JSON string. Otherwise, the
client will fall back to Application Default Credentials (ADC), which supports
user credentials from `gcloud auth application-default login`, GCE metadata
server credentials, and other standard GCP authentication methods.
"""
if not secretmanager:
raise ImportError(
"google-cloud-secret-manager package is required for Secret Manager integration. "
Expand All @@ -423,18 +432,28 @@ def _get_gsm_secrets_client() -> "secretmanager.SecretManagerServiceClient": #
)

credentials_json = os.environ.get("GCP_GSM_CREDENTIALS")
if not credentials_json:
raise ValueError(
"No Google Cloud credentials found. "
"Please set the `GCP_GSM_CREDENTIALS` environment variable."
if credentials_json:
click.echo(
"Using GCP service account credentials from GCP_GSM_CREDENTIALS env var.", err=True
)
return cast(
"secretmanager.SecretManagerServiceClient",
secretmanager.SecretManagerServiceClient.from_service_account_info(
json.loads(credentials_json)
),
)

return cast(
"secretmanager.SecretManagerServiceClient",
secretmanager.SecretManagerServiceClient.from_service_account_info(
json.loads(credentials_json)
),
click.echo(
"GCP_GSM_CREDENTIALS not set. Using Application Default Credentials (ADC).", err=True
)
try:
return secretmanager.SecretManagerServiceClient()
except google.auth.exceptions.DefaultCredentialsError:
raise ValueError(
"No Google Cloud credentials found. "
"Either set the `GCP_GSM_CREDENTIALS` environment variable with service account JSON, "
"or run `gcloud auth application-default login` to authenticate with your user account."
) from None


def _print_ci_secrets_masks(
Expand Down