config

package
v1.0.42663-pre Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config manages the CLI's user-level configuration file.

Config file location follows XDG Base Directory Specification:

  • $XDG_CONFIG_HOME/circleci/config.yml (when XDG_CONFIG_HOME is set)
  • ~/.config/circleci/config.yml (default)

Index

Constants

View Source
const DefaultHost = "https://circleci.com"

DefaultHost is the CircleCI API host used when none is configured.

View Source
const DefaultTheme = "auto"

DefaultTheme is the color theme used when none is configured. It matches the default of the --theme flag and detects the terminal background.

Variables

This section is empty.

Functions

func ActiveTelemetryOverrides

func ActiveTelemetryOverrides() []string

ActiveTelemetryOverrides returns the names of environment variables that are currently set and override the stored telemetry preference.

func Path

func Path() (string, error)

Path returns the resolved path to the default config file.

func SetHost

func SetHost(ctx context.Context, host string) error

SetHost persists the CircleCI server host. The host is not a secret, so it is always written to the config file and never touches secure storage (passing secureStorage here would make saveTo delete the keyring token).

func SetTelemetry

func SetTelemetry(ctx context.Context, enabled bool, path string) error

SetTelemetry persists the telemetry opt-in/opt-out preference. path follows the same convention as Load (empty → XDG default).

func SetTheme

func SetTheme(ctx context.Context, theme string) error

SetTheme persists the color theme preference. The theme is not a secret, so it is always written to the config file and never touches secure storage (passing secureStorage here would make saveTo delete the keyring token). Validation of the value is the caller's responsibility (see iostream.IsValidTheme).

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds all persisted CLI settings.

func Load

func Load(ctx context.Context, path string, secureStorage bool) (*Config, error)

Load reads the config file from the given path. If path is empty the default XDG path is used. Returns an empty Config if the file does not exist.

func (*Config) DeviceID

func (c *Config) DeviceID() uuid.UUID

func (*Config) EffectiveHost

func (c *Config) EffectiveHost() string

EffectiveHost returns the host, checked in priority order: CIRCLE_HOST env var → config file value → DefaultHost.

func (*Config) EffectiveTheme

func (c *Config) EffectiveTheme() string

EffectiveTheme returns the configured color theme, or DefaultTheme when none has been set.

func (*Config) EffectiveToken

func (c *Config) EffectiveToken() string

EffectiveToken returns the token from the config, falling back to the CIRCLE_TOKEN environment variable (with CIRCLE_CLI_TOKEN as a legacy alias).

func (*Config) IsTelemetry

func (c *Config) IsTelemetry() bool

IsTelemetry returns true when telemetry should be collected. Environment variables always take precedence over the stored config value. When no preference has been set, telemetry is enabled by default.

func (*Config) UserID

func (c *Config) UserID() uuid.UUID

type SaveResult

type SaveResult struct {
	// Storage is where the token actually landed.
	Storage TokenStorage
	// KeyringErr is non-nil when secure storage was requested but the OS keyring
	// could not be used, so the token transparently fell back to the config
	// file. It wraps keyring.ErrUnavailable (and may be keyring.ErrAccessDenied
	// for a denial the user can fix, such as an unconnected snap interface).
	// This is NOT a fatal error — callers may inspect it to surface guidance.
	KeyringErr error
}

SaveResult reports the outcome of a token-mutating call.

func DeleteToken

func DeleteToken(ctx context.Context, secureStorage bool) (SaveResult, error)

DeleteToken removes the stored API token from both the config file and the system keyring (when secure storage is in use).

func SetLogin

func SetLogin(ctx context.Context, host, token string, userID uuid.UUID, secureStorage bool) (SaveResult, error)

func SetLogout

func SetLogout(ctx context.Context, secureStorage bool) (SaveResult, error)

func SetToken

func SetToken(ctx context.Context, token string, secureStorage bool) (SaveResult, error)

type TokenStorage

type TokenStorage int

TokenStorage reports where a token-mutating call actually persisted (or removed from) the token, so callers can print an accurate location. When secure storage is requested but the OS keyring is unavailable, the call transparently falls back to the config file and reports StoredInFile.

const (
	// StoredInFile means the token was written to (or cleared from) the
	// plaintext config file — either because --insecure-storage was set, or
	// because secure storage was requested but the keyring was unavailable.
	StoredInFile TokenStorage = iota
	// StoredInKeyring means the token was written to (or removed from) the OS
	// keyring.
	StoredInKeyring
)

Jump to

Keyboard shortcuts

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