config

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: AGPL-3.0 Imports: 13 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 deprecated added in v0.50.0

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

Deprecated: BindCommandFlags is deprecated. Use AutoBindFlags instead, which provides explicit flag-to-key mappings without relying on baseKey concatenation.

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
--url  -> gitlab.url (override)

func BindingsFromFlags added in v0.65.0

func BindingsFromFlags(cmd *cobra.Command, platformKey string, commandKey string, overrides map[string]string) map[string]string

BindingsFromFlags generates a minimal flagBindings map based on actual flag definitions. This is a utility for commands that want to automatically derive keys from flag names. It uses the convention: flag "foo-bar" -> "platform.command.foo_bar"

func GetBool added in v0.50.0

func GetBool(key string) bool

func GetByPath added in v0.65.0

func GetByPath(data map[string]interface{}, path string) (interface{}, bool)

GetByPath retrieves a value from a nested map using dotted key notation. Example: "gitlab.runners.exploit.tags" navigates the nested structure. Returns the value (which may be a map, slice, string, etc.) and true if found. Returns nil and false if the key or any parent does not exist.

func GetEffectiveConfigPath added in v0.65.0

func GetEffectiveConfigPath(explicitPath string) string

GetEffectiveConfigPath returns the path to the resolved config file, searching the standard locations if no explicit config file was configured. Returns "" if no config file was found.

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 LoadConfigFile added in v0.65.0

func LoadConfigFile(path string) (map[string]interface{}, error)

LoadConfigFile reads a YAML config file into a mutable map. If the file does not exist or is empty, returns an empty map and no error.

func ParseBool added in v0.65.0

func ParseBool(key string, defaultValue bool) bool

ParseBool is a convenience for reading boolean config values with a fallback default.

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 SetByPath added in v0.65.0

func SetByPath(data map[string]interface{}, path string, value interface{}) error

SetByPath sets a value in a nested map using dotted key notation, creating missing parent maps as needed. Example: "gitlab.runners.exploit.tags" creates the intermediate maps gitlab → runners → exploit and sets tags. Returns an error if attempting to descend through a non-map scalar value.

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.

func WriteConfigFile added in v0.65.0

func WriteConfigFile(path string, data map[string]interface{}) (string, error)

WriteConfigFile writes a config map back to a file as deterministic YAML. It uses the yaml.v3 encoder with sorted key output to ensure consistent file ordering.

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 CommandSetup added in v0.65.0

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

CommandSetup provides a simplified interface for binding flags and validating command configuration. It eliminates repetitive boilerplate across all command Run functions.

func NewCommandSetup added in v0.65.0

func NewCommandSetup(cmd *cobra.Command) *CommandSetup

NewCommandSetup creates a new CommandSetup helper for a command. This should be called at the start of each command's Run function.

func (*CommandSetup) AddValidator added in v0.65.0

func (cs *CommandSetup) AddValidator(fn func() error) *CommandSetup

AddValidator adds a validation function to run after binding. Useful for chaining ValidateURL, ValidateToken, etc. without if-else verbosity.

func (*CommandSetup) Bind added in v0.65.0

func (cs *CommandSetup) Bind() error

Bind performs all setup: flag binding, required key validation, and custom validators. Returns early on first error.

func (*CommandSetup) MustBind added in v0.65.0

func (cs *CommandSetup) MustBind()

MustBind is like Bind but logs fatal on error. Use this for commands where failure should immediately exit the program.

func (*CommandSetup) RequireKeys added in v0.65.0

func (cs *CommandSetup) RequireKeys(keys ...string) *CommandSetup

RequireKeys marks configuration keys as required; if missing after binding, Bind() will fail.

func (*CommandSetup) WithAutoBindings added in v0.65.0

func (cs *CommandSetup) WithAutoBindings(overrides map[string]string) *CommandSetup

WithAutoBindings automatically generates flag bindings from Cobra flag definitions. It derives viper keys from flag names, with optional overrides for specific flags. Example: flag "max-artifact-size" -> key "common.max_artifact_size" (or override with map)

func (*CommandSetup) WithFlagBindings added in v0.65.0

func (cs *CommandSetup) WithFlagBindings(bindings map[string]string) *CommandSetup

WithFlagBindings sets explicit flag-to-config-key mappings, replacing any auto-derived bindings.

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"`
	Jenkins     JenkinsConfig     `mapstructure:"jenkins"`
	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

type JenkinsConfig added in v0.60.0

type JenkinsConfig struct {
	URL      string `mapstructure:"url"`
	Username string `mapstructure:"username"`
	Token    string `mapstructure:"token"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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