config

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package config holds the echo server configuration utilities

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfigRefresh sets the default interval to refresh the config.
	DefaultConfigRefresh = 10 * time.Minute
	// DefaultTLSConfig is the default TLS config used when HTTPS is enabled
	DefaultTLSConfig = &tls.Config{
		MinVersion:               tls.VersionTLS12,
		CurvePreferences:         []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
		PreferServerCipherSuites: true,
		CipherSuites: []uint16{
			tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
		},
	}
)

Functions

This section is empty.

Types

type Auth

type Auth struct {
	// Enabled - checks this first before reading your provider config
	Enabled bool `yaml:"enabled" split_words:"true" default:"true"`
	// SupportedProviders are the supported oauth providers that have been configured
	SupportedProviders []string `yaml:"supportedProviders" split_words:"true"`
}

Auth settings including providers and the ability to enable/disable auth all together

type CORS

type CORS struct {
	// AllowOrigins is a list of allowed origin to indicate whether the response can be shared with
	// requesting code from the given origin
	AllowOrigins []string `yaml:"allowOrigins"`
	// CookieInsecure allows CSRF cookie to be sent to servers that the browser considers
	// unsecured. Useful for cases where the connection is secured via VPN rather than
	// HTTPS directly.
	CookieInsecure bool `yaml:"cookieInsecure"`
}

CORS settings

type Config

type Config struct {
	// RefreshInterval holds often to reload the config
	RefreshInterval time.Duration `yaml:"refreshInterval" split_words:"true" default:"10m"`

	// Server contains the echo server settings
	Server Server `yaml:"server"`

	// Auth contains the authentication provider(s)
	Auth Auth `yaml:"auth"`

	// Authz contains the authorization settings
	Authz fgax.Config `yaml:"authz"`

	// DB contains the database configuration
	DB entdb.Config `yaml:"db"`

	// RedisConfig contains the redis configuration
	RedisConfig cache.Config `yaml:"redisConfig"`

	// Logger contains the logger used by echo functions
	Logger *zap.SugaredLogger `yaml:"logger"`

	// Tracer contains the tracing config used by datum
	Tracer otelx.Config `yaml:"tracer"`

	// Email contains email sending configuration
	Email emails.Config `yaml:"email"`
}

Config contains the configuration for the datum server

func NewServerConfig added in v0.2.3

func NewServerConfig() *Config

NewServerConfig creates a new empty config

func (*Config) GetConfig

func (c *Config) GetConfig() (*Config, error)

GetConfig implements ConfigProvider.

func (*Config) WithAutoCert

func (c *Config) WithAutoCert(host string) *Config

WithAutoCert generates a letsencrypt certificate, a valid host must be provided

func (Config) WithDefaultTLSConfig

func (c Config) WithDefaultTLSConfig() Config

WithDefaultTLSConfig sets the default TLS Configuration

func (*Config) WithTLSCerts

func (c *Config) WithTLSCerts(certFile, certKey string) *Config

WithTLSCerts sets the TLS Cert and Key locations

func (Config) WithTLSDefaults

func (c Config) WithTLSDefaults() Config

WithTLSDefaults sets tls default settings assuming a default cert and key file location.

type ConfigProvider

type ConfigProvider interface {
	// GetConfig returns the server configuration
	GetConfig() (*Config, error)
}

ConfigProvider serves as a common interface to read echo server configuration

type ConfigProviderWithRefresh

type ConfigProviderWithRefresh struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConfigProviderWithRefresh shows a config provider with automatic refresh; it contains fields and methods to manage the configuration, and refresh it periodically based on a specified interval

func NewConfigProviderWithRefresh

func NewConfigProviderWithRefresh(cfgProvider ConfigProvider) (*ConfigProviderWithRefresh, error)

NewConfigProviderWithRefresh function is a constructor function that creates a new instance of ConfigProviderWithRefresh

func (*ConfigProviderWithRefresh) Close

func (s *ConfigProviderWithRefresh) Close()

Close function is used to stop the automatic refresh of the configuration. It stops the ticker that triggers the refresh and closes the stop channel, which signals the goroutine to stop refreshing the configuration

func (*ConfigProviderWithRefresh) GetConfig

func (s *ConfigProviderWithRefresh) GetConfig() (*Config, error)

GetConfig retrieves the current echo server configuration; it acquires a read lock to ensure thread safety and returns the `config` field

type Server

type Server struct {
	// Debug enables echo's Debug option.
	Debug bool `yaml:"debug" split_words:"true" default:"false"`
	// Dev enables echo's dev mode options.
	Dev bool `yaml:"dev" split_words:"true" default:"false"`
	// Listen sets the listen address to serve the echo server on.
	Listen string `yaml:"listen" split_words:"true" default:":17608"`
	// ShutdownGracePeriod sets the grace period for in flight requests before shutting down.
	ShutdownGracePeriod time.Duration `yaml:"shutdownGracePeriod" split_words:"true" default:"10s"`
	// ReadTimeout sets the maximum duration for reading the entire request including the body.
	ReadTimeout time.Duration `yaml:"readTimeout" split_words:"true" default:"15s"`
	// WriteTimeout sets the maximum duration before timing out writes of the response.
	WriteTimeout time.Duration `yaml:"writeTimeout" split_words:"true" default:"15s"`
	// IdleTimeout sets the maximum amount of time to wait for the next request when keep-alives are enabled.
	IdleTimeout time.Duration `yaml:"idleTimeout" split_words:"true" default:"30s"`
	// ReadHeaderTimeout sets the amount of time allowed to read request headers.
	ReadHeaderTimeout time.Duration `yaml:"readHeaderTimeout" split_words:"true" default:"2s"`
	// TLS contains the tls configuration settings
	TLS TLS `yaml:"tls"`
	// CORS contains settings to allow cross origin settings and insecure cookies
	CORS CORS `yaml:"cors"`
	// Routes contains the handler functions
	Routes []http.Handler `yaml:"routes"`
	// DefaultMiddleware to enable on the echo server used on all requests
	DefaultMiddleware []echo.MiddlewareFunc `yaml:"defaultMiddleware"`
	// GraphMiddleware to enable on the echo server used on graph requests
	GraphMiddleware []echo.MiddlewareFunc `yaml:"graphMiddleware"`
	// Handler contains the required settings for REST handlers including ready checks and JWT keys
	Handler handlers.Handler `yaml:"checks"`
	// Token contains the token config settings
	Token tokens.Config `yaml:"token"`
	// SessionConfig manages sessions for users
	SessionConfig *sessions.SessionConfig
	// Sentry contains the sentry configuration
	Sentry sentry.Config `yaml:"sentry"`
}

Server settings

type TLS

type TLS struct {
	// Config contains the tls.Config settings
	Config *tls.Config `yaml:"config"`
	// Enabled turns on TLS settings for the server
	Enabled bool `yaml:"enabled" split_words:"true" default:"false"`
	// CertFile location for the TLS server
	CertFile string `yaml:"certFile" split_words:"true" default:"server.crt"`
	// CertKey file location for the TLS server
	CertKey string `yaml:"certKey" split_words:"true" default:"server.key"`
	// AutoCert generates the cert with letsencrypt, this does not work on localhost
	AutoCert bool `yaml:"autoCert" split_words:"true" default:"false"`
}

TLS settings

Jump to

Keyboard shortcuts

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