config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// Viper keys.
	KeyAccountID   = "account_id"
	KeyAccountName = "account_name"
	KeyTokenType   = "token_type"
	KeyToken       = "token"
	KeyAPIBaseURL  = "api_base_url"
)
View Source
const (
	TokenTypeUser    = "user"
	TokenTypeAccount = "account"
)

Token types.

Variables

This section is empty.

Functions

func APIBaseURL

func APIBaseURL() string

APIBaseURL returns an API base URL override, or "" for the default. Used by tests to point cfctl at a fake server.

func AccountID

func AccountID() string

AccountID returns the effective account ID (flag > env > config.yaml).

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the path to config.yaml (without creating anything).

func HasToken

func HasToken() bool

HasToken returns true if a token file exists.

func Init

func Init(accountFlag *pflag.Flag) error

Init (re)loads configuration from env vars and config.yaml, and binds the --account flag if given. Called once per command invocation.

func LoadToken

func LoadToken() (string, error)

LoadToken returns the API token: env var first, then the token file.

func RemoveToken

func RemoveToken() error

RemoveToken deletes the stored token.

func ResolveConfigDir

func ResolveConfigDir() (string, error)

ResolveConfigDir returns the resolved config directory path without creating it.

func Save

func Save(cfg *Config) error

Save writes the config to config.yaml (0600).

It uses a fresh Viper instance on purpose: writing the shared instance would also persist env-bound values, including a token from CLOUDFLARE_API_TOKEN.

func SaveToken

func SaveToken(token string) error

SaveToken writes the API token to disk with 0600 permissions (dir 0700).

func TokenEnvVar

func TokenEnvVar() string

TokenEnvVar returns the name of the env var supplying the token, or "".

func TokenPath

func TokenPath() (string, error)

TokenPath returns the path to the token file (without creating anything).

func TokenType added in v0.1.1

func TokenType() string

TokenType returns the token type recorded at login ("user", "account", or "").

Types

type Config

type Config struct {
	AccountID   string `mapstructure:"account_id"`
	AccountName string `mapstructure:"account_name"`
	// TokenType is "user" (My Profile → API Tokens) or "account"
	// (Manage Account → Account API Tokens, prefix cfat_).
	TokenType string `mapstructure:"token_type"`
}

Config holds the persisted configuration for cfctl. The token is never part of it: it lives in its own 0600 file.

func Load

func Load() (*Config, error)

Load reads the persisted config (config.yaml only; no flags or env).

Jump to

Keyboard shortcuts

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