config

package
v0.0.0-...-85a8e8d Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config allows for an external config file to be read that allows for value to be overriden based on a hostname derived configuration set.

the Configuration type defines all the configurable parameters. the config file is json, its consists of 3 sections

defaults : a Configuration instance that is the base/default configurations hosts : a mapping from host name to a named configuration [e.g. node1 : "aws"] overrrides : a set of named Configuration instances that can override the some or all of the default config values

the caller can provide a specific hostname if it chooses, otherwise the config will

a) look for a named environemnt variable, if set to something, that is used
b) look at the OS supplied hostname

*** THIS IS GENERATED CODE: DO NOT EDIT ***

Index

Constants

View Source
const (
	// ConfigFileName is default name for the configuration file
	ConfigFileName = "demo-config.json"
)

Variables

This section is empty.

Functions

func GetConfigAbsFilename

func GetConfigAbsFilename(file, projFolder string) (string, error)

GetConfigAbsFilename returns absolute path for the configuration file from the relative path to projFolder

Types

type Authz

type Authz struct {

	// Allow will allow the specified roles access to this path and its children, in format: ${path}:${role},${role}.
	Allow []string

	// AllowAny will allow any authenticated request access to this path and its children.
	AllowAny []string

	// AllowAnyRole will allow any authenticated request that include a non empty role.
	AllowAnyRole []string

	// LogAllowed specifies to log allowed access.
	LogAllowed *bool

	// LogDenied specifies to log denied access.
	LogDenied *bool

	// CertMapper specifies location of the config file for certificate based identity.
	CertMapper string

	// APIKeyMapper specifies location of the config file for API-Key based identity.
	APIKeyMapper string

	// JWTMapper specifies location of the config file for JWT based identity.
	JWTMapper string
}

Authz contains configuration for the authorization module.

func (*Authz) GetAPIKeyMapper

func (c *Authz) GetAPIKeyMapper() string

GetAPIKeyMapper specifies location of the config file for API-Key based identity.

func (*Authz) GetAllow

func (c *Authz) GetAllow() []string

GetAllow will allow the specified roles access to this path and its children, in format: ${path}:${role},${role}.

func (*Authz) GetAllowAny

func (c *Authz) GetAllowAny() []string

GetAllowAny will allow any authenticated request access to this path and its children.

func (*Authz) GetAllowAnyRole

func (c *Authz) GetAllowAnyRole() []string

GetAllowAnyRole will allow any authenticated request that include a non empty role.

func (*Authz) GetCertMapper

func (c *Authz) GetCertMapper() string

GetCertMapper specifies location of the config file for certificate based identity.

func (*Authz) GetJWTMapper

func (c *Authz) GetJWTMapper() string

GetJWTMapper specifies location of the config file for JWT based identity.

func (*Authz) GetLogAllowed

func (c *Authz) GetLogAllowed() bool

GetLogAllowed specifies to log allowed access.

func (*Authz) GetLogDenied

func (c *Authz) GetLogDenied() bool

GetLogDenied specifies to log denied access.

type AuthzConfig

type AuthzConfig interface {
	// Allow will allow the specified roles access to this path and its children, in format: ${path}:${role},${role}.
	GetAllow() []string
	// AllowAny will allow any authenticated request access to this path and its children.
	GetAllowAny() []string
	// AllowAnyRole will allow any authenticated request that include a non empty role.
	GetAllowAnyRole() []string
	// LogAllowed specifies to log allowed access.
	GetLogAllowed() bool
	// LogDenied specifies to log denied access.
	GetLogDenied() bool
	// CertMapper specifies location of the config file for certificate based identity.
	GetCertMapper() string
	// APIKeyMapper specifies location of the config file for API-Key based identity.
	GetAPIKeyMapper() string
	// JWTMapper specifies location of the config file for JWT based identity.
	GetJWTMapper() string
}

AuthzConfig contains configuration for the authorization module.

type CORS

