config

package
v0.9.18 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Apache-2.0 Imports: 14 Imported by: 7

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. 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 Requirements = map[string][]string{
	"Storage":    []string{"Provider"},
	"APIM":       []string{"Provider"},
	"Kubernetes": []string{"AuthorisedContainerRegistry", "UnauthorisedContainerImage"},
}

Requirements is used to dictate the required config vars for each service pack

View Source
var Spinner *spinner.Spinner

Spinner holds the current state of the CLI spinner

Functions

func GetPacks

func GetPacks() (keys []string)

GetPacks returns a list of pack names (as specified by internal/config/requirements.go)

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 SetLogFilter

func SetLogFilter(minLevel string, writer io.Writer)

SetLogFilter will override the minimum log level.

func ValidateConfigPath

func ValidateConfigPath(path string) error

ValidateConfigPath simply ensures the file exists

Types

type APIM added in v0.8.0

type APIM struct {
	Provider string  `yaml:"Provider"` // Placeholder!
	Probes   []Probe `yaml:"Probes"`
	// contains filtered or unexported fields
}

APIM service pack config options

func (APIM) IsExcluded added in v0.8.0

func (a APIM) IsExcluded() bool

IsExcluded will log and return exclusion configuration

type Azure

type Azure struct {
	Excluded         string `yaml:"Excluded"`
	TenantID         string `yaml:"TenantID"`
	SubscriptionID   string `yaml:"SubscriptionID"`
	ClientID         string `yaml:"ClientID"`
	ClientSecret     string `yaml:"ClientSecret"`
	ResourceGroup    string `yaml:"ResourceGroup"`
	ResourceLocation string `yaml:"ResourceLocation"`
	ManagementGroup  string `yaml:"ManagementGroup"`
}

Azure config options that may be required by any service pack

type CloudProviders

type CloudProviders struct {
	Azure Azure `yaml:"Azure"`
}

CloudProviders config options

type Excludable

type Excludable interface {
	IsExcluded() bool
}

Excludable is used for testing purposes only

type K8sAzure added in v0.9.0

type K8sAzure struct {
	DefaultNamespaceAIB string
	IdentityNamespace   string
}

K8sAzure contains Azure-specific options for the Kubernetes service pack

type Kubernetes

type Kubernetes struct {
	KeepPods                          string   `yaml:"KeepPods"` // TODO: Change type to bool, this would allow us to remove logic from kubernetes.GetKeepPodsFromConfig()
	Probes                            []Probe  `yaml:"Probes"`
	KubeConfigPath                    string   `yaml:"KubeConfig"`
	KubeContext                       string   `yaml:"KubeContext"`
	SystemClusterRoles                []string `yaml:"SystemClusterRoles"`
	AuthorisedContainerRegistry       string   `yaml:"AuthorisedContainerRegistry"`
	UnauthorisedContainerImage        string   `yaml:"UnauthorisedContainerImage"`
	ProbeImage                        string   `yaml:"ProbeImage"`
	ContainerRequiredDropCapabilities []string `yaml:"ContainerRequiredDropCapabilities"`
	ContainerAllowedAddCapabilities   []string `yaml:"ContainerAllowedAddCapabilities"`
	ApprovedVolumeTypes               []string `yaml:"ApprovedVolumeTypes"`
	UnapprovedHostPort                string   `yaml:"UnapprovedHostPort"`
	SystemNamespace                   string   `yaml:"SystemNamespace"`
	ProbeNamespace                    string   `yaml:"ProbeNamespace"`
	DashboardPodNamePrefix            string   `yaml:"DashboardPodNamePrefix"`
	Azure                             K8sAzure `yaml:"Azure"`
	// contains filtered or unexported fields
}

Kubernetes config options

func (Kubernetes) IsExcluded

func (k Kubernetes) IsExcluded() bool

IsExcluded will log and return exclusion configuration

type Meta

type Meta struct {
	RunOnly string // set by CLI 'run' option
}

