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
- func ActiveFromEnv() string
- func ConfigDir() (string, error)
- func HasProfileADC(name string) bool
- func ProfileADCDir(name string) (string, error)
- func ProfileADCPath(name string) (string, error)
- type Configuration
- type Runner
- func (r Runner) Activate(name string) error
- func (r Runner) Create(name string) error
- func (r Runner) Exists(name string) (bool, error)
- func (r Runner) Get(name string) (Configuration, error)
- func (r Runner) List() ([]Configuration, error)
- func (r Runner) LoginProfileADC(name string) (string, error)
- func (r Runner) SetProperty(config, key, value string) error
Constants ¶
const ADCFileName = "application_default_credentials.json"
ADCFileName is gcloud's well-known Application Default Credentials filename.
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.
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.
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
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
HasProfileADC reports whether a per-profile ADC file exists for name.
func ProfileADCDir ¶ added in v1.3.0
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
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) 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
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 ¶
SetProperty sets a config property (e.g. "project", "account") on a specific configuration without changing the active one.