config

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2016 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DockerEngine = "docker"
	NativeEngine = "native"
)

Available execution engines

View Source
const (
	ManagedDynamicConfigLink = "__managed__"
)

Managed dynamic config symlink name

View Source
const (
	// RelayConfigVersion describes the compatible Relay config file format version
	RelayConfigVersion = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

type Bundle struct {
	BundleVersion int                        `json:"cog_bundle_version" valid:"required"`
	Name          string                     `json:"name" valid:"required"`
	Version       string                     `json:"version" valid:"semver,required"`
	Permissions   []string                   `json:"permissions"`
	Docker        *DockerImage               `json:"docker" valid:"-"`
	Commands      map[string]*BundleCommand  `json:"commands" valid:"-"`
	Templates     map[string]*BundleTemplate `json:"templates" valid:"-"`
	// contains filtered or unexported fields
}

Bundle represents a command bundle's complete configuration

func ParseBundleConfig

func ParseBundleConfig(data []byte) (*Bundle, error)

ParseBundleConfig parses raw bundle configs sent by Cog

func (*Bundle) IsAvailable added in v0.7.0

func (b *Bundle) IsAvailable() bool

IsAvailable always returns true for native bundles. For Docker bundles, it returns true if the image has been downloaded successfully.

func (*Bundle) IsDocker

func (b *Bundle) IsDocker() bool

IsDocker returns true if the bundle contains a Docker stanza

func (*Bundle) NeedsRefresh added in v0.7.0

func (b *Bundle) NeedsRefresh() bool

NeedsRefresh returns true if Relay needs to refresh associated bundle assets (like Docker images)

func (*Bundle) SetAvailable added in v0.7.0

func (b *Bundle) SetAvailable(flag bool)

SetAvailable sets the availability flag

type BundleCommand

type BundleCommand struct {
	Name       string
	Executable string                          `json:"executable" valid:"required"`
	Options    map[string]*BundleCommandOption `json:"options"`
	Rules      []string                        `json:"rules"`
	EnvVars    map[string]string               `json:"env_vars"`
}

BundleCommand identifies a command within a bundle

type BundleCommandOption

type BundleCommandOption struct {
	Name        string
	Type        string `json:"type"`
	Description string `json:"description"`
	Required    bool   `json:"required"`
	ShortFlag   string `json:"short_flag"`
}

BundleCommandOption is a description of a command's option

type BundleTemplate

type BundleTemplate struct {
	Name    string
	Slack   string `json:"slack,omitempty" valid:"-"`
	HipChat string `json:"hipchat,omitempty" valid:"-"`
	IRC     string `json:"irc,omitempty" valid:"-"`
}

BundleTemplate is an output template

type CogInfo

type CogInfo struct {
	Host            string `yaml:"host" env:"RELAY_COG_HOST" valid:"hostorip,required" default:"127.0.0.1"`
	Port            int    `yaml:"port" env:"RELAY_COG_PORT" valid:"int64,required" default:"1883"`
	Token           string `yaml:"token" env:"RELAY_COG_TOKEN" valid:"required"`
	SSLEnabled      bool   `yaml:"enable_ssl" env:"RELAY_COG_ENABLE_SSL" valid:"bool" default:"false"`
	SSLCertPath     string `yaml:"ssl_cert_path" env:"RELAY_COG_SSL_CERT_PATH" valid:"-"`
	RefreshInterval string `yaml:"refresh_interval" env:"RELAY_COG_REFRESH_INTERVAL" valid:"required" default:"1m"`
}

CogInfo contains information required to connect to an upstream Cog host

func (*CogInfo) URL

func (ci *CogInfo) URL() string

URL returns a MQTT URL for the upstream Cog host

type Config

type Config struct {
	Version               int      `yaml:"version" valid:"int64,required"`
	ID                    string   `yaml:"id" env:"RELAY_ID" valid:"uuid,required"`
	MaxConcurrent         int      `yaml:"max_concurrent" env:"RELAY_MAX_CONCURRENT" valid:"int64,required" default:"16"`
	DynamicConfigRoot     string   `yaml:"dynamic_config_root" env:"RELAY_DYNAMIC_CONFIG_ROOT" valid:"-"`
	ManagedDynamicConfig  bool     `yaml:"managed_dynamic_config" env:"RELAY_MANAGED_DYNAMIC_CONFIG" valid:"bool" default:"true"`
	DynamicConfigInterval string   `yaml:"managed_dynamic_config_interval" env:"RELAY_MANAGED_DYNAMIC_CONFIG_INTERVAL" default:"5s"`
	LogLevel              string   `yaml:"log_level" env:"RELAY_LOG_LEVEL" valid:"required" default:"info"`
	LogJSON               bool     `yaml:"log_json" env:"RELAY_LOG_JSON" valid:"bool" default:"false"`
	LogPath               string   `yaml:"log_path" env:"RELAY_LOG_PATH" valid:"required" default:"stdout"`
	Cog                   *CogInfo `yaml:"cog" valid:"required"`
	EnginesEnabled        string   `yaml:"enabled_engines" env:"RELAY_ENABLED_ENGINES" valid:"exec_engines" default:"docker,native"`
	ParsedEnginesEnabled  []string
	DevMode               bool
	Docker                *DockerInfo    `yaml:"docker" valid:"-"`
	Execution             *ExecutionInfo `yaml:"execution" valid:"-"`
}

Config is the top level struct for all Relay configuration

func (*Config) DockerEnabled

func (c *Config) DockerEnabled() bool

DockerEnabled returns true when enabled_engines includes "docker"

func (*Config) LoadDynamicConfig added in v0.8.0

func (c *Config) LoadDynamicConfig(bundle string, roomName string, userName string) map[string]interface{}

LoadDynamicConfig loads the dyanmic configuration for a bundle if a) dynamic configuration is enabled and b) a config file exists for the requested bundle. Room- and user-specific configurations are layered on top, if they exist.

