gcloud

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gcloud is a thin wrapper around the gcloud CLI. Everything that touches gcloud goes through Runner so it can be faked in tests by pointing the binary at a stub on PATH.

Index

Constants

View Source
const ADCFileName = "application_default_credentials.json"

ADCFileName is gcloud's well-known Application Default Credentials filename.

View Source
const EnvADC = "GOOGLE_APPLICATION_CREDENTIALS"

EnvADC is the variable client libraries (the Go/Python/etc. SDKs, Terraform, ...) read to locate Application Default Credentials, ahead of gcloud's well-known file. Pointing it at a per-profile file is how we isolate ADC, which gcloud configurations alone do not.

View Source
const EnvActiveConfig = "CLOUDSDK_ACTIVE_CONFIG_NAME"

EnvActiveConfig is the variable gcloud reads to pick the active configuration for a single invocation. Exporting it in a shell is how we switch profiles per-shell without mutating gcloud's global state.

View Source
const EnvConfigDir = "CLOUDSDK_CONFIG"

EnvConfigDir overrides gcloud's configuration directory for an invocation.

Variables

This section is empty.

Functions

func ActiveFromEnv

func ActiveFromEnv() string

ActiveFromEnv returns the profile selected via the environment, if any.

func ConfigDir added in v1.3.0

func ConfigDir() (string, error)

ConfigDir returns gcloud's active configuration directory, mirroring gcloud's own resolution: $CLOUDSDK_CONFIG if set, else %APPDATA%\gcloud on Windows, else ~/.config/gcloud.

func HasProfileADC added in v1.3.0

func HasProfileADC(name string) bool

HasProfileADC reports whether a per-profile ADC file exists for name.

func ProfileADCDir added in v1.3.0

func ProfileADCDir(name string) (string, error)

ProfileADCDir returns the per-profile directory under the gcloud config dir that holds an isolated ADC file: <config>/profiles/<name>.

func ProfileADCPath added in v1.3.0

func ProfileADCPath(name string) (string, error)

ProfileADCPath returns the per-profile ADC file path: <config>/profiles/<name>/application_default_credentials.json.

Types

type Configuration

type Configuration struct {
	Name       string                       `json:"name"`
	IsActive   bool                         `json:"is_active"`
	Properties map[string]map[string]string `json:"properties"`
}

Configuration mirrors a single entry from `gcloud config configurations list --format=json`.

func (Configuration) Account

func (c Configuration) Account() string

Account returns the core/account property, or "" if unset.

func (Configuration) Project

func (c Configuration) Project() string

Project returns the core/project property, or "" if unset.

type Runner

type Runner struct {
	// Bin is the gcloud executable to run. Defaults to "gcloud".
	Bin string
}

Runner executes gcloud commands. The zero value runs the "gcloud" binary found on PATH.

func (Runner) Activate

func (r Runner) Activate(name string) error

Activate sets the gcloud global default configuration.

func (Runner) Create

func (r Runner) Create(name string) error

Create creates a new (empty) configuration.

func (Runner) Exists

func (r Runner) Exists(name string) (bool, error)

Exists reports whether a configuration with the given name is present.

func (Runner) Get

func (r Runner) Get(name string) (Configuration, error)

Get returns the named configuration.

func (Runner) List

func (r Runner) List() ([]Configuration, error)

List returns all gcloud configurations.

func (Runner) LoginProfileADC added in v1.3.0

func (r Runner) LoginProfileADC(name string) (string, error)

LoginProfileADC runs the interactive `gcloud auth application-default login` isolated to a throwaway config dir, then installs the resulting credentials at the per-profile ADC path, creating <config>/profiles/<name> if needed. Isolating the login keeps it from clobbering gcloud's shared well-known ADC file or other profiles. It returns the destination path on success.

func (Runner) SetProperty

func (r Runner) SetProperty(config, key, value string) error

SetProperty sets a config property (e.g. "project", "account") on a specific configuration without changing the active one.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL