config

package
v0.0.0-...-725c2af Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MPL-2.0 Imports: 10 Imported by: 30

README

#config

The package provides the following functions:

  • DefaultConfig: Returns a config object populated with the default settings.
  • CustomizeConfig: Takes a Config object (populated with config_defaults.json) and a string of json (custom settings read from config.json). Returns the config after overwriting any matching settings from the string of json.

If you need to override a setting, edit /etc/bolt/config.json The /etc/bolt/config.json file should have been created as part of the initial bolt setup, as specified in the boltengine's top level README.md

Documentation

Overview

Package config provides the default configuration for the Bolt engine. It also provides a method for overriding any default settings with a custom json string.

The config can be referenced as shown in these examples:

engine.LogInfo("config", nil, "engine > version =" + cfg.Engine.Version)
engine.LogInfo("config", nil, "workerConfig > primaryDb > host =" + cfg.WorkerConfig.PrimaryDb.Host)

Index

Constants

View Source
const (
	AuthModeHMAC = iota
	AuthModeSimple
)

AuthMode constants for mode of security verification

View Source
const ErrorQueueName = "BOLT_WORKER_ERROR"

ErrorQueueName is the name of the mq (minus prefix) where the engine waits for worker errors to log

View Source
const SCHEMA string = `` /* 11631-byte string literal not displayed */
View Source
const TestConfigJSON = `` /* 3304-byte string literal not displayed */

TestConfigJSON is a barebones engine config to be used by CreateTestEngine in unit tests

Variables

This section is empty.

Functions

This section is empty.

Types

type APICall

type APICall struct {
	ResultTimeoutMs int64         `json:"resultTimeoutMs"` // 100
	ResultTimeout   time.Duration `json:"-"`               //time to wait for the total call to complete before returning a timeout + id

	ResultZombieMs int64         `json:"resultZombieMs"` // 30000
	ResultZombie   time.Duration `json:"-"`              //time to wait between commands completing to consider this call 'zombied'

	Cache struct {
		Enabled           bool          `json:"enabled"`           // false
		ExpirationTimeSec int64         `json:"expirationTimeSec"` // 600
		ExpirationTime    time.Duration `json:"-"`
	} `json:"cache"`

	RequiredParams map[string]string `json:"requiredParams"`

	Commands         []CommandInfo `json:"commands"`
	FilterKeys       []string      `json:"filterKeys"`
	LongDescription  string        `json:"longDescription"`  // Expandable description
	ShortDescription string        `json:"shortDescription"` // Brief description
}

APICall holds performance config, required params, etc for an entire API call and is itself the definition for the consumable API

type CommandInfo

type CommandInfo struct {
	Name            string          `json:"name"`            // product/checkDuplicates
	ResultTimeoutMs int64           `json:"resultTimeoutMs"` // 6000
	ResultTimeout   time.Duration   `json:"-"`
	ReturnAfter     bool            `json:"returnAfter"` // false
	ConfigParams    json.RawMessage `json:"configParams"`
	ConfigParamsObj *gabs.Container `json:"-"`
}

CommandInfo stores command details and config within an API call

type CommandMeta

type CommandMeta struct {
	RequiredParams   map[string]string `json:"requiredParams"`
	NoStub           bool              `json:"noStub"`           // false (if true, then in stubMode engine won't generate a stub for this command)
	StubReturn       json.RawMessage   `json:"stubReturn"`       // empty, if populated, then in stubMode this message will be added to return_value in payload
	StubData         json.RawMessage   `json:"stubData"`         // empty, if populated, then in stubMode this message will be added to data in payload
	StubDelayMs      int64             `json:"stubDelayMs"`      // 0, if non-zero, then in stubMode this command will use this delay instead of the default
	LongDescription  string            `json:"longDescription"`  // Expanded description
	ShortDescription string            `json:"shortDescription"` // Brief description
}

CommandMeta is a simple holder for additional params common to each possible command

type Config

