config

package
v0.0.0-...-0f4c570 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config defines an interface for configuring a Reflow instance. This interface can be composed in multiple ways, allowing for layered configuration and also for distributions of Reflow to supply custom configuration.

A configuration is a set of keys (corresponding to toplevel keys in a YAML document). A subset of keys, defined by the package's AllKeys, correspond to objects that are configured by the Config interface. These keys may be provisioned by globally registered providers; the keys must be string formatted, and contain the (registered) name of the provider, followed by an optional comma and string argument. For example:

cache: s3,bucket,dynamodb

Configures the cache key (corresponding to Config.Cache) using the s3 provider; the argument "bucket,dynamodb" is used to configure it.

Providers may themselves look up keys to supply further configuration. For example, we may provision the cluster key (corresponding to Config.Cluster) with the ec2cluster provider, which is further configured by the ec2cluster key, for example:

cluster: ec2cluster

ec2cluster:
  zone: us-west-2a
  ami: ami-12345
  disktype: gp2
  ...

Configuration providers are registered globally, allowing for different distributions to provide different backends or configuration mechanisms.

Configuration providers may also supply additional keys (i.e., not present in the original concrete input configuration) that can be used to transmit additional configuration information across systems boundaries, for example to pass credentials from the Reflow cluster controller to individual reflowlet instances.

Index

Constants

View Source
const (
	Logger  = "logger"
	AWS     = "aws"
	AWSTool = "awstool"
	User    = "user"
	HTTPS   = "https"
	// Cache is maintained as a key for backwards compatibility purposes.
	Cache      = "cache"
	Cluster    = "cluster"
	Assoc      = "assoc"
	Repository = "repository"
)

The following are the set of keys provisioned by Config.

Variables

AllKeys defines the order in which configuration keys are provisioned. Thus, providers for keys later in the list may use configuration provided by providers for keys earlier in the list.

Functions

func Help

func Help() map[string][]Usage

Help returns Usages, organized by key.

func Marshal

func Marshal(cfg Config) ([]byte, error)

Marshal marshals the given keys into YAML-formatted bytes.

func Register

func Register(key, kind, arg, usage string, configure func(Config, string) (Config, error))

Register the configuration provider kind for the given key. The arg and usage string should describe the provider's argument.

func Unmarshal

func Unmarshal(b []byte, keys Keys) error

Unmarshal unmarshals the (YAML-configured) configuration in b into keys.

Types

type Base

type Base Keys

Base defines a base configuration with reasonable defaults where they apply.

func (Base) AWS

func (b Base) AWS() (*session.Session, error)

AWS returns new default AWS credentials.

func (Base) AWSCreds

func (b Base) AWSCreds() (*credentials.Credentials, error)

AWSCreds returns new default AWS credentials.

func (Base) AWSRegion

func (b Base) AWSRegion() (string, error)

AWSRegion the region in the key "awsregion", or else the default region us-west-2.

func (Base) AWSTool

func (b Base) AWSTool() (string, error)

AWSTool returns an error indicating no AWS CLI tool was configured.

func (Base) Assoc

func (b Base) Assoc() (assoc.Assoc, error)

Assoc returns a nil assoc.

func (Base) Cache

func (b Base) Cache() (reflow.Cache, error)

Cache returns an error indicating no cache was configured.

func (Base) CacheMode

func (b Base) CacheMode() reflow.CacheMode

CacheMode returns the default cache mode, reflow.CacheOff.

func (Base) Cluster

func (b Base) Cluster() (runner.Cluster, error)

Cluster returns an error indicating no cluster was configured.

func (Base) HTTPS

func (b Base) HTTPS() (client, server *tls.Config, err error)

HTTPS returns an error indicating no TLS certificates were configured.

func (Base) Keys

func (b Base) Keys() Keys

Keys returns the configured keys.

func (Base) Logger

func (b Base) Logger() (*log.Logger, error)

Logger returns a logger that outputs to standard error.

func (Base) Marshal

func (b Base) Marshal(keys Keys) error

Marshal populates the provided key dictionary with the keys present in this configuration. It also inlines AWS credentials so that the configuration is sealed.

func (Base) Repository

func (b Base) Repository() (reflow.Repository, error)

Repository returns a nil repository.

func (Base) User

func (b Base) User() (string, error)

User returns the current system user, or else "unknown" if not supported.

func (Base) Value

func (b Base) Value(key string) interface{}

Value returns the value for the provided key.

type Config

type Config interface {
	// CacheMode returns the configured cache mode.
	CacheMode() reflow.CacheMode

	// Assoc returns this configuration's assoc.
	Assoc() (assoc.Assoc, error)

	// Repository returns this configuration's repository.
	Repository() (reflow.Repository, error)

	// AWS returns this configuration's AWS session.
	AWS() (*session.Session, error)

	// AWSCreds provides AWS credentials directly. This differs from AWS
	// in that these credentials my be extended to user code, and should
	// be permanent.
	AWSCreds() (*credentials.Credentials, error)

	// AWSRegion returns the region to be used for all AWS operations.
	AWSRegion() (string, error)

	// AWSTool is the Docker image to be used for the AWS CLI.
	AWSTool() (string, error)

	// HTTPS returns this configuration's client and server configs.
	HTTPS() (client, server *tls.Config, err error)

	// User returns the user's id.
	User() (string, error)

	// Logger returns the configured logger.
	Logger() (*log.Logger, error)

	// Cluster returns the configured cluster.
	Cluster() (runner.Cluster, error)

	// Value returns the value of the given key.
	Value(key string) interface{}

	// Marshal marshals the current configuration into keys.
	Marshal(keys Keys) error

	// Keys returns all the keys as defined by this config.
	Keys() Keys
}

