gconfig

package
v0.15.14 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: AGPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CLIPromptTypeString cliPromptType = iota
	CLIPromptTypeFile
	CLIPromptTypePassword
)

Variables

View Source
var ErrFieldValueMustNotBeNil error = errors.New("field value must not be nil")

Functions

This section is empty.

Types

type Config

type Config []*Field

Config is the list of variables which a provider can be configured with.

func (Config) Dump

func (c Config) Dump(ctx context.Context, dumper Dumper) (map[string]string, error)

Dump renders a map[string]string where the values are mapped in different ways based on the provided dumper

use SafeDumper to get all values with secrets redacted

SSMDumper first pushes any updated secrets to ssm then returns the ssm paths to the secrets

func (Config) FindFieldByKey

func (c Config) FindFieldByKey(key string) (*Field, error)

FindFieldByKey looks up a field by its key. If the field doesn't exist in the config, an error is returned.

func (Config) Load

func (c Config) Load(ctx context.Context, l Loader) error

Load configuration using a Loader.

type Configer

type Configer interface {
	Config() Config
}

type Dumper

type Dumper interface {
	Dump(ctx context.Context, cfg Config) (map[string]string, error)
}

type Field

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

Field represents a key-value pair in a configuration to create a Field, use one of the generator functions StringField(), SecretStringField() or OptionalStringField()

func OptionalStringField

func OptionalStringField(key string, dest *OptionalStringValue, usage string, opts ...FieldOptFunc) *Field

OptionalStringField creates a new optional field with an OptionalStringValue There is no OptionalSecret type.

func SecretStringField

func SecretStringField(key string, dest *SecretStringValue, usage string, secretPathFunc SecretPathFunc, opts ...FieldOptFunc) *Field

SecretStringField creates a new field with a SecretStringValue

func StringField

func StringField(key string, dest *StringValue, usage string, opts ...FieldOptFunc) *Field

StringField creates a new field with a StringValue This field type is for non secrets for secrets, use SecretField()

func (*Field) CLIPrompt

func (s *Field) CLIPrompt() cliPromptType

func (Field) Default

func (s Field) Default() string

Default returns the default value if available else and empty string

func (Field) Description

func (s Field) Description() string

Description returns the usage string for this field

func (*Field) Get

func (s *Field) Get() string

Get returns the value if it is set, or an empty string if it is not set

func (Field) HasChanged

func (s Field) HasChanged() bool

func (Field) IsOptional

func (s Field) IsOptional() bool

IsOptional returns true if this Field is optional

func (Field) IsSecret

func (s Field) IsSecret() bool

IsSecret returns true if this Field is a secret

func (Field) Key

func (s Field) Key() string

Key returns the key for this field

func (Field) SecretPath

func (s Field) SecretPath() string

Path returns the secret path secrets loaded from config with the SSM Loader will have an secret path relevant to the loader type secrets loaded from a test loader like JSONLoader or MapLoader will not have a path and this method will return an empty string

func (*Field) Set

func (s *Field) Set(v string) error

Set the value of this string The value is only update if it has changed and Field.HasChanged will only be updated if it has changed

func (Field) String

func (s Field) String() string

String calls the Valuer.String() method for this fields value. If this field is a secret, then the response will be a redacted string. Use Field.Get() to retrieve the raw value for the field

type FieldOptFunc

type FieldOptFunc func(f *Field)

func WithCLIPrompt

func WithCLIPrompt(prompt cliPromptType) FieldOptFunc

WithCLIPrompt allows to override the type of cli prompt used to collect a value for this field when used in the context of a CLI

func WithDefaultFunc

func WithDefaultFunc(df func() string) FieldOptFunc

WithDefaultFunc sets the default function for a field The default func can be used to initialise a new config

type IncorrectArgumentsToSecretPathFuncError

type IncorrectArgumentsToSecretPathFuncError struct {
	ExpectedArgs int
	FoundArgs    int
	Key          string
}

func (IncorrectArgumentsToSecretPathFuncError) Error

type Initer

type Initer interface {
	Init(ctx context.Context) error
}

Initers perform some initialisation behaviour such as setting up API clients.

type JSONLoader

type JSONLoader struct {
	// Set this to true to skip loading secrets
	SkipLoadingSecrets bool
	Data               []byte
}

JSONLoader loads configuration from a serialized JSON payload set in the 'Data' field. if any values are prefixed with one of teh known prefixes, there are further processed e.g values prefixed with "awsssm://" will be treated as an ssm parameter and will be fetched via the aws SDK

