configuration

package
v0.135.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package configuration is a generic configuration and secret management API.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a configuration entry is not found or cannot be resolved.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Ref
	Accessor *url.URL
}

type EnvarProvider

type EnvarProvider[T EnvarType] struct {
	Envar bool `help:"Print configuration as environment variables." xor:"configwriter" group:"Provider:"`
}

EnvarProvider is a configuration provider that reads from environment variables.

func (EnvarProvider[T]) Delete

func (e EnvarProvider[T]) Delete(ctx context.Context, ref Ref) error

func (EnvarProvider[T]) Key

func (EnvarProvider[T]) Key() string

func (EnvarProvider[T]) Load

func (e EnvarProvider[T]) Load(ctx context.Context, ref Ref, key *url.URL) ([]byte, error)

func (EnvarProvider[T]) Store

func (e EnvarProvider[T]) Store(ctx context.Context, ref Ref, value []byte) (*url.URL, error)

func (EnvarProvider[T]) Writer

func (e EnvarProvider[T]) Writer() bool

type EnvarType

type EnvarType interface {
	// contains filtered or unexported methods
}

type EnvarTypeConfig

type EnvarTypeConfig struct{}

type EnvarTypeSecrets

type EnvarTypeSecrets struct{}

type FromConfig

type FromConfig struct{}

type FromConfigOrSecrets

type FromConfigOrSecrets interface {
	// contains filtered or unexported methods
}

type FromSecrets

type FromSecrets struct{}

type InlineProvider

type InlineProvider struct {
	Inline bool `help:"Write values inline in the configuration file." group:"Provider:" xor:"configwriter"`
}

InlineProvider is a configuration provider that stores configuration in its key.

func (InlineProvider) Delete

func (InlineProvider) Delete(ctx context.Context, ref Ref) error

func (InlineProvider) Key

func (InlineProvider) Key() string

func (InlineProvider) Load

func (InlineProvider) Load(ctx context.Context, ref Ref, key *url.URL) ([]byte, error)

func (InlineProvider) Store

func (InlineProvider) Store(ctx context.Context, ref Ref, value []byte) (*url.URL, error)

func (InlineProvider) Writer

func (i InlineProvider) Writer() bool

type KeychainProvider

type KeychainProvider struct {
	Keychain bool `help:"Write to the system keychain." group:"Provider:" xor:"configwriter"`
}

func (KeychainProvider) Delete

func (k KeychainProvider) Delete(ctx context.Context, ref Ref) error

func (KeychainProvider) Key

func (k KeychainProvider) Key() string

func (KeychainProvider) Load

func (k KeychainProvider) Load(ctx context.Context, ref Ref, key *url.URL) ([]byte, error)

func (KeychainProvider) Store

func (k KeychainProvider) Store(ctx context.Context, ref Ref, value []byte) (*url.URL, error)

func (KeychainProvider) Writer

func (k KeychainProvider) Writer() bool

type Manager

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

Manager is a high-level configuration manager that abstracts the details of the Resolver and Provider interfaces.

func New

func New(ctx context.Context, resolver Resolver, providers []Provider) (*Manager, error)

New configuration manager.

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, ref Ref, value any) error

Get a configuration value from the active providers.

"value" must be a pointer to a Go type that can be unmarshalled from JSON.

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]Entry, error)

func (*Manager) Mutable

func (m *Manager) Mutable() error

Mutable returns an error if the configuration manager doesn't have a writeable provider configured.

func (*Manager) Set

func (m *Manager) Set(ctx context.Context, ref Ref, value any) error

Set a configuration value in the active writing provider.

"value" must be a Go type that can be marshalled to JSON.

func (*Manager) Unset

func (m *Manager) Unset(ctx context.Context, ref Ref) error

Unset a configuration value in all providers.

type MutableProvider

