config

package
v0.330.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 30 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DIRMODE  = "directory"
	FILEMODE = "file"
	SYSMODE  = "system"
)

Cert path modes.

View Source
const (
	PEM    = "pem"
	PKCS12 = "pkcs12"
)

Cert encoding types.

View Source
const DefaultReplacementText = "****************"
View Source
const (
	SecretKeyEncodingBase64 = "base64"
)

Variables

View Source
var CertPoolEncodingTypes = map[string]func(ctx context.Context, cfg *TrustedCertPoolConfig) (pool *x509.CertPool, err error){
	PEM:    buildPoolFromPEM,
	PKCS12: buildPoolFromPKCS12,
}
View Source
var SecretKeyReader = map[string]func(cfg *SecretKeyConfig) ([]byte, error){
	SecretKeyEncodingBase64: readBase64Value,
}
View Source
var SecretKeyValidators = map[string]func(cfg *SecretKeyConfig) error{
	SecretKeyEncodingBase64: validateBase64Value,
}

Functions

func DefaultGrpcDialOptions added in v0.98.0

func DefaultGrpcDialOptions(ctx context.Context, cfg *CommonGRPCDownstreamData) ([]grpc.DialOption, error)

DefaultGRPDialOptions creates []grpc.DialOption from the given config. If cfg is nil then NewDefaultCommonGRPCDownstreamData will be used to define the dial options.

func DefaultHTTPClient

func DefaultHTTPClient(ctx context.Context, cfg *CommonDownstreamData) (*http.Client, error)

DefaultHTTPClient returns a new *http.Client with sensible defaults, in particular it has a timeout set.

func ExtractGrpcServerOptions

func ExtractGrpcServerOptions(ctx context.Context, cfg *GRPCServerConfig) ([]grpc.ServerOption, error)

func GetTrustedCAs

func GetTrustedCAs(ctx context.Context, cfg *TLSConfig) (*x509.CertPool, error)

func LoadConfig added in v0.13.0

func LoadConfig(file string, defaultConfig *DefaultConfig, customConfig interface{}) error

LoadConfig reads and validates a configuration loaded from file. file: the path to the yaml-encoded config file defaultConfig: a pointer to the default config struct to populate customConfig: a pointer to the custom config struct to populate.

func MakeTLSConfig

func MakeTLSConfig(ctx context.Context, cfg *TLSConfig) (*tls.Config, error)

func OurIdentityCertificates

func OurIdentityCertificates(cfg *TLSConfig) ([]tls.Certificate, error)

func PutDefaultConfig added in v0.175.0

func PutDefaultConfig(ctx context.Context, config *DefaultConfig) context.Context

PutDefaultConfig puts the externally-provided config into the given context, returning the new context.

func SetDefaults added in v0.216.0

func SetDefaults(setter func(key string, value interface{}))

func SetGenCodeConfigDefaults added in v0.216.0

func SetGenCodeConfigDefaults(prefix string, set func(key string, value interface{}))

func SetLibraryConfigDefaults added in v0.216.0

func SetLibraryConfigDefaults(prefix string, set func(key string, value interface{}))

func StringToSensitiveStringHookFunc added in v0.175.0

func StringToSensitiveStringHookFunc() mapstructure.DecodeHookFunc

StringToSensitiveStringHookFunc returns a DecodeHookFunc that converts strings to SensitiveString.

func TLSCiphers

func TLSCiphers(cfg *TLSConfig) (ciphers []uint16, err error)

func TLSClientAuth

func TLSClientAuth(cfg *TLSConfig) (*tls.ClientAuthType, error)

func TLSRenegotiationSupport added in v0.178.0

func TLSRenegotiationSupport(cfg *TLSConfig) (*tls.RenegotiationSupport, error)

func TLSVersions

func TLSVersions(cfg *TLSConfig) (min, max uint16, err error)

Types

type AdminConfig added in v0.130.0

