proof of concept

This commit is contained in:
Willy Kloucek
2022-03-10 14:11:44 +01:00
committed by Christian Richter
parent ee584bf865
commit f2e8c90067
10 changed files with 220 additions and 137 deletions
@@ -1,17 +1,28 @@
package config
package defaults
import (
"path"
"strings"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
)
func DefaultConfig() *Config {
return &Config{
Debug: Debug{
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:9134",
},
HTTP: HTTP{
HTTP: config.HTTP{
Addr: "127.0.0.1:9130",
Root: "/",
Namespace: "com.owncloud.web",
@@ -19,11 +30,11 @@ func DefaultConfig() *Config {
TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"),
TLS: false,
},
Service: Service{
Service: config.Service{
Name: "idp",
},
Asset: Asset{},
IDP: Settings{
Asset: config.Asset{},
IDP: config.Settings{
Iss: "https://localhost:9200",
IdentityManager: "ldap",
URIBasePath: "",
@@ -56,7 +67,7 @@ func DefaultConfig() *Config {
RefreshTokenDurationSeconds: 60 * 60 * 24 * 365 * 3, // 1 year
DyamicClientSecretDurationSeconds: 0,
},
Ldap: Ldap{
Ldap: config.Ldap{
URI: "ldap://localhost:9125",
BindDN: "cn=idp,ou=sysusers,dc=ocis,dc=test",
BindPassword: "idp",
@@ -71,3 +82,38 @@ func DefaultConfig() *Config {
},
}
}
func EnsureDefaults(cfg *config.Config) error {
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Log = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil {
cfg.Log = &config.Log{}
}
// provide with defaults for shared tracing, since we need a valid destination address for BindEnv.
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
cfg.Tracing = &config.Tracing{
Enabled: cfg.Commons.Tracing.Enabled,
Type: cfg.Commons.Tracing.Type,
Endpoint: cfg.Commons.Tracing.Endpoint,
Collector: cfg.Commons.Tracing.Collector,
}
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}
return nil
}
func Sanitize(cfg *config.Config) error {
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}
+7 -25
View File
@@ -2,9 +2,9 @@ package parser
import (
"errors"
"strings"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/idp/pkg/config/defaults"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
@@ -17,27 +17,9 @@ func ParseConfig(cfg *config.Config) error {
return err
}
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Log = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil {
cfg.Log = &config.Log{}
}
// provide with defaults for shared tracing, since we need a valid destination address for BindEnv.
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
cfg.Tracing = &config.Tracing{
Enabled: cfg.Commons.Tracing.Enabled,
Type: cfg.Commons.Tracing.Type,
Endpoint: cfg.Commons.Tracing.Endpoint,
Collector: cfg.Commons.Tracing.Collector,
}
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
err = defaults.EnsureDefaults(cfg)
if err != nil {
return err
}
// load all env variables relevant to the config in the current context.
@@ -48,9 +30,9 @@ func ParseConfig(cfg *config.Config) error {
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
err = defaults.Sanitize(cfg)
if err != nil {
return err
}
return nil