adc

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package adc handles Google Application Default Credentials.

Index

Constants

View Source
const (
	// TypeAuthorizedUser represents user credentials from gcloud auth.
	TypeAuthorizedUser = "authorized_user"
	// TypeServiceAccount represents service account credentials.
	TypeServiceAccount = "service_account"
)

Variables

This section is empty.

Functions

func FindFile

func FindFile() string

FindFile locates the ADC file using Google's standard search order. Returns empty string if not found.

Search order:

  1. GOOGLE_APPLICATION_CREDENTIALS environment variable
  2. Default location: ~/.config/gcloud/application_default_credentials.json

func FormatBrief

func FormatBrief(details *Details) string

FormatBrief creates a one-line summary of Google Cloud auth status. This is used in the provider table view.

Format: "{Type}, {Project status}, Location: {location}" Example: "User Credentials, Project: my-project, Location: us-central1".

func ReadConfig

func ReadConfig(key string) string

ReadConfig reads a value from gcloud configuration files. Supports "project" from [core] section and "region" from [compute] section. Returns empty string if config not found or key doesn't exist.

Types

type Details

type Details struct {
	State          State
	Type           string    // "User Credentials" | "Service Account"
	Account        string    // Email address or client ID
	Project        string    // Project ID
	ProjectSource  string    // "ADC (quota_project_id)" | "env (GOOGLE_VERTEX_PROJECT)" | "gcloud config" | "not set"
	Location       string    // Region
	LocationSource string    // "env (GOOGLE_VERTEX_LOCATION)" | "gcloud config" | "default"
	UniverseDomain string    // Usually "googleapis.com"
	ADCPath        string    // Path to ADC file
	LastAuth       time.Time // File modification time
	ErrorMessage   string    // Error message (only for invalid/missing states)
}

Details contains Google Cloud authentication details.

This type is used in auth.Status.GoogleCloud field (stored as interface{} to avoid import cycles).

func BuildDetails

func BuildDetails() *Details

BuildDetails creates comprehensive Google Cloud authentication status. Performs local inspection only - no network calls are made.

This function:

  1. Finds the ADC file
  2. Parses and validates it
  3. Extracts project/location from multiple sources
  4. Returns complete authentication details

type File

type File struct {
	Type           string `json:"type"`
	QuotaProjectID string `json:"quota_project_id"`
	ProjectID      string `json:"project_id"`
	Account        string `json:"account"`
	ClientID       string `json:"client_id"`
	UniverseDomain string `json:"universe_domain"`
}

File represents an Application Default Credentials JSON file.

func ParseFile

func ParseFile(path string) (*File, error)

ParseFile reads and validates an ADC JSON file.

type State

type State int

State represents the authentication state (mirrors auth.State to avoid import cycle).

const (
	// StateConfigured means credentials are configured.
	StateConfigured State = iota
	// StateMissing means required credentials are missing.
	StateMissing
	// StateInvalid means credentials are found but malformed or invalid.
	StateInvalid
)

Jump to

Keyboard shortcuts

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