profile

package
v0.1.186 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 13 Imported by: ? 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

Overview

Package profile reads and writes kcli's profiles, so a program uses the deployment and credentials kcli is set up with: Client(name) is the one-line form.

Settings live in ~/.config/kcli/config.toml (XDG_CONFIG_HOME and KCLI_CONFIG respected):

version = 1
active_profile = "default"

[defaults]
output = "table"
timeout = 30

[profiles.default]
url = "https://kasm.example.com"
auth = "api_key"
api_key = "..."
verify_tls = true

The file is a public interface shared by kcli and the SDKs: a change to its shape needs a version bump, and a reader refuses a newer version.

Secrets (API key secret, password, session token, OIDC refresh token) never live in this file; they are in the SecretStore. Precedence when resolving a value: override > environment > profile > defaults.

Index

Constants

View Source
const (
	EnvConfig       = "KCLI_CONFIG"         // path to config.toml
	EnvProfile      = "KCLI_PROFILE"        // profile name
	EnvOutput       = "KCLI_OUTPUT"         // table | wide | json | yaml
	EnvURL          = "KASM_URL"            // deployment URL
	EnvAPIKey       = "KASM_API_KEY"        // API key id
	EnvAPIKeySecret = "KASM_API_KEY_SECRET" // API key secret
	EnvSecretStore  = "KCLI_SECRET_STORE"   // keyring | file
	EnvAuth         = "KCLI_AUTH"           // api_key | password, overriding the profile
	EnvUsername     = "KASM_USERNAME"       // username for password auth
	EnvPassword     = "KASM_PASSWORD"       // password for password auth
)

Environment variables. Secrets are accepted from the environment (for CI) but never from command-line arguments.

View Source
const (
	AuthAPIKey   = "api_key"
	AuthPassword = "password"
	AuthOIDC     = "oidc"
)

Auth modes. api_key is a developer API key (HTTP Basic). password signs in as a user and sends that session's token (Bearer), which is what the self-service ("the caller") operations need, since an API key has no user. oidc is reserved for the platform's planned OIDC client authentication.

View Source
const (
	SecretAPIKeySecret = "api_key_secret"
	SecretPassword     = "password"
	// SecretSessionToken caches a password login's session token as
	// "<username>\n<token>", reused until the token expires.
	SecretSessionToken = "session_token"
	SecretOIDCRefresh  = "oidc_refresh_token"
)

Secret names, stored per profile.

View Source
const CurrentVersion = 1

CurrentVersion is the config.toml schema version this build reads and writes.

Variables

View Source
var ErrNoSecret = errors.New("secret not found")

ErrNoSecret is returned when no value is stored.

Functions

func Client

func Client(name string, opts ...sdk.Option) (*sdk.Client, error)

Client returns a client for the named profile, as kcli would use it: the environment, then the profile, then the defaults. An empty name is the active profile (KCLI_PROFILE, then active_profile). opts apply after the profile's timeout and TLS setting. A password profile signs in, or reuses kcli's cached session token, and never prompts.

func Dir

func Dir() string

Dir returns the kcli configuration directory.

func Path

func Path() string

Path returns the config file path.

Types

type Config

type Config struct {
	Version       int                `toml:"version"`
	ActiveProfile string             `toml:"active_profile"`
	Defaults      Defaults           `toml:"defaults"`
	Profiles      map[string]Profile `toml:"profiles"`
}

Config is the on-disk document.

func Load

func Load() (*Config, error)

Load reads the config file. A missing file yields New().

func LoadFrom

func LoadFrom(path string) (*Config, error)

LoadFrom reads a config file at an explicit path.

func New

func New() *Config

New returns an empty configuration with defaults and one empty profile.

func (*Config) ProfileNames

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

ProfileNames returns profile names sorted.

func (*Config) Resolve

func (c *Config) Resolve(o Overrides) (*Resolved, error)

Resolve applies precedence (flags > env > profile > defaults) and returns the effective settings. It does not require the profile to be fully configured; callers that need a client check Resolved.URL and credentials.

func (*Config) Save

func (c *Config) Save() error

Save writes the config with owner-only permissions.

func (*Config) SaveTo

func (c *Config) SaveTo(path string) error

SaveTo writes the config to an explicit path.

type Defaults

type Defaults struct {
	Output  string `toml:"output"`
	Timeout int    `toml:"timeout"` // seconds
}

Defaults apply to every profile unless overridden.

type OIDC

type OIDC struct {
	Issuer   string   `toml:"issuer"`
	ClientID string   `toml:"client_id"`
	Scopes   []string `toml:"scopes,omitempty"`
}

OIDC holds the non-secret half of an OIDC client configuration. Tokens go in the secret store. Not yet used by any command.

type Overrides

type Overrides struct {
	Profile     string
	URL         string
	Output      string
	Timeout     int
	NoVerifyTLS bool
}

Overrides are the values supplied on the command line. Empty means unset.

type Profile

type Profile struct {
	URL       string `toml:"url"`
	Auth      string `toml:"auth"`
	APIKey    string `toml:"api_key,omitempty"`
	Username  string `toml:"username,omitempty"`
	VerifyTLS *bool  `toml:"verify_tls,omitempty"`
	OIDC      *OIDC  `toml:"oidc,omitempty"`
}

Profile describes one deployment and how to authenticate to it.

type Resolved

type Resolved struct {
	ProfileName string
	Profile     Profile
	URL         string
	Auth        string
	APIKey      string
	// APIKeySecret is set only when it came from the environment. Otherwise the
	// caller fetches it from the secret store.
	APIKeySecret string
	Username     string
	// Password is set only when it came from the environment (KASM_PASSWORD).
	Password  string
	VerifyTLS bool
	Timeout   int
	Output    string
}

Resolved is the effective configuration for one invocation.

func (*Resolved) Authenticator

func (r *Resolved) Authenticator(store SecretStore, prompt func(username string) (string, error), opts ...sdk.Option) (sdk.Authenticator, error)

Authenticator returns the credentials for r, with secrets from the environment or store:

  • api_key: the key ID and its secret, as HTTP Basic.
  • password: a session token as Bearer. The token cached in store is reused until two minutes before it expires; otherwise it signs in with the password from KASM_PASSWORD, the store, or prompt (nil means none), and caches the new token. A token the server rejects is replaced once.

opts configure the sign-in request (HTTP client, user agent, trace).

type SecretStore

type SecretStore interface {
	Get(profile, key string) (string, error)
	Set(profile, key, value string) error
	Delete(profile, key string) error
	// Name identifies the backend for `kcli config show`.
	Name() string
}

SecretStore is a per-profile secret store.

func OpenSecrets

func OpenSecrets(configDir string, warn io.Writer) (SecretStore, error)

OpenSecrets returns the secret store for the profiles in configDir. The system keyring (macOS Keychain, Secret Service, Windows Credential Manager) is preferred. When it is unavailable, typically on headless Linux without D-Bus, secrets fall back to an owner-only credentials.toml in configDir. KCLI_SECRET_STORE=keyring|file forces one or the other. warn receives a one-line notice the first time a fallback happens; nil discards it.

type SetupError

type SetupError struct {
	// contains filtered or unexported fields
}

SetupError is a profile that cannot authenticate as configured: no URL, API key, secret, username or password. Its message says how to fix it.

func (*SetupError) Error

func (e *SetupError) Error() string

Jump to

Keyboard shortcuts

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