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
- Variables
- func Dir() (string, error)
- func EnvironmentEndpoints(env string) (map[string]string, bool)
- func EnvironmentFor(urls map[string]string) (string, map[string]string)
- func IsCredentialStore(v string) bool
- func IsEnvironment(env string) bool
- func IsService(name string) bool
- func Path() (string, error)
- func ServiceEnvVar(service string) string
- type Config
- type Defaults
- type File
- type Organization
- type Profile
- type User
Constants ¶
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.
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.
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.
const ( DefaultAuth = "https://auth.api.norcube.com" DefaultWebApp = "https://app.norcube.com" DefaultSnapDB = "https://snapdb.api.norcube.com/app/v1" DefaultLangsync = "https://langsync.api.norcube.com" DefaultDomainradar = "https://domainradar.api.norcube.com/app/v1" DefaultBilling = "https://billing.api.norcube.com/app/v1" DefaultPrompthub = "https://prompthub.api.norcube.com" )
Production endpoints.
const DefaultProfileName = "default"
DefaultProfileName is used when nothing names a profile.
const EnvConfigFile = "NORCUBE_CONFIG_FILE"
EnvConfigFile names the config file explicitly.
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 ¶
var Services = []string{ ServiceAuth, ServiceWebApp, ServiceSnapDB, ServiceLangsync, ServiceDomainradar, ServiceBilling, ServicePrompthub, }
Services lists every service the CLI has an endpoint for, in display order.
Functions ¶
func Dir ¶ added in v0.16.0
Dir is the directory holding the config file, its lock files and the file credential store.
func EnvironmentEndpoints ¶ added in v0.16.0
EnvironmentEndpoints returns the built-in endpoints of a named environment. Custom (and unknown) environments have none.
func EnvironmentFor ¶ added in v0.16.0
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
IsCredentialStore reports whether v names a credential store.
func IsEnvironment ¶ added in v0.16.0
IsEnvironment reports whether env is a valid profile environment.
func Path ¶
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
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) SetEndpoint ¶ added in v0.16.0
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 ¶
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.
type Organization ¶
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.