config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigExists

func ConfigExists(filename string) bool

ConfigExists checks if a configuration file exists

func CreateDefaultConfigFile

func CreateDefaultConfigFile(filename string) error

CreateDefaultConfigFile creates a default configuration file

func GetConfigFilePath

func GetConfigFilePath(configFile string) string

GetConfigFilePath returns the path to the configuration file

func SaveConfig

func SaveConfig(config *Config, filename string) error

SaveConfig saves the configuration to a YAML file

func ValidateConfig

func ValidateConfig(config *Config) error

ValidateConfig validates the entire configuration

Types

type APIKeyAuth

type APIKeyAuth struct {
	Header string `yaml:"header" mapstructure:"header"`
	Value  string `yaml:"value" mapstructure:"value"`
}

APIKeyAuth represents API key authentication via custom headers

type AlertChannelConfig

type AlertChannelConfig struct {
	Type     string                 `yaml:"type" mapstructure:"type"` // slack, email, webhook
	Name     string                 `yaml:"name" mapstructure:"name"`
	Enabled  bool                   `yaml:"enabled" mapstructure:"enabled"`
	Settings map[string]interface{} `yaml:"settings" mapstructure:"settings"`
}

AlertChannelConfig represents a single alert channel

type AlertRuleConfig

type AlertRuleConfig struct {
	Name      string   `yaml:"name" mapstructure:"name"`
	Severity  []string `yaml:"severity" mapstructure:"severity"`             // low, medium, high, critical
	Endpoints []string `yaml:"endpoints,omitempty" mapstructure:"endpoints"` // empty means all
	Channels  []string `yaml:"channels" mapstructure:"channels"`
}

AlertRuleConfig defines when alerts should be triggered

type AlertingConfig

type AlertingConfig struct {
	Enabled  bool                 `yaml:"enabled" mapstructure:"enabled"`
	Channels []AlertChannelConfig `yaml:"channels" mapstructure:"channels"`
	Rules    []AlertRuleConfig    `yaml:"rules" mapstructure:"rules"`
}

AlertingConfig contains alerting configuration

type AuthConfig

type AuthConfig struct {
	Type   AuthType    `yaml:"type" mapstructure:"type"`
	Bearer *BearerAuth `yaml:"bearer,omitempty" mapstructure:"bearer"`
	Basic  *BasicAuth  `yaml:"basic,omitempty" mapstructure:"basic"`
	APIKey *APIKeyAuth `yaml:"api_key,omitempty" mapstructure:"api_key"`
	OAuth2 *OAuth2Auth `yaml:"oauth2,omitempty" mapstructure:"oauth2"`
}

AuthConfig contains authentication configuration for endpoints

type AuthType

type AuthType string

AuthType represents the type of authentication

const (
	AuthTypeNone   AuthType = "none"
	AuthTypeBearer AuthType = "bearer"
	AuthTypeBasic  AuthType = "basic"
	AuthTypeAPIKey AuthType = "api_key"
	AuthTypeOAuth2 AuthType = "oauth2"
)

type BasicAuth

type BasicAuth struct {
	Username string `yaml:"username" mapstructure:"username"`
	Password string `yaml:"password" mapstructure:"password"`
}

BasicAuth represents HTTP Basic authentication

type BearerAuth

type BearerAuth struct {
	Token string `yaml:"token" mapstructure:"token"`
}

BearerAuth represents Bearer token authentication

type Config

type Config struct {
	Project   ProjectConfig    `yaml:"project" mapstructure:"project"`
	Global    GlobalConfig     `yaml:"global" mapstructure:"global"`
	Endpoints []EndpointConfig `yaml:"endpoints" mapstructure:"endpoints"`
	Alerting  AlertingConfig   `yaml:"alerting" mapstructure:"alerting"`
	Reporting ReportingConfig  `yaml:"reporting" mapstructure:"reporting"`
	Retention RetentionConfig  `yaml:"retention" mapstructure:"retention"`
}

Config represents the complete DriftWatch configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a configuration with sensible defaults

func LoadConfig

func LoadConfig(configFile string) (*Config, error)

LoadConfig loads configuration from file and environment variables

func (*Config) AddEndpoint

func (c *Config) AddEndpoint(endpoint EndpointConfig) error

AddEndpoint adds a new endpoint to the configuration

func (*Config) GetEnabledEndpoints

func (c *Config) GetEnabledEndpoints() []EndpointConfig

GetEnabledEndpoints returns only enabled endpoints

func (*Config) GetEndpoint

func (c *Config) GetEndpoint(id string) (*EndpointConfig, error)

GetEndpoint retrieves an endpoint by ID

