gcloud

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 6 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 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.

Variables

This section is empty.

Functions

func ActiveFromEnv

func ActiveFromEnv() string

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

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) 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