Documentation
¶
Index ¶
- Constants
- func AutoRefreshToken(cfg *ConfigFile) (string, error)
- func AutoRefreshTokenToPath(cfg *ConfigFile, configPath string) (string, error)
- func BuildCommands(spec *Spec) []*cli.Command
- func ConfigDir() string
- func ConfigPath() string
- func ExchangeAPIKey(cfg *ConfigFile, configPath string) (string, error)
- func ExecuteTokenCommand(tokenCommand string) (string, error)
- func FormatEnvOverrides(overrides []EnvOverride, mask bool) string
- func FormatOutput(data []byte, format string) error
- func GetAuthToken(cfg *ConfigFile) string
- func HasAPIKeyConfig(cfg *ConfigFile) bool
- func HasOIDCConfig(cfg *ConfigFile) bool
- func HasTokenCommandConfig(cfg *ConfigFile) bool
- func InitCommand() *cli.Command
- func KnownEnvVarNames() []string
- func LoginCommand() *cli.Command
- func LoginFromConfig(cfg *ConfigFile, configPath string) (string, error)
- func LoginWithOIDCConfig(cfg *ConfigFile, configPath string) (string, error)
- func LoginWithTokenCommand(cfg *ConfigFile, configPath, tokenCommand string) (string, error)
- func NewApp(specData []byte) (*cli.App, error)
- func ReadBodyInput(data, dataFile string) ([]byte, error)
- func ResolveToken(token, tokenCommand string) (string, error)
- func SaveConfig(cfg *ConfigFile) error
- func SaveConfigToPath(cfg *ConfigFile, path string) error
- func SetConfigPath(path string)
- func ValidateOutputFormat(format string) error
- type APIError
- type AuthRetryAction
- type AuthRetryEvent
- type Client
- type Components
- type ConfigAPI
- type ConfigAPIKey
- type ConfigAuth
- type ConfigFile
- type ConfigOIDC
- type EnvOverride
- type MediaType
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Schema
- type SchemaType
- type Server
- type Spec
- type SpecInfo
- type Tag
- type TokenResponse
Constants ¶
const SampleConfig = `` /* 1224-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func AutoRefreshToken ¶
func AutoRefreshToken(cfg *ConfigFile) (string, error)
AutoRefreshToken attempts to refresh the OIDC token if it is near expiry.
func AutoRefreshTokenToPath ¶
func AutoRefreshTokenToPath(cfg *ConfigFile, configPath string) (string, error)
AutoRefreshTokenToPath attempts to refresh the OIDC token if it is near expiry and saves refreshed tokens to configPath.
func BuildCommands ¶
BuildCommands converts parsed OpenAPI operations into a cli.Command tree grouped by tag.
func ConfigDir ¶
func ConfigDir() string
ConfigDir returns the directory containing the active config file.
func ExchangeAPIKey ¶
func ExchangeAPIKey(cfg *ConfigFile, configPath string) (string, error)
ExchangeAPIKey exchanges an NGC API key for a bearer token, updates the config, and saves it. Returns the new token. NGC Personal/Service API keys (those prefixed with "nvapi-") are bearer tokens themselves and are returned as-is without contacting the authn endpoint.
func ExecuteTokenCommand ¶
ExecuteTokenCommand runs a shell command that prints a bearer token.
func FormatEnvOverrides ¶ added in v1.6.0
func FormatEnvOverrides(overrides []EnvOverride, mask bool) string
FormatEnvOverrides returns a multiline string describing each override for human display. Layout:
NICO_BASE_URL=http://localhost:8388 -> api.base NICO_TOKEN=eyJh...REDACTED -> auth.token (sensitive)
When mask is true, sensitive values are replaced with a short prefix followed by "...REDACTED". When mask is false, full values are printed. The final line is terminated with a newline.
func FormatOutput ¶
func GetAuthToken ¶
func GetAuthToken(cfg *ConfigFile) string
GetAuthToken returns the best available bearer token from the config. Priority: auth.token > auth.oidc.token > auth.api_key.token
func HasAPIKeyConfig ¶
func HasAPIKeyConfig(cfg *ConfigFile) bool
HasAPIKeyConfig returns true when NGC API key settings are present.
func HasOIDCConfig ¶
func HasOIDCConfig(cfg *ConfigFile) bool
HasOIDCConfig returns true when OIDC credentials are present in the config.
func HasTokenCommandConfig ¶
func HasTokenCommandConfig(cfg *ConfigFile) bool
HasTokenCommandConfig returns true when an auth token command is configured.
func InitCommand ¶
InitCommand returns the 'init' CLI command that generates a sample config.
func KnownEnvVarNames ¶ added in v1.6.0
func KnownEnvVarNames() []string
KnownEnvVarNames returns every NICO_* env var nicocli recognizes, sorted alphabetically. Useful for tests and documentation generation.
func LoginFromConfig ¶
func LoginFromConfig(cfg *ConfigFile, configPath string) (string, error)
LoginFromConfig performs a login using the configured auth method and returns the current bearer token.
func LoginWithOIDCConfig ¶
func LoginWithOIDCConfig(cfg *ConfigFile, configPath string) (string, error)
LoginWithOIDCConfig performs a non-interactive OIDC login from config.
func LoginWithTokenCommand ¶
func LoginWithTokenCommand(cfg *ConfigFile, configPath, tokenCommand string) (string, error)
LoginWithTokenCommand runs a shell command that prints a bearer token, stores it in config, and returns it.
func ReadBodyInput ¶
ReadBodyInput reads request body from --data flag or --data-file flag. Use "--data-file -" to read from stdin.
func ResolveToken ¶
ResolveToken returns the token or executes the token command.
func SaveConfig ¶
func SaveConfig(cfg *ConfigFile) error
SaveConfig writes the config back to ConfigPath(), preserving unknown keys.
func SaveConfigToPath ¶
func SaveConfigToPath(cfg *ConfigFile, path string) error
SaveConfigToPath writes the config to a specific path, preserving any unknown keys the user may have manually added.
func SetConfigPath ¶
func SetConfigPath(path string)
SetConfigPath overrides the default config file path for the process lifetime.
func ValidateOutputFormat ¶
ValidateOutputFormat returns an error if format is outside the allowed set. The empty string is treated as valid so the StringFlag default ("json") and callers that pass an unset value continue to work.
Without this validator, FormatOutput silently routed any unknown value to formatJSON, so a typo like `--output xml` exited 0 and produced JSON -- dangerous in scripts that branch on the requested format.
Types ¶
type AuthRetryAction ¶
type AuthRetryAction string
const ( AuthRetryActionLogin AuthRetryAction = "login" AuthRetryActionRetry AuthRetryAction = "retry" AuthRetryActionSkip AuthRetryAction = "skip" )
type AuthRetryEvent ¶
type Client ¶
type Components ¶
type ConfigAPIKey ¶
type ConfigAuth ¶
type ConfigAuth struct {
Token string `yaml:"token,omitempty"`
TokenCommand string `yaml:"token_command,omitempty"`
OIDC *ConfigOIDC `yaml:"oidc,omitempty"`
APIKey *ConfigAPIKey `yaml:"api_key,omitempty"`
}
type ConfigFile ¶
type ConfigFile struct {
API ConfigAPI `yaml:"api"`
Auth ConfigAuth `yaml:"auth"`
}
ConfigFile mirrors the ~/.nico/config.yaml structure.
func LoadConfig ¶
func LoadConfig() (*ConfigFile, error)
LoadConfig reads config from the active path (override or default).
func LoadConfigFromPath ¶
func LoadConfigFromPath(path string) (*ConfigFile, error)
LoadConfigFromPath reads a config file at a specific path.
type ConfigOIDC ¶
type ConfigOIDC struct {
TokenURL string `yaml:"token_url,omitempty"`
ClientID string `yaml:"client_id,omitempty"`
ClientSecret string `yaml:"client_secret,omitempty"`
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
Token string `yaml:"token,omitempty"`
RefreshToken string `yaml:"refresh_token,omitempty"`
ExpiresAt string `yaml:"expires_at,omitempty"`
}
type EnvOverride ¶ added in v1.6.0
type EnvOverride struct {
// Name is the environment variable name (e.g. "NICO_BASE_URL").
Name string
// ConfigPath is a human-readable description of where the value lands.
// Direct config fields use dotted YAML paths (e.g. "api.base"); env
// vars that feed only the flag layer carry a parenthesized note instead.
ConfigPath string
// Value is the current value of the env var. Empty for unset env vars.
Value string
// Sensitive marks values that should be masked in casual display
// (tokens, passwords, client secrets, NGC API keys).
Sensitive bool
// Applied is true when ApplyEnvOverrides actually wrote this value
// back into the ConfigFile. Env vars that only feed flags
// (e.g. NICO_KEYCLOAK_URL) are reported but not applied here.
Applied bool
}
EnvOverride describes a single NICO_* environment variable, the config field (or flag) it influences, and the value currently set in the process environment. Values are returned exactly as os.Getenv reports them; the caller is responsible for masking when displaying sensitive data.
func ApplyEnvOverrides ¶ added in v1.6.0
func ApplyEnvOverrides(cfg *ConfigFile) []EnvOverride
ApplyEnvOverrides reads every NICO_* env var from the process environment and writes its value into the matching ConfigFile field, overriding whatever was loaded from the config YAML. It returns the list of overrides that were actually applied (apply func != nil and env var was set to a non-empty string), in registry order.
Env vars that influence only the flag layer (e.g. NICO_KEYCLOAK_URL) are not applied here -- urfave/cli reads them via the flag's EnvVars list. Use EnvOverridesFromEnvironment to get every NICO_* env var that is set, applied or not.
func EnvOverridesFromEnvironment ¶ added in v1.6.0
func EnvOverridesFromEnvironment() []EnvOverride
EnvOverridesFromEnvironment returns every NICO_* env var that is set (to a non-empty value) in the current process environment, regardless of whether ApplyEnvOverrides would write it back to ConfigFile. Useful for the --debug listing and the interactive `env` command.
func KnownEnvVarDescriptors ¶ added in v1.6.0
func KnownEnvVarDescriptors() []EnvOverride
KnownEnvVarDescriptors returns metadata for every NICO_* env var nicocli recognizes, in registry order, with Value left empty and Applied set to true for direct config-field overrides (false for flag-only entries like NICO_KEYCLOAK_URL). Use this for static documentation surfaces (help output, generated docs); use EnvOverridesFromEnvironment when you want the values currently set in the process environment.
type RequestBody ¶
type Schema ¶
type Schema struct {
Ref string `yaml:"$ref"`
Type SchemaType `yaml:"type"`
Format string `yaml:"format"`
Enum []string `yaml:"enum"`
Properties map[string]*Schema `yaml:"properties"`
Required []string `yaml:"required"`
Items *Schema `yaml:"items"`
MinLength *int `yaml:"minLength"`
MaxLength *int `yaml:"maxLength"`
Minimum *int `yaml:"minimum"`
Maximum *int `yaml:"maximum"`
Default interface{} `yaml:"default"`
}
type SchemaType ¶
type SchemaType string
SchemaType handles OpenAPI 3.1 type fields that can be a string or a list of strings.
func (*SchemaType) UnmarshalYAML ¶
func (t *SchemaType) UnmarshalYAML(value *yaml.Node) error
type Spec ¶
type Spec struct {
Info SpecInfo `yaml:"info"`
Servers []Server `yaml:"servers"`
Tags []Tag `yaml:"tags"`
Paths map[string]PathItem `yaml:"paths"`
Components Components `yaml:"components"`
}