type CORS struct {

	// Enabled specifies if the CORS is enabled.
	Enabled *bool

	// MaxAge indicates how long (in seconds) the results of a preflight request can be cached.
	MaxAge int

	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	AllowedOrigins []string

	// AllowedMethods is a list of methods the client is allowed to use with cross-domain requests.
	AllowedMethods []string

	// AllowedHeaders is list of non simple headers the client is allowed to use with cross-domain requests.
	AllowedHeaders []string

	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS API specification.
	ExposedHeaders []string

	// AllowCredentials indicates whether the request can include user credentials.
	AllowCredentials *bool

	// OptionsPassthrough instructs preflight to let other potential next handlers to process the OPTIONS method.
	OptionsPassthrough *bool

	// Debug flag adds additional output to debug server side CORS issues.
	Debug *bool
}

CORS contains configuration for CORS.

func (*CORS) GetAllowCredentials

func (c *CORS) GetAllowCredentials() bool

GetAllowCredentials indicates whether the request can include user credentials.

func (*CORS) GetAllowedHeaders

func (c *CORS) GetAllowedHeaders() []string

GetAllowedHeaders is list of non simple headers the client is allowed to use with cross-domain requests.

func (*CORS) GetAllowedMethods

func (c *CORS) GetAllowedMethods() []string

GetAllowedMethods is a list of methods the client is allowed to use with cross-domain requests.

func (*CORS) GetAllowedOrigins

func (c *CORS) GetAllowedOrigins() []string

GetAllowedOrigins is a list of origins a cross-domain request can be executed from.

func (*CORS) GetDebug

func (c *CORS) GetDebug() bool

GetDebug flag adds additional output to debug server side CORS issues.

func (*CORS) GetEnabled

func (c *CORS) GetEnabled() bool

GetEnabled specifies if the CORS is enabled.

func (*CORS) GetExposedHeaders

func (c *CORS) GetExposedHeaders() []string

GetExposedHeaders indicates which headers are safe to expose to the API of a CORS API specification.

func (*CORS) GetMaxAge

func (c *CORS) GetMaxAge() int

GetMaxAge indicates how long (in seconds) the results of a preflight request can be cached.

func (*CORS) GetOptionsPassthrough

func (c *CORS) GetOptionsPassthrough() bool

GetOptionsPassthrough instructs preflight to let other potential next handlers to process the OPTIONS method.

type CORSConfig

type CORSConfig interface {
	// Enabled specifies if the CORS is enabled.
	GetEnabled() bool
	// MaxAge indicates how long (in seconds) the results of a preflight request can be cached.
	GetMaxAge() int
	// AllowedOrigins is a list of origins a cross-domain request can be executed from.
	GetAllowedOrigins() []string
	// AllowedMethods is a list of methods the client is allowed to use with cross-domain requests.
	GetAllowedMethods() []string
	// AllowedHeaders is list of non simple headers the client is allowed to use with cross-domain requests.
	GetAllowedHeaders() []string
	// ExposedHeaders indicates which headers are safe to expose to the API of a CORS API specification.
	GetExposedHeaders() []string
	// AllowCredentials indicates whether the request can include user credentials.
	GetAllowCredentials() bool
	// OptionsPassthrough instructs preflight to let other potential next handlers to process the OPTIONS method.
	GetOptionsPassthrough() bool
	// Debug flag adds additional output to debug server side CORS issues.
	GetDebug() bool
}

CORSConfig contains configuration for CORSConfig.

type Configuration

type Configuration struct {

	// Datacenter specifies the Datacenter where the instance is running.
	Datacenter string

	// Environment specifies the deployment environment.
	Environment string

	// ServiceName specifies the service name to be used in logs and folders names.
	ServiceName string

	// HTTP contains the config for the Public HTTP.
	HTTP HTTPServer

	// HTTPS contains the config for the HTTPS/JSON API Service.
	HTTPS HTTPServer

	// Authz contains configuration for the API authorization layer.
	Authz Authz

	// Audit contains configuration for the audit logger.
	Audit Logger

	// CryptoProv specifies the configuration for crypto providers.
	CryptoProv CryptoProv

	// Metrics specifies the metrics pipeline configuration.
	Metrics Metrics

	// Logger contains configuration for the logger.
	Logger Logger

	// LogLevels specifies the log levels per package.
	LogLevels []RepoLogLevel

	// RootCA specifies the location of PEM-encoded certificate.
	RootCA string
}

