config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config stores and resolves nvfleetint credential profiles.

Index

Constants

View Source
const (
	// DefaultAPIURL is the production Fleet Intelligence API root.
	DefaultAPIURL = "https://api.fleet-intelligence.nvidia.com"
	// DefaultProfileName is the profile `auth add` targets when no name is
	// given, so single-tenant setup never has to invent one.
	DefaultProfileName = "default"
	// EnvAPIURL overrides the resolved API URL for the current process.
	EnvAPIURL = "NVFLEETINT_API_URL"
	// EnvAPIKey overrides the resolved API key for the current process.
	EnvAPIKey = "NVFLEETINT_API_KEY"
	// EnvLegacyAPIKey is the pre-rename name of EnvAPIKey. It is deliberately
	// not read — it exists so a command that finds no credentials can point at
	// the variable the user actually exported instead of failing with an error
	// that never mentions it.
	EnvLegacyAPIKey = "NVFLEETINT_SERVICE_KEY"
)
View Source
const ReservedProfileName = "none"

ReservedProfileName is the token printed when no profile is in use, so it cannot also name one.

Variables

View Source
var (
	// ErrProfileNotFound reports a reference to a profile that is not stored.
	ErrProfileNotFound = errors.New("profile not found")
	// ErrProfileExists reports an attempt to add a profile that already exists.
	ErrProfileExists = errors.New("profile already exists")
	// ErrNoProfile reports that no profile is selected and no credentials are available.
	ErrNoProfile = errors.New("no profile configured")
)

Errors callers can match on to add command-specific hints.

Functions

func Path

func Path() (string, error)

Path returns the location of the configuration file.

func Save

func Save(cfg Config) error

Save writes the configuration file with owner-only permissions.

func ValidateProfileName added in v1.0.0

func ValidateProfileName(name string) error

ValidateProfileName rejects names that would need quoting in YAML or a shell.

Types

type Config

type Config struct {
	CurrentProfile string             `yaml:"current_profile,omitempty"`
	Profiles       map[string]Profile `yaml:"profiles,omitempty"`
}

Config is the on-disk configuration file.

func Edit added in v1.0.0

func Edit(mutate func(*Config) error) (Config, error)

Edit locks the config, loads the latest contents, applies mutate, and writes the complete file back. It is used by auth mutators so concurrent commands cannot overwrite each other's profile changes.

func Load

func Load() (Config, error)

Load reads the configuration file, returning an empty config when it is absent.

func (*Config) AddProfile added in v1.0.0

func (c *Config) AddProfile(name string, profile Profile) error

AddProfile stores a new profile, refusing to overwrite an existing one. The first profile added also becomes the current profile.

func (Config) Profile added in v1.0.0

func (c Config) Profile(name string) (Profile, error)

Profile returns the named profile.

func (Config) ProfileNames added in v1.0.0

func (c Config) ProfileNames() []string

ProfileNames returns the stored profile names in sorted order.

func (*Config) RemoveProfile added in v1.0.0

func (c *Config) RemoveProfile(name string) error

RemoveProfile deletes a profile. Removing the current profile always clears the selection — no profile is auto-selected in its place, so the next one must be chosen explicitly with `auth use`.

func (Config) Resolve added in v1.0.0

func (c Config) Resolve(profileName string) (Resolved, error)

Resolve returns the credentials a command should use.

Precedence, highest first:

  1. an explicitly named profile (--profile), whose values are used verbatim;
  2. the current profile, with NVFLEETINT_API_KEY / NVFLEETINT_API_URL overlaid field by field.

An explicit selection deliberately ignores the credential environment variables: with several tenants configured, a stale NVFLEETINT_API_KEY would otherwise send one tenant's key to another tenant's endpoint.

A current profile that is no longer stored is reported in Resolved.MissingCurrentProfile rather than returned as an error, so the environment overlay still applies. Only an explicit selection — where the user named the profile — fails outright.

func (*Config) UpdateProfile added in v1.0.0

func (c *Config) UpdateProfile(name string, profile Profile) error

UpdateProfile replaces the stored values for an existing profile.

func (*Config) UseProfile added in v1.0.0

func (c *Config) UseProfile(name string) error

UseProfile selects an existing profile as the default.

type Profile added in v1.0.0

type Profile struct {
	APIURL string `yaml:"api_url"`
	APIKey string `yaml:"api_key"`
}

Profile is one named set of Fleet Intelligence credentials.

type Resolved added in v1.0.0

type Resolved struct {
	Profile            string
	APIURL             string
	APIKey             string
	APIURLSource       Source
	APIKeySource       Source
	ProfilesConfigured bool
	// EnvIgnored names the credential environment variables that were set but
	// skipped because a profile was selected explicitly. Only the variables
	// actually set are listed, so a note built from it cannot claim more than
	// what is really in the environment.
	EnvIgnored []string
	// MissingCurrentProfile names the profile current_profile points at when
	// that profile is no longer stored. Resolution continues instead of
	// failing, so callers must treat this as the reason a resolved set has no
	// profile in it rather than as an aside.
	MissingCurrentProfile string
	// ConfigError reports a configuration file that could not be read or
	// parsed while the environment still supplied a complete credential set.
	// Resolution succeeded, so this is a warning to surface, not a failure —
	// without it the stored profiles simply appear not to exist.
	ConfigError error
}

Resolved is the credential set a command should use, plus where each half of it came from so `auth status` can explain itself.

func Resolve added in v1.0.0

func Resolve(profileName string) (Resolved, error)

Resolve loads the config and resolves the credentials for profileName.

type Source added in v1.0.0

type Source string

Source names where a resolved value came from.

const (
	// SourceProfile marks a value read from a stored profile.
	SourceProfile Source = "profile"
	// SourceEnvironment marks a value read from an environment variable.
	SourceEnvironment Source = "environment"
	// SourceDefault marks a value that fell back to a built-in default.
	SourceDefault Source = "default"
)

Jump to

Keyboard shortcuts

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