config

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 12 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 (

	// 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"
)
View Source
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) APIKey

func (c *Config) APIKey() string

APIKey returns the management api key from config/env/flags.

func (*Config) APIKeyFromFlagOrEnv added in v0.34.0

func (c *Config) APIKeyFromFlagOrEnv() bool

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) AccountID

func (c *Config) AccountID() string

AccountID returns the account ID from config/env/flags.

func (*Config) AccountIDSource added in v0.34.0

func (c *Config) AccountIDSource() (string, string)

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

func (c *Config) ActiveContext() string

ActiveContext returns the active context name: --context flag if set, else current_context.

func (*Config) BindPFlag

func (c *Config) BindPFlag(key string, flag *pflag.Flag)

BindPFlag binds a viper key to a pflag.Flag.

func (*Config) ConfigFilePath

func (c *Config) ConfigFilePath() string

ConfigFilePath returns the path to the loaded config file.

func (*Config) ConsoleURL added in v0.25.0

func (c *Config) ConsoleURL() string

ConsoleURL returns the web console base URL from config/env/flags.

func (*Config) ContextNames

func (c *Config) ContextNames() []string

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

func (c *Config) CurrentContext() string

CurrentContext returns the current_context value from the config file.

func (*Config) DeleteContext

func (c *Config) DeleteContext(name string)

DeleteContext removes a named context from the file data. If the deleted context is the current_context, it is also cleared.

func (*Config) Endpoint

func (c *Config) Endpoint() string

Endpoint returns the API endpoint from config/env/flags.

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

func (c *Config) JSONOutput() bool

JSONOutput returns whether JSON output is enabled.

func (*Config) Load

func (c *Config) Load(configPath string) error

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

func (c *Config) OAuthClientID() string

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

func (c *Config) SetAPIKey(k string)

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

func (c *Config) SetAccountID(id string)

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

func (c *Config) SetCurrentContext(name string)

SetCurrentContext sets the current_context in the file data.

func (*Config) TokenStore added in v0.34.0

func (c *Config) TokenStore() string

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

func (c *Config) WriteToFile() error

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.

Jump to

Keyboard shortcuts

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