Configuration contains the configuration for the server.

func Load

func Load(configFilename, envKeyName, hostnameOverride string) (*Configuration, error)

Load will attempt to load the configuration from the supplied filename. Overrides defined in the config file will be applied based on the hostname the hostname used is dervied from [in order]

  1. the hostnameOverride parameter if not ""
  2. the value of the Environment variable in envKeyName, if not ""
  3. the OS supplied hostname

func LoadConfig

func LoadConfig(configFile string) (*Configuration, string, error)

LoadConfig will load the server configuration from the named config file, apply any overrides, and resolve relative directory locations.

type Configurations

type Configurations struct {
	// Default contains the base configuration, this applies unless it override by a specifc named config
	Defaults Configuration

	// a map of hostname to named configuration
	Hosts map[string]string

	// a map of named configuration overrides
	Overrides map[string]Configuration
}

Configurations is the entire set of configurations, these consist of

a base/default configuration
a set of hostname -> named overrides
named overrides -> config overrides

func LoadConfigurations

func LoadConfigurations(filename string) (*Configurations, error)

LoadConfigurations decodes the json config file, or returns an error typically you'd just use Load, but this can be useful if you need to do more intricate examination of the entire set of configurations

func (*Configurations) For

func (configs *Configurations) For(envKeyName, hostnameOverride string) (*Configuration, error)

For returns the Configuration for the indicated host, with all the overrides applied. the hostname used is dervied from [in order]

  1. the hostnameOverride parameter if not ""
  2. the value of the Environemnt variable in envKeyName, if not ""
  3. the OS supplied hostname

func (*Configurations) Selection

func (configs *Configurations) Selection(envKeyName, hostnameOverride string) (HostSelection, error)

Selection returns the final resolved hostname, and if applicable, override section name for the supplied host specifiers

type CryptoProv

type CryptoProv struct {

	// Default specifies the location of the configuration file for default provider.
	Default string

	// Providers specifies the list of locations of the configuration files.
	Providers []string
}

CryptoProv specifies the configuration for crypto providers.

type Duration

type Duration time.Duration

Duration represents a period of time, its the same as time.Duration but supports better marshalling from json

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON encodes our custom Duration value as a quoted version of its underlying value's String() output this means you get a duration with a trailing units indicator, e.g. "10m0s"

func (Duration) String

func (d Duration) String() string

String returns a string formatted version of the duration in a valueUnits format, e.g. 5m0s for 5 minutes

func (Duration) TimeDuration

func (d Duration) TimeDuration() time.Duration

TimeDuration returns this duration in a time.Duration type

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON handles decoding our custom json serialization for Durations json values that are numbers are treated as seconds json values that are strings, can use the standard time.Duration units indicators e.g. this can decode val:100 as well as val:"10m"

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory is used to create Configuration instance

func DefaultFactory

func DefaultFactory() (*Factory, error)

DefaultFactory returns default configuration factory

func NewFactory

func NewFactory(nodeInfo netutil.NodeInfo, searchDirs []string) (*Factory, error)

NewFactory returns new configuration factory

func (*Factory) LoadConfig

func (f *Factory) LoadConfig(configFile string) (*Configuration, string, error)

LoadConfig will load the server configuration from the named config file, apply any overrides, and resolve relative directory locations.

func (*Factory) LoadConfigForHostName

func (f *Factory) LoadConfigForHostName(configFile, hostnameOverride string) (*Configuration, string, error)

LoadConfigForHostName will load the server configuration from the named config file for specified host name, apply any overrides, and resolve relative directory locations.

type HTTPServer

