config

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config provides shared configuration types and validation helpers for pipeleek. This package centralizes common configuration patterns across all platform scanners.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoBindFlags added in v0.50.0

func AutoBindFlags(cmd *cobra.Command, flagMappings map[string]string) error

AutoBindFlags automatically binds all flags from a command to Viper using the provided key mappings.

func BindCommandFlags added in v0.50.0

func BindCommandFlags(cmd *cobra.Command, baseKey string, overrides map[string]string) error

BindCommandFlags binds a command's flags (including inherited ones) to Viper keys. Keys are derived from the provided baseKey plus the normalized flag name, unless an override is provided in the overrides map (flag name -> viper key).

Example:

BindCommandFlags(cmd, "gitlab.scan", map[string]string{"gitlab": "gitlab.url"})
--threads -> gitlab.scan.threads
--gitlab  -> gitlab.url (override)

func GetBool added in v0.50.0

func GetBool(key string) bool

func GetInt added in v0.50.0

func GetInt(key string) int

func GetString added in v0.50.0

func GetString(key string) string

func GetStringSlice added in v0.50.0

func GetStringSlice(key string) []string

func GetViper added in v0.50.0

func GetViper() *viper.Viper

func InitializeViper added in v0.50.0

func InitializeViper(configFile string) error

func ParseMaxArtifactSize

func ParseMaxArtifactSize(sizeStr string) (int64, error)

ParseMaxArtifactSize parses a human-readable size string (e.g., "500MB", "1GB") into bytes.

func RequireConfigKeys added in v0.50.0

func RequireConfigKeys(keys ...string) error

RequireConfigKeys validates that all required configuration keys have non-empty values. This allows flags to be satisfied by either CLI flags or config file values. Call this after AutoBindFlags to validate required values from any source.

func ResetViper added in v0.50.0

func ResetViper()

ResetViper resets the global Viper instance for testing

func ValidateThreadCount

func ValidateThreadCount(threads int) error

ValidateThreadCount validates that the thread count is within acceptable bounds.

func ValidateToken

func ValidateToken(token string, fieldName string) error

ValidateToken validates that a token is not empty.

func ValidateURL

func ValidateURL(urlStr string, fieldName string) error

ValidateURL validates that a string is a valid URL.

Types

type AzureDevOpsConfig added in v0.50.0

type AzureDevOpsConfig struct {
	URL   string `mapstructure:"url"`
	Token string `mapstructure:"token"`
}

AzureDevOpsConfig contains Azure DevOps-specific configuration

type BitBucketConfig added in v0.50.0

type BitBucketConfig struct {
	URL      string `mapstructure:"url"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
}

BitBucketConfig contains BitBucket-specific configuration

type CommonConfig added in v0.50.0

type CommonConfig struct {
	Threads                int      `mapstructure:"threads"`
	TruffleHogVerification bool     `mapstructure:"trufflehog_verification"`
	MaxArtifactSize        string   `mapstructure:"max_artifact_size"`
	ConfidenceFilter       []string `mapstructure:"confidence_filter"`
	HitTimeout             string   `mapstructure:"hit_timeout"`
}

CommonConfig contains common configuration settings

type CommonScanOptions

type CommonScanOptions struct {
	// ConfidenceFilter filters results by confidence level
	ConfidenceFilter []string
	// MaxScanGoRoutines controls the number of concurrent scanning threads
	MaxScanGoRoutines int
	// TruffleHogVerification enables/disables TruffleHog credential verification
	TruffleHogVerification bool
	// Artifacts enables/disables artifact scanning
	Artifacts bool
	// MaxArtifactSize is the maximum size of artifacts to scan (in bytes)
	MaxArtifactSize int64
	// Owned filters to only owned repositories
	Owned bool
	// HitTimeout is the maximum time to wait for hit detection per scan item
	HitTimeout time.Duration
}

CommonScanOptions contains configuration fields that are shared across all platform scanners. This helps reduce duplication and ensures consistency in option handling.

func DefaultCommonScanOptions

func DefaultCommonScanOptions() CommonScanOptions

DefaultCommonScanOptions returns sensible default values for common scan options.

type Config added in v0.50.0

type Config struct {
	GitLab      GitLabConfig      `mapstructure:"gitlab"`
	GitHub      GitHubConfig      `mapstructure:"github"`
	BitBucket   BitBucketConfig   `mapstructure:"bitbucket"`
	AzureDevOps AzureDevOpsConfig `mapstructure:"azure_devops"`
	Gitea       GiteaConfig       `mapstructure:"gitea"`
	Common      CommonConfig      `mapstructure:"common"`
}

Config represents the complete configuration structure for pipeleek. It supports configuration for all platforms and common settings.

func UnmarshalConfig added in v0.50.0

func UnmarshalConfig() (*Config, error)

type GitHubConfig added in v0.50.0

type GitHubConfig struct {
	URL   string `mapstructure:"url"`
	Token string `mapstructure:"token"`
}

GitHubConfig contains GitHub-specific configuration

type GitLabConfig added in v0.50.0

type GitLabConfig struct {
	URL    string `mapstructure:"url"`
	Token  string `mapstructure:"token"`
	Cookie string `mapstructure:"cookie"`
}

GitLabConfig contains GitLab-specific configuration

type GiteaConfig added in v0.50.0

type GiteaConfig struct {
	URL   string `mapstructure:"url"`
	Token string `mapstructure:"token"`
}

GiteaConfig contains Gitea-specific configuration

Jump to

Keyboard shortcuts

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