type AdminConfig struct {
	ContextTimeout time.Duration          `yaml:"contextTimeout" mapstructure:"contextTimeout" validate:"nonnil"`
	HTTP           CommonHTTPServerConfig `yaml:"http" mapstructure:"http"`
}

type AuthenticationConfig added in v0.103.0

type AuthenticationConfig struct {
	JWTAuth *jwtauth.Config `yaml:"jwtauth" mapstructure:"jwtauth"`
}

AuthenticationConfig struct.

type CertKeyPair

type CertKeyPair struct {
	CertPath *string `yaml:"certPath" mapstructure:"certPath"`
	KeyPath  *string `yaml:"keyPath" mapstructure:"keyPath"`
}

type CommonDownstreamData

type CommonDownstreamData struct {
	ServiceURL      string              `yaml:"serviceURL" mapstructure:"serviceURL"`
	ClientTransport Transport           `yaml:"clientTransport" mapstructure:"clientTransport"`
	ClientTimeout   time.Duration       `yaml:"clientTimeout" mapstructure:"clientTimeout" validate:"timeout=1ms:60s"`
	Headers         map[string][]string `yaml:"headers" mapstructure:"headers"`
}

CommonDownstreamData collects all the client http configuration.

func DefaultCommonDownstreamData

func DefaultCommonDownstreamData() *CommonDownstreamData

func (*CommonDownstreamData) Validate

func (g *CommonDownstreamData) Validate() error

type CommonGRPCDownstreamData added in v0.56.0

type CommonGRPCDownstreamData struct {
	ServiceAddress string     `yaml:"serviceAddress" mapstructure:"serviceAddress"`
	TLS            *TLSConfig `yaml:"tls" mapstructure:"tls"`
	WithBlock      bool       `yaml:"withBlock" mapstructure:"withBlock"`
}

CommonGRPCDownstreamData collects all the client gRPC configuration.

func NewDefaultCommonGRPCDownstreamData added in v0.56.0

func NewDefaultCommonGRPCDownstreamData() *CommonGRPCDownstreamData

type CommonHTTPServerConfig

type CommonHTTPServerConfig struct {
	Common       CommonServerConfig `yaml:"common" mapstructure:"common"`
	BasePath     string             `yaml:"basePath" mapstructure:"basePath" validate:"omitempty,startswith=/"`
	ReadTimeout  time.Duration      `yaml:"readTimeout" mapstructure:"readTimeout" validate:"nonnil"`
	WriteTimeout time.Duration      `yaml:"writeTimeout" mapstructure:"writeTimeout" validate:"nonnil"`
}

TODO: Inline CommonServerConfig When specifying this configuration value, any common properties should be found at the same level as any HTTP-specific properties, not nested within a separate 'common' component. For an example how this should be done, see GRPCServerConfig. The change should continue to support legacy configurations that nest 'common' properties but encourage users to migrate their properties inline.

func (*CommonHTTPServerConfig) Validate

func (c *CommonHTTPServerConfig) Validate() error

type CommonServerConfig

type CommonServerConfig struct {
	HostName string     `yaml:"hostName" mapstructure:"hostName"`
	Port     int        `yaml:"port" mapstructure:"port" validate:"min=0,max=65534"`
	TLS      *TLSConfig `yaml:"tls" mapstructure:"tls"`
}

type CommonTemporalDownstreamData added in v0.283.0

type CommonTemporalDownstreamData struct {
	HostPort  string `yaml:"hostPort" mapstructure:"hostPort"`
	Identity  string `yaml:"identity" mapstructure:"identity"`
	Namespace string `yaml:"namespace" mapstructure:"namespace"`
}

type ConfigReader added in v0.175.0

type ConfigReader interface {
	// Get returns an interface{}.
	// For a specific value use one of the Get____ methods.
	Get(key string) (interface{}, error)

	// GetString retrieves the associated key value as a string.
	GetString(key string) (string, error)

	// Unmarshal deserializes the loaded cofig into a struct.
	Unmarshal(config interface{}) error
}

ConfigReader lists the methods exposed by ConfigReaderImpl.

type ConfigReaderBuilder added in v0.175.0

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

