config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Maintenance  bool                `default:"false"`                                    // $QUARTERDECK_MAINTENANCE
	BindAddr     string              `split_words:"true" default:":8088"`                 // $QUARTERDECK_BIND_ADDR
	Mode         string              `default:"release"`                                  // $QUARTERDECK_MODE
	LogLevel     logger.LevelDecoder `split_words:"true" default:"info"`                  // $QUARTERDECK_LOG_LEVEL
	ConsoleLog   bool                `split_words:"true" default:"false"`                 // $QUARTERDECK_CONSOLE_LOG
	AllowOrigins []string            `split_words:"true" default:"http://localhost:3000"` // $QUARTERDECK_ALLOW_ORIGINS
	EmailURL     URLConfig           `split_words:"true"`
	SendGrid     emails.Config       `split_words:"false"`
	RateLimit    RateLimitConfig     `split_words:"true"`
	Reporting    ReportingConfig
	Database     DatabaseConfig
	Token        TokenConfig
	Sentry       sentry.Config
	// contains filtered or unexported fields
}

Config uses envconfig to load the required settings from the environment, parse and validate them, loading defaults where necessary in preparation for running the Quarterdeck API service. This is the top-level config, all sub configurations need to be defined as properties of this Config.

func New

func New() (conf Config, err error)

New loads and parses the config from the environment and validates it, marking it as processed so that external users can determine if the config is ready for use. This should be the only way Config objects are created for use in the application.

func (Config) AllowAllOrigins

func (c Config) AllowAllOrigins() bool

Returns true if the allow origins slice contains one entry that is a "*"

func (Config) GetLogLevel

func (c Config) GetLogLevel() zerolog.Level

func (Config) IsZero

func (c Config) IsZero() bool

Returns true if the config has not been correctly processed from the environment.

func (Config) Mark

func (c Config) Mark() (_ Config, err error)

Mark a manually constructed config as processed as long as it is valid.

func (Config) Validate

func (c Config) Validate() (err error)

Custom validations are added here, particularly validations that require one or more fields to be processed before the validation occurs. NOTE: ensure that all nested config validation methods are called here.

type DatabaseConfig

type DatabaseConfig struct {
	URL      string `default:"sqlite3:////data/db/quarterdeck.db"` // $QUARTERDECK_DATABASE_URL
	ReadOnly bool   `split_words:"true" default:"false"`           // $QUARTERDECK_DATABASE_READ_ONLY
}

type RateLimitConfig added in v0.5.2

type RateLimitConfig struct {
	Enabled   bool          `default:"true"`
	PerSecond float64       `default:"10" split_words:"true"`
	Burst     int           `default:"30"`
	TTL       time.Duration `default:"5m"`
}

Used by the Rate Limiter middleware Limit: represents the number of tokens that can be added to the token bucket per second Burst: maximum number of tokens/requests in a "token bucket" which is initially full empty token bucket results in failed requests TTL: //number of minutes before an IP is removed from the ratelimiter map NOTE: If Burst is not included the config, then all requests will be rejected! The Validate() method checks to see if the all required values for the RateLimiter middleware are populated and will fail startup if they are not populated

func (RateLimitConfig) Validate added in v0.7.0

func (c RateLimitConfig) Validate() error

type ReportingConfig added in v0.5.2

type ReportingConfig struct {
	EnableDailyPLG bool   `default:"true" split_words:"true"`
	Domain         string `default:"rotational.app"`
	DashboardURL   string `split_words:"true"`
}

Uses by the daily PLG reports and other Quarterdeck email reporting tools.

type TokenConfig

type TokenConfig struct {
	Keys            map[string]string `required:"false"`                      // $QUARTERDECK_TOKEN_KEYS
	Audience        string            `default:"https://rotational.app"`      // $QUARTERDECK_TOKEN_AUDIENCE
	RefreshAudience string            `required:"false"`                      // $QUARTERDECK_TOKEN_REFRESH_AUDIENCE
	Issuer          string            `default:"https://auth.rotational.app"` // $QUARTERDECK_TOKEN_ISSUER
	AccessDuration  time.Duration     `split_words:"true" default:"1h"`       // $QUARTERDECK_TOKEN_ACCESS_DURATION
	RefreshDuration time.Duration     `split_words:"true" default:"2h"`       // $QUARTERDECK_TOKEN_REFRESH_DURATION
	RefreshOverlap  time.Duration     `split_words:"true" default:"-15m"`     // $QUARTERDECK_TOKEN_REFRESH_OVERLAP
}

type URLConfig added in v0.5.2

type URLConfig struct {
	Base   string `split_words:"true" default:"https://rotational.app"`
	Verify string `split_words:"true" default:"/verify"`
	Invite string `split_words:"true" default:"/invite"`
}

func (URLConfig) InviteURL added in v0.5.2

func (c URLConfig) InviteURL(token string) (string, error)

Construct an invite URL from the token.

func (URLConfig) Validate added in v0.5.2

func (c URLConfig) Validate() error

func (URLConfig) VerifyURL added in v0.5.2

func (c URLConfig) VerifyURL(token string) (string, error)

Construct a verify URL from the token.

Jump to

Keyboard shortcuts

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