config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

Config Engineering Notes

Internal code to manage config, including Cloud Driver parameters and Test Packs

Log Filter Guidelines

Probr Log Levels:

  • ERROR - Behavior that is a result of a definite misconfiguration or code failure
  • WARN - Behavior that is likely due to a misconfiguration, but is not fatal
  • NOTICE - (1) User config information to prevent confusion, or (2) behavior that could result from a misconfiguration but also may be intentional
  • INFO - Non-verbose information that doesn't fit the above criteria
  • DEBUG - Any potentially helpful information that doesn't fit the above criteria

Multi-line logs should be formatted prior to log.Printf(...). By using this command multiple times, each line will get a separate timestamp and will appear to be separate entries.

For example, Results: could be read as if an empty string was being output.

However, by misusing log.Printf we may cause a similar appearance:

log.Printf("[NOTICE] Results:")
log.Printf("[NOTICE] %s", myVar)
// Prints:
// 2020/09/28 11:18:01 [NOTICE] Results:
// 2020/09/28 11:18:01 [NOTICE] {"some": "information"}

Config

Configuration docs are located in the README at the top level of the probr repository.

When creating new config vars, remember to do the following:

  1. Add an entry to the struct ConfigVars in internal/config/config.go
  2. Add an entry (matching the config vars struct) to setEnvOrDefaults in internal/config/defaults.go
  3. Add logic (matching the defaults entry) to internal/config/getters.go
  4. If appropriate, add logic to cmd/probr-cli/flags.go

By following the above steps, you will have accomplished the following:

  1. A new variable will be available across the entire probr codebase
  2. That variable will have a default value
  3. An environment variable can be set to override the default value
  4. The env var can be overridden by a provided yaml config file
  5. If set, a flag can be used to override the all other values

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Spinner *spinner.Spinner

Functions

func Init

func Init(configPath string) error

Init will override config.Vars with the content retrieved from a filepath

func LineBreakReplacer

func LineBreakReplacer(s string) string

LineBreakReplacer replaces carriage return (\r), linefeed (\n), formfeed (\f) and other similar characters with a space.

func LogConfigState added in v0.3.0

func LogConfigState()

func SetLogFilter added in v0.4.0

func SetLogFilter(minLevel string, writer io.Writer)

Override the minmium log level.

func ValidateConfigPath

func ValidateConfigPath(path string) error

ValidateConfigPath simply ensures the file exists

Types

type ConfigVars

type ConfigVars struct {
	// NOTE: Env and Defaults are ONLY available if corresponding logic is added to defaults.go and getters.go
	ServicePacks                  servicePacks   `yaml:"ServicePacks"`
	CloudProviders                cloudProviders `yaml:"CloudProviders"`
	OutputType                    string         `yaml:"OutputType"`
	CucumberDir                   string         `yaml:"CucumberDir"`
	AuditDir                      string         `yaml:"AuditDir"`
	AuditEnabled                  string         `yaml:"AuditEnabled"`
	LogLevel                      string         `yaml:"LogLevel"`
	OverwriteHistoricalAudits     string         `yaml:"OverwriteHistoricalAudits"`
	AuthorisedContainerRegistry   string         `yaml:"AuthorisedContainerRegistry"`
	UnauthorisedContainerRegistry string         `yaml:"UnauthorisedContainerRegistry"`
	ProbeImage                    string         `yaml:"ProbeImage"`
	Probes                        []Probe        `yaml:"Probes"`
	Tags                          string         `yaml:"Tags"`
	VarsFile                      string         // set by flags only
	NoSummary                     bool           // set by flags only
	Silent                        bool           // set by flags only
	TagExclusions                 []string       // set programatically
}

ConfigVars contains all possible config vars

var Vars ConfigVars

Vars is a singleton instance of ConfigVars

func NewConfig

func NewConfig(c string) (ConfigVars, error)

NewConfig overrides the current config.Vars values

func (*ConfigVars) GetTags added in v0.3.0

func (ctx *ConfigVars) GetTags() string

GetTags parses Tags with TagExclusions

func (*ConfigVars) HandleExclusion added in v0.3.0

func (ctx *ConfigVars) HandleExclusion(name, justification string)

type Probe added in v0.3.0

type Probe struct {
	Name          string `yaml:"Name"`
	Excluded      bool   `yaml:"Excluded"`
	Justification string `yaml:"Justification"`
}

Jump to

Keyboard shortcuts

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