zrok/controller/config.go

130 lines
2.7 KiB
Go
Raw Normal View History

package controller
2022-08-09 17:34:00 +02:00
import (
2023-01-18 20:05:10 +01:00
"time"
2022-08-09 17:34:00 +02:00
"github.com/michaelquigley/cf"
"github.com/openziti/zrok/controller/store"
2022-08-09 17:34:00 +02:00
"github.com/pkg/errors"
)
const ConfigVersion = 2
2022-12-01 19:40:57 +01:00
type Config struct {
V int
Admin *AdminConfig
Endpoint *EndpointConfig
Email *EmailConfig
Influx *InfluxConfig
Limits *LimitsConfig
Maintenance *MaintenanceConfig
Metrics *MetricsConfig
Registration *RegistrationConfig
ResetPassword *ResetPasswordConfig
Store *store.Config
Ziti *ZitiConfig
2023-01-18 20:05:10 +01:00
}
type AdminConfig struct {
Secrets []string `cf:"+secret"`
TouLink string
}
2022-08-09 17:18:24 +02:00
type EndpointConfig struct {
Host string
Port int
}
type EmailConfig struct {
Host string
Port int
Username string
Password string `cf:"+secret"`
From string
}
2022-09-09 19:23:30 +02:00
type RegistrationConfig struct {
RegistrationUrlTemplate string
TokenStrategy string
2022-09-09 19:23:30 +02:00
}
type ResetPasswordConfig struct {
ResetUrlTemplate string
}
2022-08-12 17:03:15 +02:00
type ZitiConfig struct {
ApiEndpoint string
Username string
Password string `cf:"+secret"`
2022-08-12 17:03:15 +02:00
}
type MetricsConfig struct {
ServiceName string
}
type InfluxConfig struct {
Url string
Bucket string
Org string
Token string `cf:"+secret"`
}
type MaintenanceConfig struct {
ResetPassword *ResetPasswordMaintenanceConfig
Registration *RegistrationMaintenanceConfig
}
type RegistrationMaintenanceConfig struct {
ExpirationTimeout time.Duration
CheckFrequency time.Duration
2023-01-12 21:09:04 +01:00
BatchLimit int
}
type ResetPasswordMaintenanceConfig struct {
ExpirationTimeout time.Duration
CheckFrequency time.Duration
BatchLimit int
}
2023-01-13 15:42:42 +01:00
const Unlimited = -1
type LimitsConfig struct {
Environments int
Shares int
}
2023-01-12 21:09:04 +01:00
func DefaultConfig() *Config {
return &Config{
2023-01-13 15:42:42 +01:00
Limits: &LimitsConfig{
Environments: Unlimited,
Shares: Unlimited,
},
Metrics: &MetricsConfig{
ServiceName: "metrics",
},
2023-01-12 21:09:04 +01:00
Maintenance: &MaintenanceConfig{
ResetPassword: &ResetPasswordMaintenanceConfig{
ExpirationTimeout: time.Minute * 15,
CheckFrequency: time.Minute * 15,
BatchLimit: 500,
},
2023-01-12 21:09:04 +01:00
Registration: &RegistrationMaintenanceConfig{
2023-01-12 22:00:09 +01:00
ExpirationTimeout: time.Hour * 24,
2023-01-12 21:09:04 +01:00
CheckFrequency: time.Hour,
BatchLimit: 500,
},
},
}
}
2023-01-12 21:12:48 +01:00
func LoadConfig(path string) (*Config, error) {
cfg := DefaultConfig()
2022-08-09 17:34:00 +02:00
if err := cf.BindYaml(cfg, path, cf.DefaultOptions()); err != nil {
return nil, errors.Wrapf(err, "error loading controller config '%v'", path)
}
2022-12-01 19:40:57 +01:00
if cfg.V != ConfigVersion {
return nil, errors.Errorf("expecting configuration version '%v', your configuration is version '%v'; please see zrok.io for changelog and configuration documentation", ConfigVersion, cfg.V)
}
2022-08-09 17:34:00 +02:00
return cfg, nil
}