type Config struct {
	Engine struct {
		Version           string `json:"version"`     // v1
		Bind              string `json:"bind"`        // :443
		TLSCertFile       string `json:"tlsCertFile"` // cert.pem
		TLSKeyFile        string `json:"tlsKeyFile"`  // key.pem
		TLSEnabled        bool   `json:"tlsEnabled"`  // false
		AuthMode          string `json:"authMode"`    // "hmac" (or "simple")
		AuthModeValue     int    `json:"-"`
		MQUrl             string `json:"mqUrl"`             //amqp://guest:guest@localhost:5672/
		PrettyOutput      bool   `json:"prettyOutput"`      //false (true enabled indented and line breaks in JSON responses)
		ExtraConfigFolder string `json:"extraConfigFolder"` // "etc/bolt"
		TraceEnabled      bool   `json:"traceEnabled"`      //true (enables per-command trace output in api calls)
		DocsEnabled       bool   `json:"docsEnabled"`
		Advanced          struct {
			ReadTimeout              string `json:"readTimeout"`              //30s
			WriteTimeout             string `json:"writeTimeout"`             //30s
			CompleteResultLoopFreq   string `json:"completeResultLoopFreq"`   // 10s
			CompleteResultExpiration string `json:"completeResultExpiration"` // 30s
			ShutdownResultExpiration string `json:"shutdownResultExpiration"` // 30s
			ShutdownForceQuit        string `json:"shutdownForceQuit"`        // 120s
			StubMode                 bool   `json:"stubMode"`                 //false (true enables spining up a 'stub' worker for all config'ed commands)
			StubDelayMs              int64  `json:"stubDelayMs"`              //100
			DebugFormEnabled         bool   `json:"debugFormEnabled"`         // true
			MaxHTTPHeaderKBytes      int    `json:"maxHTTPHeaderKBytes"`      // 0 (default go http lib makes it 1MB)
			QueuePrefix              string `json:"queuePrefix"`              // "" default, this string will be prefixed on the queue for every command name
		} `json:"advanced"`
	} `json:"engine"`

	Logging struct {
		Type  string `json:"type"`  //fs, syslog, mongodb (or add more in bolt/logging.go)
		Level string `json:"level"` //debug, info, warn, error, fatal, panic

		LogStatsDuration string `json:"logStatsDuration"` // for logstats

		//fs options
		FsDebugPath string `json:"fsDebugPath"`
		FsInfoPath  string `json:"fsInfoPath"`
		FsWarnPath  string `json:"fsWarnPath"`
		FsErrorPath string `json:"fsErrorPath"`
		FsFatalPath string `json:"fsFatalPath"`
		FsPanicPath string `json:"fsPanicPath"`

		//syslog options
		SyslogProtocol string `json:"syslogProtocol"` //udp
		SyslogIPPort   string `json:"syslogIPPort"`   //localhost:445

		//mongodb options
		MongoIPPort     string `json:"mongoIPPort"`     //localhost:27017
		MongoDb         string `json:"mongoDb"`         //db
		MongoCollection string `json:"mongoCollection"` //collection
	} `json:"logging"`

	Security struct {
		VerifyTimeout    int64            `json:"verifyTimeout"` //30
		Groups           []SecurityGroups `json:"groups"`
		HandlerAccess    []HandlerAccess  `json:"handlerAccess"`    //[]
		CorsDomains      []string         `json:"corsDomains"`      //[]
		CorsAutoAddLocal bool             `json:"corsAutoAddLocal"` //true
	} `json:"security"`

	Cache struct {
		Type      string `json:"type"`      // redis
		Host      string `json:"host"`      // localhost:1234
		Pass      string `json:"pass"`      //
		TimeoutMs int64  `json:"timeoutMs"` // 2000
	} `json:"cache"`

	APICalls        map[string]APICall     `json:"apiCalls"`
	CommandMetas    map[string]CommandMeta `json:"commandMeta"`
	WorkerConfig    json.RawMessage        `json:"workerConfig"`
	WorkerConfigObj *gabs.Container        `json:"-"`
}

Config structure created from the config_defauls.json file using jsonutils Website- https://github.com/bashtian/jsonutils go get github.com/bashtian/jsonutils/cmd/jsonutil jsonutil -x -c=false -f /etc/bolt/config.json

func BuildConfig

func BuildConfig(cfgdir, cfgpath string) (*Config, error)

BuildConfig creates an engine config by first reading the default config, then overriding it with the contents of config.json cfgdir: Directory containing the customized config.json - Typically: "/etc/bolt/" cfgpath: Full path to config.json - Typically: "/etc/bolt/config.json"

func CustomizeConfig

func CustomizeConfig(config *Config, custom string) (*Config, error)

CustomizeConfig takes an existing Config (usually defaults) and a string of json (usually the client's custom config settings).

func DefaultConfig

func DefaultConfig() (*Config, error)

DefaultConfig returns a default configuration variable to the caller.

func (*Config) JSON

func (cfg *Config) JSON() (string, error)

JSON outputs the config struct as a JSON string

type HandlerAccess

type HandlerAccess struct {
	HandlerURL string `json:"handler"` // full url of handler or APICall to limit access - ex: /work/v1/addProduct, or /pending.  Checked for exact match to request url in context.go
	APICall    string `json:"apiCall"` // api call name only. ie v1/addProduct.  Checked as prefix to request url in context.go
	//if either handlerURL or apiCall is matched and non-blank string, the below access rules will apply
	DenyGroups  []string `json:"denyGroups"`  //[]
	AllowGroups []string `json:"allowGroups"` //[]
}

HandlerAccess holds handler names and arrays of groups to either deny or allow access.

type SecurityGroups

type SecurityGroups struct {
	Name              string `json:"name"`              // readonly
	Hmackey           string `json:"hmackey"`           // N9d*22UuzdA443Nur2eL23:a2fvTqe
	RequestsPerSecond int64  `json:"requestsPerSecond"` // 0
}

SecurityGroups holds group names and their corresponding HMAC keys

Jump to

Keyboard shortcuts

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