A Config provides a number of methods to mint new objects that are used in Reflow. It is safe to call each method multiple times, but they should not be called concurrently.

func Make

func Make(cfg Config) (Config, error)

Make evaluates a config's keys: for each key in AllKeys (and in the order defined by AllKeys), Make parses its provider, and provisions the key accordingly. Make returns errors if a provider cannot be found or if the provider fails to configure the given key.

func Parse

func Parse(b []byte) (Config, error)

Parse parses and provisions a configuration from the YAML-formatted bytes b.

func ParseFile

func ParseFile(filename string) (Config, error)

ParseFile reads and then parses the configuration from the provided filename.

type Flag

type Flag struct {
	Config
	// contains filtered or unexported fields
}

Flag exposes a FlagSet that overrides a set of config keys.

func (*Flag) Init

func (f *Flag) Init(flags *flag.FlagSet)

Initialize this Flag config with the provided flag set. A flag is registered for each key in the top level AllKeys.

func (*Flag) Value

func (f *Flag) Value(key string) interface{}

Value returns the flag override value for key key, or else the value from the layered configuration.

type KeyConfig

type KeyConfig struct {
	Config
	Key string
	Val interface{}
}

KeyConfig provides default values for keys that do not exist in the underlying configuration.

func (*KeyConfig) Marshal

func (c *KeyConfig) Marshal(keys Keys) error

Marshal adds the key-value pair carried by this struct into keys, if it is not added by Config.Marshal.

func (*KeyConfig) Value

func (c *KeyConfig) Value(key string) interface{}

Value returns this KeyConfig's value for the config's key, if it is not returned by the underlying configuration's Value.

type Keys

type Keys map[string]interface{}

Keys is a map of string keys to configuration values.

type OnceConfig

type OnceConfig struct {
	Config
	// contains filtered or unexported fields
}

OnceConfig memoizes the first call of the following methods to the underlying config: Assoc, Repository, AWS, AWCreds, and HTTPS.

func Once

func Once(cfg Config) *OnceConfig

Once constructs a new OnceConfig using the provided underlying configuration.

func (*OnceConfig) AWS

func (o *OnceConfig) AWS() (*session.Session, error)

AWS returns the result of the first call to the underlying configuration's AWS.

func (*OnceConfig) AWSCreds

func (o *OnceConfig) AWSCreds() (*credentials.Credentials, error)

AWSCreds returns the result of the first call to the underlying configuration's AWSCreds.

func (*OnceConfig) Assoc

func (o *OnceConfig) Assoc() (assoc.Assoc, error)

Assoc returns the result of the first call to the underlying configuration's Assoc.

func (*OnceConfig) HTTPS

func (o *OnceConfig) HTTPS() (client, server *tls.Config, err error)

HTTPS returns the result of the first call to the underlying configuration's HTTPS.

func (*OnceConfig) Repository

func (o *OnceConfig) Repository() (reflow.Repository, error)

Repository returns the result of the first call to the underlying configuration's Repository.

type Provider

type Provider struct {
	Configure        func(cfg Config, arg string) (Config, error)
	Kind, Arg, Usage string
}

A Provider provisions a single key in a configuration. Providers must be registered via the package's Register function.

func Lookup

func Lookup(key, kind string) (Provider, bool)

Lookup returns the Provider of kind for key.

type Usage

type Usage struct {
	Kind, Arg, Usage string
}

Usage contains usage information for a provider.

Directories

Path Synopsis
Package all imports all standard configuration providers in Reflow.
Package all imports all standard configuration providers in Reflow.
Package awsenvconfig configures AWS credentials to be derived from the user's environment.
Package awsenvconfig configures AWS credentials to be derived from the user's environment.
Package ec2config defines and registers configuration providers using Amazon's EC2 metadata service.
Package ec2config defines and registers configuration providers using Amazon's EC2 metadata service.
Package httpscaconfig defines a configuration provider named "httpsca" which can be used to configure HTTPS certificates via an on-disk certificate authority.
Package httpscaconfig defines a configuration provider named "httpsca" which can be used to configure HTTPS certificates via an on-disk certificate authority.
Package httpsconfig defines a configuration provider named "file" which can be used to configure HTTPS certificates.
Package httpsconfig defines a configuration provider named "file" which can be used to configure HTTPS certificates.
Package s3config defines a configuration provider named "s3" which can be used to configure S3-based caches.
Package s3config defines a configuration provider named "s3" which can be used to configure S3-based caches.

Jump to

Keyboard shortcuts

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