Meta config options

type Probe

type Probe struct {
	Name      string     `yaml:"Name"`
	Excluded  string     `yaml:"Excluded"`
	Scenarios []Scenario `yaml:"Scenarios"`
}

Probe config options

func (Probe) IsExcluded

func (p Probe) IsExcluded() bool

IsExcluded will log and return exclusion configuration

type Scenario

type Scenario struct {
	Name     string `yaml:"Name"`
	Excluded string `yaml:"Excluded"`
}

Scenario config options

func (Scenario) IsExcluded

func (s Scenario) IsExcluded() bool

IsExcluded will log and return exclusion configuration

type ServicePacks

type ServicePacks struct {
	Kubernetes Kubernetes `yaml:"Kubernetes"`
	Storage    Storage    `yaml:"Storage"`
	APIM       APIM       `yaml:"APIM"`
}

ServicePacks config options

type Storage

type Storage struct {
	Provider string  `yaml:"Provider"` // Placeholder!
	Probes   []Probe `yaml:"Probes"`
	// contains filtered or unexported fields
}

Storage service pack config options

func (Storage) IsExcluded

func (s Storage) IsExcluded() bool

IsExcluded will log and return exclusion configuration

type VarOptions added in v0.9.0

type VarOptions struct {
	// NOTE: Env and Defaults are ONLY available if corresponding logic is added to defaults.go
	ServicePacks              ServicePacks   `yaml:"ServicePacks"`
	CloudProviders            CloudProviders `yaml:"CloudProviders"`
	OutputType                string         `yaml:"OutputType"`
	WriteDirectory            string         `yaml:"WriteDirectory"`
	AuditEnabled              string         `yaml:"AuditEnabled"`
	LogLevel                  string         `yaml:"LogLevel"`
	OverwriteHistoricalAudits string         `yaml:"OverwriteHistoricalAudits"`
	TagExclusions             []string       `yaml:"TagExclusions"`
	WriteConfig               string         `yaml:"WriteConfig"`
	Tags                      string         // set by flags
	VarsFile                  string         // set by flags only
	NoSummary                 bool           // set by flags only
	Silent                    bool           // set by flags only
	Meta                      Meta           // set by CLI options only
	ResultsFormat             string         // set by flags only
}

VarOptions contains all top-level config vars

var Vars VarOptions

Vars is a singleton instance of VarOptions

func NewConfig

func NewConfig(c string) (VarOptions, error)

NewConfig overrides the current config.Vars values

func (*VarOptions) AuditDir added in v0.9.0

func (ctx *VarOptions) AuditDir() string

AuditDir creates and returns -audit- directory within WriteDirectory

func (*VarOptions) CucumberDir added in v0.9.0

func (ctx *VarOptions) CucumberDir() string

CucumberDir creates and returns -cucumber- directory within WriteDirectory

func (*VarOptions) GetTags added in v0.9.0

func (ctx *VarOptions) GetTags() string

GetTags returns Tags, prioritising command line parameter over vars file

func (*VarOptions) GetWriteDirectory added in v0.9.0

func (ctx *VarOptions) GetWriteDirectory() string

GetWriteDirectory creates and returns the output folder specified in settings

func (*VarOptions) LogConfigState added in v0.9.0

func (ctx *VarOptions) LogConfigState()

LogConfigState will write the config file to the write directory

func (*VarOptions) Overwrite added in v0.9.0

func (ctx *VarOptions) Overwrite() bool

Overwrite returns the string value of the OverwriteHistoricalAudits in bool format

func (*VarOptions) SetTags added in v0.9.0

func (ctx *VarOptions) SetTags(tags map[string][]string)

SetTags will parse the tags specified in Vars.Tags

func (*VarOptions) TmpDir added in v0.9.0

func (ctx *VarOptions) TmpDir() string

TmpDir creates and returns -tmp- directory within WriteDirectory

Jump to

Keyboard shortcuts

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