2023-03-07 23:10:42 +01:00
|
|
|
package config
|
|
|
|
|
2023-07-26 15:14:49 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/auth/thirdparty"
|
|
|
|
)
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
type ServerConfig struct {
|
2023-07-26 15:14:49 +02:00
|
|
|
HTTP HTTPConfig `yaml:"http"`
|
|
|
|
Database DatabaseConfig `yaml:"database"`
|
|
|
|
CORS CORSConfig `yaml:"cors"`
|
|
|
|
Auth AuthConfig `yaml:"auth"`
|
2023-03-07 23:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultServerConfig() ServerConfig {
|
|
|
|
return ServerConfig{
|
2023-07-26 15:14:49 +02:00
|
|
|
HTTP: NewDefaultHTTPConfig(),
|
|
|
|
Database: NewDefaultDatabaseConfig(),
|
|
|
|
CORS: NewDefaultCORSConfig(),
|
|
|
|
Auth: NewDefaultAuthConfig(),
|
2023-03-07 23:10:42 +01:00
|
|
|
}
|
|
|
|
}
|
2023-07-26 15:14:49 +02:00
|
|
|
|
|
|
|
type AuthConfig struct {
|
|
|
|
Local *LocalAuthConfig `yaml:"local"`
|
|
|
|
Remote *RemoteAuthConfig `yaml:"remote"`
|
|
|
|
RoleExtractionRules []string `yaml:"roleExtractionRules"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDefaultAuthConfig() AuthConfig {
|
|
|
|
return AuthConfig{
|
|
|
|
Local: &LocalAuthConfig{
|
|
|
|
PrivateKeyPath: "server-key.json",
|
|
|
|
},
|
|
|
|
Remote: nil,
|
|
|
|
RoleExtractionRules: []string{
|
|
|
|
fmt.Sprintf("jwt.%s != nil ? str(jwt.%s) : ''", thirdparty.DefaultRoleKey, thirdparty.DefaultRoleKey),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type LocalAuthConfig struct {
|
|
|
|
PrivateKeyPath InterpolatedString `yaml:"privateKeyPath"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemoteAuthConfig struct {
|
|
|
|
JsonWebKeySetURL InterpolatedString `yaml:"jwksUrl"`
|
|
|
|
RefreshInterval *InterpolatedDuration `yaml:"refreshInterval"`
|
|
|
|
}
|