Documentation
¶
Index ¶
- Variables
- func ClearIdentityCache()
- func NoColor() bool
- func ResolveAccount(flagValue string) string
- func ResolveActiveConfigName() string
- func ResolveCredentialsFile() string
- func ResolveProject(flagValue string) string
- func ResolveRegion(flagValue string) string
- func ResolveZone(flagValue string) string
- type GcloudConfig
- type IdentityType
- type ProxyConfig
- type ServiceAccountCredentials
Constants ¶
This section is empty.
Variables ¶
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") )
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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