If any configuration files exist, but cannot be properly processed (read, parsed as YAML, etc), an empty map is returned.

func (*Config) ManagedDynamicConfigRefreshDuration added in v0.9.0

func (c *Config) ManagedDynamicConfigRefreshDuration() time.Duration

ManagedDynamicConfigRefreshDuration returns DynamicConfigInterval as a time.Duration

func (*Config) NativeEnabled

func (c *Config) NativeEnabled() bool

NativeEnabled returns true when enabled_engines includes "native"

func (*Config) RefreshDuration

func (c *Config) RefreshDuration() time.Duration

RefreshDuration returns RefreshInterval as a time.Duration

func (*Config) Verify added in v0.7.0

func (c *Config) Verify() error

Verify sanity checks the configuration to ensure it's correct

type DockerImage

type DockerImage struct {
	Image string   `json:"image" valid:"notempty,required"`
	Tag   string   `json:"tag" valid:"-"`
	Binds []string `json:"binds"`
}

DockerImage identifies the bundle's image name and version

func (*DockerImage) PrettyImageName

func (di *DockerImage) PrettyImageName() string

PrettyImageName returns a prettified version of a Docker image include repository, name, and tag

type DockerInfo

type DockerInfo struct {
	UseEnv               bool   `yaml:"use_env" env:"RELAY_DOCKER_USE_ENV" valid:"-" default:"false"`
	SocketPath           string `yaml:"socket_path" env:"RELAY_DOCKER_SOCKET_PATH" valid:"dockersocket,required" default:"unix:///var/run/docker.sock"`
	ContainerMemory      int    `yaml:"container_memory" env:"RELAY_DOCKER_CONTAINER_MEMORY" valid:"required" default:"16"`
	CleanInterval        string `yaml:"clean_interval" env:"RELAY_DOCKER_CLEAN_INTERVAL" valid:"required" default:"5m"`
	CommandDriverVersion string `yaml:"command_driver_version" env:"RELAY_DOCKER_CIRCUIT_DRIVER_VERSION" valid:"required"`
	RegistryHost         string `yaml:"registry_host" env:"RELAY_DOCKER_REGISTRY_HOST" valid:"host,required" default:"index.docker.io"`
	RegistryUser         string `yaml:"registry_user" env:"RELAY_DOCKER_REGISTRY_USER" valid:"-"`
	RegistryEmail        string `yaml:"registry_email" env:"RELAY_DOCKER_REGISTRY_EMAIL" valid:"-"`
	RegistryPassword     string `yaml:"registry_password" env:"RELAY_DOCKER_REGISTRY_PASSWORD" valid:"-"`
}

DockerInfo contains information required to interact with dockerd and external Docker registries

func (*DockerInfo) CleanDuration

func (di *DockerInfo) CleanDuration() time.Duration

CleanDuration returns CleanInterval as a time.Duration

type ExecutionInfo

type ExecutionInfo struct {
	ExtraEnv       []string `yaml:"env" env:"RELAY_CONTAINER_ENV"`
	ParsedExtraEnv map[string]string
}

ExecutionInfo applies to every container for a given Relay host

type RawConfig added in v0.7.0

type RawConfig []byte

RawConfig is unparsed config.Config data

func LoadConfig

func LoadConfig(path string) (RawConfig, error)

LoadConfig reads a config file off disk

func (RawConfig) IsEmpty added in v0.7.0

func (rc RawConfig) IsEmpty() bool

IsEmpty returns true if RawConfig's backing byte array is empty

func (RawConfig) Parse added in v0.7.0

func (rc RawConfig) Parse(dockerDriverTag string) (*Config, error)

Parse parses Relay's raw config and then produces a final version incorporating default values and environment variable values. Finalization proceeds using the following steps: 1. Parse YAML and populate new Config struct instance with values 2. Set default values on unassigned fields (for fields with defaults) 3. Apply environment variable overrides 4. Validate the finalized config

Jump to

Keyboard shortcuts

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