func (JSONLoader) Load

func (l JSONLoader) Load(ctx context.Context) (map[string]string, error)

type Loader

type Loader interface {
	// Load configuration. Returns a map of config values.
	// The keys of the map are the value names, and the values
	// are the actual values of the config.
	// For example:
	//	{"orgUrl": "http://my-org.com"}
	//
	// Returns an error if loading the values fails.
	//
	// The Loader should internally handle sourcing the configuration for example from a map or environment variables
	Load(ctx context.Context) (map[string]string, error)
}

Loader loads configuration for Common Fate providers.

type MapLoader

type MapLoader struct {
	// Set this to true to skip loading secrets
	SkipLoadingSecrets bool
	Values             map[string]string
}

MapLoader looks up values in it's Values map when loading configuration.

It's useful for writing tests which use genv to configure things.

func (*MapLoader) Load

func (l *MapLoader) Load(ctx context.Context) (map[string]string, error)

Under the hood, this just uses the json loader so we get all the SSM loading capability

type OptionalStringValue

type OptionalStringValue struct {
	Value *string
}

OptionalStringValue value implements the Valuer interface

func (*OptionalStringValue) Get

func (s *OptionalStringValue) Get() string

Get the value of the string

func (*OptionalStringValue) IsSet

func (s *OptionalStringValue) IsSet() bool

Get the value of the string

func (*OptionalStringValue) Set

func (s *OptionalStringValue) Set(value string)

Set the value of the string

func (OptionalStringValue) String

func (s OptionalStringValue) String() string

String calls OptionalStringValue.Get()

type SSMDumper

type SSMDumper struct {
	Suffix string
	// secret path args are optional args passed through to the secret args functions
	SecretPathArgs []interface{}
}

SSMDumper will upload any secrets to SSM which have changed and then return the tokenised ssm path as the value

func (SSMDumper) Dump

func (d SSMDumper) Dump(ctx context.Context, c Config) (map[string]string, error)

type SSMGetter

type SSMGetter struct{}

func (SSMGetter) GetSecret

func (g SSMGetter) GetSecret(ctx context.Context, path string) (string, error)

type SafeDumper

type SafeDumper struct{}

SafeDumper implements the Dumper interface which dumps the values of the config as a map for logging or diagnostic purposes. Secret values are redacted by virtue of the String() method of the value fields.

func (SafeDumper) Dump

func (SafeDumper) Dump(ctx context.Context, c Config) (map[string]string, error)

type SecretGetter

type SecretGetter interface {
	GetSecret(ctx context.Context, path string) (string, error)
}

type SecretPathFunc

type SecretPathFunc func(args ...interface{}) (string, error)

func WithArgs

func WithArgs(path string, expectedCount int) SecretPathFunc

WithArgs returns a SecretPathFunc which is intended to be used when dynamic formatting of the path is required. For example a path refers to an id entered by a user, we only know this at dump time. The SSMDumper takes in args which are passed to the the format string

func WithNoArgs

func WithNoArgs(path string) SecretPathFunc

Use this if the path is a simple string

type SecretStringValue

type SecretStringValue struct {
	Value string
}

SecretStringValue value implements the Valuer interface, it should be used for secrets in configuration structs.

It is configured to automatically redact the secret for common logging usecases like Zap, fmt.Println and json.Marshal

func (*SecretStringValue) Get

func (s *SecretStringValue) Get() string

Get the raw value of the secret

func (SecretStringValue) MarshalJSON

func (s SecretStringValue) MarshalJSON() ([]byte, error)

MarshalJSON returns a redacted value bytes for this secret

func (*SecretStringValue) Set

func (s *SecretStringValue) Set(value string)

Set the value of the secret

func (SecretStringValue) String

func (s SecretStringValue) String() string

String returns a redacted value for this secret

type StringValue

type StringValue struct {
	Value string
}

StringValue value implements the Valuer interface

func (*StringValue) Get

func (s *StringValue) Get() string

Get the value of the string

func (*StringValue) Set

func (s *StringValue) Set(value string)

Set the value of the string

func (StringValue) String

func (s StringValue) String() string

String calls StringValue.Get()

type Tester

type Tester interface {
	// TestConfig is expected to be called on a loaded config after Init has been called.
	TestConfig(ctx context.Context) error
}

Tester interface is used to run tests on config

type Valuer

type Valuer interface {
	Set(s string)
	Get() string
	String() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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