diff --git a/accounts/cmd/accounts/main.go b/accounts/cmd/accounts/main.go index 35262ccad8..d7788426be 100644 --- a/accounts/cmd/accounts/main.go +++ b/accounts/cmd/accounts/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/accounts/pkg/command" - "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/accounts/cmd/helper/defaultconfig/main.go b/accounts/cmd/helper/defaultconfig/main.go new file mode 100644 index 0000000000..e2b574505c --- /dev/null +++ b/accounts/cmd/helper/defaultconfig/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + + accountsdefaults "github.com/owncloud/ocis/accounts/pkg/config/defaults" + idpdefaults "github.com/owncloud/ocis/idp/pkg/config/defaults" + "gopkg.in/yaml.v2" +) + +func main() { + + fn1 := accountsdefaults.FullDefaultConfig + fn2 := idpdefaults.FullDefaultConfig + + b, err := yaml.Marshal(fn1()) + if err != nil { + return + } + fmt.Println(string(b)) + + b, err = yaml.Marshal(fn2()) + if err != nil { + return + } + fmt.Println(string(b)) +} diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 9a4609d7e4..3a3d3dd593 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -28,7 +28,7 @@ type Config struct { HashDifficulty int `ocisConfig:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY" desc:"The hash difficulty makes sure that validating a password takes at least a certain amount of time."` DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"If this flag is set the service will setup the demo users and groups."` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Asset defines the available asset configuration. diff --git a/accounts/pkg/config/defaultconfig.go b/accounts/pkg/config/defaultconfig.go deleted file mode 100644 index 394cf2155f..0000000000 --- a/accounts/pkg/config/defaultconfig.go +++ /dev/null @@ -1,68 +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:9182", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9181", - 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:9180", - Namespace: "com.owncloud.api", - }, - Service: Service{ - Name: "accounts", - }, - Asset: Asset{}, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - HashDifficulty: 11, - DemoUsersAndGroups: true, - Repo: Repo{ - Backend: "CS3", - Disk: Disk{ - Path: path.Join(defaults.BaseDataPath(), "accounts"), - }, - CS3: CS3{ - ProviderAddr: "localhost:9215", - }, - }, - Index: Index{ - UID: UIDBound{ - Lower: 0, - Upper: 1000, - }, - GID: GIDBound{ - Lower: 0, - Upper: 1000, - }, - }, - ServiceUser: ServiceUser{ - UUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Username: "", - UID: 0, - GID: 0, - }, - } -} diff --git a/accounts/pkg/config/defaults/defaultconfig.go b/accounts/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..bf62637ece --- /dev/null +++ b/accounts/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,112 @@ +package defaults + +import ( + "path" + "strings" + + "github.com/owncloud/ocis/accounts/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:9182", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9181", + 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:9180", + Namespace: "com.owncloud.api", + }, + Service: config.Service{ + Name: "accounts", + }, + Asset: config.Asset{}, + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + HashDifficulty: 11, + DemoUsersAndGroups: true, + Repo: config.Repo{ + Backend: "CS3", + Disk: config.Disk{ + Path: path.Join(defaults.BaseDataPath(), "accounts"), + }, + CS3: config.CS3{ + ProviderAddr: "localhost:9215", + }, + }, + Index: config.Index{ + UID: config.UIDBound{ + Lower: 0, + Upper: 1000, + }, + GID: config.GIDBound{ + Lower: 0, + Upper: 1000, + }, + }, + ServiceUser: config.ServiceUser{ + UUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Username: "", + UID: 0, + GID: 0, + }, + } +} + +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, "/") + } + cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) +} diff --git a/accounts/pkg/config/grpc.go b/accounts/pkg/config/grpc.go index a89e0ca005..148fda9250 100644 --- a/accounts/pkg/config/grpc.go +++ b/accounts/pkg/config/grpc.go @@ -3,5 +3,5 @@ package config // GRPC defines the available grpc configuration. type GRPC struct { Addr string `ocisConfig:"addr" env:"ACCOUNTS_GRPC_ADDR" desc:"The address of the grpc service."` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } diff --git a/accounts/pkg/config/http.go b/accounts/pkg/config/http.go index 6a8828ea9a..a71b095a20 100644 --- a/accounts/pkg/config/http.go +++ b/accounts/pkg/config/http.go @@ -3,10 +3,10 @@ package config // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr" env:"ACCOUNTS_HTTP_ADDR" desc:"The address of the http service."` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` Root string `ocisConfig:"root" env:"ACCOUNTS_HTTP_ROOT" desc:"The root path of the http service."` CacheTTL int `ocisConfig:"cache_ttl" env:"ACCOUNTS_CACHE_TTL" desc:"The cache time for the static assets."` - CORS CORS + CORS CORS `ocisConfig:"cors"` } // CORS defines the available cors configuration. diff --git a/accounts/pkg/config/parser/parse.go b/accounts/pkg/config/parser/parse.go index fb801aed28..f689ee528c 100644 --- a/accounts/pkg/config/parser/parse.go +++ b/accounts/pkg/config/parser/parse.go @@ -2,11 +2,11 @@ package parser import ( "errors" - "strings" - - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/accounts/pkg/config" + defaults "github.com/owncloud/ocis/accounts/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,11 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) + defaults.Sanitize(cfg) return nil } diff --git a/accounts/pkg/config/service.go b/accounts/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/accounts/pkg/config/service.go +++ b/accounts/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/accounts/pkg/service/v0/accounts_permission_test.go b/accounts/pkg/service/v0/accounts_permission_test.go index 8c8dbd0786..e349ab6da9 100644 --- a/accounts/pkg/service/v0/accounts_permission_test.go +++ b/accounts/pkg/service/v0/accounts_permission_test.go @@ -13,7 +13,7 @@ import ( accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0" "github.com/golang/protobuf/ptypes/empty" - "github.com/owncloud/ocis/accounts/pkg/config" + config "github.com/owncloud/ocis/accounts/pkg/config/defaults" olog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/roles" diff --git a/audit/pkg/config/config.go b/audit/pkg/config/config.go index 2041e52bcc..33c98abf0f 100644 --- a/audit/pkg/config/config.go +++ b/audit/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` @@ -18,7 +18,7 @@ type Config struct { Events Events `ocisConfig:"events"` Auditlog Auditlog `ocisConfig:"auditlog"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Events combines the configuration options for the event bus. diff --git a/audit/pkg/config/service.go b/audit/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/audit/pkg/config/service.go +++ b/audit/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/docs/extensions/_includes/.gitignore b/docs/extensions/_includes/.gitignore index a463a88c51..3b7434f105 100644 --- a/docs/extensions/_includes/.gitignore +++ b/docs/extensions/_includes/.gitignore @@ -1 +1,2 @@ *_configvars.md +*-example.yaml \ No newline at end of file diff --git a/docs/extensions/accounts/configuration.md b/docs/extensions/accounts/configuration.md index 584b5b1830..8fffa2559a 100644 --- a/docs/extensions/accounts/configuration.md +++ b/docs/extensions/accounts/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/accounts-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/accounts_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/glauth/configuration.md b/docs/extensions/glauth/configuration.md index 7132fe0e50..e45a0c0aa9 100644 --- a/docs/extensions/glauth/configuration.md +++ b/docs/extensions/glauth/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/glauth-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/glauth_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/graph-explorer/configuration.md b/docs/extensions/graph-explorer/configuration.md index c27fe24673..a88cabd2d6 100644 --- a/docs/extensions/graph-explorer/configuration.md +++ b/docs/extensions/graph-explorer/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/graph-explorer-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/graph-explorer_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/graph/configuration.md b/docs/extensions/graph/configuration.md index 786dfb1339..dbd212255c 100644 --- a/docs/extensions/graph/configuration.md +++ b/docs/extensions/graph/configuration.md @@ -7,6 +7,8 @@ geekdocEditPath: edit/master/docs/extensions/graph geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config +{{< include file="extensions/_includes/graph-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/graph_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/idm/configuration.md b/docs/extensions/idm/configuration.md index 14200bcde0..1595260c78 100644 --- a/docs/extensions/idm/configuration.md +++ b/docs/extensions/idm/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/idm-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/idm_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/idp/configuration.md b/docs/extensions/idp/configuration.md index bc6011eac8..8aa88d203b 100644 --- a/docs/extensions/idp/configuration.md +++ b/docs/extensions/idp/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/idp-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/idp_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/nats/configuration.md b/docs/extensions/nats/configuration.md index 20ba82f34b..4d414c90de 100644 --- a/docs/extensions/nats/configuration.md +++ b/docs/extensions/nats/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/nats-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/nats_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/notifications/configuration.md b/docs/extensions/notifications/configuration.md index 7da0ba47b6..7e260efbd5 100644 --- a/docs/extensions/notifications/configuration.md +++ b/docs/extensions/notifications/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/notifications-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/notifications_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/ocs/configuration.md b/docs/extensions/ocs/configuration.md index 502fead64e..af9bd28c45 100644 --- a/docs/extensions/ocs/configuration.md +++ b/docs/extensions/ocs/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/ocs-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/ocs_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/proxy/configuration.md b/docs/extensions/proxy/configuration.md index 785922489a..e127a10155 100644 --- a/docs/extensions/proxy/configuration.md +++ b/docs/extensions/proxy/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/proxy-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/proxy_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/settings/configuration.md b/docs/extensions/settings/configuration.md index b20e913a7f..ac61a75705 100644 --- a/docs/extensions/settings/configuration.md +++ b/docs/extensions/settings/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/settings-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/settings_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/store/configuration.md b/docs/extensions/store/configuration.md index a974e254af..d556218cf1 100644 --- a/docs/extensions/store/configuration.md +++ b/docs/extensions/store/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/store-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/store_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/thumbnails/configuration.md b/docs/extensions/thumbnails/configuration.md index 7b6e85bde5..1f10b13667 100644 --- a/docs/extensions/thumbnails/configuration.md +++ b/docs/extensions/thumbnails/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/thumbnails-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/thumbnails_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/web/configuration.md b/docs/extensions/web/configuration.md index d55237fd90..ee3e60d7d8 100644 --- a/docs/extensions/web/configuration.md +++ b/docs/extensions/web/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/web-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/web_configvars.md" >}} \ No newline at end of file diff --git a/docs/extensions/webdav/configuration.md b/docs/extensions/webdav/configuration.md index 7ae4a04860..53c2820012 100644 --- a/docs/extensions/webdav/configuration.md +++ b/docs/extensions/webdav/configuration.md @@ -8,5 +8,8 @@ geekdocFilePath: configuration.md geekdocCollapseSection: true --- +## Example YAML Config + +{{< include file="extensions/_includes/webdav-config-example.yaml" language="yaml" >}} {{< include file="extensions/_includes/webdav_configvars.md" >}} \ No newline at end of file diff --git a/docs/helpers/configenvextractor.go b/docs/helpers/configenvextractor.go index bc504fc32e..1d5b9f6f81 100644 --- a/docs/helpers/configenvextractor.go +++ b/docs/helpers/configenvextractor.go @@ -6,14 +6,20 @@ import ( "log" "os" "os/exec" + "path" "path/filepath" "strings" "text/template" ) +var targets = map[string]string{ + "example-config-generator.go.tmpl": "output/exampleconfig/example-config-generator.go", + "extractor.go.tmpl": "output/env/runner.go", +} + func main() { fmt.Println("Getting relevant packages") - paths, err := filepath.Glob("../../*/pkg/config/defaultconfig.go") + paths, err := filepath.Glob("../../*/pkg/config/defaults/defaultconfig.go") if err != nil { log.Fatal(err) } @@ -24,27 +30,36 @@ func main() { for i := range paths { paths[i] = replacer.Replace(paths[i]) } - content, err := ioutil.ReadFile("extractor.go.tmpl") + + for template, output := range targets { + GenerateIntermediateCode(template, output, paths) + RunIntermediateCode(output) + } + fmt.Println("Cleaning up") + os.RemoveAll("output") +} + +func GenerateIntermediateCode(templatePath string, intermediateCodePath string, paths []string) { + content, err := ioutil.ReadFile(templatePath) if err != nil { log.Fatal(err) } - fmt.Println("Generating intermediate go code") + fmt.Println("Generating intermediate go code for " + intermediateCodePath + " using template " + templatePath) tpl := template.Must(template.New("").Parse(string(content))) - os.Mkdir("output", 0700) - runner, err := os.Create("output/runner.go") + os.MkdirAll(path.Dir(intermediateCodePath), 0700) + runner, err := os.Create(intermediateCodePath) if err != nil { log.Fatal(err) } tpl.Execute(runner, paths) - fmt.Println("Running intermediate go code") - os.Chdir("output") +} + +func RunIntermediateCode(intermediateCodePath string) { + fmt.Println("Running intermediate go code for " + intermediateCodePath) os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis") - out, err := exec.Command("go", "run", "runner.go").Output() + out, err := exec.Command("go", "run", intermediateCodePath).Output() if err != nil { log.Fatal(err) } fmt.Println(string(out)) - fmt.Println("Cleaning up") - os.Chdir("../") - os.RemoveAll("output") } diff --git a/docs/helpers/example-config-generator.go.tmpl b/docs/helpers/example-config-generator.go.tmpl new file mode 100644 index 0000000000..705a5e875a --- /dev/null +++ b/docs/helpers/example-config-generator.go.tmpl @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "log" + "os" + "path/filepath" + "strings" + + "gopkg.in/yaml.v2" + {{- range $key, $value := .}} + pkg{{$key}} "{{$value}}" + {{- end}} +) + +func main() { + replacer := strings.NewReplacer( + "github.com/owncloud/ocis/", "", + "/pkg/config/defaults", "", + ) + cfg := map[string]string{ + {{- range $key, $value := .}} + replacer.Replace("{{$value}}"): func() string { + fmt.Println("Generating example YAML config for {{ $value -}}") + c := pkg{{$key}}.DefaultConfig() + pkg{{$key}}.EnsureDefaults(c) + pkg{{$key}}.Sanitize(c) + yml, err := yaml.Marshal(c) + if err != nil { + log.Fatalf("Marshalling yaml for pkg0 failed: %s\n", err) + } + return "# Autogenerated\n" + string(yml) + }(), + {{- end}} + } + for pkg, yml := range cfg { + targetFolders := []string{ + // TODO: comment in when it is clear how to commit this to the structure of the master|main branch + // filepath.Join("../../", pkg, "/config"), + "../../docs/extensions/_includes/", + } + for _, targetFolder := range targetFolders { + os.MkdirAll(targetFolder, 0700) + targetYamlFile, err := os.Create(filepath.Join(targetFolder, replacer.Replace(pkg) + "-config-example.yaml")) + if err != nil { + log.Fatalf("Failed to create target file for : %s", err) + } + defer targetYamlFile.Close() + targetYamlFile.WriteString(yml) + } + } +} + diff --git a/docs/helpers/extractor.go.tmpl b/docs/helpers/extractor.go.tmpl index 3503ea2274..76ec507b3a 100644 --- a/docs/helpers/extractor.go.tmpl +++ b/docs/helpers/extractor.go.tmpl @@ -23,13 +23,13 @@ type ConfigField struct { func main() { fmt.Println("Generating documentation for environment variables:") -content, err := ioutil.ReadFile("../../../docs/templates/CONFIGURATION.tmpl") +content, err := ioutil.ReadFile("../../docs/templates/CONFIGURATION.tmpl") if err != nil { log.Fatal(err) } replacer := strings.NewReplacer( "github.com/owncloud/ocis/", "", - "/pkg/config", "", + "/pkg/config/defaults", "", ) var fields []ConfigField var targetFile *os.File @@ -41,7 +41,7 @@ m := map[string]interface{}{ {{- end }} } - targetFolder := "../../../docs/extensions/_includes/" + targetFolder := "../../docs/extensions/_includes/" for pkg, conf := range m { fields = GetAnnotatedVariables(conf) if len(fields) > 0 { diff --git a/glauth/cmd/glauth/main.go b/glauth/cmd/glauth/main.go index 6a2a83249d..4ecc5b53d9 100644 --- a/glauth/cmd/glauth/main.go +++ b/glauth/cmd/glauth/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/glauth/pkg/command" - "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 7de14cf687..2628e18ae6 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -24,7 +24,7 @@ type Config struct { RoleBundleUUID string `ocisConfig:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Backend defined the available backend configuration. diff --git a/glauth/pkg/config/defaultconfig.go b/glauth/pkg/config/defaultconfig.go deleted file mode 100644 index 503321d8ee..0000000000 --- a/glauth/pkg/config/defaultconfig.go +++ /dev/null @@ -1,51 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9129", - }, - Service: Service{ - Name: "glauth", - }, - Ldap: Ldap{ - Enabled: true, - Addr: "127.0.0.1:9125", - Namespace: "com.owncloud.ldap", - }, - Ldaps: Ldaps{ - Enabled: true, - Addr: "127.0.0.1:9126", - Namespace: "com.owncloud.ldaps", - Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), - Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), - }, - Backend: Backend{ - Datastore: "accounts", - BaseDN: "dc=ocis,dc=test", - Insecure: false, - NameFormat: "cn", - GroupFormat: "ou", - Servers: nil, - SSHKeyAttr: "sshPublicKey", - UseGraphAPI: true, - }, - Fallback: FallbackBackend{ - Datastore: "", - BaseDN: "dc=ocis,dc=test", - Insecure: false, - NameFormat: "cn", - GroupFormat: "ou", - Servers: nil, - SSHKeyAttr: "sshPublicKey", - UseGraphAPI: true, - }, - RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin - } -} diff --git a/glauth/pkg/config/defaults/defaultconfig.go b/glauth/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..12774c4888 --- /dev/null +++ b/glauth/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,90 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9129", + }, + Service: config.Service{ + Name: "glauth", + }, + Ldap: config.Ldap{ + Enabled: true, + Addr: "127.0.0.1:9125", + Namespace: "com.owncloud.ldap", + }, + Ldaps: config.Ldaps{ + Enabled: true, + Addr: "127.0.0.1:9126", + Namespace: "com.owncloud.ldaps", + Cert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Key: path.Join(defaults.BaseDataPath(), "ldap", "ldap.key"), + }, + Backend: config.Backend{ + Datastore: "accounts", + BaseDN: "dc=ocis,dc=test", + Insecure: false, + NameFormat: "cn", + GroupFormat: "ou", + Servers: nil, + SSHKeyAttr: "sshPublicKey", + UseGraphAPI: true, + }, + Fallback: config.FallbackBackend{ + Datastore: "", + BaseDN: "dc=ocis,dc=test", + Insecure: false, + NameFormat: "cn", + GroupFormat: "ou", + Servers: nil, + SSHKeyAttr: "sshPublicKey", + UseGraphAPI: true, + }, + RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to santizie here atm +} diff --git a/glauth/pkg/config/ldap.go b/glauth/pkg/config/ldap.go index b0780084a6..0c4602cf7e 100644 --- a/glauth/pkg/config/ldap.go +++ b/glauth/pkg/config/ldap.go @@ -4,5 +4,5 @@ package config type Ldap struct { Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAP_ENABLED"` Addr string `ocisConfig:"addr" env:"GLAUTH_LDAP_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } diff --git a/glauth/pkg/config/ldaps.go b/glauth/pkg/config/ldaps.go index 2c09f2530b..927b493d1f 100644 --- a/glauth/pkg/config/ldaps.go +++ b/glauth/pkg/config/ldaps.go @@ -4,7 +4,7 @@ package config type Ldaps struct { Enabled bool `ocisConfig:"enabled" env:"GLAUTH_LDAPS_ENABLED"` Addr string `ocisConfig:"addr" env:"GLAUTH_LDAPS_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` Cert string `ocisConfig:"cert" env:"GLAUTH_LDAPS_CERT"` Key string `ocisConfig:"key" env:"GLAUTH_LDAPS_KEY"` } diff --git a/glauth/pkg/config/parser/parse.go b/glauth/pkg/config/parser/parse.go index de91a18232..1d9326a727 100644 --- a/glauth/pkg/config/parser/parse.go +++ b/glauth/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/glauth/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,29 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -48,6 +27,6 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config - + defaults.Sanitize(cfg) return nil } diff --git a/glauth/pkg/config/service.go b/glauth/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/glauth/pkg/config/service.go +++ b/glauth/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/graph-explorer/cmd/graph-explorer/main.go b/graph-explorer/cmd/graph-explorer/main.go index a8357cb1f2..aca5c050f6 100644 --- a/graph-explorer/cmd/graph-explorer/main.go +++ b/graph-explorer/cmd/graph-explorer/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/graph-explorer/pkg/command" - "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 2d70fd664a..82f90fc246 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -20,7 +20,7 @@ type Config struct { GraphExplorer GraphExplorer `ocisConfig:"graph_explorer"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // GraphExplorer defines the available graph-explorer configuration. diff --git a/graph-explorer/pkg/config/defaultconfig.go b/graph-explorer/pkg/config/defaultconfig.go deleted file mode 100644 index 454cb239a6..0000000000 --- a/graph-explorer/pkg/config/defaultconfig.go +++ /dev/null @@ -1,26 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9136", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9135", - Root: "/graph-explorer", - Namespace: "com.owncloud.web", - }, - Service: Service{ - Name: "graph-explorer", - }, - GraphExplorer: GraphExplorer{ - ClientID: "ocis-explorer.js", - Issuer: "https://localhost:9200", - GraphURLBase: "https://localhost:9200", - GraphURLPath: "/graph", - }, - } -} diff --git a/graph-explorer/pkg/config/defaults/defaultconfig.go b/graph-explorer/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..860d0fdf39 --- /dev/null +++ b/graph-explorer/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,73 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/graph-explorer/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9136", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9135", + Root: "/graph-explorer", + Namespace: "com.owncloud.web", + }, + Service: config.Service{ + Name: "graph-explorer", + }, + GraphExplorer: config.GraphExplorer{ + ClientID: "ocis-explorer.js", + Issuer: "https://localhost:9200", + GraphURLBase: "https://localhost:9200", + GraphURLPath: "/graph", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root == "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/graph-explorer") + } +} diff --git a/graph-explorer/pkg/config/http.go b/graph-explorer/pkg/config/http.go index 8990a455e2..040f808db7 100644 --- a/graph-explorer/pkg/config/http.go +++ b/graph-explorer/pkg/config/http.go @@ -4,7 +4,7 @@ package config type HTTP struct { Addr string `ocisConfig:"addr" env:"GRAPH_EXPLORER_HTTP_ADDR"` Root string `ocisConfig:"root" env:"GRAPH_EXPLORER_HTTP_ROOT"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } // CORS defines the available cors configuration. diff --git a/graph-explorer/pkg/config/parser/parse.go b/graph-explorer/pkg/config/parser/parse.go index c9127c292f..b9801ba948 100644 --- a/graph-explorer/pkg/config/parser/parse.go +++ b/graph-explorer/pkg/config/parser/parse.go @@ -2,9 +2,9 @@ package parser import ( "errors" - "strings" "github.com/owncloud/ocis/graph-explorer/pkg/config" + "github.com/owncloud/ocis/graph-explorer/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -17,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -49,9 +28,7 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/graph-explorer/pkg/config/service.go b/graph-explorer/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/graph-explorer/pkg/config/service.go +++ b/graph-explorer/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/graph/cmd/graph/main.go b/graph/cmd/graph/main.go index ec85f23718..ddce12e82a 100644 --- a/graph/cmd/graph/main.go +++ b/graph/cmd/graph/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/graph/pkg/command" - "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 88e4c11669..6a46eb0cb9 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -24,7 +24,7 @@ type Config struct { Spaces Spaces `ocisConfig:"spaces"` Identity Identity `ocisConfig:"identity"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } type Spaces struct { diff --git a/graph/pkg/config/defaultconfig.go b/graph/pkg/config/defaultconfig.go deleted file mode 100644 index 134f3419b6..0000000000 --- a/graph/pkg/config/defaultconfig.go +++ /dev/null @@ -1,55 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9124", - Token: "", - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9120", - Namespace: "com.owncloud.graph", - Root: "/graph", - }, - Service: Service{ - Name: "graph", - }, - Reva: Reva{ - Address: "127.0.0.1:9142", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - Spaces: Spaces{ - WebDavBase: "https://localhost:9200", - WebDavPath: "/dav/spaces/", - DefaultQuota: "1000000000", - Insecure: false, - }, - Identity: Identity{ - Backend: "cs3", - LDAP: LDAP{ - URI: "ldap://localhost:9125", - Insecure: false, - BindDN: "", - BindPassword: "", - UseServerUUID: false, - WriteEnabled: false, - UserBaseDN: "ou=users,dc=ocis,dc=test", - UserSearchScope: "sub", - UserFilter: "(objectClass=inetOrgPerson)", - UserEmailAttribute: "mail", - UserDisplayNameAttribute: "displayName", - UserNameAttribute: "uid", - // FIXME: switch this to some more widely available attribute by default - // ideally this needs to be constant for the lifetime of a users - UserIDAttribute: "owncloudUUID", - GroupBaseDN: "ou=groups,dc=ocis,dc=test", - GroupSearchScope: "sub", - GroupFilter: "(objectclass=groupOfNames)", - GroupNameAttribute: "cn", - GroupIDAttribute: "owncloudUUID", - }, - }, - } -} diff --git a/graph/pkg/config/defaults/defaultconfig.go b/graph/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..9c2eba50cb --- /dev/null +++ b/graph/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,93 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/graph/pkg/config" +) + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9124", + Token: "", + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9120", + Namespace: "com.owncloud.graph", + Root: "/graph", + }, + Service: config.Service{ + Name: "graph", + }, + Reva: config.Reva{ + Address: "127.0.0.1:9142", + }, + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Spaces: config.Spaces{ + WebDavBase: "https://localhost:9200", + WebDavPath: "/dav/spaces/", + DefaultQuota: "1000000000", + Insecure: false, + }, + Identity: config.Identity{ + Backend: "cs3", + LDAP: config.LDAP{ + URI: "ldap://localhost:9125", + Insecure: false, + BindDN: "", + BindPassword: "", + UseServerUUID: false, + WriteEnabled: false, + UserBaseDN: "ou=users,dc=ocis,dc=test", + UserSearchScope: "sub", + UserFilter: "(objectClass=inetOrgPerson)", + UserEmailAttribute: "mail", + UserDisplayNameAttribute: "displayName", + UserNameAttribute: "uid", + // FIXME: switch this to some more widely available attribute by default + // ideally this needs to be constant for the lifetime of a users + UserIDAttribute: "owncloudUUID", + GroupBaseDN: "ou=groups,dc=ocis,dc=test", + GroupSearchScope: "sub", + GroupFilter: "(objectclass=groupOfNames)", + GroupNameAttribute: "cn", + GroupIDAttribute: "owncloudUUID", + }, + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/graph/pkg/config/http.go b/graph/pkg/config/http.go index 64351105b0..3ce0de1b77 100644 --- a/graph/pkg/config/http.go +++ b/graph/pkg/config/http.go @@ -3,6 +3,6 @@ package config // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr" env:"GRAPH_HTTP_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` Root string `ocisConfig:"root" env:"GRAPH_HTTP_ROOT"` } diff --git a/graph/pkg/config/parser/parse.go b/graph/pkg/config/parser/parse.go index 367089f852..a1892f0950 100644 --- a/graph/pkg/config/parser/parse.go +++ b/graph/pkg/config/parser/parse.go @@ -2,9 +2,9 @@ package parser import ( "errors" - "strings" "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -17,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/graph/pkg/config/service.go b/graph/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/graph/pkg/config/service.go +++ b/graph/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/graph/pkg/service/v0/graph_test.go b/graph/pkg/service/v0/graph_test.go index 3043bacb89..e475af9e3f 100644 --- a/graph/pkg/service/v0/graph_test.go +++ b/graph/pkg/service/v0/graph_test.go @@ -15,7 +15,7 @@ import ( . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/graph/mocks" - "github.com/owncloud/ocis/graph/pkg/config" + "github.com/owncloud/ocis/graph/pkg/config/defaults" service "github.com/owncloud/ocis/graph/pkg/service/v0" "github.com/owncloud/ocis/graph/pkg/service/v0/errorcode" "github.com/stretchr/testify/mock" @@ -34,7 +34,7 @@ var _ = Describe("Graph", func() { gatewayClient = &mocks.GatewayClient{} httpClient = &mocks.HTTPClient{} svc = service.NewService( - service.Config(config.DefaultConfig()), + service.Config(defaults.DefaultConfig()), service.WithGatewayClient(gatewayClient), service.WithHTTPClient(httpClient), ) diff --git a/idm/cmd/idm/main.go b/idm/cmd/idm/main.go index 680d58dafb..7463a99c78 100644 --- a/idm/cmd/idm/main.go +++ b/idm/cmd/idm/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/idm/pkg/command" - "github.com/owncloud/ocis/idm/pkg/config" + "github.com/owncloud/ocis/idm/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/idm/pkg/config/config.go b/idm/pkg/config/config.go index 44a97887c8..4917a55429 100644 --- a/idm/pkg/config/config.go +++ b/idm/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -21,7 +21,7 @@ type Config struct { ServiceUserPasswords ServiceUserPasswords `ocisConfig:"service_user_passwords"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } type Settings struct { diff --git a/idm/pkg/config/defaults/defaultconfig.go b/idm/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..b1042376aa --- /dev/null +++ b/idm/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,60 @@ +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"), + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here +} diff --git a/idm/pkg/config/parser/parse.go b/idm/pkg/config/parser/parse.go index 22b3429cc1..9847623cfc 100644 --- a/idm/pkg/config/parser/parse.go +++ b/idm/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/idm/pkg/config" + "github.com/owncloud/ocis/idm/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,29 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -47,5 +26,7 @@ func ParseConfig(cfg *config.Config) error { } } + defaults.Sanitize(cfg) + return nil } diff --git a/idm/pkg/config/service.go b/idm/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/idm/pkg/config/service.go +++ b/idm/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/idp/cmd/idp/main.go b/idp/cmd/idp/main.go index c60ac2f401..f2faebb068 100644 --- a/idp/cmd/idp/main.go +++ b/idp/cmd/idp/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/idp/pkg/command" - "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 4e5e4b0d13..a8ca6e384b 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -22,7 +22,7 @@ type Config struct { IDP Settings `ocisConfig:"idp"` Ldap Ldap `ocisConfig:"ldap"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Ldap defines the available LDAP configuration. diff --git a/idp/pkg/config/defaultconfig.go b/idp/pkg/config/defaults/defaultconfig.go similarity index 62% rename from idp/pkg/config/defaultconfig.go rename to idp/pkg/config/defaults/defaultconfig.go index 823291596b..e965278665 100644 --- a/idp/pkg/config/defaultconfig.go +++ b/idp/pkg/config/defaults/defaultconfig.go @@ -1,17 +1,28 @@ -package config +package defaults import ( "path" + "strings" + "github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ Addr: "127.0.0.1:9134", }, - HTTP: HTTP{ + HTTP: config.HTTP{ Addr: "127.0.0.1:9130", Root: "/", Namespace: "com.owncloud.web", @@ -19,11 +30,11 @@ func DefaultConfig() *Config { TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"), TLS: false, }, - Service: Service{ + Service: config.Service{ Name: "idp", }, - Asset: Asset{}, - IDP: Settings{ + Asset: config.Asset{}, + IDP: config.Settings{ Iss: "https://localhost:9200", IdentityManager: "ldap", URIBasePath: "", @@ -56,7 +67,7 @@ func DefaultConfig() *Config { RefreshTokenDurationSeconds: 60 * 60 * 24 * 365 * 3, // 1 year DyamicClientSecretDurationSeconds: 0, }, - Ldap: Ldap{ + Ldap: config.Ldap{ URI: "ldap://localhost:9125", BindDN: "cn=idp,ou=sysusers,dc=ocis,dc=test", BindPassword: "idp", @@ -71,3 +82,35 @@ func DefaultConfig() *Config { }, } } + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/idp/pkg/config/http.go b/idp/pkg/config/http.go index 4d528e027c..b76b48f56e 100644 --- a/idp/pkg/config/http.go +++ b/idp/pkg/config/http.go @@ -4,7 +4,7 @@ package config type HTTP struct { Addr string `ocisConfig:"addr" env:"IDP_HTTP_ADDR"` Root string `ocisConfig:"root" env:"IDP_HTTP_ROOT"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` TLSCert string `ocisConfig:"tls_cert" env:"IDP_TRANSPORT_TLS_CERT"` TLSKey string `ocisConfig:"tls_key" env:"IDP_TRANSPORT_TLS_KEY"` TLS bool `ocisConfig:"tls" env:"IDP_TLS"` diff --git a/idp/pkg/config/log.go b/idp/pkg/config/log.go index 39ba2d9e51..4183ee357a 100644 --- a/idp/pkg/config/log.go +++ b/idp/pkg/config/log.go @@ -2,8 +2,8 @@ package config // Log defines the available log configuration. type Log struct { - Level string `mapstructure:"level" env:"OCIS_LOG_LEVEL;IDP_LOG_LEVEL"` - Pretty bool `mapstructure:"pretty" env:"OCIS_LOG_PRETTY;IDP_LOG_PRETTY"` - Color bool `mapstructure:"color" env:"OCIS_LOG_COLOR;IDP_LOG_COLOR"` - File string `mapstructure:"file" env:"OCIS_LOG_FILE;IDP_LOG_FILE"` + Level string `ocisConfig:"level" env:"OCIS_LOG_LEVEL;IDP_LOG_LEVEL"` + Pretty bool `ocisConfig:"pretty" env:"OCIS_LOG_PRETTY;IDP_LOG_PRETTY"` + Color bool `ocisConfig:"color" env:"OCIS_LOG_COLOR;IDP_LOG_COLOR"` + File string `ocisConfig:"file" env:"OCIS_LOG_FILE;IDP_LOG_FILE"` } diff --git a/idp/pkg/config/parser/parse.go b/idp/pkg/config/parser/parse.go index d5561337e5..07732d41ec 100644 --- a/idp/pkg/config/parser/parse.go +++ b/idp/pkg/config/parser/parse.go @@ -2,9 +2,9 @@ package parser import ( "errors" - "strings" "github.com/owncloud/ocis/idp/pkg/config" + "github.com/owncloud/ocis/idp/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -17,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/idp/pkg/config/service.go b/idp/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/idp/pkg/config/service.go +++ b/idp/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/nats/cmd/nats/main.go b/nats/cmd/nats/main.go index 2c6cdac1e7..a117af3cb0 100644 --- a/nats/cmd/nats/main.go +++ b/nats/cmd/nats/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/nats/pkg/command" - "github.com/owncloud/ocis/nats/pkg/config" + "github.com/owncloud/ocis/nats/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/nats/pkg/config/config.go b/nats/pkg/config/config.go index af3257f34b..bc8d670fc3 100644 --- a/nats/pkg/config/config.go +++ b/nats/pkg/config/config.go @@ -8,16 +8,16 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` Nats Nats `ociConfig:"nats"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Nats is the nats config diff --git a/nats/pkg/config/defaultconfig.go b/nats/pkg/config/defaultconfig.go deleted file mode 100644 index de1238e761..0000000000 --- a/nats/pkg/config/defaultconfig.go +++ /dev/null @@ -1,16 +0,0 @@ -package config - -// NOTE: Most of this configuration is not needed to keep it as simple as possible -// TODO: Clean up unneeded configuration - -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "nats", - }, - Nats: Nats{ - Host: "127.0.0.1", - Port: 9233, - }, - } -} diff --git a/nats/pkg/config/defaults/defaultconfig.go b/nats/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..03f5167b3e --- /dev/null +++ b/nats/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,45 @@ +package defaults + +import "github.com/owncloud/ocis/nats/pkg/config" + +// NOTE: Most of this configuration is not needed to keep it as simple as possible +// TODO: Clean up unneeded configuration + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "nats", + }, + Nats: config.Nats{ + Host: "127.0.0.1", + Port: 9233, + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/nats/pkg/config/parser/parse.go b/nats/pkg/config/parser/parse.go index 04e4e2b0a0..fb198fac2c 100644 --- a/nats/pkg/config/parser/parse.go +++ b/nats/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/nats/pkg/config" + "github.com/owncloud/ocis/nats/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,17 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -36,5 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } + defaults.Sanitize(cfg) + return nil } diff --git a/nats/pkg/config/service.go b/nats/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/nats/pkg/config/service.go +++ b/nats/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/notifications/cmd/notifications/main.go b/notifications/cmd/notifications/main.go index 6b43234330..29d60a18ba 100644 --- a/notifications/cmd/notifications/main.go +++ b/notifications/cmd/notifications/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/notifications/pkg/command" - "github.com/owncloud/ocis/notifications/pkg/config" + "github.com/owncloud/ocis/notifications/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/notifications/pkg/config/config.go b/notifications/pkg/config/config.go index 8ac7da5d8f..bda3539d69 100644 --- a/notifications/pkg/config/config.go +++ b/notifications/pkg/config/config.go @@ -8,16 +8,16 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Log *Log `ocisConfig:"log"` Debug Debug `ocisConfig:"debug"` Notifications Notifications `ocisConfig:"notifications"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Notifications definces the config options for the notifications service. diff --git a/notifications/pkg/config/defaultconfig.go b/notifications/pkg/config/defaultconfig.go deleted file mode 100644 index d5fb6e3498..0000000000 --- a/notifications/pkg/config/defaultconfig.go +++ /dev/null @@ -1,27 +0,0 @@ -package config - -// NOTE: Most of this configuration is not needed to keep it as simple as possible -// TODO: Clean up unneeded configuration - -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "notifications", - }, - Notifications: Notifications{ - SMTP: SMTP{ - Host: "127.0.0.1", - Port: "1025", - Sender: "god@example.com", - Password: "godisdead", - }, - Events: Events{ - Endpoint: "127.0.0.1:9233", - Cluster: "test-cluster", - ConsumerGroup: "notifications", - }, - RevaGateway: "127.0.0.1:9142", - MachineAuthSecret: "change-me-please", - }, - } -} diff --git a/notifications/pkg/config/defaults/defaultconfig.go b/notifications/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..22647168c5 --- /dev/null +++ b/notifications/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,56 @@ +package defaults + +import "github.com/owncloud/ocis/notifications/pkg/config" + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +// NOTE: Most of this configuration is not needed to keep it as simple as possible +// TODO: Clean up unneeded configuration + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "notifications", + }, + Notifications: config.Notifications{ + SMTP: config.SMTP{ + Host: "127.0.0.1", + Port: "1025", + Sender: "god@example.com", + Password: "godisdead", + }, + Events: config.Events{ + Endpoint: "127.0.0.1:9233", + Cluster: "test-cluster", + ConsumerGroup: "notifications", + }, + RevaGateway: "127.0.0.1:9142", + MachineAuthSecret: "change-me-please", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/notifications/pkg/config/parser/parse.go b/notifications/pkg/config/parser/parse.go index 5bc4e6e571..36231a708b 100644 --- a/notifications/pkg/config/parser/parse.go +++ b/notifications/pkg/config/parser/parse.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/owncloud/ocis/notifications/pkg/config" + "github.com/owncloud/ocis/notifications/pkg/config/defaults" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -16,17 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -36,5 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } + defaults.Sanitize(cfg) + return nil } diff --git a/notifications/pkg/config/service.go b/notifications/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/notifications/pkg/config/service.go +++ b/notifications/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go index 64e4df1829..9767f2d933 100644 --- a/ocis-pkg/config/defaultconfig.go +++ b/ocis-pkg/config/defaultconfig.go @@ -1,23 +1,23 @@ package config import ( - accounts "github.com/owncloud/ocis/accounts/pkg/config" + 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" - idp "github.com/owncloud/ocis/idp/pkg/config" - 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" + 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/defaults" + notifications "github.com/owncloud/ocis/notifications/pkg/config/defaults" + ocs "github.com/owncloud/ocis/ocs/pkg/config/defaults" + proxy "github.com/owncloud/ocis/proxy/pkg/config/defaults" + settings "github.com/owncloud/ocis/settings/pkg/config/defaults" + storage "github.com/owncloud/ocis/storage/pkg/config/defaults" + store "github.com/owncloud/ocis/store/pkg/config/defaults" + thumbnails "github.com/owncloud/ocis/thumbnails/pkg/config/defaults" + web "github.com/owncloud/ocis/web/pkg/config/defaults" + webdav "github.com/owncloud/ocis/webdav/pkg/config/defaults" ) func DefaultConfig() *Config { diff --git a/ocs/cmd/ocs/main.go b/ocs/cmd/ocs/main.go index ca3ea14b36..22f6a011ed 100644 --- a/ocs/cmd/ocs/main.go +++ b/ocs/cmd/ocs/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/ocs/pkg/command" - "github.com/owncloud/ocis/ocs/pkg/config" + "github.com/owncloud/ocis/ocs/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 2c9693adca..3659d08f3e 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -27,7 +27,7 @@ type Config struct { StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // IdentityManagement keeps track of the OIDC address. This is because Reva requisite of uniqueness for users diff --git a/ocs/pkg/config/defaultconfig.go b/ocs/pkg/config/defaultconfig.go deleted file mode 100644 index 0ed8378ba4..0000000000 --- a/ocs/pkg/config/defaultconfig.go +++ /dev/null @@ -1,37 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9114", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9110", - Root: "/ocs", - Namespace: "com.owncloud.web", - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - Service: Service{ - Name: "ocs", - }, - - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - AccountBackend: "accounts", - Reva: Reva{Address: "127.0.0.1:9142"}, - StorageUsersDriver: "ocis", - MachineAuthAPIKey: "change-me-please", - IdentityManagement: IdentityManagement{ - Address: "https://localhost:9200", - }, - } -} diff --git a/ocs/pkg/config/defaults/defaultconfig.go b/ocs/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..9c57e897f0 --- /dev/null +++ b/ocs/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,87 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/ocs/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9114", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9110", + Root: "/ocs", + Namespace: "com.owncloud.web", + CORS: config.CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Service: config.Service{ + Name: "ocs", + }, + + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + AccountBackend: "accounts", + Reva: config.Reva{ + Address: "127.0.0.1:9142", + }, + StorageUsersDriver: "ocis", + MachineAuthAPIKey: "change-me-please", + IdentityManagement: config.IdentityManagement{ + Address: "https://localhost:9200", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } + +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/ocs/pkg/config/http.go b/ocs/pkg/config/http.go index b965e78b3b..d951aed831 100644 --- a/ocs/pkg/config/http.go +++ b/ocs/pkg/config/http.go @@ -4,8 +4,8 @@ package config type HTTP struct { Addr string `ocisConfig:"addr" env:"OCS_HTTP_ADDR"` Root string `ocisConfig:"root" env:"OCS_HTTP_ROOT"` - Namespace string - CORS CORS `ocisConfig:"cors"` + Namespace string `ocisConfig:"-" yaml:"-"` + CORS CORS `ocisConfig:"cors"` } // CORS defines the available cors configuration. diff --git a/ocs/pkg/config/parser/parse.go b/ocs/pkg/config/parser/parse.go index 96f4205dfc..f5cbc34cbd 100644 --- a/ocs/pkg/config/parser/parse.go +++ b/ocs/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocs/pkg/config" + "github.com/owncloud/ocis/ocs/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/ocs/pkg/config/service.go b/ocs/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/ocs/pkg/config/service.go +++ b/ocs/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/proxy/cmd/proxy/main.go b/proxy/cmd/proxy/main.go index f67b685f34..144059b229 100644 --- a/proxy/cmd/proxy/main.go +++ b/proxy/cmd/proxy/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/proxy/pkg/command" - "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 277b7dff2d..6cda66b8f3 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -34,7 +34,7 @@ type Config struct { InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` AuthMiddleware AuthMiddleware `ocisConfig:"auth_middleware"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Policy enables us to use multiple directors. diff --git a/proxy/pkg/config/defaultconfig.go b/proxy/pkg/config/defaults/defaultconfig.go similarity index 71% rename from proxy/pkg/config/defaultconfig.go rename to proxy/pkg/config/defaults/defaultconfig.go index 12bcbe806d..eaa328b5a0 100644 --- a/proxy/pkg/config/defaultconfig.go +++ b/proxy/pkg/config/defaults/defaultconfig.go @@ -1,18 +1,20 @@ -package config +package defaults import ( "path" + "strings" "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/proxy/pkg/config" ) -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ Addr: "127.0.0.1:9205", Token: "", }, - HTTP: HTTP{ + HTTP: config.HTTP{ Addr: "0.0.0.0:9200", Root: "/", Namespace: "com.owncloud.web", @@ -20,26 +22,26 @@ func DefaultConfig() *Config { TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), TLS: true, }, - Service: Service{ + Service: config.Service{ Name: "proxy", }, - OIDC: OIDC{ + OIDC: config.OIDC{ Issuer: "https://localhost:9200", Insecure: true, //Insecure: true, - UserinfoCache: UserinfoCache{ + UserinfoCache: config.UserinfoCache{ Size: 1024, TTL: 10, }, }, - TokenManager: TokenManager{ + TokenManager: config.TokenManager{ JWTSecret: "Pive-Fumkiu4", }, PolicySelector: nil, - Reva: Reva{ + Reva: config.Reva{ Address: "127.0.0.1:9142", }, - PreSignedURL: PreSignedURL{ + PreSignedURL: config.PreSignedURL{ AllowedHTTPMethods: []string{"GET"}, Enabled: true, }, @@ -55,11 +57,11 @@ func DefaultConfig() *Config { } } -func DefaultPolicies() []Policy { - return []Policy{ +func DefaultPolicies() []config.Policy { + return []config.Policy{ { Name: "ocis", - Routes: []Route{ + Routes: []config.Route{ { Endpoint: "/", Backend: "http://localhost:9100", @@ -81,7 +83,7 @@ func DefaultPolicies() []Policy { Backend: "http://localhost:9140", }, { - Type: RegexRoute, + Type: config.RegexRoute, Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs Backend: "http://localhost:9110", }, @@ -90,7 +92,7 @@ func DefaultPolicies() []Policy { Backend: "http://localhost:9140", }, { - Type: QueryRoute, + Type: config.QueryRoute, Endpoint: "/remote.php/?preview=1", Backend: "http://localhost:9115", }, @@ -152,7 +154,7 @@ func DefaultPolicies() []Policy { }, { Name: "oc10", - Routes: []Route{ + Routes: []config.Route{ { Endpoint: "/", Backend: "http://localhost:9100", @@ -212,3 +214,40 @@ func DefaultPolicies() []Policy { }, } } + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } + +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.Policies == nil { + cfg.Policies = DefaultPolicies() + } + + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/proxy/pkg/config/http.go b/proxy/pkg/config/http.go index 8ab5530632..3253894149 100644 --- a/proxy/pkg/config/http.go +++ b/proxy/pkg/config/http.go @@ -4,7 +4,7 @@ package config type HTTP struct { Addr string `ocisConfig:"addr" env:"PROXY_HTTP_ADDR"` Root string `ocisConfig:"root" env:"PROXY_HTTP_ROOT"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` TLSCert string `ocisConfig:"tls_cert" env:"PROXY_TRANSPORT_TLS_CERT"` TLSKey string `ocisConfig:"tls_key" env:"PROXY_TRANSPORT_TLS_KEY"` TLS bool `ocisConfig:"tls" env:"PROXY_TLS"` diff --git a/proxy/pkg/config/parser/parse.go b/proxy/pkg/config/parser/parse.go index 55105cfcbc..ef6d2cec4d 100644 --- a/proxy/pkg/config/parser/parse.go +++ b/proxy/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,29 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -48,15 +26,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - - if cfg.Policies == nil { - cfg.Policies = config.DefaultPolicies() - } - - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/proxy/pkg/config/service.go b/proxy/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/proxy/pkg/config/service.go +++ b/proxy/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/proxy/pkg/proxy/proxy_test.go b/proxy/pkg/proxy/proxy_test.go index a0300e64d1..f64362c491 100644 --- a/proxy/pkg/proxy/proxy_test.go +++ b/proxy/pkg/proxy/proxy_test.go @@ -4,7 +4,7 @@ import ( "net/url" "testing" - "github.com/owncloud/ocis/proxy/pkg/config" + "github.com/owncloud/ocis/proxy/pkg/config/defaults" ) type matchertest struct { @@ -13,8 +13,8 @@ type matchertest struct { } func TestPrefixRouteMatcher(t *testing.T) { - cfg := config.DefaultConfig() - cfg.Policies = config.DefaultPolicies() + cfg := defaults.DefaultConfig() + cfg.Policies = defaults.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -33,8 +33,8 @@ func TestPrefixRouteMatcher(t *testing.T) { } func TestQueryRouteMatcher(t *testing.T) { - cfg := config.DefaultConfig() - cfg.Policies = config.DefaultPolicies() + cfg := defaults.DefaultConfig() + cfg.Policies = defaults.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -61,8 +61,8 @@ func TestQueryRouteMatcher(t *testing.T) { } func TestRegexRouteMatcher(t *testing.T) { - cfg := config.DefaultConfig() - cfg.Policies = config.DefaultPolicies() + cfg := defaults.DefaultConfig() + cfg.Policies = defaults.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ diff --git a/settings/cmd/settings/main.go b/settings/cmd/settings/main.go index cfee45c698..ce7ff878f4 100644 --- a/settings/cmd/settings/main.go +++ b/settings/cmd/settings/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/settings/pkg/command" - "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 8e9e5f1eff..ef0e3d31a9 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -23,7 +23,7 @@ type Config struct { Asset Asset `ocisConfig:"asset"` TokenManager TokenManager `ocisConfig:"token_manager"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Asset defines the available asset configuration. diff --git a/settings/pkg/config/defaultconfig.go b/settings/pkg/config/defaultconfig.go deleted file mode 100644 index 7f72e50a30..0000000000 --- a/settings/pkg/config/defaultconfig.go +++ /dev/null @@ -1,44 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Service: Service{ - Name: "settings", - }, - Debug: Debug{ - Addr: "127.0.0.1:9194", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9190", - Namespace: "com.owncloud.web", - Root: "/", - CacheTTL: 604800, // 7 days - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9191", - Namespace: "com.owncloud.api", - }, - DataPath: path.Join(defaults.BaseDataPath(), "settings"), - Asset: Asset{ - Path: "", - }, - TokenManager: TokenManager{ - JWTSecret: "Pive-Fumkiu4", - }, - } -} diff --git a/settings/pkg/config/defaults/defaultconfig.go b/settings/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..e86f5b6b2b --- /dev/null +++ b/settings/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,87 @@ +package defaults + +import ( + "path" + "strings" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/settings/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Service: config.Service{ + Name: "settings", + }, + Debug: config.Debug{ + Addr: "127.0.0.1:9194", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9190", + Namespace: "com.owncloud.web", + Root: "/", + CacheTTL: 604800, // 7 days + CORS: config.CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + GRPC: config.GRPC{ + Addr: "127.0.0.1:9191", + Namespace: "com.owncloud.api", + }, + DataPath: path.Join(defaults.BaseDataPath(), "settings"), + Asset: config.Asset{ + Path: "", + }, + TokenManager: config.TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } +} diff --git a/settings/pkg/config/grpc.go b/settings/pkg/config/grpc.go index 016b61fa91..fc399ca6bb 100644 --- a/settings/pkg/config/grpc.go +++ b/settings/pkg/config/grpc.go @@ -3,5 +3,5 @@ package config // GRPC defines the available grpc configuration. type GRPC struct { Addr string `ocisConfig:"addr" env:"SETTINGS_GRPC_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } diff --git a/settings/pkg/config/http.go b/settings/pkg/config/http.go index f2099febf9..fa23bd1fe2 100644 --- a/settings/pkg/config/http.go +++ b/settings/pkg/config/http.go @@ -3,7 +3,7 @@ package config // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr" env:"SETTINGS_HTTP_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` Root string `ocisConfig:"root" env:"SETTINGS_HTTP_ROOT"` CacheTTL int `ocisConfig:"cache_ttl" env:"SETTINGS_CACHE_TTL"` CORS CORS `ocisConfig:"cors"` diff --git a/settings/pkg/config/parser/parse.go b/settings/pkg/config/parser/parse.go index f1c7c94362..ec2926d146 100644 --- a/settings/pkg/config/parser/parse.go +++ b/settings/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/settings/pkg/config" + "github.com/owncloud/ocis/settings/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,29 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } - + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -48,10 +26,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/settings/pkg/config/service.go b/settings/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/settings/pkg/config/service.go +++ b/settings/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/storage/cmd/storage/main.go b/storage/cmd/storage/main.go index 78ccf99eca..4503dac725 100644 --- a/storage/cmd/storage/main.go +++ b/storage/cmd/storage/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/config" + "github.com/owncloud/ocis/storage/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/storage/pkg/config/defaultconfig.go b/storage/pkg/config/defaults/defaultconfig.go similarity index 81% rename from storage/pkg/config/defaultconfig.go rename to storage/pkg/config/defaults/defaultconfig.go index b66e55f1ac..142b05db7f 100644 --- a/storage/pkg/config/defaultconfig.go +++ b/storage/pkg/config/defaults/defaultconfig.go @@ -1,10 +1,11 @@ -package config +package defaults import ( "os" "path" "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/storage/pkg/config" ) const ( @@ -15,23 +16,32 @@ const ( defaultUserLayout = "{{.Id.OpaqueId}}" ) -func DefaultConfig() *Config { - return &Config{ +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ // log is inherited - Debug: Debug{ + Debug: config.Debug{ Addr: "127.0.0.1:9109", }, - Reva: Reva{ + Reva: config.Reva{ JWTSecret: "Pive-Fumkiu4", SkipUserGroupsInToken: false, TransferSecret: "replace-me-with-a-transfer-secret", TransferExpires: 24 * 60 * 60, - OIDC: OIDC{ + OIDC: config.OIDC{ Issuer: defaultPublicURL, Insecure: false, IDClaim: "preferred_username", }, - LDAP: LDAP{ + LDAP: config.LDAP{ Hostname: "localhost", Port: 9126, CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), @@ -49,7 +59,7 @@ func DefaultConfig() *Config { BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", BindPassword: "reva", IDP: defaultPublicURL, - UserSchema: LDAPUserSchema{ + UserSchema: config.LDAPUserSchema{ UID: "ownclouduuid", Mail: "mail", DisplayName: "displayname", @@ -57,7 +67,7 @@ func DefaultConfig() *Config { UIDNumber: "uidnumber", GIDNumber: "gidnumber", }, - GroupSchema: LDAPGroupSchema{ + GroupSchema: config.LDAPGroupSchema{ GID: "cn", Mail: "mail", DisplayName: "cn", @@ -65,10 +75,10 @@ func DefaultConfig() *Config { GIDNumber: "gidnumber", }, }, - UserGroupRest: UserGroupRest{ + UserGroupRest: config.UserGroupRest{ RedisAddress: "localhost:6379", }, - UserOwnCloudSQL: UserOwnCloudSQL{ + UserOwnCloudSQL: config.UserOwnCloudSQL{ DBUsername: "owncloud", DBPassword: "secret", DBHost: "mysql", @@ -80,18 +90,18 @@ func DefaultConfig() *Config { JoinOwnCloudUUID: false, EnableMedialSearch: false, }, - OCDav: OCDav{ + OCDav: config.OCDav{ WebdavNamespace: defaultStorageNamespace, DavFilesNamespace: defaultStorageNamespace, }, - Archiver: Archiver{ + Archiver: config.Archiver{ MaxNumFiles: 10000, MaxSize: 1073741824, ArchiverURL: "/archiver", }, - UserStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ + UserStorage: config.StorageConfig{ + EOS: config.DriverEOS{ + DriverCommon: config.DriverCommon{ Root: "/eos/dockertest/reva", ShareFolder: defaultShareFolder, UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", @@ -105,14 +115,14 @@ func DefaultConfig() *Config { CacheDirectory: os.TempDir(), GatewaySVC: defaultGatewayAddr, }, - Local: DriverCommon{ + Local: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), ShareFolder: defaultShareFolder, UserLayout: "{{.Username}}", EnableHome: false, }, - OwnCloudSQL: DriverOwnCloudSQL{ - DriverCommon: DriverCommon{ + OwnCloudSQL: config.DriverOwnCloudSQL{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), ShareFolder: defaultShareFolder, UserLayout: "{{.Username}}", @@ -125,16 +135,16 @@ func DefaultConfig() *Config { DBPort: 3306, DBName: "owncloud", }, - S3: DriverS3{ - DriverCommon: DriverCommon{}, + S3: config.DriverS3{ + DriverCommon: config.DriverCommon{}, Region: "default", AccessKey: "", SecretKey: "", Endpoint: "", Bucket: "", }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ + S3NG: config.DriverS3NG{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), ShareFolder: defaultShareFolder, UserLayout: defaultUserLayout, @@ -146,17 +156,17 @@ func DefaultConfig() *Config { Endpoint: "", Bucket: "", }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ + OCIS: config.DriverOCIS{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), ShareFolder: defaultShareFolder, UserLayout: defaultUserLayout, }, }, }, - MetadataStorage: StorageConfig{ - EOS: DriverEOS{ - DriverCommon: DriverCommon{ + MetadataStorage: config.StorageConfig{ + EOS: config.DriverEOS{ + DriverCommon: config.DriverCommon{ Root: "/eos/dockertest/reva", ShareFolder: defaultShareFolder, UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", @@ -179,16 +189,16 @@ func DefaultConfig() *Config { SingleUsername: "", GatewaySVC: defaultGatewayAddr, }, - Local: DriverCommon{ + Local: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), }, - OwnCloudSQL: DriverOwnCloudSQL{}, - S3: DriverS3{ - DriverCommon: DriverCommon{}, + OwnCloudSQL: config.DriverOwnCloudSQL{}, + S3: config.DriverS3{ + DriverCommon: config.DriverCommon{}, Region: "default", }, - S3NG: DriverS3NG{ - DriverCommon: DriverCommon{ + S3NG: config.DriverS3NG{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", UserLayout: defaultUserLayout, @@ -200,8 +210,8 @@ func DefaultConfig() *Config { Endpoint: "", Bucket: "", }, - OCIS: DriverOCIS{ - DriverCommon: DriverCommon{ + OCIS: config.DriverOCIS{ + DriverCommon: config.DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", UserLayout: defaultUserLayout, @@ -209,8 +219,8 @@ func DefaultConfig() *Config { }, }, }, - Frontend: FrontendPort{ - Port: Port{ + Frontend: config.FrontendPort{ + Port: config.Port{ MaxCPUs: "", LogLevel: "", GRPCNetwork: "", @@ -241,14 +251,14 @@ func DefaultConfig() *Config { OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", OCSResourceInfoCacheTTL: 0, - Middleware: Middleware{}, + Middleware: config.Middleware{}, }, - DataGateway: DataGatewayPort{ - Port: Port{}, + DataGateway: config.DataGatewayPort{ + Port: config.Port{}, PublicURL: "", }, - Gateway: Gateway{ - Port: Port{ + Gateway: config.Gateway{ + Port: config.Port{ Endpoint: defaultGatewayAddr, DebugAddr: "127.0.0.1:9143", GRPCNetwork: "tcp", @@ -262,17 +272,17 @@ func DefaultConfig() *Config { HomeMapping: "", EtagCacheTTL: 0, }, - StorageRegistry: StorageRegistry{ + StorageRegistry: config.StorageRegistry{ Driver: "spaces", HomeProvider: "/home", // unused for spaces, static currently not supported JSON: "", }, - AppRegistry: AppRegistry{ + AppRegistry: config.AppRegistry{ Driver: "static", MimetypesJSON: "", }, - Users: Users{ - Port: Port{ + Users: config.Users{ + Port: config.Port{ Endpoint: "localhost:9144", DebugAddr: "127.0.0.1:9145", GRPCNetwork: "tcp", @@ -282,8 +292,8 @@ func DefaultConfig() *Config { Driver: "ldap", UserGroupsCacheExpiration: 5, }, - Groups: Groups{ - Port: Port{ + Groups: config.Groups{ + Port: config.Port{ Endpoint: "localhost:9160", DebugAddr: "127.0.0.1:9161", GRPCNetwork: "tcp", @@ -293,37 +303,37 @@ func DefaultConfig() *Config { Driver: "ldap", GroupMembersCacheExpiration: 5, }, - AuthProvider: Users{ - Port: Port{}, + AuthProvider: config.Users{ + Port: config.Port{}, Driver: "ldap", UserGroupsCacheExpiration: 0, }, - AuthBasic: Port{ + AuthBasic: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9146", DebugAddr: "127.0.0.1:9147", Services: []string{"authprovider"}, Endpoint: "localhost:9146", }, - AuthBearer: Port{ + AuthBearer: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9148", DebugAddr: "127.0.0.1:9149", Services: []string{"authprovider"}, Endpoint: "localhost:9148", }, - AuthMachine: Port{ + AuthMachine: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9166", DebugAddr: "127.0.0.1:9167", Services: []string{"authprovider"}, Endpoint: "localhost:9166", }, - AuthMachineConfig: AuthMachineConfig{ + AuthMachineConfig: config.AuthMachineConfig{ MachineAuthAPIKey: "change-me-please", }, - Sharing: Sharing{ - Port: Port{ + Sharing: config.Sharing{ + Port: config.Port{ Endpoint: "localhost:9150", DebugAddr: "127.0.0.1:9151", GRPCNetwork: "tcp", @@ -343,13 +353,13 @@ func DefaultConfig() *Config { PublicEnableExpiredSharesCleanup: true, PublicJanitorRunInterval: 60, UserStorageMountID: "", - Events: Events{ + Events: config.Events{ Address: "127.0.0.1:9233", ClusterID: "test-cluster", }, }, - StorageShares: StoragePort{ - Port: Port{ + StorageShares: config.StoragePort{ + Port: config.Port{ Endpoint: "localhost:9154", DebugAddr: "127.0.0.1:9156", GRPCNetwork: "tcp", @@ -361,8 +371,8 @@ func DefaultConfig() *Config { AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", }, - StorageUsers: StoragePort{ - Port: Port{ + StorageUsers: config.StoragePort{ + Port: config.Port{ Endpoint: "localhost:9157", DebugAddr: "127.0.0.1:9159", GRPCNetwork: "tcp", @@ -376,9 +386,9 @@ func DefaultConfig() *Config { HTTPPrefix: "data", TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), }, - StoragePublicLink: PublicStorage{ - StoragePort: StoragePort{ - Port: Port{ + StoragePublicLink: config.PublicStorage{ + StoragePort: config.StoragePort{ + Port: config.Port{ Endpoint: "localhost:9178", DebugAddr: "127.0.0.1:9179", GRPCNetwork: "tcp", @@ -389,8 +399,8 @@ func DefaultConfig() *Config { PublicShareProviderAddr: "", UserProviderAddr: "", }, - StorageMetadata: StoragePort{ - Port: Port{ + StorageMetadata: config.StoragePort{ + Port: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9215", HTTPNetwork: "tcp", @@ -401,10 +411,10 @@ func DefaultConfig() *Config { ExposeDataServer: false, DataServerURL: "http://localhost:9216/data", TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), - DataProvider: DataProvider{}, + DataProvider: config.DataProvider{}, }, - AppProvider: AppProvider{ - Port: Port{ + AppProvider: config.AppProvider{ + Port: config.Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9164", DebugAddr: "127.0.0.1:9165", @@ -412,12 +422,12 @@ func DefaultConfig() *Config { Services: []string{"appprovider"}, }, ExternalAddr: "127.0.0.1:9164", - WopiDriver: WopiDriver{}, + WopiDriver: config.WopiDriver{}, AppsURL: "/app/list", OpenURL: "/app/open", NewURL: "/app/new", }, - Permissions: Port{ + Permissions: config.Port{ Endpoint: "localhost:9191", }, Configs: nil, @@ -427,10 +437,18 @@ func DefaultConfig() *Config { ChecksumPreferredUploadType: "", DefaultUploadProtocol: "tus", }, - Tracing: Tracing{ + Tracing: config.Tracing{ Service: "storage", Type: "jaeger", }, - Asset: Asset{}, + Asset: config.Asset{}, } } + +func EnsureDefaults(cfg *config.Config) { + // TODO: IMPLEMENT ME! +} + +func Sanitize(cfg *config.Config) { + // TODO: IMPLEMENT ME! +} diff --git a/store/cmd/store/main.go b/store/cmd/store/main.go index f20f59258e..06cc58efa5 100644 --- a/store/cmd/store/main.go +++ b/store/cmd/store/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/store/pkg/command" - "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index 585fd7424a..7c8bc6ae11 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -20,5 +20,5 @@ type Config struct { Datapath string `ocisConfig:"data_path" env:"STORE_DATA_PATH"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } diff --git a/store/pkg/config/defaultconfig.go b/store/pkg/config/defaultconfig.go deleted file mode 100644 index c2d42f4301..0000000000 --- a/store/pkg/config/defaultconfig.go +++ /dev/null @@ -1,26 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9464", - Token: "", - Pprof: false, - Zpages: false, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9460", - Namespace: "com.owncloud.api", - }, - Service: Service{ - Name: "store", - }, - Datapath: path.Join(defaults.BaseDataPath(), "store"), - } -} diff --git a/store/pkg/config/defaults/defaultconfig.go b/store/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..2381ceb4a7 --- /dev/null +++ b/store/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,65 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/store/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9464", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: config.GRPC{ + Addr: "127.0.0.1:9460", + Namespace: "com.owncloud.api", + }, + Service: config.Service{ + Name: "store", + }, + Datapath: path.Join(defaults.BaseDataPath(), "store"), + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/store/pkg/config/grpc.go b/store/pkg/config/grpc.go index ed87112dd5..095e30f6b5 100644 --- a/store/pkg/config/grpc.go +++ b/store/pkg/config/grpc.go @@ -3,5 +3,5 @@ package config // GRPC defines the available grpc configuration. type GRPC struct { Addr string `ocisConfig:"addr" env:"STORE_GRPC_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } diff --git a/store/pkg/config/parser/parse.go b/store/pkg/config/parser/parse.go index a0f532c9e1..3538a608f4 100644 --- a/store/pkg/config/parser/parse.go +++ b/store/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/store/pkg/config" + "github.com/owncloud/ocis/store/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -16,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,6 +28,6 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config - + defaults.Sanitize(cfg) return nil } diff --git a/store/pkg/config/service.go b/store/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/store/pkg/config/service.go +++ b/store/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/thumbnails/cmd/thumbnails/main.go b/thumbnails/cmd/thumbnails/main.go index 2098a63413..945b3ec15d 100644 --- a/thumbnails/cmd/thumbnails/main.go +++ b/thumbnails/cmd/thumbnails/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/thumbnails/pkg/command" - "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 2311a4e4dd..fff0d33f48 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -21,7 +21,7 @@ type Config struct { Thumbnail Thumbnail `ocisConfig:"thumbnail"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // FileSystemStorage defines the available filesystem storage configuration. diff --git a/thumbnails/pkg/config/defaultconfig.go b/thumbnails/pkg/config/defaultconfig.go deleted file mode 100644 index 5e4a3e4232..0000000000 --- a/thumbnails/pkg/config/defaultconfig.go +++ /dev/null @@ -1,41 +0,0 @@ -package config - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" -) - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9189", - Token: "", - Pprof: false, - Zpages: false, - }, - GRPC: GRPC{ - Addr: "127.0.0.1:9185", - Namespace: "com.owncloud.api", - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9186", - Root: "/thumbnails", - Namespace: "com.owncloud.web", - }, - Service: Service{ - Name: "thumbnails", - }, - Thumbnail: Thumbnail{ - Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, - FileSystemStorage: FileSystemStorage{ - RootDirectory: path.Join(defaults.BaseDataPath(), "thumbnails"), - }, - WebdavAllowInsecure: true, - RevaGateway: "127.0.0.1:9142", - CS3AllowInsecure: false, - TransferTokenSecret: "changemeplease", - DataEndpoint: "http://127.0.0.1:9186/thumbnails/data", - }, - } -} diff --git a/thumbnails/pkg/config/defaults/defaultconfig.go b/thumbnails/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..f52e21232d --- /dev/null +++ b/thumbnails/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,80 @@ +package defaults + +import ( + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/thumbnails/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9189", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: config.GRPC{ + Addr: "127.0.0.1:9185", + Namespace: "com.owncloud.api", + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9186", + Root: "/thumbnails", + Namespace: "com.owncloud.web", + }, + Service: config.Service{ + Name: "thumbnails", + }, + Thumbnail: config.Thumbnail{ + Resolutions: []string{"16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"}, + FileSystemStorage: config.FileSystemStorage{ + RootDirectory: path.Join(defaults.BaseDataPath(), "thumbnails"), + }, + WebdavAllowInsecure: false, + RevaGateway: "127.0.0.1:9142", + CS3AllowInsecure: false, + TransferTokenSecret: "changemeplease", + DataEndpoint: "http://127.0.0.1:9186/thumbnails/data", + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // nothing to sanitize here atm +} diff --git a/thumbnails/pkg/config/grpc.go b/thumbnails/pkg/config/grpc.go index 9682ed12c5..51bacff506 100644 --- a/thumbnails/pkg/config/grpc.go +++ b/thumbnails/pkg/config/grpc.go @@ -3,5 +3,5 @@ package config // GRPC defines the available grpc configuration. type GRPC struct { Addr string `ocisConfig:"addr" env:"THUMBNAILS_GRPC_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } diff --git a/thumbnails/pkg/config/http.go b/thumbnails/pkg/config/http.go index f3b4d57284..9dc731261f 100644 --- a/thumbnails/pkg/config/http.go +++ b/thumbnails/pkg/config/http.go @@ -4,5 +4,5 @@ package config type HTTP struct { Addr string `ocisConfig:"addr" env:"THUMBNAILS_HTTP_ADDR"` Root string `ocisConfig:"root" env:"THUMBNAILS_HTTP_ROOT"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` } diff --git a/thumbnails/pkg/config/parser/parse.go b/thumbnails/pkg/config/parser/parse.go index 5fa62fb15e..705425a650 100644 --- a/thumbnails/pkg/config/parser/parse.go +++ b/thumbnails/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/thumbnails/pkg/config" + "github.com/owncloud/ocis/thumbnails/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -16,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,6 +28,7 @@ func ParseConfig(cfg *config.Config) error { } // sanitize config + defaults.Sanitize(cfg) return nil } diff --git a/thumbnails/pkg/config/service.go b/thumbnails/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/thumbnails/pkg/config/service.go +++ b/thumbnails/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/web/cmd/web/main.go b/web/cmd/web/main.go index 7334862fee..f46816b8c0 100644 --- a/web/cmd/web/main.go +++ b/web/cmd/web/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/web/pkg/command" - "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index d403136e18..4b571ba857 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -22,7 +22,7 @@ type Config struct { File string `ocisConfig:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string Web Web `ocisConfig:"web"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } // Asset defines the available asset configuration. diff --git a/web/pkg/config/defaultconfig.go b/web/pkg/config/defaultconfig.go deleted file mode 100644 index 018cac2d0a..0000000000 --- a/web/pkg/config/defaultconfig.go +++ /dev/null @@ -1,42 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9104", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9100", - Root: "/", - Namespace: "com.owncloud.web", - CacheTTL: 604800, // 7 days - }, - Service: Service{ - Name: "web", - }, - Asset: Asset{ - Path: "", - }, - Web: Web{ - Path: "", - ThemeServer: "https://localhost:9200", - ThemePath: "/themes/owncloud/theme.json", - Config: WebConfig{ - Server: "https://localhost:9200", - Theme: "", - Version: "0.1.0", - OpenIDConnect: OIDC{ - MetadataURL: "", - Authority: "https://localhost:9200", - ClientID: "web", - ResponseType: "code", - Scope: "openid profile email", - }, - Apps: []string{"files", "search", "media-viewer", "external"}, - }, - }, - } -} diff --git a/web/pkg/config/defaults/defaultconfig.go b/web/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..8e921bbaad --- /dev/null +++ b/web/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,93 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/web/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9104", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9100", + Root: "/", + Namespace: "com.owncloud.web", + CacheTTL: 604800, // 7 days + }, + Service: config.Service{ + Name: "web", + }, + Asset: config.Asset{ + Path: "", + }, + Web: config.Web{ + Path: "", + ThemeServer: "https://localhost:9200", + ThemePath: "/themes/owncloud/theme.json", + Config: config.WebConfig{ + Server: "https://localhost:9200", + Theme: "", + Version: "0.1.0", + OpenIDConnect: config.OIDC{ + MetadataURL: "", + Authority: "https://localhost:9200", + ClientID: "web", + ResponseType: "code", + Scope: "openid profile email", + }, + Apps: []string{"files", "search", "media-viewer", "external"}, + }, + }, + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") + } + // build well known openid-configuration endpoint if it is not set + if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { + cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" + } +} diff --git a/web/pkg/config/http.go b/web/pkg/config/http.go index 317b93497f..ac074ab2ed 100644 --- a/web/pkg/config/http.go +++ b/web/pkg/config/http.go @@ -3,7 +3,7 @@ package config // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr" env:"WEB_HTTP_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` Root string `ocisConfig:"root" env:"WEB_HTTP_ROOT"` CacheTTL int `ocisConfig:"cache_ttl" env:"WEB_CACHE_TTL"` } diff --git a/web/pkg/config/parser/parse.go b/web/pkg/config/parser/parse.go index 2151f613e4..2f8fe31d02 100644 --- a/web/pkg/config/parser/parse.go +++ b/web/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/web/pkg/config" + "github.com/owncloud/ocis/web/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,14 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") - } - // build well known openid-configuration endpoint if it is not set - if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { - cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" - } + defaults.Sanitize(cfg) return nil } diff --git a/web/pkg/config/service.go b/web/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/web/pkg/config/service.go +++ b/web/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` } diff --git a/webdav/cmd/webdav/main.go b/webdav/cmd/webdav/main.go index f03fd520c8..88b1185d71 100644 --- a/webdav/cmd/webdav/main.go +++ b/webdav/cmd/webdav/main.go @@ -4,11 +4,11 @@ import ( "os" "github.com/owncloud/ocis/webdav/pkg/command" - "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config/defaults" ) func main() { - if err := command.Execute(config.DefaultConfig()); err != nil { + if err := command.Execute(defaults.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 04fb193e56..1c64f29233 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -8,9 +8,9 @@ import ( // Config combines all available configuration parts. type Config struct { - *shared.Commons + *shared.Commons `ocisConfig:"-" yaml:"-"` - Service Service + Service Service `ocisConfig:"-" yaml:"-"` Tracing *Tracing `ocisConfig:"tracing"` Log *Log `ocisConfig:"log"` @@ -22,5 +22,5 @@ type Config struct { WebdavNamespace string `ocisConfig:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` //TODO: prevent this cross config RevaGateway string `ocisConfig:"reva_gateway" env:"REVA_GATEWAY"` - Context context.Context + Context context.Context `ocisConfig:"-" yaml:"-"` } diff --git a/webdav/pkg/config/defaultconfig.go b/webdav/pkg/config/defaultconfig.go deleted file mode 100644 index 3bf74acd25..0000000000 --- a/webdav/pkg/config/defaultconfig.go +++ /dev/null @@ -1,29 +0,0 @@ -package config - -func DefaultConfig() *Config { - return &Config{ - Debug: Debug{ - Addr: "127.0.0.1:9119", - Token: "", - Pprof: false, - Zpages: false, - }, - HTTP: HTTP{ - Addr: "127.0.0.1:9115", - Root: "/", - Namespace: "com.owncloud.web", - CORS: CORS{ - AllowedOrigins: []string{"*"}, - AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, - AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, - AllowCredentials: true, - }, - }, - Service: Service{ - Name: "webdav", - }, - OcisPublicURL: "https://127.0.0.1:9200", - WebdavNamespace: "/users/{{.Id.OpaqueId}}", - RevaGateway: "127.0.0.1:9142", - } -} diff --git a/webdav/pkg/config/defaults/defaultconfig.go b/webdav/pkg/config/defaults/defaultconfig.go new file mode 100644 index 0000000000..8c2e164703 --- /dev/null +++ b/webdav/pkg/config/defaults/defaultconfig.go @@ -0,0 +1,77 @@ +package defaults + +import ( + "strings" + + "github.com/owncloud/ocis/webdav/pkg/config" +) + +func FullDefaultConfig() *config.Config { + cfg := DefaultConfig() + + EnsureDefaults(cfg) + Sanitize(cfg) + + return cfg +} + +func DefaultConfig() *config.Config { + return &config.Config{ + Debug: config.Debug{ + Addr: "127.0.0.1:9119", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: config.HTTP{ + Addr: "127.0.0.1:9115", + Root: "/", + Namespace: "com.owncloud.web", + CORS: config.CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Service: config.Service{ + Name: "webdav", + }, + OcisPublicURL: "https://127.0.0.1:9200", + WebdavNamespace: "/users/{{.Id.OpaqueId}}", + RevaGateway: "127.0.0.1:9142", + } +} + +func EnsureDefaults(cfg *config.Config) { + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &config.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Log == nil { + cfg.Log = &config.Log{} + } + // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. + if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { + cfg.Tracing = &config.Tracing{ + Enabled: cfg.Commons.Tracing.Enabled, + Type: cfg.Commons.Tracing.Type, + Endpoint: cfg.Commons.Tracing.Endpoint, + Collector: cfg.Commons.Tracing.Collector, + } + } else if cfg.Tracing == nil { + cfg.Tracing = &config.Tracing{} + } +} + +func Sanitize(cfg *config.Config) { + // sanitize config + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + +} diff --git a/webdav/pkg/config/http.go b/webdav/pkg/config/http.go index 4ce2f2dcd2..ebf8332c3c 100644 --- a/webdav/pkg/config/http.go +++ b/webdav/pkg/config/http.go @@ -11,7 +11,7 @@ type CORS struct { // HTTP defines the available http configuration. type HTTP struct { Addr string `ocisConfig:"addr" env:"WEBDAV_HTTP_ADDR"` - Namespace string + Namespace string `ocisConfig:"-" yaml:"-"` Root string `ocisConfig:"root" env:"WEBDAV_HTTP_ROOT"` CORS CORS `ocisConfig:"cors"` } diff --git a/webdav/pkg/config/parser/parse.go b/webdav/pkg/config/parser/parse.go index 33c893db4a..629f85220e 100644 --- a/webdav/pkg/config/parser/parse.go +++ b/webdav/pkg/config/parser/parse.go @@ -2,10 +2,10 @@ package parser import ( "errors" - "strings" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/webdav/pkg/config" + "github.com/owncloud/ocis/webdav/pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" ) @@ -17,28 +17,7 @@ func ParseConfig(cfg *config.Config) error { return err } - // provide with defaults for shared logging, since we need a valid destination address for BindEnv. - if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { - cfg.Log = &config.Log{ - Level: cfg.Commons.Log.Level, - Pretty: cfg.Commons.Log.Pretty, - Color: cfg.Commons.Log.Color, - File: cfg.Commons.Log.File, - } - } else if cfg.Log == nil { - cfg.Log = &config.Log{} - } - // provide with defaults for shared tracing, since we need a valid destination address for BindEnv. - if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil { - cfg.Tracing = &config.Tracing{ - Enabled: cfg.Commons.Tracing.Enabled, - Type: cfg.Commons.Tracing.Type, - Endpoint: cfg.Commons.Tracing.Endpoint, - Collector: cfg.Commons.Tracing.Collector, - } - } else if cfg.Tracing == nil { - cfg.Tracing = &config.Tracing{} - } + defaults.EnsureDefaults(cfg) // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { @@ -48,10 +27,7 @@ func ParseConfig(cfg *config.Config) error { } } - // sanitize config - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } + defaults.Sanitize(cfg) return nil } diff --git a/webdav/pkg/config/service.go b/webdav/pkg/config/service.go index f98aa3d27e..c019b73046 100644 --- a/webdav/pkg/config/service.go +++ b/webdav/pkg/config/service.go @@ -2,5 +2,5 @@ package config // Service defines the available service configuration. type Service struct { - Name string + Name string `ocisConfig:"-" yaml:"-"` }