func (*Config) ListEndpoints

func (c *Config) ListEndpoints() []EndpointConfig

ListEndpoints returns all endpoints

func (*Config) RemoveEndpoint

func (c *Config) RemoveEndpoint(id string) error

RemoveEndpoint removes an endpoint from the configuration

func (*Config) UpdateEndpoint

func (c *Config) UpdateEndpoint(id string, updated EndpointConfig) error

UpdateEndpoint updates an existing endpoint

type EndpointConfig

type EndpointConfig struct {
	ID              string            `yaml:"id" mapstructure:"id"`
	URL             string            `yaml:"url" mapstructure:"url"`
	Method          string            `yaml:"method" mapstructure:"method"`
	SpecFile        string            `yaml:"spec_file,omitempty" mapstructure:"spec_file"`
	Interval        time.Duration     `yaml:"interval" mapstructure:"interval"`
	Headers         map[string]string `yaml:"headers,omitempty" mapstructure:"headers"`
	Auth            *AuthConfig       `yaml:"auth,omitempty" mapstructure:"auth"`
	Validation      ValidationConfig  `yaml:"validation" mapstructure:"validation"`
	RequestBodyFile string            `yaml:"request_body_file,omitempty" mapstructure:"request_body_file"`
	Timeout         time.Duration     `yaml:"timeout,omitempty" mapstructure:"timeout"`
	RetryCount      int               `yaml:"retry_count,omitempty" mapstructure:"retry_count"`
	Enabled         bool              `yaml:"enabled" mapstructure:"enabled"`
}

EndpointConfig represents configuration for a single API endpoint

type GlobalConfig

type GlobalConfig struct {
	UserAgent   string        `yaml:"user_agent" mapstructure:"user_agent"`
	Timeout     time.Duration `yaml:"timeout" mapstructure:"timeout"`
	RetryCount  int           `yaml:"retry_count" mapstructure:"retry_count"`
	RetryDelay  time.Duration `yaml:"retry_delay" mapstructure:"retry_delay"`
	MaxWorkers  int           `yaml:"max_workers" mapstructure:"max_workers"`
	DatabaseURL string        `yaml:"database_url" mapstructure:"database_url"`
}

GlobalConfig contains global settings that apply to all endpoints

type OAuth2Auth

type OAuth2Auth struct {
	TokenURL     string            `yaml:"token_url" mapstructure:"token_url"`
	ClientID     string            `yaml:"client_id" mapstructure:"client_id"`
	ClientSecret string            `yaml:"client_secret" mapstructure:"client_secret"`
	Scopes       []string          `yaml:"scopes,omitempty" mapstructure:"scopes"`
	ExtraParams  map[string]string `yaml:"extra_params,omitempty" mapstructure:"extra_params"`
}

OAuth2Auth represents OAuth 2.0 client credentials flow

type ProjectConfig

type ProjectConfig struct {
	Name        string `yaml:"name" mapstructure:"name"`
	Description string `yaml:"description" mapstructure:"description"`
	Version     string `yaml:"version" mapstructure:"version"`
}

ProjectConfig contains project-level settings

type ReportingConfig

type ReportingConfig struct {
	RetentionDays int    `yaml:"retention_days" mapstructure:"retention_days"`
	ExportFormat  string `yaml:"export_format" mapstructure:"export_format"` // json, csv, yaml
	IncludeBody   bool   `yaml:"include_body" mapstructure:"include_body"`
}

ReportingConfig contains reporting configuration

type RetentionConfig

type RetentionConfig struct {
	MonitoringRunsDays int           `yaml:"monitoring_runs_days" mapstructure:"monitoring_runs_days"`
	DriftsDays         int           `yaml:"drifts_days" mapstructure:"drifts_days"`
	AlertsDays         int           `yaml:"alerts_days" mapstructure:"alerts_days"`
	AutoCleanup        bool          `yaml:"auto_cleanup" mapstructure:"auto_cleanup"`
	CleanupInterval    time.Duration `yaml:"cleanup_interval" mapstructure:"cleanup_interval"`
}

RetentionConfig contains data retention policies

type ValidationConfig

type ValidationConfig struct {
	StrictMode     bool     `yaml:"strict_mode" mapstructure:"strict_mode"`
	IgnoreFields   []string `yaml:"ignore_fields,omitempty" mapstructure:"ignore_fields"`
	RequiredFields []string `yaml:"required_fields,omitempty" mapstructure:"required_fields"`
}

ValidationConfig contains validation-specific settings

type ValidationError

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

ValidationError represents a configuration validation error

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors represents multiple validation errors

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Jump to

Keyboard shortcuts

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