Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyDefaults(v *viper.Viper)
- func ApplyEnvOverrides(v *viper.Viper)
- func GetConfigDir() string
- func GetConfigFile(dir string) string
- func GetCredentials() (string, string, error)
- func GetDefaultConfigDir() string
- func GetEffectiveConfigDir(configDirFlag *pflag.Flag) string
- func GetServiceName() string
- func ReadInConfig(v *viper.Viper) error
- func RemoveCredentials() error
- func ResetGlobalConfig()
- func SetTestServiceName(t *testing.T)
- func SetupViper(configDir string) error
- func StoreCredentials(apiKey, projectID string) error
- func StoreCredentialsToFile(apiKey, projectID string) error
- func ValidConfigOptions() iter.Seq[string]
- func ValidateOutputFormat(format string, allowEnv bool) error
- type Config
- type ConfigOutput
Constants ¶
const ( ConfigFileName = "config.yaml" DefaultAPIURL = "https://console.cloud.timescale.com/public/api/v1" DefaultAnalytics = true DefaultColor = true DefaultConsoleURL = "https://console.cloud.timescale.com" DefaultDebug = false DefaultDocsMCP = true DefaultDocsMCPURL = "https://mcp.tigerdata.com/docs" DefaultGatewayURL = "https://console.cloud.timescale.com/api" DefaultOutput = "table" DefaultPasswordStorage = "keyring" DefaultReleasesURL = "https://cli.tigerdata.com" DefaultVersionCheckInterval = 24 * time.Hour )
Variables ¶
var BuildTime = "unknown"
var ErrNotLoggedIn = errors.New("not logged in")
var GitCommit = "unknown"
var Version = "dev"
These variables are set at build time via ldflags in the GoReleaser pipeline for production releases. Default values are used for local development builds.
Functions ¶
func ApplyDefaults ¶ added in v0.8.0
func ApplyEnvOverrides ¶ added in v0.8.0
func GetConfigDir ¶
func GetConfigDir() string
TODO: This function is currently used to get the directory that the API key fallback file should be stored in (see credentials.go). But ideally, those functions would take a Config struct and use the ConfigDir field instead.
func GetConfigFile ¶
func GetCredentials ¶ added in v0.12.0
GetCredentials retrieves the API key and project ID from storage Returns (apiKey, projectID, error) where apiKey is in "publicKey:secretKey" format
func GetDefaultConfigDir ¶
func GetDefaultConfigDir() string
func GetEffectiveConfigDir ¶
func GetServiceName ¶
func GetServiceName() string
GetServiceName returns the appropriate service name for keyring operations
func ReadInConfig ¶ added in v0.8.0
func RemoveCredentials ¶ added in v0.12.0
func RemoveCredentials() error
RemoveCredentials removes stored credentials from keyring and file fallback
func ResetGlobalConfig ¶
func ResetGlobalConfig()
ResetGlobalConfig clears the global viper state for testing This is mainly used to reset viper configuration between test runs
func SetTestServiceName ¶ added in v0.7.1
SetTestServiceName sets a unique service name for testing based on the test name This allows tests to use unique service names to avoid conflicts when running in parallel The cleanup is automatically registered with t.Cleanup()
func SetupViper ¶
SetupViper configures the global Viper instance with defaults, env vars, and config file
func StoreCredentials ¶ added in v0.12.0
StoreCredentials stores the API key (public:secret) and project ID together The credentials are stored as JSON with api_key and project_id fields
func StoreCredentialsToFile ¶ added in v0.12.0
StoreCredentialsToFile stores credentials to file (test helper)
func ValidConfigOptions ¶ added in v0.15.2
func ValidateOutputFormat ¶ added in v0.2.0
Types ¶
type Config ¶
type Config struct {
APIURL string `mapstructure:"api_url"`
Analytics bool `mapstructure:"analytics"`
Color bool `mapstructure:"color"`
ConfigDir string `mapstructure:"config_dir"`
ConsoleURL string `mapstructure:"console_url"`
Debug bool `mapstructure:"debug"`
DocsMCP bool `mapstructure:"docs_mcp"`
DocsMCPURL string `mapstructure:"docs_mcp_url"`
GatewayURL string `mapstructure:"gateway_url"`
Output string `mapstructure:"output"`
PasswordStorage string `mapstructure:"password_storage"`
ReleasesURL string `mapstructure:"releases_url"`
ServiceID string `mapstructure:"service_id"`
VersionCheckInterval time.Duration `mapstructure:"version_check_interval"`
VersionCheckLastTime time.Time `mapstructure:"version_check_last_time"`
// contains filtered or unexported fields
}
func Load ¶
Load creates a new Config instance from the current viper state This function should be called after SetupViper has been called to initialize viper
func UseTestConfig ¶ added in v0.5.1
UseTestConfig writes only the specified key-value pairs to the config file and returns a Config instance with those values set. This function is intended for testing purposes only, where you need to set up specific config file state without writing default values for unspecified keys.
func (*Config) EnsureConfigDir ¶ added in v0.8.0
func (*Config) GetConfigFile ¶ added in v0.5.1
func (*Config) UpdateField ¶ added in v0.12.0
UpdateField updates the field in the Config struct corresponding to the given key. It accepts either a string (from user input) or a typed value (string/bool from defaults). The function validates the value and updates both the struct field and viper state.
type ConfigOutput ¶ added in v0.8.0
type ConfigOutput struct {
APIURL *string `mapstructure:"api_url" json:"api_url,omitempty"`
Analytics *bool `mapstructure:"analytics" json:"analytics,omitempty"`
Color *bool `mapstructure:"color" json:"color,omitempty"`
ConfigDir *string `mapstructure:"config_dir" json:"config_dir,omitempty"`
ConsoleURL *string `mapstructure:"console_url" json:"console_url,omitempty"`
Debug *bool `mapstructure:"debug" json:"debug,omitempty"`
DocsMCP *bool `mapstructure:"docs_mcp" json:"docs_mcp,omitempty"`
DocsMCPURL *string `mapstructure:"docs_mcp_url" json:"docs_mcp_url,omitempty"`
GatewayURL *string `mapstructure:"gateway_url" json:"gateway_url,omitempty"`
Output *string `mapstructure:"output" json:"output,omitempty"`
PasswordStorage *string `mapstructure:"password_storage" json:"password_storage,omitempty"`
ReleasesURL *string `mapstructure:"releases_url" json:"releases_url,omitempty"`
ServiceID *string `mapstructure:"service_id" json:"service_id,omitempty"`
VersionCheckInterval *util.Duration `mapstructure:"version_check_interval" json:"version_check_interval,omitempty"` // [util.Duration] ensures value is marshaled in [time.Duration.String] format when output
VersionCheckLastTime *time.Time `mapstructure:"version_check_last_time" json:"version_check_last_time,omitempty"`
}
func ForOutputFromViper ¶ added in v0.8.0
func ForOutputFromViper(v *viper.Viper) (*ConfigOutput, error)