Documentation
¶
Overview ¶
Package config provides configuration management for the application.
Index ¶
- Constants
- func GetAppDir() (string, error)
- func GetCacheDir() (string, error)
- func GetConfigFilePath() (string, error)
- func GetRootDir() (string, error)
- func GetRulesetsDir() (string, error)
- type Config
- func (c *Config) GetAPIKey() string
- func (c *Config) GetAPIURL() string
- func (c *Config) GetFindingsCacheBackend() string
- func (c *Config) GetFindingsCacheDSN() string
- func (c *Config) GetFindingsCacheTable() string
- func (c *Config) GetJavaJDKHomes() map[string]string
- func (c *Config) GetJavaJDKMajor() string
- func (c *Config) Initialize(opts InitOptions) error
- func (c *Config) SetAPIKey(key string) error
- func (c *Config) SetAPIURL(url string) error
- func (c *Config) Validate() error
- type InitOptions
Constants ¶
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.
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 ¶
GetAppDir returns the path to the crypto-finder directory (~/.scanoss/crypto-finder) Creates the directory if it doesn't exist.
func GetCacheDir ¶
GetCacheDir returns the path to the cache directory (~/.scanoss/crypto-finder/cache) Creates the directory if it doesn't exist.
func GetConfigFilePath ¶
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 ¶
GetRootDir returns the path to the SCANOSS root directory (~/.scanoss) Creates the directory if it doesn't exist.
func GetRulesetsDir ¶
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 (*Config) GetFindingsCacheBackend ¶ added in v0.4.0
GetFindingsCacheBackend returns the FindingsCache backend selector ("disk" or "postgres").
func (*Config) GetFindingsCacheDSN ¶ added in v0.4.0
GetFindingsCacheDSN returns the Postgres connection string used by the PostgresFindingsCache. Empty when the backend is "disk".
func (*Config) GetFindingsCacheTable ¶ added in v0.4.0
GetFindingsCacheTable returns the Postgres table name used by the PostgresFindingsCache.
func (*Config) GetJavaJDKHomes ¶ added in v0.4.0
GetJavaJDKHomes returns the configured Java JDK homes keyed by major version.
func (*Config) GetJavaJDKMajor ¶ added in v0.4.0
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):
- Set() calls (used for CLI flags) - highest
- Environment variables (SCANOSS_API_KEY, SCANOSS_API_URL, SCANOSS_FINDINGS_CACHE_BACKEND, SCANOSS_FINDINGS_CACHE_DSN, SCANOSS_FINDINGS_CACHE_TABLE)
- Config file (~/.scanoss/crypto-finder/config.json)
- Defaults (SetDefault) - lowest
The order of setup below doesn't affect priority - viper handles it automatically.
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.