type HTTPServer struct {

	// ServiceName specifies name of the service: HTTP|HTTPS|WebAPI.
	ServiceName string

	// Disabled specifies if the service is disabled.
	Disabled *bool

	// VIPName is the FQ name of the VIP to the cluster [this is used when building the cert requests].
	VIPName string

	// BindAddr is the address that the HTTPS service should be exposed on
	BindAddr string

	// ServerTLS provides TLS config for server.
	ServerTLS TLSInfo

	// PackageLogger if set, specifies name of the package logger.
	PackageLogger string

	// AllowProfiling if set, will allow for per request CPU/Memory profiling triggered by the URI QueryString.
	AllowProfiling *bool

	// ProfilerDir specifies the directories where per-request profile information is written, if not set will write to a TMP dir.
	ProfilerDir string

	// Services is a list of services to enable for this HTTP Service.
	Services []string

	// HeartbeatSecs specifies heartbeat interval in seconds [30 secs is a minimum].
	HeartbeatSecs int

	// CORS contains configuration for CORS.
	CORS CORS
}

HTTPServer contains the configuration of the HTTPS API Service.

func (*HTTPServer) GetAllowProfiling

func (c *HTTPServer) GetAllowProfiling() bool

GetAllowProfiling if set, will allow for per request CPU/Memory profiling triggered by the URI QueryString.

func (*HTTPServer) GetBindAddr

func (c *HTTPServer) GetBindAddr() string

GetBindAddr is the address that the HTTPS service should be exposed on

func (*HTTPServer) GetCORSCfg

func (c *HTTPServer) GetCORSCfg() *CORS

GetCORSCfg contains configuration for GetCORSCfg.

func (*HTTPServer) GetDisabled

func (c *HTTPServer) GetDisabled() bool

GetDisabled specifies if the service is disabled.

func (*HTTPServer) GetHeartbeatSecs

func (c *HTTPServer) GetHeartbeatSecs() int

GetHeartbeatSecs specifies heartbeat interval in seconds [30 secs is a minimum].

func (*HTTPServer) GetPackageLogger

func (c *HTTPServer) GetPackageLogger() string

GetPackageLogger if set, specifies name of the package logger.

func (*HTTPServer) GetProfilerDir

func (c *HTTPServer) GetProfilerDir() string

GetProfilerDir specifies the directories where per-request profile information is written, if not set will write to a TMP dir.

func (*HTTPServer) GetServerTLSCfg

func (c *HTTPServer) GetServerTLSCfg() *TLSInfo

GetServerTLSCfg provides TLS config for server.

func (*HTTPServer) GetServiceName

func (c *HTTPServer) GetServiceName() string

GetServiceName specifies name of the service: HTTP|HTTPS|WebAPI.

func (*HTTPServer) GetServices

func (c *HTTPServer) GetServices() []string

GetServices is a list of services to enable for this HTTP Service.

func (*HTTPServer) GetVIPName

func (c *HTTPServer) GetVIPName() string

GetVIPName is the FQ name of the VIP to the cluster [this is used when building the cert requests].

type HTTPServerConfig

type HTTPServerConfig interface {
	// ServiceName specifies name of the service: HTTP|HTTPS|WebAPI.
	GetServiceName() string
	// Disabled specifies if the service is disabled.
	GetDisabled() bool
	// VIPName is the FQ name of the VIP to the cluster [this is used when building the cert requests].
	GetVIPName() string
	// BindAddr is the address that the HTTPS service should be exposed on
	GetBindAddr() string
	// ServerTLS provides TLS config for server.
	GetServerTLSCfg() *TLSInfo
	// PackageLogger if set, specifies name of the package logger.
	GetPackageLogger() string
	// AllowProfiling if set, will allow for per request CPU/Memory profiling triggered by the URI QueryString.
	GetAllowProfiling() bool
	// ProfilerDir specifies the directories where per-request profile information is written, if not set will write to a TMP dir.
	GetProfilerDir() string
	// Services is a list of services to enable for this HTTP Service.
	GetServices() []string
	// HeartbeatSecs specifies heartbeat GetHeartbeatSecserval in seconds [30 secs is a minimum].
	GetHeartbeatSecs() int
	// GetCORSCfg contains configuration for GetCORSCfg.
	GetCORSCfg() *CORS
}

