environment

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetConfig

func SetConfig(ctx context.Context, cfg *Config) context.Context

SetConfig stores the environment configuration in the context.

func SetSharedConfig

func SetSharedConfig(ctx context.Context, c SharedConfig) context.Context

Types

type Config

type Config struct {
	// API Keys (optional, increase rate limits)
	NVDAPIKey   string `env:"NVD_API_KEY" envDefault:""`
	GitHubToken string `env:"GITHUB_TOKEN" envDefault:""`

	// Cache Configuration
	CacheBackend    string `env:"CACHE_BACKEND" envDefault:"filesystem"`
	CacheMaxAgeDays int    `env:"HTTP_CACHE_MAX_AGE_DAYS" envDefault:"2"`

	MetadataBackend  string `env:"METADATA_BACKEND" envDefault:"filesystem"`
	BackendGCSBucket string `env:"BACKEND_GCS_BUCKET" envDefault:""`
	KeyPrefix        string `env:"GCS_PREFIX" envDefault:"v3"`
	HTTPGCSBucket    string `env:"HTTP_GCS_BUCKET" envDefault:""`
	HTTPGCSPrefix    string `env:"HTTP_GCS_PREFIX" envDefault:"v1"`

	ValkeyURL string `env:"VALKEY_URL" envDefault:"redis://localhost:6379"`

	// HIGH_MEM_SERVER is the URL of a high-memory server running the /artifact endpoint.
	// When set, artifact extraction is delegated to this server instead of running locally.
	// No default: the open-source CLI extracts locally; only the hosted server sets this.
	HighMemServer string `env:"HIGH_MEM_SERVER" envDefault:""`

	// HIGH_MEM_AUDIENCE is the audience for ID token authentication.
	// Defaults to "risk-guard-api" which is configured as a custom audience on the Cloud Run service.
	HighMemAudience string `env:"HIGH_MEM_AUDIENCE" envDefault:"risk-guard-api"`

	GoogleCloudProject string `env:"GOOGLE_CLOUD_PROJECT" envDefault:""`

	ScorePackageWorkflow string `env:"SCORE_PACKAGE_WORKFLOW" envDefault:""`
	ScoreSourceWorkflow  string `env:"SCORE_SOURCE_WORKFLOW" envDefault:""`
	ScoreDepsWorkflow    string `env:"SCORE_DEPS_WORKFLOW" envDefault:""`

	ServiceName string `env:"SERVICE_NAME" envDefault:"risk-guard"`

	SecureGit bool `env:"SECURE_GIT" envDefault:"false"`

	CloneTimeoutSeconds int `env:"CLONE_TIMEOUT_SECONDS" envDefault:"30"`
}

Config holds all validated environment variables for Risk Guard. This provides type-safe access to configuration with validation and prevents runtime errors from missing or invalid environment variables.

func Load

func Load() (*Config, error)

Load validates and returns environment configuration. It automatically loads .env file if present in the current directory. Returns an error if any validation fails.

func (*Config) Clone

func (c *Config) Clone() *Config

func (*Config) GetCacheMaxAge

func (c *Config) GetCacheMaxAge() time.Duration

GetCacheMaxAge returns the cache max age as a time.Duration.

func (*Config) GetCloneTimeout added in v0.1.0

func (c *Config) GetCloneTimeout() time.Duration

GetCloneTimeout returns the per-git-clone timeout. A value <= 0 falls back to the default.

func (*Config) GetHighMemAudience

func (c *Config) GetHighMemAudience() string

func (*Config) GetHighMemServer

func (c *Config) GetHighMemServer() string

func (*Config) GetSecureGit

func (c *Config) GetSecureGit() bool

func (*Config) String

func (c *Config) String() string

String returns a string representation of the configuration with secrets redacted. This is safe to use in logs and error messages.

type SharedConfig

type SharedConfig interface {
	GetSecureGit() bool
	GetCacheMaxAge() time.Duration
	GetCloneTimeout() time.Duration
}

SharedConfig is the minimal config contract used by code shared between the local CLI and the server. Each binary supplies its own implementation.

func GetSharedConfig

func GetSharedConfig(ctx context.Context) SharedConfig

GetSharedConfig retrieves the shared config from the context. Panics if missing to enforce initialization in the root command.

Jump to

Keyboard shortcuts

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