config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config provides configuration loading and management for the Snyk API client, integrating with go-application-framework's configuration system.

Index

Constants

View Source
const (
	// API endpoint configuration
	KeyAPIURL     = "api"
	KeyRESTAPIURL = "rest_api_url"

	// Rate limiting configuration
	KeyRateLimitBurst  = "api_rate_limit_burst"
	KeyRateLimitPeriod = "api_rate_limit_period"

	// Retry configuration
	KeyMaxRetries     = "api_max_retries"
	KeyRetryBaseDelay = "api_retry_base_delay"
	KeyRetryMaxDelay  = "api_retry_max_delay"

	// Request configuration
	KeyUserAgent = "api_user_agent"
)

Config keys used in go-application-framework configuration.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns ~/.config/snyk-api/config.yaml (or OS equivalent).

func SaveFile

func SaveFile(path string, cfg *File) error

SaveFile writes the config file, creating parent directories if needed.

Types

type APIConfig

type APIConfig struct {
	BaseURL         string
	RestBaseURL     string
	RateLimitBurst  int
	RateLimitPeriod time.Duration
	MaxRetries      int
	RetryBaseDelay  time.Duration
	RetryMaxDelay   time.Duration
	UserAgent       string
}

APIConfig holds API client configuration loaded from the framework.

func LoadFromConfiguration

func LoadFromConfiguration(cfg configuration.Configuration) *APIConfig

LoadFromConfiguration extracts API configuration from go-application-framework configuration.

type File

type File struct {
	Current  string             `yaml:"current,omitempty"`
	Profiles map[string]Profile `yaml:"profiles,omitempty"`
}

File represents the persisted config file.

func LoadFile

func LoadFile(path string) (*File, error)

LoadFile loads a config file. Missing file returns an empty config.

type FlagOverrides

type FlagOverrides struct {
	Profile    string
	Token      string
	APIURL     string
	RestAPIURL string
	APIVersion string
	OrgID      string
	GroupID    string
	ProjectID  string
	Output     string
	PageSize   *int
	Debug      *bool
}

FlagOverrides captures CLI-level overrides.

type Profile

type Profile struct {
	Token      string `yaml:"token,omitempty"`
	APIURL     string `yaml:"api_url,omitempty"`
	RestAPIURL string `yaml:"rest_api_url,omitempty"`
	APIVersion string `yaml:"api_version,omitempty"`
	OrgID      string `yaml:"org_id,omitempty"`
	GroupID    string `yaml:"group_id,omitempty"`
	ProjectID  string `yaml:"project_id,omitempty"`
	Output     string `yaml:"output,omitempty"`
	PageSize   int    `yaml:"page_size,omitempty"`
	Debug      bool   `yaml:"debug,omitempty"`
}

Profile holds user-defined defaults for a CLI profile.

type Resolved

type Resolved struct {
	ProfileName string
	Token       string
	APIURL      string
	RestAPIURL  string
	APIVersion  string
	OrgID       string
	GroupID     string
	ProjectID   string
	Output      string
	PageSize    int
	Debug       bool
}

Resolved holds the merged configuration after applying precedence.

func Resolve

func Resolve(fileCfg *File, flags FlagOverrides, env map[string]string) Resolved

Resolve merges flags > env > profile > defaults. The profile name itself is resolved by flags.profile, then SNYK_API_PROFILE, then file.Current, falling back to "default".

Jump to

Keyboard shortcuts

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