diff --git a/ocis-pkg/config/parser/parse.go b/ocis-pkg/config/parser/parse.go index aa25038dd..54c94d1e9 100644 --- a/ocis-pkg/config/parser/parse.go +++ b/ocis-pkg/config/parser/parse.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config" "github.com/owncloud/ocis/v2/ocis-pkg/config/envdecode" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" ) // ParseConfig loads the ocis configuration and @@ -36,7 +37,7 @@ func ParseConfig(cfg *config.Config, skipValidate bool) error { return Validate(cfg) } -// EnsureDefaults, ensures that all pointers in the +// EnsureDefaults ensures that all pointers in the // oCIS config (not the services configs) are initialized func EnsureDefaults(cfg *config.Config) { if cfg.Tracing == nil { @@ -67,39 +68,9 @@ func EnsureCommons(cfg *config.Config) { cfg.Commons = &shared.Commons{} } - // copy config to the commons part if set - if cfg.Log != nil { - cfg.Commons.Log = &shared.Log{ - Level: cfg.Log.Level, - Pretty: cfg.Log.Pretty, - Color: cfg.Log.Color, - File: cfg.File, - } - } else { - cfg.Commons.Log = &shared.Log{} - } - - // copy tracing to the commons part if set - if cfg.Tracing != nil { - cfg.Commons.Tracing = &shared.Tracing{ - Enabled: cfg.Tracing.Enabled, - Type: cfg.Tracing.Type, - Endpoint: cfg.Tracing.Endpoint, - Collector: cfg.Tracing.Collector, - } - } else { - cfg.Commons.Tracing = &shared.Tracing{} - } - - if cfg.CacheStore != nil { - cfg.Commons.CacheStore = &shared.CacheStore{ - Type: cfg.CacheStore.Type, - Address: cfg.CacheStore.Address, - Size: cfg.CacheStore.Size, - } - } else { - cfg.Commons.CacheStore = &shared.CacheStore{} - } + cfg.Commons.Log = structs.CopyOrZeroValue(cfg.Log) + cfg.Commons.Tracing = structs.CopyOrZeroValue(cfg.Tracing) + cfg.Commons.CacheStore = structs.CopyOrZeroValue(cfg.CacheStore) if cfg.GRPCClientTLS != nil { cfg.Commons.GRPCClientTLS = cfg.GRPCClientTLS @@ -111,12 +82,7 @@ func EnsureCommons(cfg *config.Config) { cfg.Commons.HTTPServiceTLS = cfg.HTTPServiceTLS - // copy token manager to the commons part if set - if cfg.TokenManager != nil { - cfg.Commons.TokenManager = cfg.TokenManager - } else { - cfg.Commons.TokenManager = &shared.TokenManager{} - } + cfg.Commons.TokenManager = structs.CopyOrZeroValue(cfg.TokenManager) // copy machine auth api key to the commons part if set if cfg.MachineAuthAPIKey != "" { @@ -147,6 +113,8 @@ func EnsureCommons(cfg *config.Config) { } } +// Validate checks that all required configs are set. If a required config value +// is missing an error will be returned. func Validate(cfg *config.Config) error { if cfg.TokenManager.JWTSecret == "" { return shared.MissingJWTTokenError("ocis") diff --git a/ocis-pkg/structs/structs.go b/ocis-pkg/structs/structs.go new file mode 100644 index 000000000..b6545d048 --- /dev/null +++ b/ocis-pkg/structs/structs.go @@ -0,0 +1,11 @@ +// Package structs provides some utility functions for dealing with structs. +package structs + +// CopyOrZeroValue returns a copy of s if s is not nil otherwise the zero value of T will be returned. +func CopyOrZeroValue[T any](s *T) *T { + cp := new(T) + if s != nil { + *cp = *s + } + return cp +} diff --git a/ocis-pkg/structs/structs_test.go b/ocis-pkg/structs/structs_test.go new file mode 100644 index 000000000..1e8f4096c --- /dev/null +++ b/ocis-pkg/structs/structs_test.go @@ -0,0 +1,38 @@ +package structs + +import "testing" + +type example struct { + Attribute1 string + Attribute2 string +} + +func TestCopyOrZeroValue(t *testing.T) { + var e *example + + zv := CopyOrZeroValue(e) + + if zv == nil { + t.Error("CopyOrZeroValue returned nil") + } + + if zv.Attribute1 != "" || zv.Attribute2 != "" { + t.Error("CopyOrZeroValue didn't return zero value") + } + + e2 := &example{Attribute1: "One", Attribute2: "Two"} + + cp := CopyOrZeroValue(e2) + + if cp == nil { + t.Error("CopyOrZeroValue returned nil") + } + + if cp == e2 { + t.Error("CopyOrZeroValue returned reference with same address") + } + + if cp.Attribute1 != e2.Attribute1 || cp.Attribute2 != e2.Attribute2 { + t.Error("CopyOrZeroValue didn't correctly copy attributes") + } +} diff --git a/services/app-provider/pkg/config/defaults/defaultconfig.go b/services/app-provider/pkg/config/defaults/defaultconfig.go index 57a4be834..1d8667b1f 100644 --- a/services/app-provider/pkg/config/defaults/defaultconfig.go +++ b/services/app-provider/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/app-provider/pkg/config" ) @@ -63,13 +64,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -80,13 +76,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/app-registry/pkg/config/defaults/defaultconfig.go b/services/app-registry/pkg/config/defaults/defaultconfig.go index de7e01952..777e5a196 100644 --- a/services/app-registry/pkg/config/defaults/defaultconfig.go +++ b/services/app-registry/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/app-registry/pkg/config" ) @@ -128,13 +129,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -145,13 +141,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/auth-basic/pkg/config/defaults/defaultconfig.go b/services/auth-basic/pkg/config/defaults/defaultconfig.go index 630aec30b..64f6537f3 100644 --- a/services/auth-basic/pkg/config/defaults/defaultconfig.go +++ b/services/auth-basic/pkg/config/defaults/defaultconfig.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/auth-basic/pkg/config" ) @@ -102,13 +103,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -119,13 +115,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/auth-bearer/pkg/config/defaults/defaultconfig.go b/services/auth-bearer/pkg/config/defaults/defaultconfig.go index e9a3eaf2d..980c01c34 100644 --- a/services/auth-bearer/pkg/config/defaults/defaultconfig.go +++ b/services/auth-bearer/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/auth-bearer/pkg/config" ) @@ -61,13 +62,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -78,13 +74,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/auth-machine/pkg/config/defaults/defaultconfig.go b/services/auth-machine/pkg/config/defaults/defaultconfig.go index 242db54a5..b5a16f98d 100644 --- a/services/auth-machine/pkg/config/defaults/defaultconfig.go +++ b/services/auth-machine/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/auth-machine/pkg/config" ) @@ -56,13 +57,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -77,13 +73,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/eventhistory/pkg/config/defaults/defaultconfig.go b/services/eventhistory/pkg/config/defaults/defaultconfig.go index a61d411c4..d37b6fbe1 100644 --- a/services/eventhistory/pkg/config/defaults/defaultconfig.go +++ b/services/eventhistory/pkg/config/defaults/defaultconfig.go @@ -3,7 +3,7 @@ package defaults import ( "time" - "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/config" ) @@ -51,20 +51,12 @@ func EnsureDefaults(cfg *config.Config) { cfg.Log = &config.Log{} } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS = cfg.Commons.GRPCClientTLS - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/frontend/pkg/config/defaults/defaultconfig.go b/services/frontend/pkg/config/defaults/defaultconfig.go index 526d5a81b..543bf06f0 100644 --- a/services/frontend/pkg/config/defaults/defaultconfig.go +++ b/services/frontend/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/frontend/pkg/config" ) @@ -138,13 +139,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { diff --git a/services/gateway/pkg/config/defaults/defaultconfig.go b/services/gateway/pkg/config/defaults/defaultconfig.go index adf7a8422..88dcd30b1 100644 --- a/services/gateway/pkg/config/defaults/defaultconfig.go +++ b/services/gateway/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/gateway/pkg/config" ) @@ -85,13 +86,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -106,13 +102,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TransferSecret = cfg.Commons.TransferSecret } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/graph/pkg/config/defaults/defaultconfig.go b/services/graph/pkg/config/defaults/defaultconfig.go index 7b9a4563d..d1f86fc24 100644 --- a/services/graph/pkg/config/defaults/defaultconfig.go +++ b/services/graph/pkg/config/defaults/defaultconfig.go @@ -7,6 +7,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/graph/pkg/config" ) @@ -130,12 +131,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } if cfg.Commons != nil { diff --git a/services/groups/pkg/config/defaults/defaultconfig.go b/services/groups/pkg/config/defaults/defaultconfig.go index 62cfe0e4e..e2dbb7baf 100644 --- a/services/groups/pkg/config/defaults/defaultconfig.go +++ b/services/groups/pkg/config/defaults/defaultconfig.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/groups/pkg/config" ) @@ -103,13 +104,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -120,13 +116,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/idp/pkg/config/defaults/defaultconfig.go b/services/idp/pkg/config/defaults/defaultconfig.go index c65dafda0..722a05810 100644 --- a/services/idp/pkg/config/defaults/defaultconfig.go +++ b/services/idp/pkg/config/defaults/defaultconfig.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/idp/pkg/config" ) @@ -152,13 +153,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" { diff --git a/services/notifications/pkg/config/defaults/defaultconfig.go b/services/notifications/pkg/config/defaults/defaultconfig.go index 20e3582d8..e52aa036f 100644 --- a/services/notifications/pkg/config/defaults/defaultconfig.go +++ b/services/notifications/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/notifications/pkg/config" ) @@ -59,11 +60,8 @@ func EnsureDefaults(cfg *config.Config) { if cfg.Notifications.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" { cfg.Notifications.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey } - if cfg.Notifications.GRPCClientTLS == nil { - cfg.Notifications.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.Notifications.GRPCClientTLS = cfg.Commons.GRPCClientTLS - } + if cfg.Notifications.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.Notifications.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } } diff --git a/services/ocdav/pkg/config/defaults/defaultconfig.go b/services/ocdav/pkg/config/defaults/defaultconfig.go index 6d6fae522..473522344 100644 --- a/services/ocdav/pkg/config/defaults/defaultconfig.go +++ b/services/ocdav/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/ocdav/pkg/config" ) @@ -73,13 +74,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { diff --git a/services/proxy/pkg/config/defaults/defaultconfig.go b/services/proxy/pkg/config/defaults/defaultconfig.go index daf3a7534..55afd332e 100644 --- a/services/proxy/pkg/config/defaults/defaultconfig.go +++ b/services/proxy/pkg/config/defaults/defaultconfig.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" ) @@ -249,21 +250,12 @@ func EnsureDefaults(cfg *config.Config) { cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } } diff --git a/services/search/pkg/config/defaults/defaultconfig.go b/services/search/pkg/config/defaults/defaultconfig.go index 7fb9ef946..72d5d8303 100644 --- a/services/search/pkg/config/defaults/defaultconfig.go +++ b/services/search/pkg/config/defaults/defaultconfig.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/search/pkg/config" ) @@ -83,28 +84,14 @@ func EnsureDefaults(cfg *config.Config) { cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/settings/pkg/config/defaults/defaultconfig.go b/services/settings/pkg/config/defaults/defaultconfig.go index 1c07e7005..0e2ae2c1a 100644 --- a/services/settings/pkg/config/defaults/defaultconfig.go +++ b/services/settings/pkg/config/defaults/defaultconfig.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/settings/pkg/config" rdefaults "github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults" "github.com/pkg/errors" @@ -104,20 +104,11 @@ func EnsureDefaults(cfg *config.Config) { cfg.AdminUserID = cfg.Commons.AdminUserID } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } if cfg.Commons != nil { diff --git a/services/sharing/pkg/config/defaults/defaultconfig.go b/services/sharing/pkg/config/defaults/defaultconfig.go index 5049e1d8e..8b14db4d1 100644 --- a/services/sharing/pkg/config/defaults/defaultconfig.go +++ b/services/sharing/pkg/config/defaults/defaultconfig.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/sharing/pkg/config" ) @@ -99,13 +100,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -116,13 +112,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } if cfg.UserSharingDrivers.CS3.SystemUserAPIKey == "" && cfg.Commons != nil && cfg.Commons.SystemUserAPIKey != "" { diff --git a/services/storage-publiclink/pkg/config/defaults/defaultconfig.go b/services/storage-publiclink/pkg/config/defaults/defaultconfig.go index 9497a28ed..27aa285b0 100644 --- a/services/storage-publiclink/pkg/config/defaults/defaultconfig.go +++ b/services/storage-publiclink/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config" ) @@ -59,13 +60,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -76,13 +72,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/storage-shares/pkg/config/defaults/defaultconfig.go b/services/storage-shares/pkg/config/defaults/defaultconfig.go index dcc1d3c4f..a666d4e1c 100644 --- a/services/storage-shares/pkg/config/defaults/defaultconfig.go +++ b/services/storage-shares/pkg/config/defaults/defaultconfig.go @@ -2,6 +2,7 @@ package defaults import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config" ) @@ -59,13 +60,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -76,13 +72,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/storage-system/pkg/config/defaults/defaultconfig.go b/services/storage-system/pkg/config/defaults/defaultconfig.go index 01a1a459e..3de675fa4 100644 --- a/services/storage-system/pkg/config/defaults/defaultconfig.go +++ b/services/storage-system/pkg/config/defaults/defaultconfig.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/storage-system/pkg/config" ) @@ -78,13 +79,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -103,13 +99,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.SystemUserID = cfg.Commons.SystemUserID } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/storage-users/pkg/config/defaults/defaultconfig.go b/services/storage-users/pkg/config/defaults/defaultconfig.go index 494a7c8ea..7f4ee8e59 100644 --- a/services/storage-users/pkg/config/defaults/defaultconfig.go +++ b/services/storage-users/pkg/config/defaults/defaultconfig.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/storage-users/pkg/config" ) @@ -123,13 +124,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -140,13 +136,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } if cfg.Tasks.PurgeTrashBin.UserID == "" && cfg.Commons != nil { diff --git a/services/store/pkg/config/defaults/defaultconfig.go b/services/store/pkg/config/defaults/defaultconfig.go index ffd1dc0ad..dcaea6b4c 100644 --- a/services/store/pkg/config/defaults/defaultconfig.go +++ b/services/store/pkg/config/defaults/defaultconfig.go @@ -4,7 +4,7 @@ import ( "path" "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/store/pkg/config" ) @@ -58,20 +58,11 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/thumbnails/pkg/config/defaults/defaultconfig.go b/services/thumbnails/pkg/config/defaults/defaultconfig.go index 3349521a7..1f93c1685 100644 --- a/services/thumbnails/pkg/config/defaults/defaultconfig.go +++ b/services/thumbnails/pkg/config/defaults/defaultconfig.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config" ) @@ -73,20 +74,11 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } if cfg.Commons != nil { diff --git a/services/userlog/pkg/config/defaults/defaultconfig.go b/services/userlog/pkg/config/defaults/defaultconfig.go index 5db2b5ce5..a228e387e 100644 --- a/services/userlog/pkg/config/defaults/defaultconfig.go +++ b/services/userlog/pkg/config/defaults/defaultconfig.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/userlog/pkg/config" ) @@ -62,11 +63,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS = cfg.Commons.GRPCClientTLS - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { diff --git a/services/users/pkg/config/defaults/defaultconfig.go b/services/users/pkg/config/defaults/defaultconfig.go index 1fe0ee094..5f6906601 100644 --- a/services/users/pkg/config/defaults/defaultconfig.go +++ b/services/users/pkg/config/defaults/defaultconfig.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/defaults" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/users/pkg/config" ) @@ -104,13 +105,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil { - cfg.Reva = &shared.Reva{ - Address: cfg.Commons.Reva.Address, - TLS: cfg.Commons.Reva.TLS, - } - } else if cfg.Reva == nil { - cfg.Reva = &shared.Reva{} + if cfg.Reva == nil && cfg.Commons != nil { + cfg.Reva = structs.CopyOrZeroValue(cfg.Commons.Reva) } if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil { @@ -121,13 +117,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.TokenManager = &config.TokenManager{} } - if cfg.GRPC.TLS == nil { - cfg.GRPC.TLS = &shared.GRPCServiceTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCServiceTLS != nil { - cfg.GRPC.TLS.Enabled = cfg.Commons.GRPCServiceTLS.Enabled - cfg.GRPC.TLS.Cert = cfg.Commons.GRPCServiceTLS.Cert - cfg.GRPC.TLS.Key = cfg.Commons.GRPCServiceTLS.Key - } + if cfg.GRPC.TLS == nil && cfg.Commons != nil { + cfg.GRPC.TLS = structs.CopyOrZeroValue(cfg.Commons.GRPCServiceTLS) } } diff --git a/services/webdav/pkg/config/defaults/defaultconfig.go b/services/webdav/pkg/config/defaults/defaultconfig.go index 083d0a1a3..43861991a 100644 --- a/services/webdav/pkg/config/defaults/defaultconfig.go +++ b/services/webdav/pkg/config/defaults/defaultconfig.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "github.com/owncloud/ocis/v2/ocis-pkg/structs" "github.com/owncloud/ocis/v2/services/webdav/pkg/config" ) @@ -66,12 +67,8 @@ func EnsureDefaults(cfg *config.Config) { cfg.Tracing = &config.Tracing{} } - if cfg.GRPCClientTLS == nil { - cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - if cfg.Commons != nil && cfg.Commons.GRPCClientTLS != nil { - cfg.GRPCClientTLS.Mode = cfg.Commons.GRPCClientTLS.Mode - cfg.GRPCClientTLS.CACert = cfg.Commons.GRPCClientTLS.CACert - } + if cfg.GRPCClientTLS == nil && cfg.Commons != nil { + cfg.GRPCClientTLS = structs.CopyOrZeroValue(cfg.Commons.GRPCClientTLS) } if cfg.Commons != nil {