taskcluster-worker: github.com/taskcluster/taskcluster-worker/config Index | Files | Directories

package config

import "github.com/taskcluster/taskcluster-worker/config"

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

Package Files

doc.go load.go provider.go replaceobj.go

func Load Uses

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

Load configuration from YAML config object.

func LoadFromFile Uses

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 Uses

func Providers() map[string]TransformationProvider

Providers returns a map of the registered TransformationProvider.

func Register Uses

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 Uses

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 Uses

func Schema() schematypes.Object

Schema returns the configuration file schema

type TransformationProvider Uses

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

PathSynopsis
absPackage configabs implements a TransformationProvider that replaces objects on the form: {$abs: "path"} with the value of current working folder + path.
configtestPackage configtest provides structs and logic for declarative configuration tests.
envPackage configenv implements a TransformationProvider that replaces objects on the form: {$env: "VAR"} with the value of the environment variable VAR.
hostcredentialsPackage 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.
packetPackage 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
secretsPackage 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 config imports 7 packages (graph) and is imported by 9 packages. Updated 2017-05-15. Refresh now. Tools for package owners.