config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAPIURL          = "https://console.cloud.timescale.com/public/api/v1"
	DefaultConsoleURL      = "https://console.cloud.timescale.com"
	DefaultGatewayURL      = "https://console.cloud.timescale.com/api"
	DefaultDocsMCP         = true
	DefaultDocsMCPURL      = "https://mcp.tigerdata.com/docs"
	DefaultOutput          = "table"
	DefaultAnalytics       = true
	DefaultPasswordStorage = "keyring"
	DefaultDebug           = false
	ConfigFileName         = "config.yaml"
)

Variables

View Source
var BuildTime = "unknown"
View Source
var ErrNotLoggedIn = errors.New("not logged in")
View Source
var GitCommit = "unknown"
View Source
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 ApplyDefaults(v *viper.Viper)

func ApplyEnvOverrides added in v0.8.0

func ApplyEnvOverrides(v *viper.Viper)

func GetAPIKey

func GetAPIKey() (string, error)

GetAPIKey retrieves the API key from keyring or file fallback

func GetAPIKeyFromFile

func GetAPIKeyFromFile() (string, error)

GetAPIKeyFromFile retrieves API key from ~/.config/tiger/api-key

func GetAPIKeyFromKeyring

func GetAPIKeyFromKeyring() (string, error)

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 api_key.go). But ideally, those functions would take a Config struct and use the ConfigDir field instead.

func GetConfigFile

func GetConfigFile(dir string) string

func GetDefaultConfigDir

func GetDefaultConfigDir() string

func GetEffectiveConfigDir

func GetEffectiveConfigDir(configDirFlag *pflag.Flag) string

func GetServiceName

func GetServiceName() string

GetServiceName returns the appropriate service name for keyring operations

func ReadInConfig added in v0.8.0

func ReadInConfig(v *viper.Viper) error

func RemoveAPIKey

func RemoveAPIKey() error

RemoveAPIKey removes the API key from keyring and file fallback

func RemoveAPIKeyFromFile

func RemoveAPIKeyFromFile() error

RemoveAPIKeyFromFile removes the API key file

func RemoveAPIKeyFromKeyring

func RemoveAPIKeyFromKeyring() error

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

func SetTestServiceName(t *testing.T)

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

func SetupViper(configDir string) error

SetupViper configures the global Viper instance with defaults, env vars, and config file

func StoreAPIKey

func StoreAPIKey(apiKey string) error

storeAPIKey stores the API key using keyring with file fallback

func StoreAPIKeyToFile

func StoreAPIKeyToFile(apiKey string) error

StoreAPIKeyToFile stores API key to ~/.config/tiger/api-key with restricted permissions

func StoreAPIKeyToKeyring

func StoreAPIKeyToKeyring(apiKey string) error

func ValidateOutputFormat added in v0.2.0

func ValidateOutputFormat(format string, allowEnv bool) error

Types

type Config

type Config struct {
	APIURL          string `mapstructure:"api_url" yaml:"api_url"`
	ConsoleURL      string `mapstructure:"console_url" yaml:"console_url"`
	GatewayURL      string `mapstructure:"gateway_url" yaml:"gateway_url"`
	DocsMCP         bool   `mapstructure:"docs_mcp" yaml:"docs_mcp"`
	DocsMCPURL      string `mapstructure:"docs_mcp_url" yaml:"docs_mcp_url"`
	ProjectID       string `mapstructure:"project_id" yaml:"project_id"`
	ServiceID       string `mapstructure:"service_id" yaml:"service_id"`
	Output          string `mapstructure:"output" yaml:"output"`
	Analytics       bool   `mapstructure:"analytics" yaml:"analytics"`
	PasswordStorage string `mapstructure:"password_storage" yaml:"password_storage"`
	Debug           bool   `mapstructure:"debug" yaml:"debug"`
	ConfigDir       string `mapstructure:"config_dir" yaml:"-"`
}

func FromViper added in v0.8.0

func FromViper(v *viper.Viper) (*Config, error)

func Load

func Load() (*Config, error)

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

func UseTestConfig(configDir string, values map[string]any) (*Config, error)

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 (c *Config) EnsureConfigDir() (string, error)

func (*Config) GetConfigFile added in v0.5.1

func (c *Config) GetConfigFile() string

func (*Config) Reset

func (c *Config) Reset() error

func (*Config) Set

func (c *Config) Set(key, value string) error

func (*Config) Unset

func (c *Config) Unset(key string) error

type ConfigOutput added in v0.8.0

type ConfigOutput struct {
	APIURL          *string `mapstructure:"api_url" json:"api_url,omitempty" yaml:"api_url,omitempty"`
	ConsoleURL      *string `mapstructure:"console_url" json:"console_url,omitempty" yaml:"console_url,omitempty"`
	GatewayURL      *string `mapstructure:"gateway_url" json:"gateway_url,omitempty" yaml:"gateway_url,omitempty"`
	DocsMCP         *bool   `mapstructure:"docs_mcp" json:"docs_mcp,omitempty" yaml:"docs_mcp,omitempty"`
	DocsMCPURL      *string `mapstructure:"docs_mcp_url" json:"docs_mcp_url,omitempty" yaml:"docs_mcp_url,omitempty"`
	ProjectID       *string `mapstructure:"project_id" json:"project_id,omitempty" yaml:"project_id,omitempty"`
	ServiceID       *string `mapstructure:"service_id" json:"service_id,omitempty" yaml:"service_id,omitempty"`
	Output          *string `mapstructure:"output" json:"output,omitempty" yaml:"output,omitempty"`
	Analytics       *bool   `mapstructure:"analytics" json:"analytics,omitempty" yaml:"analytics,omitempty"`
	PasswordStorage *string `mapstructure:"password_storage" json:"password_storage,omitempty" yaml:"password_storage,omitempty"`
	Debug           *bool   `mapstructure:"debug" json:"debug,omitempty" yaml:"debug,omitempty"`
	ConfigDir       *string `mapstructure:"config_dir" json:"config_dir,omitempty" yaml:"config_dir,omitempty"`
}

func ForOutputFromViper added in v0.8.0

func ForOutputFromViper(v *viper.Viper) (*ConfigOutput, error)

Jump to

Keyboard shortcuts

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