Documentation
¶
Overview ¶
Package config provides shared configuration types and validation helpers for pipeleek. This package centralizes common configuration patterns across all platform scanners.
Index ¶
- func AutoBindFlags(cmd *cobra.Command, flagMappings map[string]string) error
- func BindCommandFlags(cmd *cobra.Command, baseKey string, overrides map[string]string) errordeprecated
- func BindingsFromFlags(cmd *cobra.Command, platformKey string, commandKey string, ...) map[string]string
- func GetBool(key string) bool
- func GetByPath(data map[string]interface{}, path string) (interface{}, bool)
- func GetEffectiveConfigPath(explicitPath string) string
- func GetInt(key string) int
- func GetString(key string) string
- func GetStringSlice(key string) []string
- func GetViper() *viper.Viper
- func InitializeViper(configFile string) error
- func LoadConfigFile(path string) (map[string]interface{}, error)
- func ParseBool(key string, defaultValue bool) bool
- func ParseMaxArtifactSize(sizeStr string) (int64, error)
- func RequireConfigKeys(keys ...string) error
- func ResetViper()
- func SetByPath(data map[string]interface{}, path string, value interface{}) error
- func ValidateThreadCount(threads int) error
- func ValidateToken(token string, fieldName string) error
- func ValidateURL(urlStr string, fieldName string) error
- func WriteConfigFile(path string, data map[string]interface{}) (string, error)
- type AzureDevOpsConfig
- type BitBucketConfig
- type CommandSetup
- func (cs *CommandSetup) AddValidator(fn func() error) *CommandSetup
- func (cs *CommandSetup) Bind() error
- func (cs *CommandSetup) MustBind()
- func (cs *CommandSetup) RequireKeys(keys ...string) *CommandSetup
- func (cs *CommandSetup) WithAutoBindings(overrides map[string]string) *CommandSetup
- func (cs *CommandSetup) WithFlagBindings(bindings map[string]string) *CommandSetup
- type CommonConfig
- type CommonScanOptions
- type Config
- type GitHubConfig
- type GitLabConfig
- type GiteaConfig
- type JenkinsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoBindFlags ¶ added in v0.50.0
AutoBindFlags automatically binds all flags from a command to Viper using the provided key mappings.
func BindCommandFlags
deprecated
added in
v0.50.0
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 GetByPath ¶ added in v0.65.0
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
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 GetStringSlice ¶ added in v0.50.0
func InitializeViper ¶ added in v0.50.0
func LoadConfigFile ¶ added in v0.65.0
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
ParseBool is a convenience for reading boolean config values with a fallback default.
func ParseMaxArtifactSize ¶
ParseMaxArtifactSize parses a human-readable size string (e.g., "500MB", "1GB") into bytes.
func RequireConfigKeys ¶ added in v0.50.0
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
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 ¶
ValidateThreadCount validates that the thread count is within acceptable bounds.
func ValidateToken ¶
ValidateToken validates that a token is not empty.
func ValidateURL ¶
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 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
type GitHubConfig ¶ added in v0.50.0
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
GiteaConfig contains Gitea-specific configuration