ConfigReaderBuilder exposes the builder api for configReaderImpl. Use NewConfigReaderBuilder() and AttachEnvPrefix() to Build a ConfigReaderBuilder. Follow it up one or more calls to WithConfigFile() and/or WithConfigName() and finally use Build() to Build the configReaderImpl.

func NewConfigReaderBuilder added in v0.175.0

func NewConfigReaderBuilder() ConfigReaderBuilder

NewConfigReaderBuilder builds a new ConfigReaderBuilder.

func (ConfigReaderBuilder) AttachEnvPrefix added in v0.175.0

func (b ConfigReaderBuilder) AttachEnvPrefix(appName string) ConfigReaderBuilder

AttachEnvPrefix attaches appName as prefix.

func (ConfigReaderBuilder) Build added in v0.175.0

Build Builds and returns the ConfigReader.

func (ConfigReaderBuilder) WithConfigFile added in v0.175.0

func (b ConfigReaderBuilder) WithConfigFile(configFile string) ConfigReaderBuilder

WithConfigFile attaches the passed config file.

func (ConfigReaderBuilder) WithConfigName added in v0.175.0

func (b ConfigReaderBuilder) WithConfigName(configName string, configPath ...string) ConfigReaderBuilder

WithConfigName attaches the passed config path and name.

func (ConfigReaderBuilder) WithDefaults added in v0.216.0

func (b ConfigReaderBuilder) WithDefaults(setDefaults func(func(key string, value interface{}))) ConfigReaderBuilder

WithDefaults takes a function than can be called to set default values.

func (ConfigReaderBuilder) WithFs added in v0.175.0

WithFs attaches the file system to use.

func (ConfigReaderBuilder) WithStrictMode added in v0.175.0

func (b ConfigReaderBuilder) WithStrictMode(strict bool, ignoredKeys ...string) ConfigReaderBuilder

WithStrictMode controls if ConfigReader.Unmarshal handles unknown keys. If strict mode is false (the default), config keys with no corresponding config field are ignored. If strict mode is true, any config key with no corresponding config field will be regarded as a decoding error that will cause Unmarshal to return an error.

Also, optionally, a list of keys to ignore and exclude from strict mode checking can be provided. Beware, there's some subtleties to how ignored keys must be named, see the comments inside configreaderimpl.go for details.

type DefaultConfig

type DefaultConfig struct {
	Library LibraryConfig `yaml:"library" mapstructure:"library"`

	// config used for setting up the sysl-go admin server
	Admin   *AdminConfig  `yaml:"admin" mapstructure:"admin"`
	GenCode GenCodeConfig `yaml:"genCode" mapstructure:"genCode"`

	// development config can be used to set some config options only appropriate for dev/test environments.
	Development *DevelopmentConfig `yaml:"development" mapstructure:"development"`
}

func GetDefaultConfig added in v0.175.0

func GetDefaultConfig(ctx context.Context) *DefaultConfig

GetDefaultConfig retrieves the externally-provided config from the context. The default config is injected into the server context during bootstrapping and can therefore be called from anywhere within the running application.

type DevelopmentConfig added in v0.103.0

type DevelopmentConfig struct {
	// disableAllAuthorizationRules can be used to disable all authorization rule logic
	// guarding calls to endpoints or RPC methods, and instead unconditionally grant access.
	// This option is insecure and should not be enabled in production.
	DisableAllAuthorizationRules bool `yaml:"disableAllAuthorizationRules" mapstructure:"disableAllAuthorizationRules"`
}

DevelopmentConfig struct.

type Dialer

type Dialer struct {
	Timeout   time.Duration `yaml:"timeout" mapstructure:"timeout"`
	KeepAlive time.Duration `yaml:"keepAlive" mapstructure:"keepAlive"`
	DualStack bool          `yaml:"dualStack" mapstructure:"dualStack"`
}

Dialer is part of the Transport struct.

type GRPCServerConfig added in v0.187.0

