appconfig

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package appconfig provides the logic for watching and reading application configuration values. Application configuration values may be static or they may be dynamically loaded from external systems such as Vault, Kubernetes, AWS SSM, etc.

Application configuration is primarily used by the entrypoint with Waypoint to load (and reload) configuration values. However, this package can be used standalone if application config wants to be pulled in anywhere.

This package is also used for getting dynamic config values and rendering them into other stanzas in the waypoint.hcl.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileContent added in v0.4.0

type FileContent struct {
	Path string
	Data []byte
}

Contains the information about a file that should be written to the application's current directory.

type Option

type Option func(w *Watcher) error

Option is used to configure NewWatcher.

func WithDynamicEnabled

func WithDynamicEnabled(v bool) Option

WithDynamicEnabled sets whether we allow dynamic sources or not. This defaults to true.

If this is disabled, then all dynamic config requests are ignored. They aren't set to empty values or anything, they simply aren't set at all.

func WithLogger

func WithLogger(log hclog.Logger) Option

WithLogger sets the logger for the Watcher. If no logger is specified, the Watcher will use the default logger (hclog.L() value).

func WithNotify

func WithNotify(ch chan<- *UpdatedConfig) Option

WithNotify notifies a channel whenever there are changes to the configuration values. This will stop receiving values when the watcher is closed.

Updates will block when attempting to send on this channel. However, while blocking, multiple updates may occur that will be coalesced to a follow up update when the channel send succeeds. Therefore, receivers will always eventually receive the full current env list, but may miss intermediate sets if they are slow to receive.

func WithOriginalEnv added in v0.6.0

func WithOriginalEnv(v []string) Option

WithOriginalEnv sets an "original" set of environment variables. When an environment variable value is unset, it will use a value from here if the key exists.

The value of v is the same as os.Environ().

func WithPlugins

func WithPlugins(ps map[string]*plugin.Instance) Option

WithPlugins sets a map of already-launched plugins to use for dynamic configuration sources.

func WithRefreshInterval

func WithRefreshInterval(d time.Duration) Option

WithRefreshInterval sets the interval between checking for new values from config source plugins that don't support edge triggers.

NOTE(mitchellh): At the time of writing, we don't support edge triggered plugins at all, but we plan to at some point so the docs reflect that.

type StaticConfigSourcer added in v0.7.0

type StaticConfigSourcer struct{}

StaticConfigSourcer can be used in tests to provide a config sourcer plugin type that simply returns the value of the `value` attribute in the `configdynamic` func call.

func (*StaticConfigSourcer) ReadFunc added in v0.7.0

func (cs *StaticConfigSourcer) ReadFunc() interface{}

func (*StaticConfigSourcer) StopFunc added in v0.7.0

func (cs *StaticConfigSourcer) StopFunc() interface{}

type UpdatedConfig added in v0.4.0

type UpdatedConfig struct {
	// Indicates that EnvVars is what the application should be using. This is an
	// explicit flag because EnvVars might be reset to nil, meaning the application
	// should remove all its configuration
	UpdatedEnv bool

	// This is the list of env vars in key=value format that the application should
	// know about.
	EnvVars []string

	// DeletedEnvVars will be a list of keys that were unset during this change
	// that was previously set. Note that if the watcher is running with
	// the `WithOriginalEnv` configuration, then an unset config MIGHT not be
	// here if it is replaced with the original value in EnvVars.
	DeletedEnvVars []string

	// Indicates that Files is what should be presented on disk. This is an explicit
	// flag to match UpdatedEnv.
	UpdatedFiles bool

	// Files is the list of file paths and contents that the should be on disk for the
	// application to read.
	Files []*FileContent
}

UpdatedConfig contains any updated configuration that needs to be applied to the application.

type Watcher

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

Watcher reads application configuration values and watches for any changes.

The values that the watcher is watching can be added, removed, or updated along with any configuration sources (how to read from external systems such as Vault).

func NewWatcher

func NewWatcher(opts ...Option) (*Watcher, error)

NewWatcher creates a new Watcher instance.

This will immediately start the background goroutine for reading and updating configuration values, even if no initial values are provided. You must call Close to properly clean up resources used by the Watcher.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops all the background goroutines that this watcher started. This will block until all the background tasks have exited.

func (*Watcher) Next

func (w *Watcher) Next(ctx context.Context, iter uint64) (*UpdatedConfig, uint64, error)

Next returns the next values for the configuration AFTER the given iterator value iter. A value of 0 can be used for iter for a first read.

The return value will be the configuration values in env format (KEY=VALUE), the current iterator value that you should use with the next call to Next, and any error if it occurred.

The ctx parameter can be used for timeouts, cancellation, etc. If the context is closed, this will return the context error.

func (*Watcher) UpdateSources

func (w *Watcher) UpdateSources(ctx context.Context, v []*pb.ConfigSource) error

UpdateSources updates the configuration sources for the watcher. The behavior and semantics are identical to UpdateVars but for configuration sources, so please see the documentation for UpdateVars for more details.

func (*Watcher) UpdateVars

func (w *Watcher) UpdateVars(ctx context.Context, v []*pb.ConfigVar) error

UpdateVars updates the variables for the watcher. This replaces all the previous set variables.

This may block for some time waiting for the update loop to accept our changes. The ctx parameter can be used as a timeout. If the context is cancelled, the error returned will be the context error.

Jump to

Keyboard shortcuts

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