config

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default top-level configuration.
	DefaultConfig = Config{
		ServerConfig:        DefaultServerConfig,
		EtcdConfig:          DefaultEtcdConfig,
		JWTConfig:           DefaultJWTConfig,
		RemoteHostPattern:   ".*",
		EnableProfiling:     false,
		PasswordHashingCost: bcrypt.DefaultCost,
		FernetKey:           "RSkt1yqhOp9znrUzeCQRybYdRVqQGfO5G2VR-wF8OKc=",
	}

	DefaultServerConfig = ServerConfig{
		EnableTLS:      false,
		CertFile:       serverDefaultCertFile,
		CertKey:        serverDefaultCertKey,
		ReadTimeout:    serverDefaultReadTimeout,
		WriteTimeout:   serverDefaultWriteTimeout,
		MaxHeaderBytes: serverDefaultMaxHeaderBytes,
	}

	// DefaultEtcdConfig is the default Etcd configuration.
	DefaultEtcdConfig = EtcdConfig{
		Endpoints:            []string{"127.0.0.1:2379"},
		DialTimeout:          etcdDefaultDialTimeout,
		DialKeepAliveTime:    etcdDefaultKeepAliveTime,
		DialKeepAliveTimeout: etcdDefaultKeepAliveTimeOut,
		DialOptions:          []grpc.DialOption{grpc.WithBlock()},
	}

	// DefaultJWTConfig is the default JWT configuration.
	DefaultJWTConfig = JWTConfig{
		SigningMethod:      jwtDefaultSigningMethod,
		TTL:                jwtDefaultTTL,
		IsBearerToken:      jwtDefaultIsBearerToken,
		UserProperty:       jwtDefaultUserProperty,
		PrivateKeyLocation: jwtDefaultPrivateKeyLocation,
		PublicKeyLocation:  jwtDefaultPublicKeyLocation,
	}
)

Functions

func Load

func Load(in string) error

Load parses the YAML input s into a Config

func LoadFile

func LoadFile(in string) error

LoadFile parses the given YAMl file into a Config.

func OnConfigChange

func OnConfigChange(run func(in fsnotify.Event))

OnConfigChange defines the function be called when config file was change.

func Set

func Set(fp string, l log.Logger) error

Set sets logger and loads Config from the given file path.

func SetConfig

func SetConfig(newConf *Config)

SetConfig updates the value of configuration. newConf should be a copy of m.config instance.

func SetConfigPath

func SetConfigPath(in string)

SetConfigPath sets the path of config file

func SetConfigPermissions

func SetConfigPermissions(perm os.FileMode)

SetConfigPermissions sets the permissions for the config file.

func SetLogger

func SetLogger(l log.Logger)

SetLogger sets the manager's log instance.

func Show

func Show()

Show returns the represent of Config. For debug purpose only

func WatchConfig

func WatchConfig()

WatchConfig detects file changes and reloads config.

func Write

func Write() error

Write writes the currnet configuration to a file

Types

type AdminAuthentication

type AdminAuthentication struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

AdminAuthentication represents the `root/admin` user authentication

type Config

type Config struct {
	ServerConfig ServerConfig `yaml:"server_config"`
	EtcdConfig   EtcdConfig   `yaml:"etcd"`
	JWTConfig    JWTConfig    `yaml:"jwt"`
	MailConfig   MailConfig   `yaml:"mail,omitempty"`
	// RemoteHostPattern can define an optional regexp pattern to be matched:
	//
	// - {name} matches anything until the next dot.
	//
	// - {name:pattern} matches the given regexp pattern.
	RemoteHostPattern string `yaml:"remote_host_pattern,omitempty"`
	// PasswordHashingCost is the cost to hash the user password.
	// Check bcrypt for details: https://godoc.org/golang.org/x/crypto/bcrypt#pkg-constants
	PasswordHashingCost int    `yaml:"password_hashing_cost"`
	FernetKey           string `yaml:"fernet_key"`
	// EnableProfiling enables profiling via web interface host:port/debug/pprof/
	EnableProfiling     bool                `yaml:"enable_profiling"`
	AdminAuthentication AdminAuthentication `yaml:"admin_authentication"`
}

Config is the top-level configuration for Faythe's config file.

func Get

func Get() *Config

Get returns Config instance.

func (*Config) String

func (c *Config) String() string

String represents Configuration instance as string.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type EtcdConfig

