config

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const EnvToken = "VC_TOKEN"

EnvToken is the legacy token variable, consulted first. See Resolve.

View Source
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 Dir added in v0.7.0

func Dir() (string, error)

func HasConfig

func HasConfig() bool

func HasToken

func HasToken() bool

func IndicesDir added in v0.7.0

func IndicesDir() (string, error)

func Init

func Init()

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

func SaveToken(token string) error

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 SetIndicesDir(dir string) error

func Token

func Token() string

func TokenFromEnv added in v0.2.1

func TokenFromEnv() bool

func ValidToken

func ValidToken(token string) bool

Types

type Config

type Config struct {
	Token      string
	IndicesDir string
}

type Environment

type Environment struct {
	Name string
	API  string
	WEB  string
}

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL