Files
opencloud/services/invitations/pkg/config/defaults/defaultconfig.go
Christian Richter e0d126da5c consolidate log config in invitations
Signed-off-by: Christian Richter <c.richter@opencloud.eu>
2026-01-08 13:00:02 +01:00

76 lines
1.6 KiB
Go

package defaults
import (
"strings"
"github.com/opencloud-eu/opencloud/services/invitations/pkg/config"
)
func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
EnsureDefaults(cfg)
Sanitize(cfg)
return cfg
}
func DefaultConfig() *config.Config {
return &config.Config{
Debug: config.Debug{
Addr: "127.0.0.1:9269",
Token: "",
Pprof: false,
Zpages: false,
},
HTTP: config.HTTP{
Addr: "127.0.0.1:9265",
Root: "/graph/v1.0",
Namespace: "eu.opencloud.web",
CORS: config.CORS{
AllowedOrigins: []string{"https://localhost:9200"},
},
},
Service: config.Service{
Name: "invitations",
},
Keycloak: config.Keycloak{
BasePath: "",
ClientID: "",
ClientSecret: "",
ClientRealm: "",
UserRealm: "",
},
}
}
func EnsureDefaults(cfg *config.Config) {
if cfg.LogLevel == "" {
cfg.LogLevel = "error"
}
if cfg.Commons != nil {
cfg.HTTP.TLS = cfg.Commons.HTTPServiceTLS
}
if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &config.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else if cfg.TokenManager == nil {
cfg.TokenManager = &config.TokenManager{}
}
if (cfg.Commons != nil && cfg.Commons.OpenCloudURL != "") &&
(cfg.HTTP.CORS.AllowedOrigins == nil ||
len(cfg.HTTP.CORS.AllowedOrigins) == 1 &&
cfg.HTTP.CORS.AllowedOrigins[0] == "https://localhost:9200") {
cfg.HTTP.CORS.AllowedOrigins = []string{cfg.Commons.OpenCloudURL}
}
}
func Sanitize(cfg *config.Config) {
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
}