config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: GPL-2.0, GPL-2.0-only Imports: 9 Imported by: 0

Documentation

Overview

Package config provides configuration management for the application.

Index

Constants

View Source
const (
	DefaultAPIURL           = "https://api.scanoss.com"
	DefaultTimeout          = 30 * time.Second
	DefaultMaxRetries       = 3
	DefaultRetryDelay       = 5 * time.Second
	DefaultCacheTTL         = 7 * 24 * time.Hour  // 7 days for pinned versions
	DefaultLatestCacheTTL   = 24 * time.Hour      // 24 hours for @latest
	DefaultMaxStaleCacheAge = 30 * 24 * time.Hour // 30 days for stale cache fallback
	MaxStaleCacheAge        = 90 * 24 * time.Hour // Maximum allowed: 90 days

	// DefaultFindingsCacheBackend is the FindingsCache backend used when no
	// override is provided via flag, env, or config file.
	DefaultFindingsCacheBackend = "disk"

	// DefaultFindingsCacheTable is the Postgres table name used by the
	// PostgresFindingsCache when no override is provided.
	DefaultFindingsCacheTable = "findings_cache"
)

Default configuration values.

View Source
const (
	// RootDirName is the root directory for SCANOSS configuration.
	RootDirName = ".scanoss"

	// AppDirName is the application-specific directory.
	AppDirName = "crypto-finder"

	// ConfigFileName is the configuration file name.
	ConfigFileName = "config.json"

	// CacheDirName is the cache directory name.
	CacheDirName = "cache"

	// RulesetsDirName is the rulesets cache directory name.
	RulesetsDirName = "rulesets"
)

Variables

This section is empty.

Functions

func GetAppDir

func GetAppDir() (string, error)

GetAppDir returns the path to the crypto-finder directory (~/.scanoss/crypto-finder) Creates the directory if it doesn't exist.

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the path to the cache directory (~/.scanoss/crypto-finder/cache) Creates the directory if it doesn't exist.

func GetConfigFilePath

func GetConfigFilePath() (string, error)

GetConfigFilePath returns the path to the config file (~/.scanoss/crypto-finder/config.json) Does not create the file if it doesn't exist.

func GetRootDir

func GetRootDir() (string, error)

GetRootDir returns the path to the SCANOSS root directory (~/.scanoss) Creates the directory if it doesn't exist.

func GetRulesetsDir

func GetRulesetsDir() (string, error)

GetRulesetsDir returns the path to the rulesets cache directory (~/.scanoss/crypto-finder/cache/rulesets) Creates the directory if it doesn't exist.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config manages application configuration.

func GetInstance

func GetInstance() *Config

GetInstance returns the singleton config instance.

func (*Config) GetAPIKey

func (c *Config) GetAPIKey() string

GetAPIKey returns the configured API key.

func (*Config) GetAPIURL

func (c *Config) GetAPIURL() string

GetAPIURL returns the configured API URL.

func (*Config) GetFindingsCacheBackend added in v0.4.0

func (c *Config) GetFindingsCacheBackend() string

GetFindingsCacheBackend returns the FindingsCache backend selector ("disk" or "postgres").

func (*Config) GetFindingsCacheDSN added in v0.4.0

func (c *Config) GetFindingsCacheDSN() string

GetFindingsCacheDSN returns the Postgres connection string used by the PostgresFindingsCache. Empty when the backend is "disk".

func (*Config) GetFindingsCacheTable added in v0.4.0

func (c *Config) GetFindingsCacheTable() string

GetFindingsCacheTable returns the Postgres table name used by the PostgresFindingsCache.

func (*Config) GetJavaJDKHomes added in v0.4.0

func (c *Config) GetJavaJDKHomes() map[string]string

GetJavaJDKHomes returns the configured Java JDK homes keyed by major version.

func (*Config) GetJavaJDKMajor added in v0.4.0

func (c *Config) GetJavaJDKMajor() string

GetJavaJDKMajor returns the configured Java JDK major selector.

func (*Config) Initialize

func (c *Config) Initialize(opts InitOptions) error

Initialize loads configuration from multiple sources. Viper automatically handles priority (highest to lowest):

  1. Set() calls (used for CLI flags) - highest
  2. Environment variables (SCANOSS_API_KEY, SCANOSS_API_URL, SCANOSS_FINDINGS_CACHE_BACKEND, SCANOSS_FINDINGS_CACHE_DSN, SCANOSS_FINDINGS_CACHE_TABLE)
  3. Config file (~/.scanoss/crypto-finder/config.json)
  4. Defaults (SetDefault) - lowest

The order of setup below doesn't affect priority - viper handles it automatically.

func (*Config) SetAPIKey

func (c *Config) SetAPIKey(key string) error

SetAPIKey updates the API key and persists to config file.

func (*Config) SetAPIURL

func (c *Config) SetAPIURL(url string) error

SetAPIURL updates the API URL and persists to config file.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration.

type InitOptions added in v0.4.0

type InitOptions struct {
	//nolint:gosec // G117: APIKey is a runtime override supplied by the operator, not a hardcoded secret.
	APIKey               string
	APIURL               string
	FindingsCacheBackend string
}

InitOptions groups the runtime overrides accepted by Initialize so that adding new flag-driven configuration does not change the function signature at every call site.

Jump to

Keyboard shortcuts

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