config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIdentityNotDetermined is returned when unable to determine authenticated identity
	ErrIdentityNotDetermined = errors.New("unable to determine authenticated identity")
	// ErrClientEmailMissing is returned when service account JSON is missing client_email
	ErrClientEmailMissing = errors.New("client_email field is empty or missing")
)
View Source
var ErrNoGcloudConfig = errors.New("gcloud not configured")

ErrNoGcloudConfig is returned when gcloud is not configured

Functions

func ClearIdentityCache

func ClearIdentityCache()

ClearIdentityCache clears the cached identity (useful for testing)

func NoColor

func NoColor() bool

NoColor returns true if color output should be disabled. Respects the NO_COLOR standard (https://no-color.org/)

func ResolveAccount

func ResolveAccount(flagValue string) string

ResolveAccount determines which account to use based on priority: 1. CLI flag (passed as argument) 2. CLOUDSDK_CORE_ACCOUNT env var 3. gcloud config core/account

func ResolveActiveConfigName

func ResolveActiveConfigName() string

ResolveActiveConfigName returns the gcloud configuration name to use. Priority: CLOUDSDK_ACTIVE_CONFIG_NAME env var → gcloud properties file → "default"

func ResolveCredentialsFile

func ResolveCredentialsFile() string

ResolveCredentialsFile returns the path to service account credentials JSON. This is read-only from GOOGLE_APPLICATION_CREDENTIALS env var.

func ResolveProject

func ResolveProject(flagValue string) string

ResolveProject determines which project to use based on priority: 1. CLI flag (passed as argument) 2. CLOUDSDK_CORE_PROJECT env var 3. gcloud config active configuration Returns empty string if no default found (should show selector)

func ResolveRegion

func ResolveRegion(flagValue string) string

ResolveRegion determines which region to use based on priority: 1. CLI flag (passed as argument) 2. CLOUDSDK_COMPUTE_REGION env var 3. gcloud config compute/region

func ResolveZone

func ResolveZone(flagValue string) string

ResolveZone determines which zone to use based on priority: 1. CLI flag (passed as argument) 2. CLOUDSDK_COMPUTE_ZONE env var 3. gcloud config compute/zone

Types

type GcloudConfig

type GcloudConfig struct {
	ActiveConfig string
	Project      string
	Account      string
	Zone         string
	Region       string
}

GcloudConfig holds parsed gcloud configuration

func LoadGcloudConfig

func LoadGcloudConfig() (*GcloudConfig, error)

LoadGcloudConfig reads the default project from gcloud configuration. Returns ErrNoGcloudConfig if gcloud is not configured or no project is set.

type IdentityType

type IdentityType int

IdentityType represents the type of authenticated identity

const (
	IdentityUnknown IdentityType = iota
	IdentityUser
	IdentityServiceAccount
)

func GetAuthenticatedIdentity

func GetAuthenticatedIdentity() (string, IdentityType, error)

GetAuthenticatedIdentity returns the email/identity and type of the currently authenticated user or service account. Returns empty string if unable to determine. Results are cached to avoid repeated file reads.

Tries two methods in order: 1. User credentials from gcloud config (gcloud auth application-default login) 2. Service account from GOOGLE_APPLICATION_CREDENTIALS JSON file

func (IdentityType) String

func (t IdentityType) String() string

String returns the string representation of IdentityType

type ProxyConfig

type ProxyConfig struct {
	HTTPProxy  string
	HTTPSProxy string
	NoProxy    string
}

ProxyConfig holds HTTP/HTTPS proxy settings

func ResolveProxy

func ResolveProxy() ProxyConfig

ResolveProxy returns proxy configuration from environment. Checks both lowercase and uppercase variants (lowercase takes precedence per convention).

func (ProxyConfig) HasProxy

func (p ProxyConfig) HasProxy() bool

HasProxy returns true if any proxy is configured

func (ProxyConfig) ShouldBypassProxy

func (p ProxyConfig) ShouldBypassProxy(host string) bool

ShouldBypassProxy checks if the given host should bypass the proxy

type ServiceAccountCredentials

type ServiceAccountCredentials struct {
	Type        string `json:"type"`
	ClientEmail string `json:"client_email"`
}

ServiceAccountCredentials represents the structure of a GCP service account JSON key file

Jump to

Keyboard shortcuts

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