Documentation
¶
Index ¶
- Constants
- func Dir() (string, error)
- func HasConfig() bool
- func HasToken() bool
- func IndicesDir() (string, error)
- func Init()
- func IsCI() bool
- func RemoveToken() error
- func SaveToken(token string) error
- func SetIndicesDir(dir string) error
- func Token() string
- func TokenFromEnv() bool
- func ValidToken(token string) bool
- type Config
- type Environment
- type Resolution
- type TokenSource
Constants ¶
const EnvToken = "VC_TOKEN"
EnvToken is the legacy token variable, consulted first. See Resolve.
const EnvTokenAPI = "VULNCHECK_API_TOKEN"
EnvTokenAPI is the name shared with the VulnCheck SDKs and MCP server, and the one user-facing copy should teach. EnvToken keeps precedence over it.
Variables ¶
This section is empty.
Functions ¶
func IndicesDir ¶ added in v0.7.0
func RemoveToken ¶
func RemoveToken() error
RemoveToken clears the saved token, preserving every other setting. Note this only clears the *config file*; if a token environment variable is set the caller remains authenticated. Check Resolve().FromEnv() before claiming otherwise.
func SaveToken ¶
SaveToken writes token to vulncheck.yaml, preserving every other setting. Trimmed first: a padded paste saved verbatim fails every later run.
func SetIndicesDir ¶ added in v0.7.0
func TokenFromEnv ¶ added in v0.2.1
func TokenFromEnv() bool
func ValidToken ¶
Types ¶
type Environment ¶
type Resolution ¶ added in v1.2.0
type Resolution struct {
// Token is the token that will actually be sent to the API, or "" if none.
Token string
// Source says which location Token came from.
Source TokenSource
// Shadowed reports that a token environment variable is overriding a
// *different* token saved in vulncheck.yaml. Only true when both are
// present and their values differ — identical values cannot confuse
// anyone, and CI (env set, no config file) is never shadowed, so this
// stays quiet in automation.
Shadowed bool
// ConfigToken is the token stored in vulncheck.yaml, whether or not it
// won. Used to report shadowing; never render it to the user.
ConfigToken string
// EnvVar names the variable Token came from, or "" when Source is not
// SourceEnv. Messages must use this rather than a fixed constant, or they
// will name the wrong variable to half the users who see them.
EnvVar string
// EnvVarsSet names every token variable holding a usable value, in
// precedence order; EnvVarsSet[0] == EnvVar. Hints must clear all of them —
// clearing only the winner hands the win to the next.
EnvVarsSet []string
}
Resolution is the outcome of resolving a token from all sources. It is the single place precedence is decided; Token/HasToken/TokenFromEnv are thin wrappers so they can never drift apart.
func Resolve ¶ added in v1.2.0
func Resolve() Resolution
Resolve determines the active token. Precedence: EnvToken, EnvTokenAPI, then vulncheck.yaml; a value failing ValidToken is absent in every position. Values are trimmed as captured — net/http rejects an Authorization header containing a newline, and a trailing space returns a plain 401.
The only place the CLI reads a token environment variable. Reading one elsewhere duplicates the ValidToken rule and the precedence order.
func (Resolution) FromEnv ¶ added in v1.2.0
func (r Resolution) FromEnv() bool
FromEnv reports whether the active token came from the environment.
func (Resolution) UnsetHint ¶ added in v1.2.0
func (r Resolution) UnsetHint() string
UnsetHint names every variable to clear, as an embeddable fragment. Shell neutral: `unset` is not a command on Windows, which the CLI ships binaries for.
type TokenSource ¶ added in v1.2.0
type TokenSource string
TokenSource identifies where the active token came from. The string values are the agent-facing contract emitted by `auth status --json`.
const ( // SourceNone means no usable token was found in either location. SourceNone TokenSource = "" // SourceEnv means the token came from one of the token environment // variables; Resolution.EnvVar reports which. SourceEnv TokenSource = "env" // SourceConfig means the token came from vulncheck.yaml. SourceConfig TokenSource = "config" )