type GRPCServerConfig struct {
	CommonServerConfig `yaml:",inline" mapstructure:",squash"`
	EnableReflection   bool `yaml:"enableReflection" mapstructure:"enableReflection"`
}

type GenCodeConfig

type GenCodeConfig struct {
	Upstream   UpstreamConfig `yaml:"upstream" mapstructure:"upstream"`
	Downstream interface{}    `yaml:"downstream" mapstructure:"downstream"`
}

GenCodeConfig struct.

type LibraryConfig

type LibraryConfig struct {
	Log            LogConfig             `yaml:"log" mapstructure:"log"`
	Profiling      bool                  `yaml:"profiling" mapstructure:"profiling"`
	Health         bool                  `yaml:"health" mapstructure:"health"`
	Authentication *AuthenticationConfig `yaml:"authentication" mapstructure:"authentication"`
	Trace          TraceConfig           `yaml:"trace" mapstructure:"trace"`
}

LibraryConfig struct.

func (*LibraryConfig) Validate

func (c *LibraryConfig) Validate() error

type LogConfig

type LogConfig struct {
	Format       string    `yaml:"format" mapstructure:"format" validate:"oneof=color json text"` // Deprecated: Use Hooks#Logger
	Level        log.Level `yaml:"level" mapstructure:"level" validate:"nonnil"`
	ReportCaller bool      `yaml:"caller" mapstructure:"caller"` // Deprecated: Use Hooks#Logger

	// LogPayload logs the contents of request and response objects.
	LogPayload bool `yaml:"logPayload" mapstructure:"logPayload"`
}

LogConfig struct.

type NilValueError added in v0.175.0

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

NilValueError is raised when the key value is nil.

func (NilValueError) Error added in v0.175.0

func (e NilValueError) Error() string

type Pkcs12Store added in v0.178.0

type Pkcs12Store struct {
	Path     *string          `yaml:"path" mapstructure:"path"`
	Password *SensitiveString `yaml:"password" mapstructure:"password"`
}

type SecretKey

type SecretKey struct {
	SensitiveString
}

func MakeSecretKey

func MakeSecretKey(cfg *SecretKeyConfig) (*SecretKey, error)

type SecretKeyConfig

type SecretKeyConfig struct {
	Encoding         *string          `yaml:"encoding" mapstructure:"encoding" json:"encoding"`
	Alias            *string          `yaml:"alias,omitempty" mapstructure:"alias,omitempty" json:"alias,omitempty"`
	KeyStore         *string          `yaml:"keyStore,omitempty" mapstructure:"keyStore,omitempty" json:"keyStore,omitempty"`
	KeyStorePassword *SensitiveString `yaml:"keyStorePassword,omitempty" mapstructure:"keyStorePassword,omitempty" json:"keyStorePassword,omitempty"`
	Value            *SensitiveString `yaml:"value,omitempty" mapstructure:"value,omitempty" json:"value,omitempty"`
}

func (*SecretKeyConfig) Validate

func (s *SecretKeyConfig) Validate() error

type SensitiveString added in v0.175.0

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

func NewSensitiveString added in v0.175.0

func NewSensitiveString(from string) SensitiveString

func (*SensitiveString) MarshalJSON added in v0.175.0

func (s *SensitiveString) MarshalJSON() ([]byte, error)

func (SensitiveString) MarshalYAML added in v0.175.0

func (s SensitiveString) MarshalYAML() (interface{}, error)

Note, this one needs to be an object receiver NOT a pointer receiver.

func (SensitiveString) String added in v0.175.0

func (s SensitiveString) String() string

func (*SensitiveString) UnmarshalJSON added in v0.175.0

func (s *SensitiveString) UnmarshalJSON(data []byte) error

func (*SensitiveString) UnmarshalYAML added in v0.175.0

func (s *SensitiveString) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*SensitiveString) Value added in v0.175.0

func (s *SensitiveString) Value() string

type ServerIdentityConfig

