resolve

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package resolve decides which profile, endpoints, organization, credentials and output format one command uses, and remembers where each value came from (for `norcube config list`).

Precedence, highest first:

profile      --profile > NORCUBE_PROFILE > default_profile > "default"
organization --org > NORCUBE_ORG > project file (.langsync.json) > profile
endpoints    --endpoint-url svc=url (and --auth-url, --web-app)
             > NORCUBE_<SERVICE>_URL > profile endpoints > environment
credentials  --token-file > NORCUBE_TOKEN > profile credential_store > keyring
output       -o > NORCUBE_OUTPUT > profile output > [defaults] output > table

The project file is read by the commands that support it (LangSync); this package reports whether --org or NORCUBE_ORG already decided.

Index

Constants

View Source
const (
	EnvProfile = "NORCUBE_PROFILE"
	EnvOrg     = "NORCUBE_ORG"
	EnvToken   = "NORCUBE_TOKEN" // #nosec G101 -- the variable's name, not a credential
	EnvOutput  = "NORCUBE_OUTPUT"
)

Environment variables read here.

View Source
const (
	CredentialTokenFile = "token-file"
)

Credentials sources beyond the profile's stores.

Variables

This section is empty.

Functions

func ParseEndpoints

func ParseEndpoints(values []string) (map[string]string, error)

ParseEndpoints turns --endpoint-url values ("service=url") into a map.

func ProfileNames

func ProfileNames(f *config.File) []string

ProfileNames returns the profiles defined in f, sorted.

func ValidateProfileName

func ValidateProfileName(name string) error

ValidateProfileName rejects names that can't be a TOML table key, a keyring item or a file name on every OS.

Types

type Input

type Input struct {
	File   *config.File
	Getenv func(string) string

	Profile string // --profile
	Org     string // --org
	// Output is -o; OutputSet tells an explicit -o table from the default.
	Output    string
	OutputSet bool
	// Endpoints are --endpoint-url service=url values, plus --auth-url and
	// --web-app mapped to their services.
	Endpoints map[string]string
	TokenFile string // --token-file
}

Input is everything a command was given.

type Result

type Result struct {
	Profile Value
	// ProfileDefined is false when the profile isn't in the config file
	// yet (a first login, or the implicit "default").
	ProfileDefined bool
	Environment    Value
	Endpoints      map[string]Value

	// Org is the organization as given (slug or id); empty when none.
	// OrgOverride is true when it came from --org or NORCUBE_ORG, which
	// beat a project file.
	Org         Value
	OrgOverride bool

	// Credentials is keyring, file, env (NORCUBE_TOKEN) or token-file.
	Credentials Value
	// TokenFile is the --token-file path when Credentials is token-file.
	TokenFile string

	Output Value
	// contains filtered or unexported fields
}

Result is the resolved configuration of one command.

func Resolve

func Resolve(in Input) (*Result, error)

Resolve applies the precedence rules.

func (*Result) Config

func (r *Result) Config() *config.Config

Config returns the command's configuration for the existing commands.

func (*Result) StoredProfile

func (r *Result) StoredProfile() *config.Profile

StoredProfile returns the profile's stored settings (an empty profile when it isn't defined).

type Value

type Value struct {
	Value  string
	Source string
}

Value is a resolved setting and where it came from, e.g. "flag --org", "env NORCUBE_ORG", "profile work", "environment production", "default".

Jump to

Keyboard shortcuts

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