Add defaultconfig to extensions

This commit is contained in:
Christian Richter
2022-03-08 17:35:55 +01:00
parent f2e8c90067
commit 9734b000b3
48 changed files with 1126 additions and 840 deletions

View File

@@ -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() {

View File

@@ -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
}

View File

@@ -30,10 +30,7 @@ func ParseConfig(cfg *config.Config) error {
}
}
err = defaults.Sanitize(cfg)
if err != nil {
return err
}
defaults.Sanitize(cfg)
return nil
}

View File

@@ -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)
}
}

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -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",
},
}
}

View File

@@ -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")
}
}

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -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",
},
},
}
}

View File

@@ -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, "/")
}
}

View File

@@ -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
}

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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,
},
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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",
},
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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",
},
}
}

View File

@@ -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, "/")
}
}

View File

@@ -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
}

View File

@@ -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, "/")
}
}

View File

@@ -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
}

View File

@@ -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",
},
}
}

View File

@@ -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, "/")
}
}

View File

@@ -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
}

View File

@@ -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!
}

View File

@@ -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"),
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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",
},
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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"},
},
},
}
}

View File

@@ -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"
}
}

View File

@@ -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
}

View File

@@ -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",
}
}

View File

@@ -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, "/")
}
}

View File

@@ -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
}