config

package
Version: v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config provides configuration loading logic. Similar to how engines and plugins work each sub-package of implements a TransformationProvider interface, which provides a method to transform configuration values.

The top-level config file for taskcluster-worker has the following form:

transforms:
 - packet
 - env
 - secrets
config:
 ... // options to be transformed

In the example above configuration options from `config` will be transformed by the packet, env, and secrets TransformationProviders, in the order given.

After all configured TransformationProviders have run the configuration object constructed will be validated against the config schema required by the 'worker' package.

A TransformationProvider gets the configuration object and can do any transformations it desires. For example the "env" transformation will replace any object on the form {$env: VAR} with the value of the environment variable VAR.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(data []byte, monitor runtime.Monitor) (map[string]interface{}, error)

Load configuration from YAML config object.

func LoadFromFile

func LoadFromFile(filename string, monitor runtime.Monitor) (interface{}, error)

LoadFromFile will load configuration options from a YAML file and validate against the config file schema, returning an error message explaining what went wrong if unsuccessful.

func Providers

func Providers() map[string]TransformationProvider

Providers returns a map of the registered TransformationProvider.

func Register

func Register(name string, provider TransformationProvider)

Register will register a TransformationProvider. This is intended to be called at static initialization time (in func init()), and will thus panic if the given name already is in use.

func ReplaceObjects

func ReplaceObjects(
	config map[string]interface{},
	key string,
	replacement func(obj map[string]interface{}) (interface{}, error),
) error

ReplaceObjects will traverse through the config object and replace all objects that has a the given '$' + key property with the value returned from replacement(obj).

This is useful when implementing TransformationProviders.

func Schema

func Schema() schematypes.Object

Schema returns the configuration file schema

Types

type TransformationProvider

type TransformationProvider interface {
	Transform(config map[string]interface{}, monitor runtime.Monitor) error
}

A TransformationProvider provides a method Transform(config) that knows how to transform the configuration object. Typically, by replacing objects matching a specific pattern or overwriting specific values.

The config object is a simple JSON compatible structure, and Transform() should maintain this property. That means it consists of the following types:

- map[string]interface{}
- []interface{}
- string
- float64
- bool
- nil

Directories

Path Synopsis
Package configabs implements a TransformationProvider that replaces objects on the form: {$abs: "path"} with the value of current working folder + path.
Package configabs implements a TransformationProvider that replaces objects on the form: {$abs: "path"} with the value of current working folder + path.
Package configtest provides structs and logic for declarative configuration tests.
Package configtest provides structs and logic for declarative configuration tests.
Package configenv implements a TransformationProvider that replaces objects on the form: {$env: "VAR"} with the value of the environment variable VAR.
Package configenv implements a TransformationProvider that replaces objects on the form: {$env: "VAR"} with the value of the environment variable VAR.
Package hostcredentials implements a TransformationProvider that fetches credentials from the (oddly named) `host-secrets` service and replaces objects of the form: {$hostcredentials: [url, url]} with the credentials.
Package hostcredentials implements a TransformationProvider that fetches credentials from the (oddly named) `host-secrets` service and replaces objects of the form: {$hostcredentials: [url, url]} with the credentials.
Package configpacket implements a TransformationProvider that replaces objects on the form: {$packet: "VARIABLE"} with a value loaded from https://metadata.packet.net/metadata, following VARIABLE values are supported: - instance-id - hostname - facility - instance-type - public-ipv4 - public-ipv6 If configuration property 'packetMetaDataUrl' this will be used instead of 'https://metadata.packet.net/metadata'.
Package configpacket implements a TransformationProvider that replaces objects on the form: {$packet: "VARIABLE"} with a value loaded from https://metadata.packet.net/metadata, following VARIABLE values are supported: - instance-id - hostname - facility - instance-type - public-ipv4 - public-ipv6 If configuration property 'packetMetaDataUrl' this will be used instead of 'https://metadata.packet.net/metadata'.
Package configsecrets implements a TransformationProvider that replaces objects on the form: {$secret: "NAME", key: "KEY"} with the value of the key "KEY" taken from the secret NAME loaded from taskcluster-secrets.
Package configsecrets implements a TransformationProvider that replaces objects on the form: {$secret: "NAME", key: "KEY"} with the value of the key "KEY" taken from the secret NAME loaded from taskcluster-secrets.

Jump to

Keyboard shortcuts

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