Documentation
¶
Index ¶
- Constants
- func APIBaseURL() string
- func AccountID() string
- func ConfigPath() (string, error)
- func HasToken() bool
- func Init(accountFlag *pflag.Flag) error
- func LoadToken() (string, error)
- func RemoveToken() error
- func ResolveConfigDir() (string, error)
- func Save(cfg *Config) error
- func SaveToken(token string) error
- func TokenEnvVar() string
- func TokenPath() (string, error)
- func TokenType() string
- type Config
Constants ¶
const ( // Viper keys. KeyAccountID = "account_id" KeyAccountName = "account_name" KeyTokenType = "token_type" KeyToken = "token" KeyAPIBaseURL = "api_base_url" )
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 ¶
ConfigPath returns the path to config.yaml (without creating anything).
func Init ¶
Init (re)loads configuration from env vars and config.yaml, and binds the --account flag if given. Called once per command invocation.
func ResolveConfigDir ¶
ResolveConfigDir returns the resolved config directory path without creating it.
func Save ¶
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 TokenEnvVar ¶
func TokenEnvVar() string
TokenEnvVar returns the name of the env var supplying the token, 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.