thoth.shared.utils

Utility modules for Thoth.

Functions

get_secret_manager()

Return the global SecretManagerClient singleton, creating it if needed.

Classes

SecretManagerClient([project_id])

Client for reading secrets from Google Cloud Secret Manager.

class thoth.shared.utils.SecretManagerClient(project_id: str | None = None)[source]

Bases: object

Client for reading secrets from Google Cloud Secret Manager.

Provides lazy-initialization of the Secret Manager API client and fallback to environment variables when the API is unavailable or when running locally. Used for GitLab tokens, GCP credentials, etc.

__init__(project_id: str | None = None)[source]

Initialize the Secret Manager client (API not called until first use).

Parameters:

project_id – GCP project ID for Secret Manager. If None, uses the GCP_PROJECT_ID environment variable.

Returns:

None.

get_secret(secret_id: str, version: str = 'latest') str | None[source]

Get a secret value from Secret Manager.

Parameters:
  • secret_id – The ID of the secret to retrieve

  • version – The version of the secret (default: “latest”)

Returns:

The secret value as a string, or None if not found

get_gitlab_token() str | None[source]

Get GitLab access token.

Returns:

GitLab token or None

get_gitlab_url() str[source]

Get GitLab base URL.

Returns:

//gitlab.com)

Return type:

GitLab URL (defaults to https

get_google_credentials() str | None[source]

Get Google application credentials JSON.

Returns:

Credentials JSON string or None

thoth.shared.utils.get_secret_manager() SecretManagerClient[source]

Return the global SecretManagerClient singleton, creating it if needed.

Uses a module-level variable so that all callers share the same client and lazy-initialization happens only once.

Returns:

The global SecretManagerClient instance.

Modules

logger

Structured Logging Utilities for GCP Cloud Logging and Grafana Loki.

secrets

Google Cloud Secret Manager integration for secure credential management.