type MutableProvider interface {
	Provider
	// Writer returns true if this provider should be used to store configuration.
	//
	// Only one provider should return true.
	//
	// To be usable from the CLI, each provider must be a Kong-compatible struct
	// containing a flag that this method should return. For example:
	//
	// 	type InlineProvider struct {
	// 		Inline bool `help:"Write values inline." group:"Provider:" xor:"configwriter"`
	// 	}
	//
	//	func (i InlineProvider) Writer() bool { return i.Inline }
	//
	// The "xor" tag is used to ensure that only one writer is selected.
	Writer() bool
	// Store a configuration value and return its key.
	Store(ctx context.Context, ref Ref, value []byte) (*url.URL, error)
	// Delete a configuration value.
	Delete(ctx context.Context, ref Ref) error
}

A MutableProvider is a Provider that can update configuration.

type OnePasswordProvider

type OnePasswordProvider struct {
	OnePassword bool `name:"op" help:"Write 1Password secret references - does not write to 1Password." group:"Provider:" xor:"configwriter"`
}

OnePasswordProvider is a configuration provider that reads passwords from 1Password vaults via the "op" command line tool.

func (OnePasswordProvider) Delete

func (o OnePasswordProvider) Delete(ctx context.Context, ref Ref) error

func (OnePasswordProvider) Key

func (o OnePasswordProvider) Key() string

func (OnePasswordProvider) Load

func (o OnePasswordProvider) Load(ctx context.Context, ref Ref, key *url.URL) ([]byte, error)

func (OnePasswordProvider) Store

func (o OnePasswordProvider) Store(ctx context.Context, ref Ref, value []byte) (*url.URL, error)

func (OnePasswordProvider) Writer

func (o OnePasswordProvider) Writer() bool

type ProjectConfigResolver

type ProjectConfigResolver[From FromConfigOrSecrets] struct {
	Config string `help:"Load project configuration from TOML file." placeholder:"FILE" type:"existingfile"`
}

ProjectConfigResolver is parametric Resolver that loads values from either a project's configuration or secrets maps based on the type parameter.

func (ProjectConfigResolver[T]) Get

func (p ProjectConfigResolver[T]) Get(ctx context.Context, ref Ref) (*url.URL, error)

func (ProjectConfigResolver[T]) List

func (p ProjectConfigResolver[T]) List(ctx context.Context) ([]Entry, error)

func (ProjectConfigResolver[T]) Set

func (p ProjectConfigResolver[T]) Set(ctx context.Context, ref Ref, key *url.URL) error

func (ProjectConfigResolver[From]) Unset

func (p ProjectConfigResolver[From]) Unset(ctx context.Context, ref Ref) error

type Provider

type Provider interface {
	Key() string
	Load(ctx context.Context, ref Ref, key *url.URL) ([]byte, error)
}

Provider is a generic interface for storing and retrieving configuration and secrets.

type Ref

type Ref struct {
	Module optional.Option[string]
	Name   string
}

A Ref is a reference to a configuration value.

func NewRef

func NewRef(module, name string) Ref

NewRef creates a new Ref.

If [module] is empty, the Ref is considered to be a global configuration value.

func ParseRef

func ParseRef(s string) (Ref, error)

func (Ref) String

func (k Ref) String() string

func (*Ref) UnmarshalText

func (k *Ref) UnmarshalText(text []byte) error

type Resolver

type Resolver interface {
	Get(ctx context.Context, ref Ref) (key *url.URL, err error)
	Set(ctx context.Context, ref Ref, key *url.URL) error
	Unset(ctx context.Context, ref Ref) error
	List(ctx context.Context) ([]Entry, error)
}

A Resolver resolves configuration names to keys that are then used to load values from a Provider.

This indirection allows for the storage of configuration values to be abstracted from the configuration itself. For example, the ftl-project.toml file contains per-module and global configuration maps, but the secrets themselves may be stored in a separate secret store such as a system keychain.

Jump to

Keyboard shortcuts

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