config

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config provides structs describing Request Manager and Job Runner YAML config files. The top-level structs are RequestManager and JobRunner.

Index

Constants

View Source
const (
	DEFAULT_ADDR_REQUEST_MANAGER = "127.0.0.1:32308"
	DEFAULT_ADDR_JOB_RUNNER      = "127.0.0.1:32307"
	DEFAULT_MYSQL_DSN            = "root:@tcp(localhost:3306)/spincycle_development"
	DEFAULT_SPECS_DIR            = "specs/"
)

Default values are used when corresponding values are not specified in a config file. These are sufficient for development but not production.

Variables

This section is empty.

Functions

func Defaults

func Defaults() (RequestManager, JobRunner)

Defaults returns a RequestManager and JobRunner with all default values.

func Env

func Env(envar, def string) string

Env returns the envar value if set, else the default value.

func Load

func Load(cfgFile string, configStruct interface{}) error

Load loads a config file into the struct pointed to by configStruct.

func NewTLSConfig

func NewTLSConfig(caFile, certFile, keyFile string) (*tls.Config, error)

NewTLSConfig creates a tls.Config from the given cert, key, and ca files.

Types

type Auth

type Auth struct {
	// Callers with one of these roles are admins (allowed all ops) for all requests.
	AdminRoles []string `yaml:"admin_roles"`

	// Strict requires all requests to have ACLs, else callers are denied unless
	// they have an admin role. Strict is disabled by default which, with the default
	// auth plugin, allows all callers (no auth).
	Strict bool `yaml:"strict"`
}

The auth section of RequestManager configures role-based authentication. To enable auth, you must provide an auth plugin. Else, the default is no auth and these options are ignored.

type HTTPClient

type HTTPClient struct {
	// ServerURL is the base URL of the destination API (e.g. http://IP:port).
	// For development, this is Server.Addr. But for production, each API is
	// usually behind load balancers or some type of NAT, so this is probably
	// the load balancer/gateway address in front of the destination API.
	//
	// The default is the other API default address: DEFAULT_ADDR_REQUEST_MANAGER
	// or DEFAULT_ADDR_JOB_RUNNER.
	ServerURL string `yaml:"url"`

	// TLS specifies certificate, key, and CA files to enable TLS connections
	// to the destination API. The destation API must also be configured to use
	// TLS by specifying Server.TLS.
	//
	// The default is not using TLS.
	TLS `yaml:"tls"`
}

HTTPClient represents sections jr_client (RequestManager.JRClient) and rm_client (JobRunner.RMClient) for configuring Job Runner and Request Manager HTTP clients, respectively.

type JobRunner

type JobRunner struct {
	Server   Server     `yaml:"server"`    // API addr and TLS
	RMClient HTTPClient `yaml:"rm_client"` // JR to RM internal communication
}

JobRunner represents the top-level layout for a Job Runner (JR) YAML config file. A JR config file looks like:

---
server:
  addr: 10.0.0.55:32307
  tls:
    cert_file: myorg.crt
    key_file: myorg.key
    ca_file: myorg.ca
rm_client:
  url: https://spincycle-rm.myorg.local:32308
  tls:
    cert_file: myorg.crt
    key_file: myorg.key
    ca_file: myorg.ca

The reciprocal top-level config is RequestManager.

type MySQL

type MySQL struct {
	// DSN is the data source name for connecting to MySQL. See
	// https://github.com/go-sql-driver/mysql#dsn-data-source-name for the
	// full syntax. The "parseTime=true" parameter is automatically appended
	// to the DSN.
	//
	// The DSN must end with "/db" where db is the database name where the
	// Request Manager schema has been loaded. Full privileges should be granted
	// on this database to the MySQL user specified by the DSN.
	//
	// To enable TLS, configure the TLS options, do not use the "tls" DSN parameter.
	//
	// The default is DEFAULT_MYSQL_DSN.
	DSN string `yaml:"dsn"`

	// TLS specifies certificate, key, and CA files to enable TLS connections
	// to MySQL. If enabled, the "tls" DSN parameter is used automatically.
	//
	// The default is no TLS.
	TLS `yaml:"tls"`

	// Path to mysql CLI. This is only used for testing.
	CLIPath string `yaml:"cli_path"`
}

Configuration for a SQL database.

type RequestManager

type RequestManager struct {
	Server   Server     `yaml:"server"`    // API addr and TLS
	MySQL    MySQL      `yaml:"mysql"`     // MySQL database
	Specs    Specs      `yaml:"specs"`     // request specs
	Auth     Auth       `yaml:"auth"`      // auth plugin
	JRClient HTTPClient `yaml:"jr_client"` // RM to JR internal communication
}

Request Manager represents the top-level layout for a Request Manager (RM) YAML config file. An RM config file looks like:

---
server:
  addr: 10.0.0.50:32308
  tls:
    cert_file: myorg.crt
    key_file: myorg.key
    ca_file: myorg.ca
mysql:
  dsn: "spincycle@tcp(spin-mysql.local:3306)/spincycle_production"
specs:
  dir: /data/app/spin-rm/specs/
auth:
  admin_roles: ["dba"]
  strict: true
jr_client:
  url: https://spincycle-jr.myorg.local:32307
  tls:
    cert_file: myorg.crt
    key_file: myorg.key
    ca_file: myorg.ca

The reciprocal top-level config is JobRunner.

type Server

type Server struct {
	// Addr is the network address ("IP:port") to listen on. For development,
	// this is the address clients connect to. But for production, the API is
	// usually behind load balancers or some type of NAT, so this is only the
	// local bind address.
	//
	// Specify ":port" to listen on all interface for the given port.
	//
	// The default is DEFAULT_ADDR_REQUEST_MANAGER or DEFAULT_ADDR_JOB_RUNNER.
	Addr string `yaml:"addr"`

	// TLS specifies certificate, key, and CA files to enable TLS connections.
	// If enabled, clients must connect using HTTPS.
	//
	// The default is not using TLS.
	TLS TLS `yaml:"tls"`
}

The server section configures the server and API. Both RequestManager and JobRunner have a server section.

type Specs

type Specs struct {
	// Directory where all request specs are located. Subdirectories are ignored.
	//
	// The default is DEFAULT_SPECS_DIR.
	Dir string `yaml:"dir"`
}

The specs section of RequestManager configures the request specs.

type TLS

type TLS struct {
	// The certificate file to use.
	CertFile string `yaml:"cert_file"`

	// The key file to use.
	KeyFile string `yaml:"key_file"`

	// The CA file to use.
	CAFile string `yaml:"ca_file"`
}

TLS represents the tls sections for Server, HTTPClient, and MySQL. Each tls section is unique, allowing different TLS files for each section.

There are no defaults. Specify all files, or none.

Jump to

Keyboard shortcuts

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