Documentation
¶
Overview ¶
Package cliconfig stores and resolves the CLI's own settings — the API endpoint and credentials the user keeps in $HOME/.scanoss/settings.json.
This is NOT a project's scanoss.json (see pkg/settings), which holds that project's BOM and skip rules. The two are unrelated despite the similar file name.
The package is deliberately under internal/: reading ambient state (environment variables, a file in $HOME) is correct for a CLI and wrong for a library, so the SDK in pkg/ cannot import it even by accident.
The package is split by concern: registry.go declares which settings exist and how they are spelled, store.go reads and writes the file, and resolve.go decides which source wins for a given command.
Index ¶
- Constants
- func CLIKey(key string) string
- func EnvName(key string) string
- func IsRecognized(key string) bool
- func IsSecret(key string) bool
- func Path() (string, error)
- func Set(key, value string) error
- func StoredKey(input string) (string, bool)
- func Unset(key string) error
- type API
- type Config
- type Setting
- type Source
- type Transport
- type UnknownKeyError
Constants ¶
const ( KeyAPIURL = "api_url" KeyAPIKey = "api_key" KeyProxy = "proxy" KeyCACert = "ca_cert" )
Recognized setting keys. Keys are snake_case in the file; a new one is an entry in registry below plus, if it should affect behaviour, a rung in the resolver.
Variables ¶
This section is empty.
Functions ¶
func CLIKey ¶
CLIKey returns how key is spelled on the command line: api_key → api-key. Every recognized key the CLI prints goes through here, so its output can be pasted back into a command. It is also the flag name, deliberately the same string.
func EnvName ¶
EnvName returns the environment variable that overrides key, e.g. api_url → SCANOSS_API_URL. It mirrors what viper's SetEnvPrefix("SCANOSS") + AutomaticEnv derive, so the resolver and viper cannot disagree about a name.
func IsRecognized ¶
IsRecognized reports whether key — in its stored form — is one this version knows about. Keys the CLI does not recognize may still exist in the file: they are preserved, not rejected, but nothing reads them.
This takes the stored spelling because it guards the Go API (Set, Unset). Command arguments arrive in the command-line spelling and go through StoredKey first.
func Set ¶
Set stores value under key — the stored (snake_case) form; command arguments go through StoredKey first. It creates ~/.scanoss and the file if missing, and leaves keys already in the file that this version does not recognize untouched.
func StoredKey ¶
StoredKey maps a command-line key to the form stored in the file: api-key → api_key. There is exactly one accepted spelling per setting — the dashed one, as listed by CLIKeys — so api_key, API-KEY and apikey are all reported as unrecognized. One vocabulary means one thing to document and one error to explain.
Surrounding whitespace is trimmed: that is not a spelling, and leaving it in produces a baffling `unrecognized key " api-key"`.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the settings as stored on disk, including keys this version does not recognize.
func Load ¶
Load reads the settings file. A missing file is not an error — it yields an empty Config, and nothing is created. A malformed file IS an error: falling back to defaults would silently scan against the wrong endpoint.
type Setting ¶
Setting is one recognized setting as a command sees it: the key in its stored form, the effective value, and which source won.
type Source ¶
type Source string
Source names where a resolved value came from. `config list` reports it, and it is the only observable signal about a secret, whose value is never displayed.
type Transport ¶
Transport holds the resolved settings for how to reach the API: through which proxy, and trusting which extra certificate authority. Both are empty when nothing is configured, which means "use the environment, and the system certificate pool".
func ResolveTransport ¶
ResolveTransport returns the transport settings a command should use, applying the same ladder as ResolveAPI. Separate from ResolveAPI because the two answer different questions — where to send the request, and how to get there — but resolved the same way, and each call reads the file once.
type UnknownKeyError ¶
type UnknownKeyError struct {
Key string
}
UnknownKeyError reports a key the CLI does not recognize.
func (*UnknownKeyError) Error ¶
func (e *UnknownKeyError) Error() string