HTTPServerConfig contains the configuration of the HTTPS API Service.

type HostSelection

type HostSelection struct {
	// Hostname returns the hostname from the configuration that was used
	// this may return a fully qualified hostname, when just a name was specified
	Hostname string
	// Override contains the name of the override section, if there was one found
	// [based on the Hostname]
	Override string
}

HostSelection describes the hostname & override set that were used

type Logger

type Logger struct {

	// Directory contains where to store the log files.
	Directory string

	// MaxAgeDays controls how old files are before deletion.
	MaxAgeDays int

	// MaxSizeMb contols how large a single log file can be before its rotated.
	MaxSizeMb int
}

Logger contains information about the configuration of a logger/log rotation.

func (*Logger) GetDirectory

func (c *Logger) GetDirectory() string

GetDirectory contains where to store the log files.

func (*Logger) GetMaxAgeDays

func (c *Logger) GetMaxAgeDays() int

GetMaxAgeDays controls how old files are before deletion.

func (*Logger) GetMaxSizeMb

func (c *Logger) GetMaxSizeMb() int

GetMaxSizeMb contols how large a single log file can be before its rotated.

type LoggerConfig

type LoggerConfig interface {
	// Directory contains where to store the log files.
	GetDirectory() string
	// MaxAgeDays controls how old files are before deletion.
	GetMaxAgeDays() int
	// MaxSizeMb contols how large a single log file can be before its rotated.
	GetMaxSizeMb() int
}

LoggerConfig contains information about the configuration of a logger/log rotation.

type Metrics

type Metrics struct {

	// Provider specifies the metrics provider.
	Provider string
}

Metrics specifies the metrics pipeline configuration.

type RepoLogLevel

type RepoLogLevel struct {

	// Repo specifies the repo name, or '*' for all repos [Global].
	Repo string

	// Package specifies the package name.
	Package string

	// Level specifies the log level for the repo [ERROR,WARNING,NOTICE,INFO,DEBUG,TRACE].
	Level string
}

RepoLogLevel contains information about the log level per repo. Use * to set up global level.

type TLSInfo

type TLSInfo struct {

	// CertFile specifies location of the cert.
	CertFile string

	// KeyFile specifies location of the key.
	KeyFile string

	// TrustedCAFile specifies location of the trusted Root file.
	TrustedCAFile string

	// ClientCertAuth controls client auth: NoClientCert|RequestClientCert|RequireAnyClientCert|VerifyClientCertIfGiven|RequireAndVerifyClientCert
	ClientCertAuth string
}

TLSInfo contains configuration info for the TLS.

func (*TLSInfo) GetCertFile

func (c *TLSInfo) GetCertFile() string

GetCertFile specifies location of the cert.

func (*TLSInfo) GetClientCertAuth

func (c *TLSInfo) GetClientCertAuth() string

GetClientCertAuth controls client auth: NoClientCert|RequestClientCert|RequireAnyClientCert|VerifyClientCertIfGiven|RequireAndVerifyClientCert

func (*TLSInfo) GetKeyFile

func (c *TLSInfo) GetKeyFile() string

GetKeyFile specifies location of the key.

func (*TLSInfo) GetTrustedCAFile

func (c *TLSInfo) GetTrustedCAFile() string

GetTrustedCAFile specifies location of the trusted Root file.

type TLSInfoConfig

type TLSInfoConfig interface {
	// CertFile specifies location of the cert.
	GetCertFile() string
	// KeyFile specifies location of the key.
	GetKeyFile() string
	// TrustedCAFile specifies location of the trusted Root file.
	GetTrustedCAFile() string
	// ClientCertAuth controls client auth: NoClientCert|RequestClientCert|RequireAnyClientCert|VerifyClientCertIfGiven|RequireAndVerifyClientCert
	GetClientCertAuth() string
}

TLSInfoConfig contains configuration info for the TLS.

Jump to

Keyboard shortcuts

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