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 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 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 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 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 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 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"`
}