From 9734b000b36a1ace82935c749acff635ee4d87d8 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 8 Mar 2022 17:35:55 +0100 Subject: [PATCH] Add defaultconfig to extensions --- accounts/cmd/accounts/main.go | 2 +- accounts/pkg/config/defaults/defaultconfig.go | 3 +- accounts/pkg/config/parser/parse.go | 5 +- glauth/cmd/glauth/main.go | 4 +- glauth/pkg/config/defaultconfig.go | 51 ------ glauth/pkg/config/defaults/defaultconfig.go | 90 ++++++++++ glauth/pkg/config/parser/parse.go | 27 +-- graph-explorer/cmd/graph-explorer/main.go | 4 +- graph-explorer/pkg/config/defaultconfig.go | 26 --- .../pkg/config/defaults/defaultconfig.go | 73 ++++++++ graph-explorer/pkg/config/parser/parse.go | 29 +-- graph/cmd/graph/main.go | 4 +- graph/pkg/config/defaultconfig.go | 55 ------ graph/pkg/config/defaults/defaultconfig.go | 93 ++++++++++ graph/pkg/config/parser/parse.go | 30 +--- idm/cmd/idm/main.go | 4 +- idm/pkg/config/defaults/defaultconfig.go | 61 +++++++ idm/pkg/config/parser/parse.go | 27 +-- idp/pkg/config/defaults/defaultconfig.go | 7 +- idp/pkg/config/parser/parse.go | 10 +- nats/pkg/config/defaultconfig.go | 16 -- nats/pkg/config/defaults/defaultconfig.go | 45 +++++ nats/pkg/config/parser/parse.go | 15 +- notifications/pkg/config/defaultconfig.go | 27 --- .../pkg/config/defaults/defaultconfig.go | 56 ++++++ notifications/pkg/config/parser/parse.go | 15 +- ocis-pkg/config/defaultconfig.go | 28 +-- ocs/pkg/config/defaultconfig.go | 37 ---- ocs/pkg/config/defaults/defaultconfig.go | 87 +++++++++ ocs/pkg/config/parser/parse.go | 30 +--- .../config/{ => defaults}/defaultconfig.go | 73 ++++++-- proxy/pkg/config/parser/parse.go | 36 +--- settings/pkg/config/defaultconfig.go | 44 ----- settings/pkg/config/defaults/defaultconfig.go | 87 +++++++++ settings/pkg/config/parser/parse.go | 31 +--- .../config/{ => defaults}/defaultconfig.go | 166 ++++++++++-------- store/pkg/config/defaultconfig.go | 26 --- store/pkg/config/defaults/defaultconfig.go | 65 +++++++ store/pkg/config/parser/parse.go | 26 +-- thumbnails/pkg/config/defaultconfig.go | 41 ----- .../pkg/config/defaults/defaultconfig.go | 80 +++++++++ thumbnails/pkg/config/parser/parse.go | 25 +-- web/pkg/config/defaultconfig.go | 42 ----- web/pkg/config/defaults/defaultconfig.go | 93 ++++++++++ web/pkg/config/parser/parse.go | 34 +--- webdav/pkg/config/defaultconfig.go | 29 --- webdav/pkg/config/defaults/defaultconfig.go | 77 ++++++++ webdav/pkg/config/parser/parse.go | 30 +--- 48 files changed, 1126 insertions(+), 840 deletions(-) delete mode 100644 glauth/pkg/config/defaultconfig.go create mode 100644 glauth/pkg/config/defaults/defaultconfig.go delete mode 100644 graph-explorer/pkg/config/defaultconfig.go create mode 100644 graph-explorer/pkg/config/defaults/defaultconfig.go delete mode 100644 graph/pkg/config/defaultconfig.go create mode 100644 graph/pkg/config/defaults/defaultconfig.go create mode 100644 idm/pkg/config/defaults/defaultconfig.go delete mode 100644 nats/pkg/config/defaultconfig.go create mode 100644 nats/pkg/config/defaults/defaultconfig.go delete mode 100644 notifications/pkg/config/defaultconfig.go create mode 100644 notifications/pkg/config/defaults/defaultconfig.go delete mode 100644 ocs/pkg/config/defaultconfig.go create mode 100644 ocs/pkg/config/defaults/defaultconfig.go rename proxy/pkg/config/{ => defaults}/defaultconfig.go (71%) delete mode 100644 settings/pkg/config/defaultconfig.go create mode 100644 settings/pkg/config/defaults/defaultconfig.go rename storage/pkg/config/{ => defaults}/defaultconfig.go (81%) delete mode 100644 store/pkg/config/defaultconfig.go create mode 100644 store/pkg/config/defaults/defaultconfig.go delete mode 100644 thumbnails/pkg/config/defaultconfig.go create mode 100644 thumbnails/pkg/config/defaults/defaultconfig.go delete mode 100644 web/pkg/config/defaultconfig.go create mode 100644 web/pkg/config/defaults/defaultconfig.go delete mode 100644 webdav/pkg/config/defaultconfig.go create mode 100644 webdav/pkg/config/defaults/defaultconfig.go diff --git a/accounts/cmd/accounts/main.go b/accounts/cmd/accounts/main.go index 12ec59b8b..d7788426b 100644 --- a/accounts/cmd/accounts/main.go +++ b/accounts/cmd/accounts/main.go @@ -4,7 +4,7 @@ import ( "os" "github.com/owncloud/ocis/accounts/pkg/command" - defaults "github.com/owncloud/ocis/accounts/pkg/config/defaults" + "github.com/owncloud/ocis/accounts/pkg/config/defaults" ) func main() { diff --git a/accounts/pkg/config/defaults/defaultconfig.go b/accounts/pkg/config/defaults/defaultconfig.go index 93bf7557c..b26d18fbf 100644 --- a/accounts/pkg/config/defaults/defaultconfig.go +++ b/accounts/pkg/config/defaults/defaultconfig.go @@ -105,11 +105,10 @@ func EnsureDefaults(cfg *config.Config) error { return nil } -func Sanitize(cfg *config.Config) error { +func Sanitize(cfg *config.Config) { // sanitize config if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) - return nil } diff --git a/accounts/pkg/config/parser/parse.go b/accounts/pkg/config/parser/parse.go index a7103a65f..c252765a5 100644 --- a/accounts/pkg/config/parser/parse.go +++ b/accounts/pkg/config/parser/parse.go @@ -30,10 +30,7 @@ func ParseConfig(cfg *config.Config) error { } } - err = defaults.Sanitize(cfg) - if err != nil { - return err - } + defaults.Sanitize(cfg) return nil } diff --git a/glauth/cmd/glauth/main.go b/glauth/cmd/glauth/main.go index 6a2a83249..4ecc5b53d 100644 --- a/glauth/cmd/glauth/main.go +++ b/glauth/cmd/glauth/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/glauth/pkg/command" - "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/glauth/pkg/config/defaultconfig.go b/glauth/pkg/config/defaultconfig.go deleted file mode 100644 index 503321d8e..000000000 --- a/glauth/pkg/config/defaultconfig.go +++ /dev/null @@ -1,51 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9129", - }, - Service: Service{ - Name: "glauth", - }, - Ldap: Ldap{ - Enabled: true, - Addr: "127.0.0.1:9125", - Namespace: "com.owncloud.ldap", - }, - Ldaps: Ldaps{ - Enabled: true, - Addr: "127.0.0.1:9126", - Namespace: "com.owncloud.ldaps", - Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), - }, - Backend: Backend{ - Datastore: "accounts", - BaseDN: "dc=ocis,dc=test", - Insecure: false, - NameFormat: "cn", - GroupFormat: "ou", - Servers: nil, - SSHKeyAttr: "sshPublicKey", - UseGraphAPI: true, - }, - Fallback: FallbackBackend{ - Datastore: "", - BaseDN: "dc=ocis,dc=test", - Insecure: false, - NameFormat: "cn", - GroupFormat: "ou", - Servers: nil, - SSHKeyAttr: "sshPublicKey", - UseGraphAPI: true, - }, - RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin - } -} diff --git a/glauth/pkg/config/defaults/defaultconfig.go b/glauth/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..12774c488 --- /dev/null +++ b/glauth/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,90 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +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:9129", + }, + Service: config.Service{ + Name: "glauth", + }, + Ldap: config.Ldap{ + Enabled: true, + Addr: "127.0.0.1:9125", + Namespace: "com.owncloud.ldap", + }, + Ldaps: config.Ldaps{ + Enabled: true, + Addr: "127.0.0.1:9126", + Namespace: "com.owncloud.ldaps", + Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), + }, + Backend: config.Backend{ + Datastore: "accounts", + BaseDN: "dc=ocis,dc=test", + Insecure: false, + NameFormat: "cn", + GroupFormat: "ou", + Servers: nil, + SSHKeyAttr: "sshPublicKey", + UseGraphAPI: true, + }, + Fallback: config.FallbackBackend{ + Datastore: "", + BaseDN: "dc=ocis,dc=test", + Insecure: false, + NameFormat: "cn", + GroupFormat: "ou", + Servers: nil, + SSHKeyAttr: "sshPublicKey", + UseGraphAPI: true, + }, + RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to santizie here atm +} diff --git a/glauth/pkg/config/parser/parse.go b/glauth/pkg/config/parser/parse.go index de91a1823..1d9326a72 100644 --- a/glauth/pkg/config/parser/parse.go +++ b/glauth/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,29 +17,7 @@ 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{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -48,6 +27,6 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config - + defaults.Sanitize(cfg) return nil } diff --git a/graph-explorer/cmd/graph-explorer/main.go b/graph-explorer/cmd/graph-explorer/main.go index a8357cb1f..aca5c050f 100644 --- a/graph-explorer/cmd/graph-explorer/main.go +++ b/graph-explorer/cmd/graph-explorer/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/graph-explorer/pkg/command" - "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/graph-explorer/pkg/config/defaultconfig.go b/graph-explorer/pkg/config/defaultconfig.go deleted file mode 100644 index 454cb239a..000000000 --- a/graph-explorer/pkg/config/defaultconfig.go +++ /dev/null @@ -1,26 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9136", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9135", - Root: "/graph-explorer", - Namespace: "com.owncloud.web", - }, - Service: Service{ - Name: "graph-explorer", - }, - GraphExplorer: GraphExplorer{ - ClientID: "ocis-explorer.js", - Issuer: "https://localhost:9200", - GraphURLBase: "https://localhost:9200", - GraphURLPath: "/graph", - }, - } -} diff --git a/graph-explorer/pkg/config/defaults/defaultconfig.go b/graph-explorer/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..860d0fdf3 --- /dev/null +++ b/graph-explorer/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,73 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/graph-explorer/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:9136", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9135", + Root: "/graph-explorer", + Namespace: "com.owncloud.web", + }, + Service: config.Service{ + Name: "graph-explorer", + }, + GraphExplorer: config.GraphExplorer{ + ClientID: "ocis-explorer.js", + Issuer: "https://localhost:9200", + GraphURLBase: "https://localhost:9200", + GraphURLPath: "/graph", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root == "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/graph-explorer") + } +} diff --git a/graph-explorer/pkg/config/parser/parse.go b/graph-explorer/pkg/config/parser/parse.go index c9127c292..b9801ba94 100644 --- a/graph-explorer/pkg/config/parser/parse.go +++ b/graph-explorer/pkg/config/parser/parse.go @@ -2,9 +2,9 @@ package parser import ( "errors" - "strings" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -17,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -49,9 +28,7 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/graph/cmd/graph/main.go b/graph/cmd/graph/main.go index ec85f2371..ddce12e82 100644 --- a/graph/cmd/graph/main.go +++ b/graph/cmd/graph/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/graph/pkg/command" - "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/graph/pkg/config/defaultconfig.go b/graph/pkg/config/defaultconfig.go deleted file mode 100644 index 134f3419b..000000000 --- a/graph/pkg/config/defaultconfig.go +++ /dev/null @@ -1,55 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9124", - Token: "", - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9120", - Namespace: "com.owncloud.graph", - Root: "/graph", - }, - Service: Service{ - Name: "graph", - }, - Reva: Reva{ - Address: "127.0.0.1:9142", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - Spaces: Spaces{ - WebDavBase: "https://localhost:9200", - WebDavPath: "/dav/spaces/", - DefaultQuota: "1000000000", - Insecure: false, - }, - Identity: Identity{ - Backend: "cs3", - LDAP: LDAP{ - URI: "ldap://localhost:9125", - Insecure: false, - BindDN: "", - BindPassword: "", - UseServerUUID: false, - WriteEnabled: false, - UserBaseDN: "ou=users,dc=ocis,dc=test", - UserSearchScope: "sub", - UserFilter: "(objectClass=inetOrgPerson)", - UserEmailAttribute: "mail", - UserDisplayNameAttribute: "displayName", - UserNameAttribute: "uid", - // FIXME: switch this to some more widely available attribute by default - // ideally this needs to be constant for the lifetime of a users - UserIDAttribute: "owncloudUUID", - GroupBaseDN: "ou=groups,dc=ocis,dc=test", - GroupSearchScope: "sub", - GroupFilter: "(objectclass=groupOfNames)", - GroupNameAttribute: "cn", - GroupIDAttribute: "owncloudUUID", - }, - }, - } -} diff --git a/graph/pkg/config/defaults/defaultconfig.go b/graph/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..9c2eba50c --- /dev/null +++ b/graph/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,93 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/graph/pkg/config" +) + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9124", + Token: "", + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9120", + Namespace: "com.owncloud.graph", + Root: "/graph", + }, + Service: config.Service{ + Name: "graph", + }, + Reva: config.Reva{ + Address: "127.0.0.1:9142", + }, + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Spaces: config.Spaces{ + WebDavBase: "https://localhost:9200", + WebDavPath: "/dav/spaces/", + DefaultQuota: "1000000000", + Insecure: false, + }, + Identity: config.Identity{ + Backend: "cs3", + LDAP: config.LDAP{ + URI: "ldap://localhost:9125", + Insecure: false, + BindDN: "", + BindPassword: "", + UseServerUUID: false, + WriteEnabled: false, + UserBaseDN: "ou=users,dc=ocis,dc=test", + UserSearchScope: "sub", + UserFilter: "(objectClass=inetOrgPerson)", + UserEmailAttribute: "mail", + UserDisplayNameAttribute: "displayName", + UserNameAttribute: "uid", + // FIXME: switch this to some more widely available attribute by default + // ideally this needs to be constant for the lifetime of a users + UserIDAttribute: "owncloudUUID", + GroupBaseDN: "ou=groups,dc=ocis,dc=test", + GroupSearchScope: "sub", + GroupFilter: "(objectclass=groupOfNames)", + GroupNameAttribute: "cn", + GroupIDAttribute: "owncloudUUID", + }, + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/graph/pkg/config/parser/parse.go b/graph/pkg/config/parser/parse.go index 367089f85..a1892f095 100644 --- a/graph/pkg/config/parser/parse.go +++ b/graph/pkg/config/parser/parse.go @@ -2,9 +2,9 @@ package parser import ( "errors" - "strings" "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -17,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/idm/cmd/idm/main.go b/idm/cmd/idm/main.go index 680d58daf..7463a99c7 100644 --- a/idm/cmd/idm/main.go +++ b/idm/cmd/idm/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/idm/pkg/command" - "github.com/owncloud/ocis/idm/pkg/config" + "github.com/owncloud/ocis/idm/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/idm/pkg/config/defaults/defaultconfig.go b/idm/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..7457a1c73 --- /dev/null +++ b/idm/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,61 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/idm/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "idm", + }, + IDM: config.Settings{ + LDAPSAddr: "127.0.0.1:9235", + Cert: path.Join(defaults.BaseDataPath(), "idm", "ldap.crt"), + Key: path.Join(defaults.BaseDataPath(), "idm", "ldap.key"), + DatabasePath: path.Join(defaults.BaseDataPath(), "idm", "ocis.boltdb"), + AdminPassword: "admin", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here +} diff --git a/idm/pkg/config/parser/parse.go b/idm/pkg/config/parser/parse.go index 22b3429cc..9847623cf 100644 --- a/idm/pkg/config/parser/parse.go +++ b/idm/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/idm/pkg/config" + "github.com/owncloud/ocis/idm/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,29 +17,7 @@ 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{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -47,5 +26,7 @@ func ParseConfig(cfg *config.Config) error { } } + defaults.Sanitize(cfg) + return nil } diff --git a/idp/pkg/config/defaults/defaultconfig.go b/idp/pkg/config/defaults/defaultconfig.go index 972f2238d..e96527866 100644 --- a/idp/pkg/config/defaults/defaultconfig.go +++ b/idp/pkg/config/defaults/defaultconfig.go @@ -83,7 +83,7 @@ func DefaultConfig() *config.Config { } } -func EnsureDefaults(cfg *config.Config) error { +func EnsureDefaults(cfg *config.Config) { // 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{ @@ -106,14 +106,11 @@ func EnsureDefaults(cfg *config.Config) error { } else if cfg.Tracing == nil { cfg.Tracing = &config.Tracing{} } - - return nil } -func Sanitize(cfg *config.Config) error { +func Sanitize(cfg *config.Config) { // sanitize config if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return nil } diff --git a/idp/pkg/config/parser/parse.go b/idp/pkg/config/parser/parse.go index 0207c21ed..07732d41e 100644 --- a/idp/pkg/config/parser/parse.go +++ b/idp/pkg/config/parser/parse.go @@ -17,10 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - err = defaults.EnsureDefaults(cfg) - if err != nil { - return err - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -30,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - err = defaults.Sanitize(cfg) - if err != nil { - return err - } + defaults.Sanitize(cfg) return nil } diff --git a/nats/pkg/config/defaultconfig.go b/nats/pkg/config/defaultconfig.go deleted file mode 100644 index de1238e76..000000000 --- a/nats/pkg/config/defaultconfig.go +++ /dev/null @@ -1,16 +0,0 @@ -package config - -// NOTE: Most of this configuration is not needed to keep it as simple as possible -// TODO: Clean up unneeded configuration - -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "nats", - }, - Nats: Nats{ - Host: "127.0.0.1", - Port: 9233, - }, - } -} diff --git a/nats/pkg/config/defaults/defaultconfig.go b/nats/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..03f5167b3 --- /dev/null +++ b/nats/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,45 @@ +package defaults + +import "github.com/owncloud/ocis/nats/pkg/config" + +// NOTE: Most of this configuration is not needed to keep it as simple as possible +// TODO: Clean up unneeded configuration + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "nats", + }, + Nats: config.Nats{ + Host: "127.0.0.1", + Port: 9233, + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/nats/pkg/config/parser/parse.go b/nats/pkg/config/parser/parse.go index 04e4e2b0a..fb198fac2 100644 --- a/nats/pkg/config/parser/parse.go +++ b/nats/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/nats/pkg/config" + "github.com/owncloud/ocis/nats/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,17 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -36,5 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } + defaults.Sanitize(cfg) + return nil } diff --git a/notifications/pkg/config/defaultconfig.go b/notifications/pkg/config/defaultconfig.go deleted file mode 100644 index d5fb6e349..000000000 --- a/notifications/pkg/config/defaultconfig.go +++ /dev/null @@ -1,27 +0,0 @@ -package config - -// NOTE: Most of this configuration is not needed to keep it as simple as possible -// TODO: Clean up unneeded configuration - -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "notifications", - }, - Notifications: Notifications{ - SMTP: SMTP{ - Host: "127.0.0.1", - Port: "1025", - Sender: "god@example.com", - Password: "godisdead", - }, - Events: Events{ - Endpoint: "127.0.0.1:9233", - Cluster: "test-cluster", - ConsumerGroup: "notifications", - }, - RevaGateway: "127.0.0.1:9142", - MachineAuthSecret: "change-me-please", - }, - } -} diff --git a/notifications/pkg/config/defaults/defaultconfig.go b/notifications/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..22647168c --- /dev/null +++ b/notifications/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,56 @@ +package defaults + +import "github.com/owncloud/ocis/notifications/pkg/config" + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +// NOTE: Most of this configuration is not needed to keep it as simple as possible +// TODO: Clean up unneeded configuration + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "notifications", + }, + Notifications: config.Notifications{ + SMTP: config.SMTP{ + Host: "127.0.0.1", + Port: "1025", + Sender: "god@example.com", + Password: "godisdead", + }, + Events: config.Events{ + Endpoint: "127.0.0.1:9233", + Cluster: "test-cluster", + ConsumerGroup: "notifications", + }, + RevaGateway: "127.0.0.1:9142", + MachineAuthSecret: "change-me-please", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/notifications/pkg/config/parser/parse.go b/notifications/pkg/config/parser/parse.go index 5bc4e6e57..36231a708 100644 --- a/notifications/pkg/config/parser/parse.go +++ b/notifications/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/notifications/pkg/config" + "github.com/owncloud/ocis/notifications/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,17 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -36,5 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } + defaults.Sanitize(cfg) + return nil } diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go index a7777f6ae..9767f2d93 100644 --- a/ocis-pkg/config/defaultconfig.go +++ b/ocis-pkg/config/defaultconfig.go @@ -3,21 +3,21 @@ package config import ( accounts "github.com/owncloud/ocis/accounts/pkg/config/defaults" audit "github.com/owncloud/ocis/audit/pkg/config" - glauth "github.com/owncloud/ocis/glauth/pkg/config" - graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/config" - graph "github.com/owncloud/ocis/graph/pkg/config" - idm "github.com/owncloud/ocis/idm/pkg/config" + glauth "github.com/owncloud/ocis/glauth/pkg/config/defaults" + graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/config/defaults" + graph "github.com/owncloud/ocis/graph/pkg/config/defaults" + idm "github.com/owncloud/ocis/idm/pkg/config/defaults" idp "github.com/owncloud/ocis/idp/pkg/config/defaults" - nats "github.com/owncloud/ocis/nats/pkg/config" - notifications "github.com/owncloud/ocis/notifications/pkg/config" - ocs "github.com/owncloud/ocis/ocs/pkg/config" - proxy "github.com/owncloud/ocis/proxy/pkg/config" - settings "github.com/owncloud/ocis/settings/pkg/config" - storage "github.com/owncloud/ocis/storage/pkg/config" - store "github.com/owncloud/ocis/store/pkg/config" - thumbnails "github.com/owncloud/ocis/thumbnails/pkg/config" - web "github.com/owncloud/ocis/web/pkg/config" - webdav "github.com/owncloud/ocis/webdav/pkg/config" + nats "github.com/owncloud/ocis/nats/pkg/config/defaults" + notifications "github.com/owncloud/ocis/notifications/pkg/config/defaults" + ocs "github.com/owncloud/ocis/ocs/pkg/config/defaults" + proxy "github.com/owncloud/ocis/proxy/pkg/config/defaults" + settings "github.com/owncloud/ocis/settings/pkg/config/defaults" + storage "github.com/owncloud/ocis/storage/pkg/config/defaults" + store "github.com/owncloud/ocis/store/pkg/config/defaults" + thumbnails "github.com/owncloud/ocis/thumbnails/pkg/config/defaults" + web "github.com/owncloud/ocis/web/pkg/config/defaults" + webdav "github.com/owncloud/ocis/webdav/pkg/config/defaults" ) func DefaultConfig() *Config { diff --git a/ocs/pkg/config/defaultconfig.go b/ocs/pkg/config/defaultconfig.go deleted file mode 100644 index 0ed8378ba..000000000 --- a/ocs/pkg/config/defaultconfig.go +++ /dev/null @@ -1,37 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9114", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9110", - Root: "/ocs", - Namespace: "com.owncloud.web", - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - Service: Service{ - Name: "ocs", - }, - - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - AccountBackend: "accounts", - Reva: Reva{Address: "127.0.0.1:9142"}, - StorageUsersDriver: "ocis", - MachineAuthAPIKey: "change-me-please", - IdentityManagement: IdentityManagement{ - Address: "https://localhost:9200", - }, - } -} diff --git a/ocs/pkg/config/defaults/defaultconfig.go b/ocs/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..9c57e897f --- /dev/null +++ b/ocs/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,87 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/ocs/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:9114", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9110", + Root: "/ocs", + Namespace: "com.owncloud.web", + CORS: config.CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Service: config.Service{ + Name: "ocs", + }, + + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + AccountBackend: "accounts", + Reva: config.Reva{ + Address: "127.0.0.1:9142", + }, + StorageUsersDriver: "ocis", + MachineAuthAPIKey: "change-me-please", + IdentityManagement: config.IdentityManagement{ + Address: "https://localhost:9200", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } + +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/ocs/pkg/config/parser/parse.go b/ocs/pkg/config/parser/parse.go index 96f4205df..f5cbc34cb 100644 --- a/ocs/pkg/config/parser/parse.go +++ b/ocs/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocs/pkg/config" + "github.com/owncloud/ocis/ocs/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/proxy/pkg/config/defaultconfig.go b/proxy/pkg/config/defaults/defaultconfig.go similarity index 71% rename from proxy/pkg/config/defaultconfig.go rename to proxy/pkg/config/defaults/defaultconfig.go index 12bcbe806..eaa328b5a 100644 --- a/proxy/pkg/config/defaultconfig.go +++ b/proxy/pkg/config/defaults/defaultconfig.go @@ -1,18 +1,20 @@ -package config +package defaults import ( "path" + "strings" "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/proxy/pkg/config" ) -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ Addr: "127.0.0.1:9205", Token: "", }, - HTTP: HTTP{ + HTTP: config.HTTP{ Addr: "0.0.0.0:9200", Root: "/", Namespace: "com.owncloud.web", @@ -20,26 +22,26 @@ func DefaultConfig() *Config { TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), TLS: true, }, - Service: Service{ + Service: config.Service{ Name: "proxy", }, - OIDC: OIDC{ + OIDC: config.OIDC{ Issuer: "https://localhost:9200", Insecure: true, //Insecure: true, - UserinfoCache: UserinfoCache{ + UserinfoCache: config.UserinfoCache{ Size: 1024, TTL: 10, }, }, - TokenManager: TokenManager{ + TokenManager: config.TokenManager{ JWTSecret: "Pive-Fumkiu4", }, PolicySelector: nil, - Reva: Reva{ + Reva: config.Reva{ Address: "127.0.0.1:9142", }, - PreSignedURL: PreSignedURL{ + PreSignedURL: config.PreSignedURL{ AllowedHTTPMethods: []string{"GET"}, Enabled: true, }, @@ -55,11 +57,11 @@ func DefaultConfig() *Config { } } -func DefaultPolicies() []Policy { - return []Policy{ +func DefaultPolicies() []config.Policy { + return []config.Policy{ { Name: "ocis", - Routes: []Route{ + Routes: []config.Route{ { Endpoint: "/", Backend: "http://localhost:9100", @@ -81,7 +83,7 @@ func DefaultPolicies() []Policy { Backend: "http://localhost:9140", }, { - Type: RegexRoute, + Type: config.RegexRoute, Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs Backend: "http://localhost:9110", }, @@ -90,7 +92,7 @@ func DefaultPolicies() []Policy { Backend: "http://localhost:9140", }, { - Type: QueryRoute, + Type: config.QueryRoute, Endpoint: "/remote.php/?preview=1", Backend: "http://localhost:9115", }, @@ -152,7 +154,7 @@ func DefaultPolicies() []Policy { }, { Name: "oc10", - Routes: []Route{ + Routes: []config.Route{ { Endpoint: "/", Backend: "http://localhost:9100", @@ -212,3 +214,40 @@ func DefaultPolicies() []Policy { }, } } + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } + +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.Policies == nil { + cfg.Policies = DefaultPolicies() + } + + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/proxy/pkg/config/parser/parse.go b/proxy/pkg/config/parser/parse.go index 55105cfcb..ef6d2cec4 100644 --- a/proxy/pkg/config/parser/parse.go +++ b/proxy/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,29 +17,7 @@ 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{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -48,15 +26,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - - if cfg.Policies == nil { - cfg.Policies = config.DefaultPolicies() - } - - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/settings/pkg/config/defaultconfig.go b/settings/pkg/config/defaultconfig.go deleted file mode 100644 index 7f72e50a3..000000000 --- a/settings/pkg/config/defaultconfig.go +++ /dev/null @@ -1,44 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "settings", - }, - Debug: Debug{ - Addr: "127.0.0.1:9194", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9190", - Namespace: "com.owncloud.web", - Root: "/", - CacheTTL: 604800, // 7 days - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9191", - Namespace: "com.owncloud.api", - }, - DataPath: path.Join(defaults.BaseDataPath(), "settings"), - Asset: Asset{ - Path: "", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - } -} diff --git a/settings/pkg/config/defaults/defaultconfig.go b/settings/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..e86f5b6b2 --- /dev/null +++ b/settings/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,87 @@ +package defaults + +import ( + "path" + "strings" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/settings/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "settings", + }, + Debug: config.Debug{ + Addr: "127.0.0.1:9194", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9190", + Namespace: "com.owncloud.web", + Root: "/", + CacheTTL: 604800, // 7 days + CORS: config.CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + GRPC: config.GRPC{ + Addr: "127.0.0.1:9191", + Namespace: "com.owncloud.api", + }, + DataPath: path.Join(defaults.BaseDataPath(), "settings"), + Asset: config.Asset{ + Path: "", + }, + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/settings/pkg/config/parser/parse.go b/settings/pkg/config/parser/parse.go index f1c7c9436..ec2926d14 100644 --- a/settings/pkg/config/parser/parse.go +++ b/settings/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,29 +17,7 @@ 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{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -48,10 +26,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaults/defaultconfig.go similarity index 81% rename from storage/pkg/config/defaultconfig.go rename to storage/pkg/config/defaults/defaultconfig.go index b66e55f1a..142b05db7 100644 --- a/storage/pkg/config/defaultconfig.go +++ b/storage/pkg/config/defaults/defaultconfig.go @@ -1,10 +1,11 @@ -package config +package defaults import ( "os" "path" "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/storage/pkg/config" ) const ( @@ -15,23 +16,32 @@ const ( defaultUserLayout = "{{.Id.OpaqueId}}" ) -func DefaultConfig() *Config { - return &Config{ +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ // log is inherited - Debug: Debug{ + Debug: config.Debug{ Addr: "127.0.0.1:9109", }, - Reva: Reva{ + Reva: config.Reva{ JWTSecret: "Pive-Fumkiu4", SkipUserGroupsInToken: false, TransferSecret: "replace-me-with-a-transfer-secret", TransferExpires: 24 * 60 * 60, - OIDC: OIDC{ + OIDC: config.OIDC{ Issuer: defaultPublicURL, Insecure: false, IDClaim: "preferred_username", }, - LDAP: LDAP{ + LDAP: config.LDAP{ Hostname: "localhost", Port: 9126, CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), @@ -49,7 +59,7 @@ func DefaultConfig() *Config { BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", BindPassword: "reva", IDP: defaultPublicURL, - UserSchema: LDAPUserSchema{ + UserSchema: config.LDAPUserSchema{ UID: "ownclouduuid", Mail: "mail", DisplayName: "displayname", @@ -57,7 +67,7 @@ func DefaultConfig() *Config { UIDNumber: "uidnumber", GIDNumber: "gidnumber", }, - GroupSchema: LDAPGroupSchema{ + GroupSchema: config.LDAPGroupSchema{ GID: "cn", Mail: "mail", DisplayName: "cn", @@ -65,10 +75,10 @@ func DefaultConfig() *Config { GIDNumber: "gidnumber", }, }, - UserGroupRest: UserGroupRest{ + UserGroupRest: config.UserGroupRest{ RedisAddress: "localhost:6379", }, - UserOwnCloudSQL: UserOwnCloudSQL{ + UserOwnCloudSQL: config.UserOwnCloudSQL{ DBUsername: "owncloud", DBPassword: "secret", DBHost: "mysql", @@ -80,18 +90,18 @@ func DefaultConfig() *Config { JoinOwnCloudUUID: false, EnableMedialSearch: false, }, - OCDav: OCDav{ + OCDav: config.OCDav{ WebdavNamespace: defaultStorageNamespace, DavFilesNamespace: defaultStorageNamespace, }, - Archiver: Archiver{ + Archiver: config.Archiver{ MaxNumFiles: 10000, MaxSize: 1073741824, ArchiverURL: "/archiver", }, - UserStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ + UserStorage: config.StorageConfig{ + EOS: config.DriverEOS{ + DriverCommon: config.DriverCommon{ Root: "/eos/dockertest/reva", ShareFolder: defaultShareFolder, UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", @@ -105,14 +115,14 @@ func DefaultConfig() *Config { CacheDirectory: os.TempDir(), GatewaySVC: defaultGatewayAddr, }, - Local: DriverCommon{ + Local: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), ShareFolder: defaultShareFolder, UserLayout: "{{.Username}}", EnableHome: false, }, - OwnCloudSQL: DriverOwnCloudSQL{ - DriverCommon: DriverCommon{ + OwnCloudSQL: config.DriverOwnCloudSQL{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), ShareFolder: defaultShareFolder, UserLayout: "{{.Username}}", @@ -125,16 +135,16 @@ func DefaultConfig() *Config { DBPort: 3306, DBName: "owncloud", }, - S3: DriverS3{ - DriverCommon: DriverCommon{}, + S3: config.DriverS3{ + DriverCommon: config.DriverCommon{}, Region: "default", AccessKey: "", SecretKey: "", Endpoint: "", Bucket: "", }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ + S3NG: config.DriverS3NG{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), ShareFolder: defaultShareFolder, UserLayout: defaultUserLayout, @@ -146,17 +156,17 @@ func DefaultConfig() *Config { Endpoint: "", Bucket: "", }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ + OCIS: config.DriverOCIS{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), ShareFolder: defaultShareFolder, UserLayout: defaultUserLayout, }, }, }, - MetadataStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ + MetadataStorage: config.StorageConfig{ + EOS: config.DriverEOS{ + DriverCommon: config.DriverCommon{ Root: "/eos/dockertest/reva", ShareFolder: defaultShareFolder, UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", @@ -179,16 +189,16 @@ func DefaultConfig() *Config { SingleUsername: "", GatewaySVC: defaultGatewayAddr, }, - Local: DriverCommon{ + Local: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), }, - OwnCloudSQL: DriverOwnCloudSQL{}, - S3: DriverS3{ - DriverCommon: DriverCommon{}, + OwnCloudSQL: config.DriverOwnCloudSQL{}, + S3: config.DriverS3{ + DriverCommon: config.DriverCommon{}, Region: "default", }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ + S3NG: config.DriverS3NG{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", UserLayout: defaultUserLayout, @@ -200,8 +210,8 @@ func DefaultConfig() *Config { Endpoint: "", Bucket: "", }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ + OCIS: config.DriverOCIS{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", UserLayout: defaultUserLayout, @@ -209,8 +219,8 @@ func DefaultConfig() *Config { }, }, }, - Frontend: FrontendPort{ - Port: Port{ + Frontend: config.FrontendPort{ + Port: config.Port{ MaxCPUs: "", LogLevel: "", GRPCNetwork: "", @@ -241,14 +251,14 @@ func DefaultConfig() *Config { OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", OCSResourceInfoCacheTTL: 0, - Middleware: Middleware{}, + Middleware: config.Middleware{}, }, - DataGateway: DataGatewayPort{ - Port: Port{}, + DataGateway: config.DataGatewayPort{ + Port: config.Port{}, PublicURL: "", }, - Gateway: Gateway{ - Port: Port{ + Gateway: config.Gateway{ + Port: config.Port{ Endpoint: defaultGatewayAddr, DebugAddr: "127.0.0.1:9143", GRPCNetwork: "tcp", @@ -262,17 +272,17 @@ func DefaultConfig() *Config { HomeMapping: "", EtagCacheTTL: 0, }, - StorageRegistry: StorageRegistry{ + StorageRegistry: config.StorageRegistry{ Driver: "spaces", HomeProvider: "/home", // unused for spaces, static currently not supported JSON: "", }, - AppRegistry: AppRegistry{ + AppRegistry: config.AppRegistry{ Driver: "static", MimetypesJSON: "", }, - Users: Users{ - Port: Port{ + Users: config.Users{ + Port: config.Port{ Endpoint: "localhost:9144", DebugAddr: "127.0.0.1:9145", GRPCNetwork: "tcp", @@ -282,8 +292,8 @@ func DefaultConfig() *Config { Driver: "ldap", UserGroupsCacheExpiration: 5, }, - Groups: Groups{ - Port: Port{ + Groups: config.Groups{ + Port: config.Port{ Endpoint: "localhost:9160", DebugAddr: "127.0.0.1:9161", GRPCNetwork: "tcp", @@ -293,37 +303,37 @@ func DefaultConfig() *Config { Driver: "ldap", GroupMembersCacheExpiration: 5, }, - AuthProvider: Users{ - Port: Port{}, + AuthProvider: config.Users{ + Port: config.Port{}, Driver: "ldap", UserGroupsCacheExpiration: 0, }, - AuthBasic: Port{ + AuthBasic: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9146", DebugAddr: "127.0.0.1:9147", Services: []string{"authprovider"}, Endpoint: "localhost:9146", }, - AuthBearer: Port{ + AuthBearer: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9148", DebugAddr: "127.0.0.1:9149", Services: []string{"authprovider"}, Endpoint: "localhost:9148", }, - AuthMachine: Port{ + AuthMachine: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9166", DebugAddr: "127.0.0.1:9167", Services: []string{"authprovider"}, Endpoint: "localhost:9166", }, - AuthMachineConfig: AuthMachineConfig{ + AuthMachineConfig: config.AuthMachineConfig{ MachineAuthAPIKey: "change-me-please", }, - Sharing: Sharing{ - Port: Port{ + Sharing: config.Sharing{ + Port: config.Port{ Endpoint: "localhost:9150", DebugAddr: "127.0.0.1:9151", GRPCNetwork: "tcp", @@ -343,13 +353,13 @@ func DefaultConfig() *Config { PublicEnableExpiredSharesCleanup: true, PublicJanitorRunInterval: 60, UserStorageMountID: "", - Events: Events{ + Events: config.Events{ Address: "127.0.0.1:9233", ClusterID: "test-cluster", }, }, - StorageShares: StoragePort{ - Port: Port{ + StorageShares: config.StoragePort{ + Port: config.Port{ Endpoint: "localhost:9154", DebugAddr: "127.0.0.1:9156", GRPCNetwork: "tcp", @@ -361,8 +371,8 @@ func DefaultConfig() *Config { AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", }, - StorageUsers: StoragePort{ - Port: Port{ + StorageUsers: config.StoragePort{ + Port: config.Port{ Endpoint: "localhost:9157", DebugAddr: "127.0.0.1:9159", GRPCNetwork: "tcp", @@ -376,9 +386,9 @@ func DefaultConfig() *Config { HTTPPrefix: "data", TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), }, - StoragePublicLink: PublicStorage{ - StoragePort: StoragePort{ - Port: Port{ + StoragePublicLink: config.PublicStorage{ + StoragePort: config.StoragePort{ + Port: config.Port{ Endpoint: "localhost:9178", DebugAddr: "127.0.0.1:9179", GRPCNetwork: "tcp", @@ -389,8 +399,8 @@ func DefaultConfig() *Config { PublicShareProviderAddr: "", UserProviderAddr: "", }, - StorageMetadata: StoragePort{ - Port: Port{ + StorageMetadata: config.StoragePort{ + Port: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9215", HTTPNetwork: "tcp", @@ -401,10 +411,10 @@ func DefaultConfig() *Config { ExposeDataServer: false, DataServerURL: "http://localhost:9216/data", TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), - DataProvider: DataProvider{}, + DataProvider: config.DataProvider{}, }, - AppProvider: AppProvider{ - Port: Port{ + AppProvider: config.AppProvider{ + Port: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9164", DebugAddr: "127.0.0.1:9165", @@ -412,12 +422,12 @@ func DefaultConfig() *Config { Services: []string{"appprovider"}, }, ExternalAddr: "127.0.0.1:9164", - WopiDriver: WopiDriver{}, + WopiDriver: config.WopiDriver{}, AppsURL: "/app/list", OpenURL: "/app/open", NewURL: "/app/new", }, - Permissions: Port{ + Permissions: config.Port{ Endpoint: "localhost:9191", }, Configs: nil, @@ -427,10 +437,18 @@ func DefaultConfig() *Config { ChecksumPreferredUploadType: "", DefaultUploadProtocol: "tus", }, - Tracing: Tracing{ + Tracing: config.Tracing{ Service: "storage", Type: "jaeger", }, - Asset: Asset{}, + Asset: config.Asset{}, } } + +func EnsureDefaults(cfg *config.Config) { + // TODO: IMPLEMENT ME! +} + +func Sanitize(cfg *config.Config) { + // TODO: IMPLEMENT ME! +} diff --git a/store/pkg/config/defaultconfig.go b/store/pkg/config/defaultconfig.go deleted file mode 100644 index c2d42f430..000000000 --- a/store/pkg/config/defaultconfig.go +++ /dev/null @@ -1,26 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9464", - Token: "", - Pprof: false, - Zpages: false, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9460", - Namespace: "com.owncloud.api", - }, - Service: Service{ - Name: "store", - }, - Datapath: path.Join(defaults.BaseDataPath(), "store"), - } -} diff --git a/store/pkg/config/defaults/defaultconfig.go b/store/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..2381ceb4a --- /dev/null +++ b/store/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,65 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/store/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:9464", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: config.GRPC{ + Addr: "127.0.0.1:9460", + Namespace: "com.owncloud.api", + }, + Service: config.Service{ + Name: "store", + }, + Datapath: path.Join(defaults.BaseDataPath(), "store"), + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/store/pkg/config/parser/parse.go b/store/pkg/config/parser/parse.go index a0f532c9e..3538a608f 100644 --- a/store/pkg/config/parser/parse.go +++ b/store/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -16,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,6 +28,6 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config - + defaults.Sanitize(cfg) return nil } diff --git a/thumbnails/pkg/config/defaultconfig.go b/thumbnails/pkg/config/defaultconfig.go deleted file mode 100644 index 5e4a3e423..000000000 --- a/thumbnails/pkg/config/defaultconfig.go +++ /dev/null @@ -1,41 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9189", - Token: "", - Pprof: false, - Zpages: false, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9185", - Namespace: "com.owncloud.api", - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9186", - Root: "/thumbnails", - Namespace: "com.owncloud.web", - }, - Service: Service{ - Name: "thumbnails", - }, - Thumbnail: Thumbnail{ - Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, - FileSystemStorage: FileSystemStorage{ - RootDirectory: path.Join(defaults.BaseDataPath(), "thumbnails"), - }, - WebdavAllowInsecure: true, - RevaGateway: "127.0.0.1:9142", - CS3AllowInsecure: false, - TransferTokenSecret: "changemeplease", - DataEndpoint: "http://127.0.0.1:9186/thumbnails/data", - }, - } -} diff --git a/thumbnails/pkg/config/defaults/defaultconfig.go b/thumbnails/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..a32f7df07 --- /dev/null +++ b/thumbnails/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,80 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/thumbnails/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:9189", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: config.GRPC{ + Addr: "127.0.0.1:9185", + Namespace: "com.owncloud.api", + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9186", + Root: "/thumbnails", + Namespace: "com.owncloud.web", + }, + Service: config.Service{ + Name: "thumbnails", + }, + Thumbnail: config.Thumbnail{ + Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, + FileSystemStorage: config.FileSystemStorage{ + RootDirectory: path.Join(defaults.BaseDataPath(), "thumbnails"), + }, + WebdavAllowInsecure: true, + RevaGateway: "127.0.0.1:9142", + CS3AllowInsecure: false, + TransferTokenSecret: "changemeplease", + DataEndpoint: "http://127.0.0.1:9186/thumbnails/data", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/thumbnails/pkg/config/parser/parse.go b/thumbnails/pkg/config/parser/parse.go index 5fa62fb15..705425a65 100644 --- a/thumbnails/pkg/config/parser/parse.go +++ b/thumbnails/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -16,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,6 +28,7 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config + defaults.Sanitize(cfg) return nil } diff --git a/web/pkg/config/defaultconfig.go b/web/pkg/config/defaultconfig.go deleted file mode 100644 index 018cac2d0..000000000 --- a/web/pkg/config/defaultconfig.go +++ /dev/null @@ -1,42 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9104", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9100", - Root: "/", - Namespace: "com.owncloud.web", - CacheTTL: 604800, // 7 days - }, - Service: Service{ - Name: "web", - }, - Asset: Asset{ - Path: "", - }, - Web: Web{ - Path: "", - ThemeServer: "https://localhost:9200", - ThemePath: "/themes/owncloud/theme.json", - Config: WebConfig{ - Server: "https://localhost:9200", - Theme: "", - Version: "0.1.0", - OpenIDConnect: OIDC{ - MetadataURL: "", - Authority: "https://localhost:9200", - ClientID: "web", - ResponseType: "code", - Scope: "openid profile email", - }, - Apps: []string{"files", "search", "media-viewer", "external"}, - }, - }, - } -} diff --git a/web/pkg/config/defaults/defaultconfig.go b/web/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..8e921bbaa --- /dev/null +++ b/web/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,93 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/web/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:9104", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9100", + Root: "/", + Namespace: "com.owncloud.web", + CacheTTL: 604800, // 7 days + }, + Service: config.Service{ + Name: "web", + }, + Asset: config.Asset{ + Path: "", + }, + Web: config.Web{ + Path: "", + ThemeServer: "https://localhost:9200", + ThemePath: "/themes/owncloud/theme.json", + Config: config.WebConfig{ + Server: "https://localhost:9200", + Theme: "", + Version: "0.1.0", + OpenIDConnect: config.OIDC{ + MetadataURL: "", + Authority: "https://localhost:9200", + ClientID: "web", + ResponseType: "code", + Scope: "openid profile email", + }, + Apps: []string{"files", "search", "media-viewer", "external"}, + }, + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") + } + // build well known openid-configuration endpoint if it is not set + if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { + cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" + } +} diff --git a/web/pkg/config/parser/parse.go b/web/pkg/config/parser/parse.go index 2151f613e..2f8fe31d0 100644 --- a/web/pkg/config/parser/parse.go +++ b/web/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,14 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") - } - // build well known openid-configuration endpoint if it is not set - if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { - cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" - } + defaults.Sanitize(cfg) return nil } diff --git a/webdav/pkg/config/defaultconfig.go b/webdav/pkg/config/defaultconfig.go deleted file mode 100644 index 3bf74acd2..000000000 --- a/webdav/pkg/config/defaultconfig.go +++ /dev/null @@ -1,29 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9119", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9115", - Root: "/", - Namespace: "com.owncloud.web", - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - Service: Service{ - Name: "webdav", - }, - OcisPublicURL: "https://127.0.0.1:9200", - WebdavNamespace: "/users/{{.Id.OpaqueId}}", - RevaGateway: "127.0.0.1:9142", - } -} diff --git a/webdav/pkg/config/defaults/defaultconfig.go b/webdav/pkg/config/defaults/defaultconfig.go new file mode 100644 index 000000000..8c2e16470 --- /dev/null +++ b/webdav/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,77 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/webdav/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:9119", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9115", + Root: "/", + Namespace: "com.owncloud.web", + CORS: config.CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Service: config.Service{ + Name: "webdav", + }, + OcisPublicURL: "https://127.0.0.1:9200", + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + RevaGateway: "127.0.0.1:9142", + } +} + +func EnsureDefaults(cfg *config.Config) { + // 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{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + +} diff --git a/webdav/pkg/config/parser/parse.go b/webdav/pkg/config/parser/parse.go index 33c893db4..629f85220 100644 --- a/webdav/pkg/config/parser/parse.go +++ b/webdav/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,28 +17,7 @@ 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{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil }