appconfig

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MPL-2.0 Imports: 19 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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<- []string) 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 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 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) ([]string, 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
JackTT - Gopher 🇻🇳