Documentation
¶
Index ¶
- Constants
- func DefaultConfigPath() string
- type Config
- func (c *Config) APIKey() string
- func (c *Config) APIKeyFromFlagOrEnv() bool
- func (c *Config) AccountID() string
- func (c *Config) AccountIDSource() (string, string)
- func (c *Config) ActiveContext() string
- func (c *Config) BindPFlag(key string, flag *pflag.Flag)
- func (c *Config) ConfigFilePath() string
- func (c *Config) ConsoleURL() string
- func (c *Config) ContextNames() []string
- func (c *Config) Contexts() []ContextEntry
- func (c *Config) CurrentContext() string
- func (c *Config) DeleteContext(name string)
- func (c *Config) Endpoint() string
- func (c *Config) GetContext(name string) (ContextEntry, bool)
- func (c *Config) JSONOutput() bool
- func (c *Config) Load(configPath string) error
- func (c *Config) OAuthClientID() string
- func (c *Config) SetAPIKey(k string)
- func (c *Config) SetAccountID(id string)
- func (c *Config) SetCurrentContext(name string)
- func (c *Config) TokenStore() string
- func (c *Config) UpsertContext(ctx ContextEntry)
- func (c *Config) WriteToFile() error
- type ContextEntry
- type File
Constants ¶
const ( // KeyAPIKey is the config key for the Management API key. KeyAPIKey = "api_key" // KeyAccountID is the config key for the account ID. KeyAccountID = "account_id" // KeyEndpoint is the config key for the API endpoint. KeyEndpoint = "endpoint" // KeyConsoleURL is the config key for the web console base URL. KeyConsoleURL = "console_url" // KeyOAuthClientID is the config key for the OAuth client id, overriding the built-in one. KeyOAuthClientID = "oauth_client_id" // KeyTokenStore is the config key for where the OAuth tokens are kept: auto, keychain, or file. KeyTokenStore = "token_store" )
const AuthOAuth = "oauth"
AuthOAuth marks a context that authenticates with the OAuth login for its endpoint.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigPath ¶
func DefaultConfigPath() string
DefaultConfigPath returns the default config file path (~/.config/qcloud/config.yaml). The config file can also be written as config.yaml or config.yml.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config wraps a viper instance to provide typed access to configuration values.
func New ¶
func New() *Config
New creates a new Config backed by a fresh viper instance with defaults applied. No I/O is performed.
func (*Config) APIKeyFromFlagOrEnv ¶ added in v0.34.0
APIKeyFromFlagOrEnv reports whether an API key is set with --api-key or QDRANT_CLOUD_API_KEY. Unlike a key saved in a context, those override the OAuth login for every context.
func (*Config) AccountIDSource ¶ added in v0.34.0
AccountIDSource returns the account ID and where it comes from, in the order it is resolved: the --account-id flag, QDRANT_CLOUD_ACCOUNT_ID, the active context, then the config file. Both are empty when no account is set.
func (*Config) ActiveContext ¶
ActiveContext returns the active context name: --context flag if set, else current_context.
func (*Config) ConfigFilePath ¶
ConfigFilePath returns the path to the loaded config file.
func (*Config) ConsoleURL ¶ added in v0.25.0
ConsoleURL returns the web console base URL from config/env/flags.
func (*Config) ContextNames ¶
ContextNames returns a sorted list of all context names.
func (*Config) Contexts ¶ added in v0.34.0
func (c *Config) Contexts() []ContextEntry
Contexts returns a copy of all contexts, in file order.
func (*Config) CurrentContext ¶
CurrentContext returns the current_context value from the config file.
func (*Config) DeleteContext ¶
DeleteContext removes a named context from the file data. If the deleted context is the current_context, it is also cleared.
func (*Config) GetContext ¶
func (c *Config) GetContext(name string) (ContextEntry, bool)
GetContext returns the ContextEntry for the named context, or false if not found.
func (*Config) JSONOutput ¶
JSONOutput returns whether JSON output is enabled.
func (*Config) Load ¶
Load reads the config file. If configPath is non-empty it is used directly; otherwise QDRANT_CLOUD_CONFIG env var is checked (via viper), then the default ~/.config/qcloud/config.yaml location is used. A missing config file is not an error.
func (*Config) OAuthClientID ¶ added in v0.34.0
OAuthClientID returns the OAuth client id that overrides the built-in one, from --client-id or QDRANT_CLOUD_OAUTH_CLIENT_ID; empty means the built-in one.
func (*Config) SetAPIKey ¶
SetAPIKey overrides the api key with the highest viper priority. FOR TESTING ONLY: this bypasses the normal config precedence (file → env var → flag) and should not be used in production code paths.
func (*Config) SetAccountID ¶
SetAccountID overrides the account ID with the highest viper priority. FOR TESTING ONLY: this bypasses the normal config precedence (file → env var → flag) and should not be used in production code paths.
func (*Config) SetCurrentContext ¶
SetCurrentContext sets the current_context in the file data.
func (*Config) TokenStore ¶ added in v0.34.0
TokenStore returns where the OAuth tokens are kept, from QDRANT_CLOUD_TOKEN_STORE: auto (the default), keychain, or file.
func (*Config) UpsertContext ¶
func (c *Config) UpsertContext(ctx ContextEntry)
UpsertContext creates or updates a named context in the file data.
func (*Config) WriteToFile ¶
WriteToFile writes file data to the config file. If no file was loaded, it writes to DefaultConfigPath() as YAML.
type ContextEntry ¶
type ContextEntry struct {
Name string `mapstructure:"name" yaml:"name" json:"name"`
Endpoint string `mapstructure:"endpoint" yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
APIKey string `mapstructure:"api_key" yaml:"api_key,omitempty" json:"api_key,omitempty"`
APIKeyCommand string `mapstructure:"api_key_command" yaml:"api_key_command,omitempty" json:"api_key_command,omitempty"`
AccountID string `mapstructure:"account_id" yaml:"account_id,omitempty" json:"account_id,omitempty"`
// Auth is AuthOAuth for a context that uses the OAuth login for its endpoint ("qcloud auth login")
// instead of an API key. Empty for an API key context.
Auth string `mapstructure:"auth" yaml:"auth,omitempty" json:"auth,omitempty"`
}
ContextEntry holds the configuration for a single named context.
func (ContextEntry) IsOAuth ¶ added in v0.34.0
func (e ContextEntry) IsOAuth() bool
IsOAuth reports whether the context uses the OAuth login instead of an API key.
func (ContextEntry) Validate ¶ added in v0.34.0
func (e ContextEntry) Validate() error
Validate checks that the context has an endpoint, an account, and exactly one credential: an API key (or a command that prints one), or the OAuth login.
type File ¶
type File struct {
CurrentContext string `mapstructure:"current_context" yaml:"current_context,omitempty" json:"current_context,omitempty"`
Contexts []ContextEntry `mapstructure:"contexts" yaml:"contexts,omitempty" json:"contexts,omitempty"`
}
File holds the top-level structure of the config file.