Documentation
¶
Overview ¶
Package gcloud is the sole interface for gcloud CLI configuration state. It reads and writes the config files directly; the only time it shells out to the gcloud binary is the interactive re-login offered after a switch.
Index ¶
- Variables
- type Client
- func (c *Client) ClearLoginConfig(name string) error
- func (c *Client) Current() (string, error)
- func (c *Client) List() ([]Config, error)
- func (c *Client) LoginConfigWarning(name string) string
- func (c *Client) LoginRequired(ctx context.Context, configs []Config) []bool
- func (c *Client) Previous() (string, error)
- func (c *Client) Rename(oldName, newName string) error
- func (c *Client) SetLoginConfig(name, path string) error
- func (c *Client) Switch(name string) error
- func (c *Client) VerifyAuth(ctx context.Context, name string) *ReloginPlan
- type Config
- type ReloginPlan
Constants ¶
This section is empty.
Variables ¶
var ErrExists = errors.New("configuration already exists")
ErrExists is returned when renaming onto a configuration that already exists.
var ErrInvalidName = errors.New("invalid configuration name")
ErrInvalidName is returned when a configuration name violates gcloud's naming rule (a lowercase letter followed by lowercase letters, digits, or hyphens).
var ErrNoConfigurations = errors.New("no gcloud configurations found")
ErrNoConfigurations is returned when the config root has no configurations.
var ErrNoPrevious = errors.New("no previous configuration")
ErrNoPrevious is returned when no previous configuration has been recorded.
var ErrNotConfigured = errors.New("gcloud not configured — run 'gcloud init'")
ErrNotConfigured is returned when the gcloud config root does not exist.
var ErrNotFound = errors.New("configuration not found")
ErrNotFound is returned when a named configuration does not exist.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client operates on a gcloud config root and gctx's own state file.
func New ¶
New returns a Client rooted at the gcloud config directory. statePath is the file where gctx records the previously active configuration. kubeCachePath is the gke-gcloud-auth-plugin token cache, invalidated on every switch.
func (*Client) ClearLoginConfig ¶ added in v0.1.1
ClearLoginConfig removes the [auth] login_config_file property from a configuration, dropping the [auth] section when it becomes empty.
func (*Client) Current ¶
Current returns the name of the active configuration. When the active_config pointer is absent, gcloud treats "default" as active.
func (*Client) LoginConfigWarning ¶ added in v0.1.1
LoginConfigWarning returns a hint when the named configuration is a workforce account missing its login_config_file, or "" when there is nothing to warn.
func (*Client) LoginRequired ¶
LoginRequired reports, per configuration (by position), whether its stored credentials are missing or can no longer produce an access token — i.e. a re-login is needed. Configurations without an account are never flagged. Checks perform live token refreshes and run concurrently, bounded by authCheckTimeout.
func (*Client) Previous ¶
Previous returns the last active configuration recorded before the most recent switch, or ErrNoPrevious when none exists.
func (*Client) Rename ¶
Rename renames a configuration, updating the active_config pointer and the recorded previous configuration when they refer to the old name.
func (*Client) SetLoginConfig ¶ added in v0.1.1
SetLoginConfig persists the [auth] login_config_file property for a configuration, so its interactive login uses the workforce flow. The path must exist; it is stored as an absolute path.
func (*Client) Switch ¶
Switch activates the named configuration and records the previously active one, unless the target is already active (a no-op).
func (*Client) VerifyAuth ¶
func (c *Client) VerifyAuth(ctx context.Context, name string) *ReloginPlan
VerifyAuth checks whether the named configuration's credentials can still produce an access token, performing a live token refresh. It returns a ReloginPlan when a re-login is required, or nil when the credentials are valid or cannot be verified (best-effort).
type Config ¶
type Config struct {
Name string
Account string
Project string
Region string
// LoginConfigFile is the [auth] login_config_file property, set for
// configurations that authenticate via a workforce/BeyondCorp login config.
LoginConfigFile string
}
Config describes a single gcloud configuration.
func (Config) IsWorkforce ¶ added in v0.1.1
IsWorkforce reports whether the configuration authenticates as a workforce identity federation principal.
func (Config) NeedsLoginConfig ¶ added in v0.1.1
NeedsLoginConfig reports a workforce configuration whose login_config_file is not persisted. Without it, gcloud (and gctx's re-login) silently fall back to the standard Google OAuth flow instead of the workforce login.
type ReloginPlan ¶
type ReloginPlan struct {
Config Config
}
ReloginPlan describes how to re-authenticate a configuration whose credentials have expired.
func (*ReloginPlan) Command ¶
func (p *ReloginPlan) Command() string
Command returns the gcloud login command as it would be run.
func (*ReloginPlan) FixLoginConfigCommand ¶
func (p *ReloginPlan) FixLoginConfigCommand() string
FixLoginConfigCommand returns the gcloud command to repoint the active configuration at a valid login config file.
func (*ReloginPlan) MissingLoginConfig ¶
func (p *ReloginPlan) MissingLoginConfig() string
MissingLoginConfig returns the login_config_file path when the config points at one that does not exist — a dangling reference that would make the login command fail. It returns "" when there is no such problem.
func (*ReloginPlan) Run ¶
func (p *ReloginPlan) Run() error
Run executes the login command, wiring the current process's stdio so the interactive login flow works.