type EtcdConfig struct {
	// Endpoints is a list of URLs.
	Endpoints []string `yaml:"endpoints"`

	// AutoSyncInterval is the interval to update endpoints with its latest members.
	// 0 disables auto-sync. By default auto-sync is disabled.
	AutoSyncInterval time.Duration `yaml:"auto_sync_interval,omitempty"`

	// DialTimeout is the timeout for failing to establish a connection.
	DialTimeout time.Duration `yaml:"dial_timeout,omitempty"`

	// DialKeepAliveTime is the time after which client pings the server to see if
	// transport is alive.
	DialKeepAliveTime time.Duration `yaml:"dial_keep_alive_time,omitempty"`

	// DialKeepAliveTimeout is the time that the client waits for a response for the
	// keep-alive probe. If the response is not received in this time, the connection is closed.
	DialKeepAliveTimeout time.Duration `yaml:"dial_keep_alive_timeout,omitempty"`

	// MaxCallSendMsgSize is the client-side request send limit in bytes.
	// If 0, it defaults to 2.0 MiB (2 * 1024 * 1024).
	// Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit.
	// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
	MaxCallSendMsgSize int `yaml:"max_call_send_msg_size,omitempty"`

	// MaxCallRecvMsgSize is the client-side response receive limit.
	// If 0, it defaults to "math.MaxInt32", because range response can
	// easily exceed request send limits.
	// Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit.
	// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
	MaxCallRecvMsgSize int `yaml:"max_call_recv_msg_size,omitempty"`

	// TLS holds the client secure credentials, if any.
	TLS *tls.Config `yaml:"tls,omitempty"`

	// Username is a user name for authentication.
	Username string `yaml:"username,omitempty"`

	// Password is a password for authentication.
	Password string `yaml:"password,omitempty"`

	// RejectOldCluster when set will refuse to create a client against an outdated cluster.
	RejectOldCluster bool `yaml:"reject_old_cluster,omitempty"`

	// PermitWithoutStream when set will allow client to send keepalive pings to server without any active streams(RPCs).
	PermitWithoutStream bool `yaml:"permit_without_stream,omitempty"`

	// DialOptions is a list of dial options for the grpc client (e.g., for interceptors).
	// For example, pass "grpc.WithBlock()" to block until the underlying connection is up.
	// Without this, Dial returns immediately and connecting the server happens in background.
	DialOptions []grpc.DialOption
}

EtcdConfig stores Etcd related configurations.

func (*EtcdConfig) UnmarshalYAML

func (c *EtcdConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type JWTConfig

type JWTConfig struct {
	// SigningMethodString is a string to define the signing method
	// Valid signing methods:
	// - "RS256","RS384","RS512" (RSA signing method)
	// - "ES256","ES384","ES512" (ECDSA signing method)
	// More details here: https://github.com/dgrijalva/jwt-go#signing-methods-and-key-types
	SigningMethod string `yaml:"signing_method"`
	// PrivateKeyLocation is the private key path
	// $ openssl genrsa -out faythe.rsa 2048
	PrivateKeyLocation string `yaml:"private_key_location"`
	// PublicKeyLocation is the public key path
	// $ openssl rsa -in faythe.rsa -pubout > faythe.rsa.pub
	PublicKeyLocation string `yaml:"public_key_location"`
	// TTL - Token time to live
	TTL           time.Duration `yaml:"ttl"`
	IsBearerToken bool          `yaml:"is_bearer_token"`
	// Header is a name of the custom request header.
	// If IsBearerToken is set, the header name will be `Authorization`
	// with value format `Bearer <token-string>`.
	Header string `yaml:"header"`
	// The name of the property in the request where the user information
	// from the JWT will be stored.
	UserProperty string `yaml:"user_property"`
}

JWTConfig is a struct for specifying JWT configuration options A clone of Options struct: https://github.com/adam-hanna/jwt-auth/blob/develop/jwt/auth.go#L31

func (*JWTConfig) UnmarshalYAML

func (c *JWTConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type MailConfig

type MailConfig struct {
	Host     string `yaml:"host"`
	Protocol string `yaml:"protocol"`
	Port     int    `yaml:"port"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

MailConfig stores configs to setup a SNMP client.

func (*MailConfig) UnmarshalYAML

func (c *MailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface

type Manager

type Manager struct {
	Config *Config
	// contains filtered or unexported fields
}

Manager is a configuration manager. It maintains a global configuration, fetchs values to populate.

func NewManager

func NewManager() *Manager

NewManager returns initialized Manager instance

func (*Manager) Get

func (m *Manager) Get() *Config

Get returns Config instance.

func (*Manager) Load

func (m *Manager) Load(in string) error

Load parses the YAML input s into a Config

func (*Manager) LoadFile

func (m *Manager) LoadFile(in string) error

LoadFile parses the given YAMl file into a Config.

func (*Manager) OnConfigChange

func (m *Manager) OnConfigChange(run func(in fsnotify.Event))

OnConfigChange defines the function be called when config file was change.

func (*Manager) Set

func (m *Manager) Set(fp string, l log.Logger) error

Set sets logger and loads Config from the given file path.

func (*Manager) SetConfig

func (m *Manager) SetConfig(newConf *Config)

SetConfig updates the value of configuration. newConf should be a copy of m.config instance.

func (*Manager) SetConfigPath

func (m *Manager) SetConfigPath(in string)

SetConfigPath sets the path of config file

func (*Manager) SetConfigPermissions

func (m *Manager) SetConfigPermissions(perm os.FileMode)

SetConfigPermissions sets the permissions for the config file.

func (*Manager) SetLogger

func (m *Manager) SetLogger(l log.Logger)

SetLogger sets the manager's log instance.

func (*Manager) Show

func (m *Manager) Show()

Show returns the represent of Config. For debug purpose only

func (*Manager) WatchConfig

func (m *Manager) WatchConfig()

WatchConfig detects file changes and reloads config.

func (*Manager) Write

func (m *Manager) Write() error

Write writes the current configuration to a file.

type ServerConfig

type ServerConfig struct {
	EnableTLS      bool          `yaml:"enable_tls"`
	CertFile       string        `yaml:"cert_file"`
	CertKey        string        `yaml:"cert_key"`
	ReadTimeout    time.Duration `yaml:"read_timeout"`
	WriteTimeout   time.Duration `yaml:"write_timeout"`
	MaxHeaderBytes int           `yaml:"max_header_bytes"`
}

ServerConfig stores configs to setup HTTP Server

Jump to

Keyboard shortcuts

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