config

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package config reads and writes the CLI's configuration file.

One TOML file (schema version 2) holds named profiles. A profile picks an environment (production, or custom endpoints), an organization, and where its credentials live. Secrets never go in this file: refresh and access tokens live in the credential store the profile names (the OS keyring by default).

schema_version = 2
default_profile = "work"

[defaults]
output = "table"

[profiles.work]
environment = "production"
organization = "acme"
org_id = "0b9d2b8e-…"

[profiles.selfhosted]
environment = "custom"
organization = "acme"

Which profile, organization and endpoints a command uses is decided by package resolve, from flags, environment variables and this file.

Index

Constants

View Source
const (
	CredentialKeyring = "keyring"
	CredentialFile    = "file"
	// CredentialEnv reads an access token from NORCUBE_TOKEN and never
	// writes anything.
	CredentialEnv = "env"
)

Credential stores a profile can use.

View Source
const (
	ServiceAuth        = "auth"
	ServiceWebApp      = "web_app"
	ServiceSnapDB      = "snapdb"
	ServiceLangsync    = "langsync"
	ServiceDomainradar = "domainradar"
	ServiceBilling     = "billing"
	ServicePrompthub   = "prompthub"
)

Service keys, as used in [profiles.<name>.endpoints] and --endpoint-url.

View Source
const (
	EnvProduction = "production"
	// EnvCustom has no built-in endpoints: the profile lists its own, and
	// any it leaves out fall back to production.
	EnvCustom = "custom"
)

Environments a profile can select.

View Source
const DefaultProfileName = "default"

DefaultProfileName is used when nothing names a profile.

View Source
const EnvConfigFile = "NORCUBE_CONFIG_FILE"

EnvConfigFile names the config file explicitly.

View Source
const SchemaVersion = 2

SchemaVersion is the version this CLI writes. Files without a version are the flat version 1 format and are migrated on load.

Variables

View Source
var Services = registry.Keys()

Services lists every service the CLI has an endpoint for, in display order (the order of services.yaml).

Functions

func Dir added in v0.16.0

func Dir() (string, error)

Dir is the directory holding the config file, its lock files and the file credential store.

func EnvironmentEndpoints added in v0.16.0

func EnvironmentEndpoints(env string) (map[string]string, bool)

EnvironmentEndpoints returns the built-in endpoints of a named environment. Custom (and unknown) environments have none.

func EnvironmentFor added in v0.16.0

func EnvironmentFor(urls map[string]string) (string, map[string]string)

EnvironmentFor describes a set of service URLs as a profile environment plus overrides: the environment whose auth URL matches (production when the auth URL is empty), with every URL that differs from it as an endpoint override. An unknown auth URL is a custom environment listing every URL given.

func IsCredentialStore added in v0.16.0

func IsCredentialStore(v string) bool

IsCredentialStore reports whether v names a credential store.

func IsEnvironment added in v0.16.0

func IsEnvironment(env string) bool

IsEnvironment reports whether env is a valid profile environment.

func IsService added in v0.16.0

func IsService(name string) bool

IsService reports whether name is a known service key.

func Path

func Path() (string, error)

Path returns the config file location: NORCUBE_CONFIG_FILE, else $XDG_CONFIG_HOME/norcube/config.toml (on every OS), else the OS user config directory (~/.config on Linux, ~/Library/Application Support on macOS, %AppData% on Windows).

func ServiceEnvVar added in v0.16.0

func ServiceEnvVar(service string) string

ServiceEnvVar is the environment variable that overrides a service's endpoint: NORCUBE_WEB_APP for the web app, NORCUBE_<SERVICE>_URL for the rest.

Types

type Config

type Config struct {
	Profile     string
	Environment string

	Auth        string
	WebApp      string
	SnapDB      string
	Langsync    string
	Domainradar string
	Billing     string
	Prompthub   string

	User      User
	ActiveOrg Organization
}

Config is the configuration one command runs with: the selected profile with every endpoint resolved. Package resolve builds it.

func (*Config) Endpoint added in v0.16.0

func (c *Config) Endpoint(service string) string

Endpoint returns the resolved URL of a service.

func (*Config) SetEndpoint added in v0.16.0

func (c *Config) SetEndpoint(service, url string)

SetEndpoint sets the resolved URL of a service.

type Defaults added in v0.16.0

type Defaults struct {
	Output string `toml:"output"`
	// Pager turns automatic paging of long tables on or off; nil means on.
	Pager          *bool  `toml:"pager"`
	MaxAttempts    int    `toml:"max_attempts"`
	ReadTimeout    string `toml:"read_timeout"`
	ConnectTimeout string `toml:"connect_timeout"`
}

Defaults apply to every profile unless the profile, an environment variable or a flag says otherwise.

type File added in v0.16.0

type File struct {
	SchemaVersion  int                 `toml:"schema_version"`
	DefaultProfile string              `toml:"default_profile"`
	Defaults       Defaults            `toml:"defaults"`
	Profiles       map[string]*Profile `toml:"profiles"`
}

File is the on-disk configuration.

func Load

func Load() (*File, error)

Load reads the config file. A missing file is an empty configuration. A version 1 file is migrated to version 2 and written back (with a backup of the original) before it is returned.

func Update added in v0.16.0

func Update(fn func(*File) error) (*File, error)

Update changes the config file under its lock: it re-reads the file (migrating a version 1 file), lets fn change it, and writes it back atomically. Keys this CLI doesn't know are kept.

func (*File) Profile added in v0.16.0

func (f *File) Profile(name string) *Profile

Profile returns the named profile, creating it in f if missing.

type Organization

type Organization struct {
	ID   string
	Slug string
	Name string
}

Organization is an organization as the CLI knows it.

type Profile added in v0.16.0

type Profile struct {
	// Environment is production or custom.
	Environment string `toml:"environment"`
	// Organization is what the user chose (usually the slug); OrgID and
	// OrgName are what the CLI resolved it to.
	Organization string `toml:"organization"`
	OrgID        string `toml:"org_id"`
	OrgName      string `toml:"org_name"`
	// CredentialStore is keyring (default), file or env.
	CredentialStore string `toml:"credential_store"`
	Output          string `toml:"output"`
	// Endpoints override the environment's URL per service key.
	Endpoints map[string]string `toml:"endpoints"`
	// User is who signed in with this profile, recorded at login.
	User User `toml:"user"`
}

Profile is one named set of environment, organization and credentials.

func (*Profile) ActiveOrg added in v0.16.0

func (p *Profile) ActiveOrg() Organization

ActiveOrg returns the profile's organization.

func (*Profile) SetActiveOrg added in v0.16.0

func (p *Profile) SetActiveOrg(o Organization)

SetActiveOrg records the profile's organization.

type User

type User struct {
	ID    string `toml:"id"`
	Name  string `toml:"name"`
	Email string `toml:"email"`
}

User is the signed-in account.

Jump to

Keyboard shortcuts

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