Documentation
¶
Overview ¶
Package config handles the delivery of the config to the rest of the API. Config is loaded by the CLI layer (cmd/) via viper and passed in via SetConfig.
Index ¶
Constants ¶
const CfgKey string = "cfg-object"
CfgKey is the key used to store the config object in the request context.
const (
// DefaultConfigFile is the default (relative) path for the config file.
DefaultConfigFile = "config.yaml"
)
const MaxStringLength int = 16
stored in two places: here and in the db schema
Variables ¶
var ( // DefaultConfigBytes contains the YAML bytes of the default config file. //go:embed default-config.yaml DefaultConfigBytes []byte // TeamRange is a helper-slice used to loop over every team. TeamRange []types.TeamNum )
exported
Functions ¶
func ConfigMiddleware ¶
func ConfigMiddleware() gin.HandlerFunc
Middleware stores the config connection object in the gin context. This can be retrieved as necessary in routes.
func SetConfig ¶
func SetConfig(newCfg *APIConfigSpec)
SetConfig stores the config in the global state. Must be called before Get() or TeamRange. Panics if called more than once.
Types ¶
type APIConfigSpec ¶
type APIConfigSpec struct {
NumTeams types.TeamNum `yaml:"num_teams" mapstructure:"num_teams" json:"num_teams" example:"5"`
StartPaused types.PauseState `yaml:"start_paused" mapstructure:"start_paused" json:"start_paused" example:"false"`
Sinks Sinks `yaml:"sinks" mapstructure:"sinks" json:"sinks"`
Boxes []BoxSpec `yaml:"boxes" mapstructure:"boxes" json:"boxes"`
UserLists []UserListSpec `yaml:"user_lists" mapstructure:"user_lists" json:"user_lists"`
HTTP HTTPSpec `yaml:"http" mapstructure:"http" json:"http"`
}
APIConfigSpec defines the entire API configuration file.
func Get ¶
func Get(c *gin.Context) *APIConfigSpec
Get returns the config object stored in the request context. Panics on error.
func GetE ¶
func GetE(c *gin.Context) (*APIConfigSpec, error)
GetE returns the config object stored in the request context.
func (*APIConfigSpec) Validate ¶
func (cfg *APIConfigSpec) Validate() error
Validate validates the API configuration.
type BoxSpec ¶
type BoxSpec struct {
Name types.BoxName `yaml:"name" mapstructure:"name" json:"name" example:"scrapyard"`
Host string `yaml:"host" mapstructure:"host" json:"host" example:"127.0.0.{}"`
Services []types.ServiceSpec `yaml:"services" mapstructure:"services" json:"services"`
}
BoxSpec contains the config specification of one box. It is the parent to a list of services. The Name is enforced to be unique, but multiple boxes can have identical services or hosts.
type HTTPSpec ¶
type HTTPSpec struct {
Host string `yaml:"host" mapstructure:"host" json:"host" example:"127.0.0.1"`
Port int `yaml:"port" mapstructure:"port" json:"port" example:"8888"`
}
HTTPSpec defines the settings applied to the API's listener.
type OTelBatching ¶
type OTelBatching struct {
BatchSize int `yaml:"batch_size" mapstructure:"batch_size" json:"batch_size" example:"20"`
ExportInterval int `yaml:"export_interval" mapstructure:"export_interval" json:"export_interval" example:"5"`
MaxQueueSize int `yaml:"max_queue_size" mapstructure:"max_queue_size" json:"max_queue_size" example:"200"`
}
OTelBatching controls how log records are batched before export. Zero values use defaults (BatchSize: 20, ExportInterval: 5s, MaxQueueSize: 200).
type OTelConfig ¶
type OTelConfig struct {
Endpoint string `yaml:"endpoint" mapstructure:"endpoint" json:"endpoint" example:"http://localhost:4318"`
Username string `yaml:"username" mapstructure:"username" json:"username" example:"admin"`
Password string `yaml:"password" mapstructure:"password" json:"password" example:"secret"`
BasicAuth string `yaml:"basic_auth" mapstructure:"basic_auth" json:"basic_auth" example:"dXNlcjpwYXNz"`
// OpenObserve specific header
StreamName string `yaml:"stream_name" mapstructure:"stream_name" json:"stream_name" example:"quincy"`
// Batching settings
Batching OTelBatching `yaml:"batching" mapstructure:"batching" json:"batching"`
}
type PGConfig ¶
type PGConfig struct {
Host string `yaml:"host" mapstructure:"host" json:"host" example:"localhost"`
Port uint16 `yaml:"port" mapstructure:"port" json:"port" example:"5432"`
Username string `yaml:"username" mapstructure:"username" json:"username" example:"postgres"`
Password string `yaml:"password" mapstructure:"password" json:"password" example:"postgres"`
Database string `yaml:"database" mapstructure:"database" json:"database" example:"quincy"`
SSLMode string `yaml:"ssl_mode" mapstructure:"ssl_mode" json:"ssl_mode" example:"prefer"`
MaxConns int32 `yaml:"max_conns" mapstructure:"max_conns" json:"max_conns" example:"10"`
}
type Sinks ¶
type Sinks struct {
PGConfig PGConfig `yaml:"postgres" mapstructure:"postgres" json:"postgres"`
OTelConfig OTelConfig `yaml:"otel" mapstructure:"otel" json:"otel"`
}
func (*Sinks) DBOr501 ¶
func (s *Sinks) DBOr501(endpoint gin.HandlerFunc) gin.HandlerFunc
DBOr501 returns the original endpoint if the db is configured. Otherwise it returns a simple 501 not implemented. This is used to make endpoints that require the db sink to be enabled.
func (*Sinks) DBOrNOP ¶
func (s *Sinks) DBOrNOP(endpoint gin.HandlerFunc) gin.HandlerFunc
DBOrNOP returns the original endpoint if the db is configured. Otherwise it is a no-op. This is used to make middlewares that require the db sink to be enabled.
func (*Sinks) OTelEnabled ¶
type UserListSpec ¶
type UserListSpec struct {
Name types.UserListName `yaml:"name" mapstructure:"name" json:"name" example:"local users"`
DomainName string `yaml:"domain" mapstructure:"domain" json:"domain,omitempty" example:"quin.cy"`
NetBIOSName string `yaml:"netbios" mapstructure:"netbios" json:"netbios,omitempty" example:"QUIN"`
Users []UserSpec `yaml:"users" mapstructure:"users" json:"users"`
}
UserListSpec contains the definition of a userlist. Userlists have a unique name. Optionally, they can have a Domain or NetBIOS name. These apply to every user in the list.