Authentication

The recommended way to authenticate to the google-cloud-deploy-v1 library is to useApplication Default Credentials (ADC).To review all of your authentication options, seeCredentials lookup.

Quickstart

The following example shows how to set up authentication for a local developmentenvironment with your user credentials.

NOTE: This method isnot recommended for running in production. User credentialsshould be used only during development.

  1. Download and install the Google Cloud CLI.
  2. Set up a local ADC file with your user credentials:
gcloud auth application-default login
  1. Write code as if already authenticated.

For more information about setting up authentication for a local development environment, seeSet up Application Default Credentials.

Credential Lookup

The google-cloud-deploy-v1 library provides several mechanisms to configure your system.Generally, using Application Default Credentials to facilitate automatic credentials discovery is the easist method. But if you need to explicitly specifycredentials, there are several methods available to you.

Credentials are accepted in the following ways, in the following order or precedence:

  1. Credentials specified in method arguments
  2. Credentials specified in configuration
  3. Credentials pointed to or included in environment variables
  4. Credentials found in local ADC file
  5. Credentials returned by the metadata server for the attached service account (GCP)

Configuration

You can configure a path to a JSON credentials file, either for an individual client object orglobally, for all client objects. The JSON file can contain credentials created forworkload identity federation,workforce identity federation, or aservice account key.

Note: Service account keys are a security risk if not managed correctly. You shouldchoose a more secure alternative to service account keyswhenever possible.

To configure a credentials file for an individual client initialization:

require"google/cloud/deploy/v1"client=::Google::Cloud::Deploy::V1::CloudDeploy::Client.newdo|config|config.credentials="path/to/credentialfile.json"end

To configure a credentials file globally for all clients:

require"google/cloud/deploy/v1"::Google::Cloud::Deploy::V1::CloudDeploy::Client.configuredo|config|config.credentials="path/to/credentialfile.json"endclient=::Google::Cloud::Deploy::V1::CloudDeploy::Client.new

Environment Variables

You can also use an environment variable to provide a JSON credentials file.The environment variable can contain a path to the credentials file or, forenvironments such as Docker containers where writing files is not encouraged,you can include the credentials file itself.

The JSON file can contain credentials created forworkload identity federation,workforce identity federation, or aservice account key.

Note: Service account keys are a security risk if not managed correctly. You shouldchoose a more secure alternative to service account keyswhenever possible.

The environment variables that google-cloud-deploy-v1checks for credentials are:

  • GOOGLE_CLOUD_CREDENTIALS - Path to JSON file, or JSON contents
  • GOOGLE_APPLICATION_CREDENTIALS - Path to JSON file
require"google/cloud/deploy/v1"ENV["GOOGLE_APPLICATION_CREDENTIALS"]="path/to/credentialfile.json"client=::Google::Cloud::Deploy::V1::CloudDeploy::Client.new

Local ADC file

You can set up a local ADC file with your user credentials for authentication duringdevelopment. If credentials are not provided in code or in environment variables,then the local ADC credentials are discovered.

Follow the steps inQuickstart to set up a local ADC file.

Google Cloud Platform environments

When running on Google Cloud Platform (GCP), including Google Compute Engine(GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google CloudFunctions (GCF) and Cloud Run, credentials are retrieved from the attachedservice account automatically. Code should be written as if already authenticated.

For more information, seeSet up ADC for Google Cloud services.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.