Documentation
¶
Overview ¶
Package config stores and resolves nvfleetint credential profiles.
Index ¶
- Constants
- Variables
- func Path() (string, error)
- func Save(cfg Config) error
- func ValidateProfileName(name string) error
- type Config
- func (c *Config) AddProfile(name string, profile Profile) error
- func (c Config) Profile(name string) (Profile, error)
- func (c Config) ProfileNames() []string
- func (c *Config) RemoveProfile(name string) error
- func (c Config) Resolve(profileName string) (Resolved, error)
- func (c *Config) UpdateProfile(name string, profile Profile) error
- func (c *Config) UseProfile(name string) error
- type Profile
- type Resolved
- type Source
Constants ¶
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" )
const ReservedProfileName = "none"
ReservedProfileName is the token printed when no profile is in use, so it cannot also name one.
Variables ¶
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 ValidateProfileName ¶ added in v1.0.0
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
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 (*Config) AddProfile ¶ added in v1.0.0
AddProfile stores a new profile, refusing to overwrite an existing one. The first profile added also becomes the current profile.
func (Config) ProfileNames ¶ added in v1.0.0
ProfileNames returns the stored profile names in sorted order.
func (*Config) RemoveProfile ¶ added in v1.0.0
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
Resolve returns the credentials a command should use.
Precedence, highest first:
- an explicitly named profile (--profile), whose values are used verbatim;
- 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
UpdateProfile replaces the stored values for an existing profile.
func (*Config) UseProfile ¶ added in v1.0.0
UseProfile selects an existing profile as the default.
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.
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" )