type ServerIdentityConfig struct {
	CertKeyPair *CertKeyPair `yaml:"certKeyPair" mapstructure:"certKeyPair"`
	// Add Pkcs12Store to store cert and key as it is protected by password
	PKCS12Store *Pkcs12Store `yaml:"p12Store" mapstructure:"p12Store"`
}

type TLSConfig

type TLSConfig struct {
	MinVersion         *string                 `yaml:"min" mapstructure:"min"`
	MaxVersion         *string                 `yaml:"max" mapstructure:"max"`
	ClientAuth         *string                 `yaml:"clientAuth" mapstructure:"clientAuth"`
	Ciphers            []string                `yaml:"ciphers" mapstructure:"ciphers"`
	ServerIdentities   []*ServerIdentityConfig `yaml:"serverIdentities" mapstructure:"serverIdentities"` // One server needs more than 1 identities in some cases.
	TrustedCertPool    *TrustedCertPoolConfig  `yaml:"trustedCertPool" mapstructure:"trustedCertPool"`
	InsecureSkipVerify bool                    `yaml:"insecureSkipVerify" mapstructure:"insecureSkipVerify"`
	SelfSigned         bool                    `yaml:"selfSigned" mapstructure:"selfSigned"`
	Renegotiation      *string                 `yaml:"renegotiation" mapstructure:"renegotiation"` // Downward compatibility for low version TLS.
}

func (*TLSConfig) Validate

func (t *TLSConfig) Validate() error

type TemporalServerConfig added in v0.289.0

type TemporalServerConfig struct {
	HostPort  string `yaml:"hostPort" mapstructure:"hostPort"`
	Namespace string `yaml:"namespace" mapstructure:"namespace"`
}

type TraceConfig added in v0.200.0

type TraceConfig struct {
	IncomingHeaderForID string `yaml:"incomingHeaderForID" mapstructure:"incomingHeaderForID"`
}

TraceConfig struct.

type Transport

type Transport struct {
	Dialer                Dialer        `yaml:"dialer" mapstructure:"dialer"`
	MaxIdleConns          int           `yaml:"maxIdleConns" mapstructure:"maxIdleConns"`
	IdleConnTimeout       time.Duration `yaml:"idleConnTimeout" mapstructure:"idleConnTimeout"`
	TLSHandshakeTimeout   time.Duration `yaml:"tLSHandshakeTimeout" mapstructure:"tLSHandshakeTimeout"`
	ExpectContinueTimeout time.Duration `yaml:"expectContinueTimeout" mapstructure:"expectContinueTimeout"`
	ClientTLS             *TLSConfig    `yaml:"tls" mapstructure:"tls"`
	ProxyURL              string        `yaml:"proxyURL" mapstructure:"proxyURL"`
	UseProxy              bool          `yaml:"useProxy" mapstructure:"useProxy"`
}

Transport is used to initialise DefaultHTTPTransport.

type TrustedCertPoolConfig

type TrustedCertPoolConfig struct {
	Mode     *string          `yaml:"mode" mapstructure:"mode"`
	Encoding *string          `yaml:"encoding" mapstructure:"encoding"`
	Path     *string          `yaml:"path" mapstructure:"path"`
	Password *SensitiveString `yaml:"password" mapstructure:"password"`
}

type UpstreamConfig

type UpstreamConfig struct {
	ContextTimeout time.Duration          `yaml:"contextTimeout" mapstructure:"contextTimeout" validate:"nonnil"`
	HTTP           CommonHTTPServerConfig `yaml:"http" mapstructure:"http"`
	GRPC           GRPCServerConfig       `yaml:"grpc" mapstructure:"grpc"`
	Temporal       TemporalServerConfig   `yaml:"temporal" mapstructure:"temporal"`
}

UpstreamConfig struct.

func (*UpstreamConfig) Validate added in v0.85.0

func (c *UpstreamConfig) Validate() error

type ValueConversionError added in v0.175.0

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

ValueConversionError is raised when the key value is incompatible with the invoked method.

func (ValueConversionError) Error added in v0.175.0

func (e ValueConversionError) Error() string

Jump to

Keyboard shortcuts

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