2023-03-13 19:19:38 +01:00
package config
2022-07-21 22:43:42 +02:00
2022-08-09 17:34:00 +02:00
import (
2023-05-11 20:35:49 +02:00
"time"
2023-03-27 21:29:25 +02:00
"github.com/openziti/zrok/controller/emailUi"
2023-03-13 19:19:38 +01:00
"github.com/openziti/zrok/controller/env"
2023-03-10 20:25:29 +01:00
"github.com/openziti/zrok/controller/limits"
2023-03-15 21:14:06 +01:00
"github.com/openziti/zrok/controller/metrics"
2023-03-07 20:31:39 +01:00
"github.com/openziti/zrok/controller/zrokEdgeSdk"
2023-01-18 20:05:10 +01:00
2022-08-09 17:34:00 +02:00
"github.com/michaelquigley/cf"
2023-01-13 21:01:34 +01:00
"github.com/openziti/zrok/controller/store"
2022-08-09 17:34:00 +02:00
"github.com/pkg/errors"
)
2022-07-22 19:53:39 +02:00
2023-04-05 17:45:40 +02:00
const ConfigVersion = 3
2022-12-01 19:40:57 +01:00
2022-07-21 22:43:42 +02:00
type Config struct {
2023-05-23 19:51:33 +02:00
V int
Admin * AdminConfig
Bridge * metrics . BridgeConfig
Endpoint * EndpointConfig
Email * emailUi . Config
2023-05-23 20:21:37 +02:00
Invites * InvitesConfig
2023-05-23 19:51:33 +02:00
Limits * limits . Config
Maintenance * MaintenanceConfig
Metrics * metrics . Config
Passwords * PasswordsConfig
Registration * RegistrationConfig
ResetPassword * ResetPasswordConfig
Store * store . Config
Ziti * zrokEdgeSdk . Config
2024-01-17 22:37:46 +01:00
Tls * TlsConfig
2023-01-18 20:05:10 +01:00
}
2022-12-01 20:48:23 +01:00
type AdminConfig struct {
2023-06-16 17:52:42 +02:00
Secrets [ ] string ` cf:"+secret" `
TouLink string
ProfileEndpoint string
2022-12-01 20:48:23 +01:00
}
2022-08-09 17:18:24 +02:00
type EndpointConfig struct {
Host string
Port int
}
2023-05-23 20:21:37 +02:00
type InvitesConfig struct {
InvitesOpen bool
TokenStrategy string
TokenContact string
}
2023-05-23 19:51:33 +02:00
type MaintenanceConfig struct {
ResetPassword * ResetPasswordMaintenanceConfig
Registration * RegistrationMaintenanceConfig
2022-09-09 19:23:30 +02:00
}
2023-05-23 19:51:33 +02:00
type PasswordsConfig struct {
2023-05-11 20:35:49 +02:00
Length int
RequireCapital bool
RequireNumeric bool
RequireSpecial bool
ValidSpecialCharacters string
}
2023-05-23 19:51:33 +02:00
type RegistrationConfig struct {
RegistrationUrlTemplate string
2023-01-20 18:08:40 +01:00
}
2023-05-23 19:51:33 +02:00
type ResetPasswordConfig struct {
ResetUrlTemplate string
2023-01-12 17:04:56 +01:00
}
type RegistrationMaintenanceConfig struct {
ExpirationTimeout time . Duration
CheckFrequency time . Duration
2023-01-12 21:09:04 +01:00
BatchLimit int
2023-01-12 17:04:56 +01:00
}
2023-01-20 18:08:40 +01:00
type ResetPasswordMaintenanceConfig struct {
2023-01-20 17:00:46 +01:00
ExpirationTimeout time . Duration
CheckFrequency time . Duration
BatchLimit int
}
2024-01-17 22:37:46 +01:00
type TlsConfig struct {
CertPath string
KeyPath string
}
2023-01-12 21:09:04 +01:00
func DefaultConfig ( ) * Config {
return & Config {
2023-03-10 20:25:29 +01:00
Limits : limits . DefaultConfig ( ) ,
2023-01-12 21:09:04 +01:00
Maintenance : & MaintenanceConfig {
2023-01-20 18:08:40 +01:00
ResetPassword : & ResetPasswordMaintenanceConfig {
2023-01-20 17:00:46 +01:00
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-05-23 19:51:33 +02:00
Passwords : & PasswordsConfig {
Length : 8 ,
RequireCapital : true ,
RequireNumeric : true ,
RequireSpecial : true ,
ValidSpecialCharacters : ` !@$&*_-., "#%'()+/:;<=>?[\]^ { |}~ ` ,
} ,
2023-01-12 21:09:04 +01:00
}
}
2023-01-12 21:12:48 +01:00
func LoadConfig ( path string ) ( * Config , error ) {
cfg := DefaultConfig ( )
2023-03-13 19:19:38 +01:00
if err := cf . BindYaml ( cfg , path , env . GetCfOptions ( ) ) ; err != nil {
2022-08-09 17:34:00 +02:00
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
}