diff --git a/.gitignore b/.gitignore index a8f281df2e3..818d3a0f8e3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ node_modules/ ocis/ocis ocis/cmd/ocis/__debug_bin ocis/cmd/ocis/config/ -config/ .idea diff --git a/.make/docs.mk b/.make/docs.mk index 575d0ad4b74..1b1ea2e9aa0 100644 --- a/.make/docs.mk +++ b/.make/docs.mk @@ -3,10 +3,12 @@ SKIP_CONFIG_DOCS_GENERATE ?= 0 CONFIG_DOCS_BASE_PATH ?= ../docs/extensions .PHONY: config-docs-generate -config-docs-generate: $(FLAEX) - @if [ $(SKIP_CONFIG_DOCS_GENERATE) -ne 1 ]; then \ - $(FLAEX) >| $(CONFIG_DOCS_BASE_PATH)/$(NAME)/configuration.md \ - ; fi; +config-docs-generate: #$(FLAEX) +# since https://github.com/owncloud/ocis/pull/2708 flaex can no longer be used +# TODO: how to document configuration +# @if [ $(SKIP_CONFIG_DOCS_GENERATE) -ne 1 ]; then \ +# $(FLAEX) >| $(CONFIG_DOCS_BASE_PATH)/$(NAME)/configuration.md \ +# ; fi; .PHONY: grpc-docs-generate grpc-docs-generate: buf-generate diff --git a/.vscode/launch.json b/.vscode/launch.json index 011c22d18c8..1df7882e22a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,6 +20,6 @@ // set insecure options because we don't have valid certificates in dev environments "OCIS_INSECURE": "true", } - }, + } ] -} \ No newline at end of file +} diff --git a/accounts/cmd/accounts/main.go b/accounts/cmd/accounts/main.go index 553fc79ef76..35262ccad86 100644 --- a/accounts/cmd/accounts/main.go +++ b/accounts/cmd/accounts/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index 6769cf0f826..1ea262c31d0 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -5,10 +5,11 @@ import ( "os" "strconv" + "github.com/owncloud/ocis/accounts/pkg/flagset" + "github.com/asim/go-micro/plugins/client/grpc/v4" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" ) diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index 0ad37476124..87727b5762f 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -5,10 +5,11 @@ import ( "os" "strconv" + "github.com/owncloud/ocis/accounts/pkg/flagset" + "github.com/asim/go-micro/plugins/client/grpc/v4" tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" ) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index 086e50554e7..dfb723db9c0 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -4,9 +4,10 @@ import ( "fmt" "os" + "github.com/owncloud/ocis/accounts/pkg/flagset" + "github.com/asim/go-micro/plugins/client/grpc/v4" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" ) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index c4757d23e01..19eae93b2f4 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -3,24 +3,16 @@ package command import ( "context" "os" - "strings" + + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) -var ( - defaultConfigPaths = []string{"/etc/ocis", "$HOME/.ocis", "./config"} - defaultFilename = "accounts" -) - // Execute is the entry point for the ocis-accounts command. func Execute(cfg *config.Config) error { app := &cli.App{ @@ -28,16 +20,12 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Provide accounts and groups for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Server.Version = version.String return ParseConfig(c, cfg) @@ -68,60 +56,30 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("accounts"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - -// ParseConfig loads accounts configuration from Viper known paths. +// ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("ACCOUNTS") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName(defaultFilename) - - for _, v := range defaultConfigPaths { - viper.AddConfigPath(v) - } + conf, err := ociscfg.BindSourcesToStructs("accounts", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("Unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("Failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(cfg), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree. @@ -131,10 +89,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Accounts.Supervised = true - } - cfg.Accounts.Log.File = cfg.Log.File + cfg.Accounts.Commons = cfg.Commons return SutureService{ cfg: cfg.Accounts, } diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 6dbabfaffa3..45298d29805 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -4,11 +4,12 @@ import ( "context" "strings" + "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/oklog/run" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" "github.com/owncloud/ocis/accounts/pkg/metrics" "github.com/owncloud/ocis/accounts/pkg/server/grpc" "github.com/owncloud/ocis/accounts/pkg/server/http" @@ -23,34 +24,21 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend) - // When running on single binary mode the before hook from the root command won't get called. We manually - // call this before hook from ocis command, so the configuration can be loaded. - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - if origins := ctx.StringSlice("cors-allowed-origins"); len(origins) != 0 { - cfg.HTTP.CORS.AllowedOrigins = origins - } - if methods := ctx.StringSlice("cors-allowed-methods"); len(methods) != 0 { - cfg.HTTP.CORS.AllowedMethods = methods - } - if headers := ctx.StringSlice("cors-allowed-headers"); len(headers) != 0 { - cfg.HTTP.CORS.AllowedOrigins = headers + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "accounts").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { - logger := NewLogger(cfg) + logger := log.LoggerFromConfig("accounts", *cfg.Log) err := tracing.Configure(cfg) if err != nil { return err diff --git a/accounts/pkg/command/update_account.go b/accounts/pkg/command/update_account.go index 2d66fdd7ecd..71f8c2c661e 100644 --- a/accounts/pkg/command/update_account.go +++ b/accounts/pkg/command/update_account.go @@ -4,9 +4,10 @@ import ( "errors" "fmt" + "github.com/owncloud/ocis/accounts/pkg/flagset" + "github.com/asim/go-micro/plugins/client/grpc/v4" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/urfave/cli/v2" "google.golang.org/genproto/protobuf/field_mask" @@ -24,7 +25,6 @@ func UpdateAccount(cfg *config.Config) *cli.Command { Flags: flagset.UpdateAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { if len(c.StringSlice("password_policies")) > 0 { - // StringSliceFlag doesn't support Destination a.PasswordProfile.PasswordPolicies = c.StringSlice("password_policies") } diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index c89358db524..e61530d16b8 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,6 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListAccountsWithConfig(cfg), Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Server.Name) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index a98554f0e2f..4ae123db68e 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -1,140 +1,143 @@ // Package config should be moved to internal package config -import "context" +import ( + "context" + "path" + + "github.com/owncloud/ocis/ocis-pkg/shared" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // LDAP defines the available ldap configuration. type LDAP struct { - Hostname string - Port int - BaseDN string - UserFilter string - GroupFilter string - BindDN string - BindPassword string - IDP string - Schema LDAPSchema + Hostname string `ocisConfig:"hostname"` + Port int `ocisConfig:"port"` + BaseDN string `ocisConfig:"base_dn"` + UserFilter string `ocisConfig:"user_filter"` + GroupFilter string `ocisConfig:"group_filter"` + BindDN string `ocisConfig:"bind_dn"` + BindPassword string `ocisConfig:"bind_password"` + IDP string `ocisConfig:"idp"` + Schema LDAPSchema `ocisConfig:"schema"` } // LDAPSchema defines the available ldap schema configuration. type LDAPSchema struct { - AccountID string - Identities string - Username string - DisplayName string - Mail string - Groups string + AccountID string `ocisConfig:"account_id"` + Identities string `ocisConfig:"identities"` + Username string `ocisConfig:"username"` + DisplayName string `ocisConfig:"display_name"` + Mail string `ocisConfig:"mail"` + Groups string `ocisConfig:"groups"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allowed_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string - CacheTTL int - CORS CORS + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Root string `ocisConfig:"root"` + CacheTTL int `ocisConfig:"cache_ttl"` + CORS CORS `ocisConfig:"cors"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string - Namespace string + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` } // Server configures a server. type Server struct { - Version string - Name string - HashDifficulty int - DemoUsersAndGroups bool + Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` + HashDifficulty int `ocisConfig:"hash_difficulty"` + DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `ocisConfig:"path"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string -} - -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string + JWTSecret string `ocisConfig:"jwt_secret"` } // Repo defines which storage implementation is to be used. type Repo struct { - Backend string - Disk Disk - CS3 CS3 + Backend string `ocisConfig:"backend"` + Disk Disk `ocisConfig:"disk"` + CS3 CS3 `ocisConfig:"cs3"` } // Disk is the local disk implementation of the storage. type Disk struct { - Path string + Path string `ocisConfig:"path"` } // CS3 is the cs3 implementation of the storage. type CS3 struct { - ProviderAddr string - DataURL string - DataPrefix string - JWTSecret string + ProviderAddr string `ocisConfig:"provider_addr"` + DataURL string `ocisConfig:"data_url"` + DataPrefix string `ocisConfig:"data_prefix"` + JWTSecret string `ocisConfig:"jwt_secret"` } // ServiceUser defines the user required for EOS. type ServiceUser struct { - UUID string - Username string - UID int64 - GID int64 + UUID string `ocisConfig:"uuid"` + Username string `ocisConfig:"username"` + UID int64 `ocisConfig:"uid"` + GID int64 `ocisConfig:"gid"` } // Index defines config for indexes. type Index struct { - UID, GID Bound + UID Bound `ocisConfig:"uid"` + GID Bound `ocisConfig:"gid"` } // Bound defines a lower and upper bound. type Bound struct { - Lower, Upper int64 + Lower int64 `ocisConfig:"lower"` + Upper int64 `ocisConfig:"upper"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Config merges all Account config parameters. type Config struct { - LDAP LDAP - HTTP HTTP - GRPC GRPC - Server Server - Asset Asset - Log Log - TokenManager TokenManager - Repo Repo - Index Index - ServiceUser ServiceUser - Tracing Tracing + *shared.Commons + + LDAP LDAP `ocisConfig:"ldap"` + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` + Server Server `ocisConfig:"server"` + Asset Asset `ocisConfig:"asset"` + Log *shared.Log `ocisConfig:"log"` + TokenManager TokenManager `ocisConfig:"token_manager"` + Repo Repo `ocisConfig:"repo"` + Index Index `ocisConfig:"index"` + ServiceUser ServiceUser `ocisConfig:"service_user"` + Tracing Tracing `ocisConfig:"tracing"` Context context.Context Supervised bool @@ -142,5 +145,81 @@ type Config struct { // New returns a new config. func New() *Config { - return &Config{} + return &Config{ + Log: &shared.Log{}, + } +} + +func DefaultConfig() *Config { + return &Config{ + LDAP: LDAP{}, + 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", + }, + Server: Server{ + Name: "accounts", + HashDifficulty: 11, + DemoUsersAndGroups: true, + }, + Asset: Asset{}, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Repo: Repo{ + Backend: "CS3", + Disk: Disk{ + Path: path.Join(defaults.BaseDataPath(), "accounts"), + }, + CS3: CS3{ + ProviderAddr: "localhost:9215", + DataURL: "http://localhost:9216", + DataPrefix: "data", + JWTSecret: "Pive-Fumkiu4", + }, + }, + Index: Index{ + UID: Bound{ + Lower: 0, + Upper: 1000, + }, + GID: Bound{ + Lower: 0, + Upper: 1000, + }, + }, + ServiceUser: ServiceUser{ + UUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + Username: "", + UID: 0, + GID: 0, + }, + Tracing: Tracing{ + Type: "jaeger", + Service: "accounts", + }, + } +} + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r } diff --git a/accounts/pkg/config/mappings.go b/accounts/pkg/config/mappings.go new file mode 100644 index 00000000000..4789fc8d690 --- /dev/null +++ b/accounts/pkg/config/mappings.go @@ -0,0 +1,148 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_FILE", "ACCOUNTS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "ACCOUNTS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "ACCOUNTS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "ACCOUNTS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "ACCOUNTS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "ACCOUNTS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "ACCOUNTS_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"ACCOUNTS_HTTP_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, + }, + { + EnvVars: []string{"ACCOUNTS_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"ACCOUNTS_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"ACCOUNTS_CACHE_TTL"}, + Destination: &cfg.HTTP.CacheTTL, + }, + { + EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + { + EnvVars: []string{"ACCOUNTS_GRPC_ADDR"}, + Destination: &cfg.GRPC.Addr, + }, + { + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + { + EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"}, + Destination: &cfg.Server.HashDifficulty, + }, + { + EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"}, + Destination: &cfg.Server.DemoUsersAndGroups, + }, + { + EnvVars: []string{"ACCOUNTS_ASSET_PATH"}, + Destination: &cfg.Asset.Path, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET", "ACCOUNTS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + { + EnvVars: []string{"ACCOUNTS_STORAGE_BACKEND"}, + Destination: &cfg.Repo.Backend, + }, + { + EnvVars: []string{"ACCOUNTS_STORAGE_DISK_PATH"}, + Destination: &cfg.Repo.Disk.Path, + }, + { + EnvVars: []string{"ACCOUNTS_STORAGE_CS3_PROVIDER_ADDR"}, + Destination: &cfg.Repo.CS3.ProviderAddr, + }, + { + EnvVars: []string{"ACCOUNTS_STORAGE_CS3_DATA_URL"}, + Destination: &cfg.Repo.CS3.DataURL, + }, + { + EnvVars: []string{"ACCOUNTS_STORAGE_CS3_DATA_PREFIX"}, + Destination: &cfg.Repo.CS3.DataPrefix, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET", "ACCOUNTS_STORAGE_CS3_JWT_SECRET"}, + Destination: &cfg.Repo.CS3.JWTSecret, + }, + { + EnvVars: []string{"ACCOUNTS_SERVICE_USER_UUID"}, + Destination: &cfg.ServiceUser.UUID, + }, + { + EnvVars: []string{"ACCOUNTS_SERVICE_USER_USERNAME"}, + Destination: &cfg.ServiceUser.Username, + }, + { + EnvVars: []string{"ACCOUNTS_SERVICE_USER_UID"}, + Destination: &cfg.ServiceUser.UID, + }, + { + EnvVars: []string{"ACCOUNTS_SERVICE_USER_GID"}, + Destination: &cfg.ServiceUser.GID, + }, + { + EnvVars: []string{"ACCOUNTS_UID_INDEX_LOWER_BOUND"}, + Destination: &cfg.Index.UID.Lower, + }, + { + EnvVars: []string{"ACCOUNTS_GID_INDEX_LOWER_BOUND"}, + Destination: &cfg.Index.GID.Lower, + }, + { + EnvVars: []string{"ACCOUNTS_UID_INDEX_UPPER_BOUND"}, + Destination: &cfg.Index.UID.Upper, + }, + { + EnvVars: []string{"ACCOUNTS_GID_INDEX_UPPER_BOUND"}, + Destination: &cfg.Index.GID.Upper, + }, + } +} diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index abc32ec5716..3815f0784ae 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -1,292 +1,12 @@ package flagset import ( - "path" - "github.com/owncloud/ocis/accounts/pkg/config" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" "github.com/owncloud/ocis/ocis-pkg/flags" "github.com/urfave/cli/v2" ) -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"ACCOUNTS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"ACCOUNTS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"ACCOUNTS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "accounts"), - Usage: "Service name for tracing", - EnvVars: []string{"ACCOUNTS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.HTTP.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http namespace", - EnvVars: []string{"ACCOUNTS_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9181"), - Usage: "Address to bind http server", - EnvVars: []string{"ACCOUNTS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/"), - Usage: "Root path of http server", - EnvVars: []string{"ACCOUNTS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.IntFlag{ - Name: "http-cache-ttl", - Value: flags.OverrideDefaultInt(cfg.HTTP.CacheTTL, 604800), - Usage: "Set the static assets caching duration in seconds", - EnvVars: []string{"ACCOUNTS_CACHE_TTL"}, - Destination: &cfg.HTTP.CacheTTL, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-origins", - Value: cli.NewStringSlice("*"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"ACCOUNTS_CORS_ALLOW_ORIGINS", "OCIS_CORS_ALLOW_ORIGINS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-methods", - Value: cli.NewStringSlice("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"ACCOUNTS_CORS_ALLOW_METHODS", "OCIS_CORS_ALLOW_METHODS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-headers", - Value: cli.NewStringSlice("Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"ACCOUNTS_CORS_ALLOW_HEADERS", "OCIS_CORS_ALLOW_HEADERS"}, - }, - &cli.BoolFlag{ - Name: "cors-allow-credentials", - Value: flags.OverrideDefaultBool(cfg.HTTP.CORS.AllowCredentials, true), - Usage: "Allow credentials for CORS", - EnvVars: []string{"ACCOUNTS_CORS_ALLOW_CREDENTIALS", "OCIS_CORS_ALLOW_CREDENTIALS"}, - }, - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.GRPC.Addr, "127.0.0.1:9180"), - Usage: "Address to bind grpc server", - EnvVars: []string{"ACCOUNTS_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.IntFlag{ - Name: "accounts-hash-difficulty", - Value: flags.OverrideDefaultInt(cfg.Server.HashDifficulty, 11), - Usage: "accounts password hash difficulty", - EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"}, - Destination: &cfg.Server.HashDifficulty, - }, - &cli.BoolFlag{ - Name: "demo-users-and-groups", - Value: flags.OverrideDefaultBool(cfg.Server.DemoUsersAndGroups, true), - Usage: "Enable demo users and groups", - EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"}, - Destination: &cfg.Server.DemoUsersAndGroups, - }, - &cli.StringFlag{ - Name: "asset-path", - Value: flags.OverrideDefaultString(cfg.Asset.Path, ""), - Usage: "Path to custom assets", - EnvVars: []string{"ACCOUNTS_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - &cli.StringFlag{ - Name: "jwt-secret", - Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"), - Usage: "Used to create JWT to talk to reva, should equal reva's jwt-secret", - EnvVars: []string{"ACCOUNTS_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - &cli.StringFlag{ - Name: "storage-backend", - Value: flags.OverrideDefaultString(cfg.Repo.Backend, "CS3"), - Usage: "Which backend to use to store accounts data (CS3 or disk)", - EnvVars: []string{"ACCOUNTS_STORAGE_BACKEND"}, - Destination: &cfg.Repo.Backend, - }, - &cli.StringFlag{ - Name: "storage-disk-path", - Value: flags.OverrideDefaultString(cfg.Repo.Disk.Path, path.Join(defaults.BaseDataPath(), "accounts")), - Usage: "Path on the local disk to store accounts data when backend is set to disk", - EnvVars: []string{"ACCOUNTS_STORAGE_DISK_PATH"}, - Destination: &cfg.Repo.Disk.Path, - }, - &cli.StringFlag{ - Name: "storage-cs3-provider-addr", - Value: flags.OverrideDefaultString(cfg.Repo.CS3.ProviderAddr, "localhost:9215"), - Usage: "bind address for the metadata storage provider", - EnvVars: []string{"ACCOUNTS_STORAGE_CS3_PROVIDER_ADDR"}, - Destination: &cfg.Repo.CS3.ProviderAddr, - }, - &cli.StringFlag{ - Name: "storage-cs3-data-url", - Value: flags.OverrideDefaultString(cfg.Repo.CS3.DataURL, "http://localhost:9216"), - Usage: "http endpoint of the metadata storage", - EnvVars: []string{"ACCOUNTS_STORAGE_CS3_DATA_URL"}, - Destination: &cfg.Repo.CS3.DataURL, - }, - &cli.StringFlag{ - Name: "storage-cs3-data-prefix", - Value: flags.OverrideDefaultString(cfg.Repo.CS3.DataPrefix, "data"), - Usage: "path prefix for the http endpoint of the metadata storage, without leading slash", - EnvVars: []string{"ACCOUNTS_STORAGE_CS3_DATA_PREFIX"}, - Destination: &cfg.Repo.CS3.DataPrefix, - }, - &cli.StringFlag{ - Name: "storage-cs3-jwt-secret", - Value: flags.OverrideDefaultString(cfg.Repo.CS3.JWTSecret, "Pive-Fumkiu4"), - Usage: "Used to create JWT to talk to reva, should equal reva's jwt-secret", - EnvVars: []string{"ACCOUNTS_STORAGE_CS3_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.Repo.CS3.JWTSecret, - }, - &cli.StringFlag{ - Name: "service-user-uuid", - Value: flags.OverrideDefaultString(cfg.ServiceUser.UUID, "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad"), - Usage: "uuid of the internal service user (required on EOS)", - EnvVars: []string{"ACCOUNTS_SERVICE_USER_UUID"}, - Destination: &cfg.ServiceUser.UUID, - }, - &cli.StringFlag{ - Name: "service-user-username", - Value: flags.OverrideDefaultString(cfg.ServiceUser.Username, ""), - Usage: "username of the internal service user (required on EOS)", - EnvVars: []string{"ACCOUNTS_SERVICE_USER_USERNAME"}, - Destination: &cfg.ServiceUser.Username, - }, - &cli.Int64Flag{ - Name: "service-user-uid", - Value: flags.OverrideDefaultInt64(cfg.ServiceUser.UID, 0), - Usage: "uid of the internal service user (required on EOS)", - EnvVars: []string{"ACCOUNTS_SERVICE_USER_UID"}, - Destination: &cfg.ServiceUser.UID, - }, - &cli.Int64Flag{ - Name: "service-user-gid", - Value: flags.OverrideDefaultInt64(cfg.ServiceUser.GID, 0), - Usage: "gid of the internal service user (required on EOS)", - EnvVars: []string{"ACCOUNTS_SERVICE_USER_GID"}, - Destination: &cfg.ServiceUser.GID, - }, - &cli.Int64Flag{ - Name: "uid-index-lower-bound", - Value: flags.OverrideDefaultInt64(cfg.Index.UID.Lower, 0), - Usage: "define a starting point for the account UID", - EnvVars: []string{"ACCOUNTS_UID_INDEX_LOWER_BOUND"}, - Destination: &cfg.Index.UID.Lower, - }, - &cli.Int64Flag{ - Name: "gid-index-lower-bound", - Value: flags.OverrideDefaultInt64(cfg.Index.GID.Lower, 1000), - Usage: "define a starting point for the account GID", - EnvVars: []string{"ACCOUNTS_GID_INDEX_LOWER_BOUND"}, - Destination: &cfg.Index.GID.Lower, - }, - &cli.Int64Flag{ - Name: "uid-index-upper-bound", - Value: flags.OverrideDefaultInt64(cfg.Index.UID.Upper, 0), - Usage: "define an ending point for the account UID", - EnvVars: []string{"ACCOUNTS_UID_INDEX_UPPER_BOUND"}, - Destination: &cfg.Index.UID.Upper, - }, - &cli.Int64Flag{ - Name: "gid-index-upper-bound", - Value: flags.OverrideDefaultInt64(cfg.Index.GID.Upper, 1000), - Usage: "define an ending point for the account GID", - EnvVars: []string{"ACCOUNTS_GID_INDEX_UPPER_BOUND"}, - Destination: &cfg.Index.GID.Upper, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, - } -} - // UpdateAccountWithConfig applies update command flags to cfg func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { if a.PasswordProfile == nil { diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index deb52596e8b..89cf6c346bc 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -12,11 +12,10 @@ import ( mgrpcc "github.com/asim/go-micro/plugins/client/grpc/v4" empty "github.com/golang/protobuf/ptypes/empty" - - "github.com/owncloud/ocis/accounts/pkg/command" "github.com/owncloud/ocis/accounts/pkg/config" "github.com/owncloud/ocis/accounts/pkg/proto/v0" svc "github.com/owncloud/ocis/accounts/pkg/service/v0" + oclog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" settings "github.com/owncloud/ocis/settings/pkg/proto/v0" "github.com/stretchr/testify/assert" @@ -86,7 +85,7 @@ func init() { var hdlr *svc.Service var err error - if hdlr, err = svc.New(svc.Logger(command.NewLogger(cfg)), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { + if hdlr, err = svc.New(svc.Logger(oclog.LoggerFromConfig("accounts", *cfg.Log)), svc.Config(cfg), svc.RoleService(buildRoleServiceMock())); err != nil { log.Fatalf("Could not create new service") } diff --git a/accounts/pkg/service/v0/service.go b/accounts/pkg/service/v0/service.go index b95455204b7..e4a5feefbda 100644 --- a/accounts/pkg/service/v0/service.go +++ b/accounts/pkg/service/v0/service.go @@ -8,6 +8,8 @@ import ( "strings" "time" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/pkg/errors" "github.com/owncloud/ocis/ocis-pkg/service/grpc" @@ -109,6 +111,10 @@ func (s Service) buildIndex() (*indexer.Indexer, error) { func configFromSvc(cfg *config.Config) (*idxcfg.Config, error) { c := idxcfg.New() + if cfg.Log == nil { + cfg.Log = &shared.Log{} + } + defer func(cfg *config.Config) { l := log.NewLogger(log.Color(cfg.Log.Color), log.Pretty(cfg.Log.Pretty), log.Level(cfg.Log.Level)) if r := recover(); r != nil { diff --git a/changelog/unreleased/revamp-config.md b/changelog/unreleased/revamp-config.md new file mode 100644 index 00000000000..d57114543b6 --- /dev/null +++ b/changelog/unreleased/revamp-config.md @@ -0,0 +1,7 @@ +Change: Restructure Configuration Parsing + +Tags: ocis + +CLI flags are no longer needed for subcommands, as we rely solely on env variables and config files. This greatly simplifies configuration and deployment. + +https://github.com/owncloud/ocis/pull/2708 diff --git a/deployments/examples/cs3_users_ocis/config/ocis/entrypoint-override.sh b/deployments/examples/cs3_users_ocis/config/ocis/entrypoint-override.sh index ac598cb60fc..2fd09563b20 100644 --- a/deployments/examples/cs3_users_ocis/config/ocis/entrypoint-override.sh +++ b/deployments/examples/cs3_users_ocis/config/ocis/entrypoint-override.sh @@ -3,7 +3,6 @@ set -e mkdir -p /var/tmp/ocis/.config/ -cp /config/proxy-config.json /var/tmp/ocis/.config/proxy-config.json cp /config/web-config.dist.json /var/tmp/ocis/.config/web-config.json sed -i 's/ocis.owncloud.test/'${OCIS_DOMAIN:-ocis.owncloud.test}'/g' /var/tmp/ocis/.config/web-config.json @@ -15,8 +14,4 @@ ocis kill accounts # stop builtin LDAP server since we use external LDAP only ocis kill glauth -ocis kill proxy -sleep 10 -ocis proxy server # workaround for loading proxy configuration - wait # wait for oCIS to exit diff --git a/deployments/examples/cs3_users_ocis/config/ocis/proxy-config.json b/deployments/examples/cs3_users_ocis/config/ocis/proxy.json similarity index 100% rename from deployments/examples/cs3_users_ocis/config/ocis/proxy-config.json rename to deployments/examples/cs3_users_ocis/config/ocis/proxy.json diff --git a/deployments/examples/cs3_users_ocis/docker-compose.yml b/deployments/examples/cs3_users_ocis/docker-compose.yml index e0a4dcc1e5b..4386238ec69 100644 --- a/deployments/examples/cs3_users_ocis/docker-compose.yml +++ b/deployments/examples/cs3_users_ocis/docker-compose.yml @@ -75,8 +75,6 @@ services: STORAGE_LDAP_GROUPFILTER: '(&(objectclass=groupOfUniqueNames)(objectclass=owncloud)(ownclouduuid={{.OpaqueId}}*))' # web ui WEB_UI_CONFIG: "/var/tmp/ocis/.config/web-config.json" - # proxy - PROXY_CONFIG_FILE: "/var/tmp/ocis/.config/proxy-config.json" # General oCIS config OCIS_URL: https://${OCIS_DOMAIN:-ocis.owncloud.test} OCIS_DOMAIN: ${OCIS_DOMAIN:-ocis.owncloud.test} @@ -91,7 +89,7 @@ services: volumes: - ./config/ocis/entrypoint-override.sh:/entrypoint-override.sh - ./config/ocis/web-config.dist.json:/config/web-config.dist.json - - ./config/ocis/proxy-config.json:/config/proxy-config.json + - ./config/ocis/proxy.json:/etc/ocis/proxy.json - ocis-data:/var/lib/ocis labels: - "traefik.enable=true" diff --git a/deployments/examples/oc10_ocis_parallel/config/ocis/entrypoint-override.sh b/deployments/examples/oc10_ocis_parallel/config/ocis/entrypoint-override.sh index 547ece0141b..cd72bb548d9 100755 --- a/deployments/examples/oc10_ocis_parallel/config/ocis/entrypoint-override.sh +++ b/deployments/examples/oc10_ocis_parallel/config/ocis/entrypoint-override.sh @@ -1,11 +1,5 @@ #!/bin/sh set -e - -mkdir -p /var/tmp/ocis/.config/ -cp /config/proxy-config.dist.json /var/tmp/ocis/.config/proxy-config.json -# TODO: remove replace logic when log level configuration is fixed -sed -i 's/PROXY_LOG_LEVEL/${PROXY_LOG_LEVEL}/g' /var/tmp/ocis/.config/proxy-config.json - ocis server & sleep 10 @@ -14,9 +8,4 @@ ocis kill idp ocis kill glauth ocis kill accounts -# workaround for loading proxy configuration -ocis kill proxy -sleep 10 -ocis proxy server & - wait diff --git a/deployments/examples/oc10_ocis_parallel/config/ocis/proxy-config.dist.json b/deployments/examples/oc10_ocis_parallel/config/ocis/proxy.json similarity index 99% rename from deployments/examples/oc10_ocis_parallel/config/ocis/proxy-config.dist.json rename to deployments/examples/oc10_ocis_parallel/config/ocis/proxy.json index 1bf70e362d0..6333545dac0 100644 --- a/deployments/examples/oc10_ocis_parallel/config/ocis/proxy-config.dist.json +++ b/deployments/examples/oc10_ocis_parallel/config/ocis/proxy.json @@ -106,4 +106,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/deployments/examples/oc10_ocis_parallel/docker-compose.yml b/deployments/examples/oc10_ocis_parallel/docker-compose.yml index 86b448a4f1f..3469715c0fb 100644 --- a/deployments/examples/oc10_ocis_parallel/docker-compose.yml +++ b/deployments/examples/oc10_ocis_parallel/docker-compose.yml @@ -108,7 +108,6 @@ services: OCIS_STORAGE_READ_ONLY: "false" # TODO: conflict with OWNCLOUDSQL -> https://github.com/owncloud/ocis/issues/2303 # General oCIS config OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose - PROXY_LOG_LEVEL: ${PROXY_LOG_LEVEL:-error} OCIS_URL: https://${CLOUD_DOMAIN:-cloud.owncloud.test} PROXY_TLS: "false" # do not use SSL between Traefik and oCIS PROXY_CONFIG_FILE: "/var/tmp/ocis/.config/proxy-config.json" @@ -120,7 +119,7 @@ services: OCIS_INSECURE: "${INSECURE:-false}" volumes: - ./config/ocis/entrypoint-override.sh:/entrypoint-override.sh - - ./config/ocis/proxy-config.dist.json:/config/proxy-config.dist.json + - ./config/ocis/proxy.json:/etc/ocis/proxy.json - ocis-data:/var/lib/ocis # shared volume with oC10 - oc10-data:/mnt/data diff --git a/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh b/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh index d90e287a947..6cd8f27182f 100644 --- a/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh +++ b/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh @@ -3,7 +3,6 @@ set -e mkdir -p /var/tmp/ocis/.config/ -cp /config/proxy-config.json /var/tmp/ocis/.config/proxy-config.json cp /config/web-config.dist.json /var/tmp/ocis/.config/web-config.json sed -i 's/ocis.owncloud.test/'${OCIS_DOMAIN:-ocis.owncloud.test}'/g' /var/tmp/ocis/.config/web-config.json @@ -26,8 +25,4 @@ ocis accounts update --password $STORAGE_LDAP_BIND_PASSWORD $REVA_USER_UUID echo "default secrets changed" echo "##################################################" -ocis kill proxy -sleep 10 -ocis proxy server # workaround for loading proxy configuration - wait # wait for oCIS to exit diff --git a/deployments/examples/ocis_hello/config/ocis/proxy-config.json b/deployments/examples/ocis_hello/config/ocis/proxy.json similarity index 100% rename from deployments/examples/ocis_hello/config/ocis/proxy-config.json rename to deployments/examples/ocis_hello/config/ocis/proxy.json diff --git a/deployments/examples/ocis_hello/docker-compose.yml b/deployments/examples/ocis_hello/docker-compose.yml index d6c1c35f148..19aac699193 100644 --- a/deployments/examples/ocis_hello/docker-compose.yml +++ b/deployments/examples/ocis_hello/docker-compose.yml @@ -62,8 +62,6 @@ services: OCIS_MACHINE_AUTH_API_KEY: ${OCIS_MACHINE_AUTH_API_KEY:-change-me-please} # web ui WEB_UI_CONFIG: "/var/tmp/ocis/.config/web-config.json" - # proxy - PROXY_CONFIG_FILE: "/var/tmp/ocis/.config/proxy-config.json" # make settings service available to oCIS Hello SETTINGS_GRPC_ADDR: 0.0.0.0:9191 # INSECURE: needed if oCIS / Traefik is using self generated certificates @@ -71,7 +69,7 @@ services: volumes: - ./config/ocis/entrypoint-override.sh:/entrypoint-override.sh - ./config/ocis/web-config.dist.json:/config/web-config.dist.json - - ./config/ocis/proxy-config.json:/config/proxy-config.json + - ./config/ocis/proxy.json:/etc/ocis/proxy.json - ocis-data:/var/lib/ocis labels: - "traefik.enable=true" diff --git a/docs/ocis/config.md b/docs/ocis/config.md new file mode 100644 index 00000000000..aa6a367bf8f --- /dev/null +++ b/docs/ocis/config.md @@ -0,0 +1,173 @@ +--- +title: "Configuration" +date: "2021-11-09T00:03:16+0100" +weight: 2 +geekdocRepo: https://github.com/owncloud/ocis +geekdocEditPath: edit/master/ocis/templates +geekdocFilePath: config.md +--- + +{{< toc >}} + +## Configuration Framework + +In order to simplify deployments and development the configuration model from oCIS aims to be simple yet flexible. + +## Overview of the approach + +{{< svg src="ocis/static/ocis-config-redesign.drawio.svg" >}} + +## In-depth configuration + +Since we include a set of predefined extensions within the single binary, configuring an extension can be done in a variety of ways. Since we work with complex types, having as many cli per config value scales poorly, so we limited the options to config files and environment variables, leaving cli flags for common values, such as logging (`--log-level`, `--log-pretty`, `--log-file` or `--log-color`). + +The hierarchy is clear enough, leaving us with: + +_(each element above overwrites its precedent)_ + +1. env variables +2. extension config +3. ocis config + +This is manifested in the previous diagram. We can then speak about "configuration file arithmetics", where resulting config transformations happen through a series of steps. An administrator must be aware of these sources, since mis-managing them can be a source of confusion, having undesired transformations on config files believed not to be applied. + +## Flows + +Let's explore the various flows with examples and workflows. + +### Examples + +Let's explore with examples this approach. + +#### Expected loading locations: + +- `$HOME/.ocis/config/` +- `/etc/ocis/` +- `.config/` + +followed by the extension name. When configuring the proxy, a valid full path that will get loaded is `$HOME/.ocis/config/proxy.yaml`. + +#### Only config files + +The following config files are present in the default loading locations: + +_ocis.yaml_ +```yaml +proxy: + http: + addr: localhost:1111 + log: + pretty: false + color: false + level: info +accounts: + http: + addr: localhost:2222 + log: + level: debug + color: false + pretty: false +log: + pretty: true + color: true + level: info +``` + +_proxy.yaml_ +```yaml +http: + addr: localhost:3333 +``` + +_accounts.yaml_ +```yaml +http: + addr: localhost:4444 +``` + +Note that the extension files will overwrite values from the main `ocis.yaml`, causing `ocis server` to run with the following configuration: + +```yaml +proxy: + http: + addr: localhost:3333 +accounts: + http: + addr: localhost:4444 +log: + pretty: true + color: true + level: info +``` + +#### Using ENV variables + +The logging configuration if defined in the main ocis.yaml is inherited by all extensions. It can be, however, overwritten by a single extension file if desired. The same example can be used to demonstrate environment values overwrites. With the same set of config files now we have the following command `PROXY_HTTP_ADDR=localhost:5555 ocis server`, now the resulting config looks like: + +```yaml +proxy: + http: + addr: localhost:5555 +accounts: + http: + addr: localhost:4444 +log: + pretty: true + color: true + level: info +``` + +### Workflows + +Since one can run an extension using the runtime (supervised) or not (unsupervised), we ensure correct behavior in both modes, expecting the same outputs. + +#### Supervised + +You are using the supervised mode whenever you issue the `ocis server` command. We start the runtime on port `9250` (by default) that listens for commands regarding the lifecycle of the supervised extensions. When an extension runs supervised and is killed, the only way to provide / overwrite configuration values will be through an extension config file. This is due to the parent process has already started, and it already has its own environment. + +#### Unsupervised + +All the points from the priority section hold true. An unsupervised extension can be started with the format: `ocis [extension]` i.e: `ocis proxy`. First, `ocis.yaml` is parsed, then `proxy.yaml` followed by environment variables. + +## Shared Values + +When running in supervised mode (`ocis server`) it is beneficial to have common values for logging, so that the log output is correctly formatted, or everything is piped to the same file without duplicating config keys and values all over the place. This is possible using the global `log` config key: + +_ocis.yaml_ +```yaml +log: + level: error + color: true + pretty: true + file: /var/tmp/ocis_output.log +``` + +There is, however, the option for extensions to overwrite this global values by declaring their own logging directives: + +_ocis.yaml_ +```yaml +log: + level: info + color: false + pretty: false +``` + +One can go as far as to make the case of an extension overwriting its shared logging config that received from the main `ocis.yaml` file. Because things can get out of hands pretty fast we recommend not mixing logging configuration values and either use the same global logging values for all extensions. + +{{< hint warning >}} +When overwriting a globally shared logging values, one *MUST* specify all values. +{{< /hint >}} + +### Log config keys + +```yaml +log: + level: [ error | warning | info | debug ] + color: [ true | false ] + pretty: [ true | false ] + file: [ path/to/log/file ] # MUST not be used with pretty = true +``` + +## Default config values (in yaml) + +TBD. Needs to be generated and merged with the env mappings. diff --git a/docs/ocis/deployment/basic-remote-setup.md b/docs/ocis/deployment/basic-remote-setup.md index 6569309ab6b..efa76e1fdf5 100644 --- a/docs/ocis/deployment/basic-remote-setup.md +++ b/docs/ocis/deployment/basic-remote-setup.md @@ -53,7 +53,7 @@ PROXY_TRANSPORT_TLS_CERT=./certs/your-host.crt \ If you generated these certificates on your own, you might need to set `OCIS_INSECURE` to `true`. -For more configuration options check the configuration section in [oCIS]({{< ref "../configuration" >}}) and the oCIS extensions. +For more configuration options check the configuration section in [oCIS]({{< ref "../config" >}}) and the oCIS extensions. ## Start the oCIS fullstack server with Docker Compose diff --git a/docs/ocis/getting-started/_index.md b/docs/ocis/getting-started/_index.md index b602fcadabc..92e00c4390c 100644 --- a/docs/ocis/getting-started/_index.md +++ b/docs/ocis/getting-started/_index.md @@ -71,7 +71,7 @@ Open [https://localhost:9200](https://localhost:9200) and [login using one of th ### Basic Management Commands -The oCIS single binary contains multiple extensions and the `ocis` command helps you to manage them. You already used `ocis server` to run all available extensions in the [Run oCIS]({{< ref "#run-ocis" >}}) section. We now will show you some more management commands, which you may also explore by typing `ocis --help` or going to the [docs]({{< ref "../configuration" >}}). +The oCIS single binary contains multiple extensions and the `ocis` command helps you to manage them. You already used `ocis server` to run all available extensions in the [Run oCIS]({{< ref "#run-ocis" >}}) section. We now will show you some more management commands, which you may also explore by typing `ocis --help` or going to the [docs]({{< ref "../config" >}}). To start oCIS server: diff --git a/docs/ocis/static/ocis-config-redesign.drawio.svg b/docs/ocis/static/ocis-config-redesign.drawio.svg new file mode 100644 index 00000000000..ff2ee40fac5 --- /dev/null +++ b/docs/ocis/static/ocis-config-redesign.drawio.svg @@ -0,0 +1,4 @@ + + + +
> ocis server
> ocis server

# global logging config
log:
  pretty: true
  color: true
  level: info
proxy:
  http:
    addr: localhost:9200
  log:
    pretty: false
    color: false
    level: info
accounts:
  log:
    level: debug
    color: false
    pretty: false

# global logging config...
ocis.yaml
ocis.yaml

  http:
    addr: localhost:1234
  log:
    pretty: false
    color: false
    level: info

http:...
proxy.yaml
proxy.yaml

  http:
    addr: localhost:5678


http:...
accounts.yaml
accounts.yaml
resulting proxy config values
resulting proxy config values
resulting accounts config values
resulting accounts config values

  http:
    addr: localhost:1234
  log:
    pretty: false
    color: false
    level: info


http:...
notice how even if ocis supplies
with logging configuration, the values
from the extension overwrite the inherited
values. This can also be achieved using an
environment variable.
notice how even if ocis supplies...

  http:
    addr: localhost:5678
  log:
    pretty: true
    color: true
    level: info


http:...
on the other hand here we see the extension
inherited the logging information from the parent.
The same holds true from any value. Values from
ocis.yaml are carried down to their respective
extensions.
on the other hand here we see the extension...
Viewer does not support full SVG 1.1
\ No newline at end of file diff --git a/glauth/pkg/command/health.go b/glauth/pkg/command/health.go index 3deb2db70dd..1ee1362ecdb 100644 --- a/glauth/pkg/command/health.go +++ b/glauth/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/glauth/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index d8b39a9804d..e6017cfef5c 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/glauth/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/sync" + oclog "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -23,21 +21,16 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve GLAuth API for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Version = version.String return nil }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -59,58 +52,32 @@ func Execute(cfg *config.Config) error { // NewLogger initializes a service-specific logger instance. func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("glauth"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) + return oclog.LoggerFromConfig("glauth", *cfg.Log) } -// ParseConfig loads glauth configuration from Viper known paths. +// ParseConfig loads glauth configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("GLAUTH") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("glauth") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("glauth", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } - - return nil + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(cfg), false) + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the glauth command to be embedded and supervised by a suture supervisor tree. @@ -120,10 +87,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.GLAuth.Supervised = true - } - cfg.GLAuth.Log.File = cfg.Log.File + cfg.GLAuth.Commons = cfg.Commons return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index b3ae41e53d2..d3e903503f0 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -8,7 +8,6 @@ import ( "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/glauth/pkg/flagset" "github.com/owncloud/ocis/glauth/pkg/metrics" "github.com/owncloud/ocis/glauth/pkg/server/debug" "github.com/owncloud/ocis/glauth/pkg/server/glauth" @@ -24,24 +23,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - // StringSliceFlag doesn't support Destination - // UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli - if len(ctx.StringSlice("backend-server")) > 0 { - cfg.Backend.Servers = ctx.StringSlice("backend-server") - } - if len(ctx.StringSlice("fallback-server")) > 0 { - cfg.Fallback.Servers = ctx.StringSlice("fallback-server") - } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) + + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Strs("backend-server", ctx.StringSlice("backend-server")).Str("service", "glauth").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 0d88c318a0a..d547180d7ca 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -1,78 +1,79 @@ package config -import "context" +import ( + "context" + "path" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/shared" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Root string `ocisConfig:"root"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Ldap defined the available LDAP configuration. type Ldap struct { - Addr string - Enabled bool + Enabled bool `ocisConfig:"enabled"` + Addr string `ocisConfig:"addr"` } // Ldaps defined the available LDAPS configuration. type Ldaps struct { - Addr string - Enabled bool - Cert string - Key string + Addr string `ocisConfig:"addr"` + Enabled bool `ocisConfig:"enabled"` + Cert string `ocisConfig:"cert"` + Key string `ocisConfig:"key"` } // Backend defined the available backend configuration. type Backend struct { - Datastore string - BaseDN string - Insecure bool - NameFormat string - GroupFormat string - Servers []string - SSHKeyAttr string - UseGraphAPI bool + Datastore string `ocisConfig:"datastore"` + BaseDN string `ocisConfig:"base_dn"` + Insecure bool `ocisConfig:"insecure"` + NameFormat string `ocisConfig:"name_format"` + GroupFormat string `ocisConfig:"group_format"` + Servers []string `ocisConfig:"servers"` + SSHKeyAttr string `ocisConfig:"ssh_key_attr"` + UseGraphAPI bool `ocisConfig:"use_graph_api"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Tracing Tracing - Ldap Ldap - Ldaps Ldaps - Backend Backend - Fallback Backend - Version string - RoleBundleUUID string + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Tracing Tracing `ocisConfig:"tracing"` + Ldap Ldap `ocisConfig:"ldap"` + Ldaps Ldaps `ocisConfig:"ldaps"` + Backend Backend `ocisConfig:"backend"` + Fallback Backend `ocisConfig:"fallback"` + Version string `ocisConfig:"version"` + RoleBundleUUID string `ocisConfig:"role_bundle_uuid"` Context context.Context Supervised bool @@ -82,3 +83,47 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9129", + }, + HTTP: HTTP{}, + Tracing: Tracing{ + Type: "jaeger", + Service: "glauth", + }, + Ldap: Ldap{ + Enabled: true, + Addr: "127.0.0.1:9125", + }, + Ldaps: Ldaps{ + Addr: "127.0.0.1:9126", + Enabled: true, + 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: Backend{ + 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/mappings.go b/glauth/pkg/config/mappings.go new file mode 100644 index 00000000000..4867fc9ea2a --- /dev/null +++ b/glauth/pkg/config/mappings.go @@ -0,0 +1,167 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL", "GLAUTH_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "GLAUTH_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "GLAUTH_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "GLAUTH_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"GLAUTH_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "GLAUTH_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "GLAUTH_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GLAUTH_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GLAUTH_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"GLAUTH_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"GLAUTH_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"GLAUTH_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"GLAUTH_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"GLAUTH_ROLE_BUNDLE_ID"}, + Destination: &cfg.RoleBundleUUID, + }, + { + EnvVars: []string{"GLAUTH_LDAP_ADDR"}, + Destination: &cfg.Ldap.Addr, + }, + { + EnvVars: []string{"GLAUTH_LDAP_ENABLED"}, + Destination: &cfg.Ldap.Enabled, + }, + { + EnvVars: []string{"GLAUTH_LDAPS_ADDR"}, + Destination: &cfg.Ldaps.Addr, + }, + { + EnvVars: []string{"GLAUTH_LDAPS_ENABLED"}, + Destination: &cfg.Ldaps.Enabled, + }, + { + EnvVars: []string{"GLAUTH_LDAPS_CERT"}, + Destination: &cfg.Ldaps.Cert, + }, + { + EnvVars: []string{"GLAUTH_LDAPS_KEY"}, + Destination: &cfg.Ldaps.Key, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_BASEDN"}, + Destination: &cfg.Backend.BaseDN, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_NAME_FORMAT"}, + Destination: &cfg.Backend.NameFormat, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_GROUP_FORMAT"}, + Destination: &cfg.Backend.GroupFormat, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_SSH_KEY_ATTR"}, + Destination: &cfg.Backend.SSHKeyAttr, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_DATASTORE"}, + Destination: &cfg.Backend.Datastore, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_INSECURE"}, + Destination: &cfg.Backend.Insecure, + }, + { + EnvVars: []string{"GLAUTH_BACKEND_USE_GRAPHAPI"}, + Destination: &cfg.Backend.UseGraphAPI, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_BASEDN"}, + Destination: &cfg.Fallback.BaseDN, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_NAME_FORMAT"}, + Destination: &cfg.Fallback.NameFormat, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_GROUP_FORMAT"}, + Destination: &cfg.Fallback.GroupFormat, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_SSH_KEY_ATTR"}, + Destination: &cfg.Fallback.SSHKeyAttr, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_DATASTORE"}, + Destination: &cfg.Fallback.Datastore, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_INSECURE"}, + Destination: &cfg.Fallback.Insecure, + }, + { + EnvVars: []string{"GLAUTH_FALLBACK_USE_GRAPHAPI"}, + Destination: &cfg.Fallback.UseGraphAPI, + }, + } +} diff --git a/glauth/pkg/flagset/flagset.go b/glauth/pkg/flagset/flagset.go deleted file mode 100644 index 9b939e0d4ee..00000000000 --- a/glauth/pkg/flagset/flagset.go +++ /dev/null @@ -1,299 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"GLAUTH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"GLAUTH_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9129"), - Usage: "Address to debug endpoint", - EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"GLAUTH_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "config-file", - Value: flags.OverrideDefaultString(cfg.File, ""), - Usage: "Path to config file", - EnvVars: []string{"GLAUTH_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"GLAUTH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"GLAUTH_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"GLAUTH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"GLAUTH_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "glauth"), - Usage: "Service name for tracing", - EnvVars: []string{"GLAUTH_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9129"), - Usage: "Address to bind debug server", - EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"GLAUTH_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"GLAUTH_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"GLAUTH_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "role-bundle-id", - Value: flags.OverrideDefaultString(cfg.RoleBundleUUID, "71881883-1768-46bd-a24d-a356a2afdf7f"), // BundleUUIDRoleAdmin - Usage: "roleid used to make internal grpc requests", - EnvVars: []string{"GLAUTH_ROLE_BUNDLE_ID"}, - Destination: &cfg.RoleBundleUUID, - }, - - &cli.StringFlag{ - Name: "ldap-addr", - Value: flags.OverrideDefaultString(cfg.Ldap.Addr, "127.0.0.1:9125"), - Usage: "Address to bind ldap server", - EnvVars: []string{"GLAUTH_LDAP_ADDR"}, - Destination: &cfg.Ldap.Addr, - }, - &cli.BoolFlag{ - Name: "ldap-enabled", - Value: flags.OverrideDefaultBool(cfg.Ldap.Enabled, true), - Usage: "Enable ldap server", - EnvVars: []string{"GLAUTH_LDAP_ENABLED"}, - Destination: &cfg.Ldap.Enabled, - }, - - &cli.StringFlag{ - Name: "ldaps-addr", - Value: flags.OverrideDefaultString(cfg.Ldaps.Addr, "127.0.0.1:9126"), - Usage: "Address to bind ldaps server", - EnvVars: []string{"GLAUTH_LDAPS_ADDR"}, - Destination: &cfg.Ldaps.Addr, - }, - &cli.BoolFlag{ - Name: "ldaps-enabled", - Value: flags.OverrideDefaultBool(cfg.Ldaps.Enabled, true), - Usage: "Enable ldaps server", - EnvVars: []string{"GLAUTH_LDAPS_ENABLED"}, - Destination: &cfg.Ldaps.Enabled, - }, - &cli.StringFlag{ - Name: "ldaps-cert", - Value: flags.OverrideDefaultString(cfg.Ldaps.Cert, path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt")), - Usage: "path to ldaps certificate in PEM format", - EnvVars: []string{"GLAUTH_LDAPS_CERT"}, - Destination: &cfg.Ldaps.Cert, - }, - &cli.StringFlag{ - Name: "ldaps-key", - Value: flags.OverrideDefaultString(cfg.Ldaps.Key, path.Join(defaults.BaseDataPath(), "ldap", "ldap.key")), - Usage: "path to ldaps key in PEM format", - EnvVars: []string{"GLAUTH_LDAPS_KEY"}, - Destination: &cfg.Ldaps.Key, - }, - - // backend config - - &cli.StringFlag{ - Name: "backend-basedn", - Value: flags.OverrideDefaultString(cfg.Backend.BaseDN, "dc=ocis,dc=test"), - Usage: "base distinguished name to expose", - EnvVars: []string{"GLAUTH_BACKEND_BASEDN"}, - Destination: &cfg.Backend.BaseDN, - }, - &cli.StringFlag{ - Name: "backend-name-format", - Value: flags.OverrideDefaultString(cfg.Backend.NameFormat, "cn"), - Usage: "name attribute for entries to expose. typically cn or uid", - EnvVars: []string{"GLAUTH_BACKEND_NAME_FORMAT"}, - Destination: &cfg.Backend.NameFormat, - }, - &cli.StringFlag{ - Name: "backend-group-format", - Value: flags.OverrideDefaultString(cfg.Backend.GroupFormat, "ou"), - Usage: "name attribute for entries to expose. typically ou, cn or dc", - EnvVars: []string{"GLAUTH_BACKEND_GROUP_FORMAT"}, - Destination: &cfg.Backend.GroupFormat, - }, - &cli.StringFlag{ - Name: "backend-ssh-key-attr", - Value: flags.OverrideDefaultString(cfg.Backend.SSHKeyAttr, "sshPublicKey"), - Usage: "ssh key attribute for entries to expose", - EnvVars: []string{"GLAUTH_BACKEND_SSH_KEY_ATTR"}, - Destination: &cfg.Backend.SSHKeyAttr, - }, - &cli.StringFlag{ - Name: "backend-datastore", - Value: flags.OverrideDefaultString(cfg.Backend.Datastore, "accounts"), - // TODO bring back config / flat file support - Usage: "datastore to use as the backend. one of accounts, ldap or owncloud", - EnvVars: []string{"GLAUTH_BACKEND_DATASTORE"}, - Destination: &cfg.Backend.Datastore, - }, - &cli.BoolFlag{ - Name: "backend-insecure", - Value: flags.OverrideDefaultBool(cfg.Backend.Insecure, false), - Usage: "Allow insecure requests to the datastore", - EnvVars: []string{"GLAUTH_BACKEND_INSECURE"}, - Destination: &cfg.Backend.Insecure, - }, - &cli.StringSliceFlag{ - Name: "backend-server", - Value: cli.NewStringSlice(), - Usage: `--backend-server https://demo.owncloud.com/apps/graphapi/v1.0 [--backend-server "https://demo2.owncloud.com/apps/graphapi/v1.0"]`, - EnvVars: []string{"GLAUTH_BACKEND_SERVERS"}, - }, - &cli.BoolFlag{ - Name: "backend-use-graphapi", - Value: flags.OverrideDefaultBool(cfg.Backend.UseGraphAPI, true), - Usage: "use Graph API, only for owncloud datastore", - EnvVars: []string{"GLAUTH_BACKEND_USE_GRAPHAPI"}, - Destination: &cfg.Backend.UseGraphAPI, - }, - - // fallback config - - &cli.StringFlag{ - Name: "fallback-basedn", - Value: flags.OverrideDefaultString(cfg.Fallback.BaseDN, "dc=ocis,dc=test"), - Usage: "base distinguished name to expose", - EnvVars: []string{"GLAUTH_FALLBACK_BASEDN"}, - Destination: &cfg.Fallback.BaseDN, - }, - &cli.StringFlag{ - Name: "fallback-name-format", - Value: flags.OverrideDefaultString(cfg.Fallback.NameFormat, "cn"), - Usage: "name attribute for entries to expose. typically cn or uid", - EnvVars: []string{"GLAUTH_FALLBACK_NAME_FORMAT"}, - Destination: &cfg.Fallback.NameFormat, - }, - &cli.StringFlag{ - Name: "fallback-group-format", - Value: flags.OverrideDefaultString(cfg.Fallback.GroupFormat, "ou"), - Usage: "name attribute for entries to expose. typically ou, cn or dc", - EnvVars: []string{"GLAUTH_FALLBACK_GROUP_FORMAT"}, - Destination: &cfg.Fallback.GroupFormat, - }, - &cli.StringFlag{ - Name: "fallback-ssh-key-attr", - Value: flags.OverrideDefaultString(cfg.Fallback.SSHKeyAttr, "sshPublicKey"), - Usage: "ssh key attribute for entries to expose", - EnvVars: []string{"GLAUTH_FALLBACK_SSH_KEY_ATTR"}, - Destination: &cfg.Fallback.SSHKeyAttr, - }, - &cli.StringFlag{ - Name: "fallback-datastore", - Value: flags.OverrideDefaultString(cfg.Fallback.Datastore, ""), - // TODO bring back config / flat file support - Usage: "datastore to use as the fallback. one of accounts, ldap or owncloud", - EnvVars: []string{"GLAUTH_FALLBACK_DATASTORE"}, - Destination: &cfg.Fallback.Datastore, - }, - &cli.BoolFlag{ - Name: "fallback-insecure", - Value: flags.OverrideDefaultBool(cfg.Fallback.Insecure, false), - Usage: "Allow insecure requests to the datastore", - EnvVars: []string{"GLAUTH_FALLBACK_INSECURE"}, - Destination: &cfg.Fallback.Insecure, - }, - &cli.StringSliceFlag{ - Name: "fallback-server", - Value: cli.NewStringSlice("https://demo.owncloud.com/apps/graphapi/v1.0"), - Usage: `--fallback-server http://internal1.example.com [--fallback-server http://internal2.example.com]`, - EnvVars: []string{"GLAUTH_FALLBACK_SERVERS"}, - }, - &cli.BoolFlag{ - Name: "fallback-use-graphapi", - Value: flags.OverrideDefaultBool(cfg.Fallback.UseGraphAPI, true), - Usage: "use Graph API, only for owncloud datastore", - EnvVars: []string{"GLAUTH_FALLBACK_USE_GRAPHAPI"}, - Destination: &cfg.Fallback.UseGraphAPI, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} diff --git a/go.mod b/go.mod index 74354b499a1..e9d84a31d11 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( github.com/golang-jwt/jwt/v4 v4.1.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/golang/protobuf v1.5.2 + github.com/gookit/config/v2 v2.0.27 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 github.com/iancoleman/strcase v0.2.0 @@ -51,7 +52,6 @@ require ( github.com/rs/zerolog v1.26.0 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.2.1 - github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.7.0 github.com/thejerf/suture/v4 v4.0.1 github.com/urfave/cli/v2 v2.3.0 @@ -69,11 +69,13 @@ require ( google.golang.org/genproto v0.0.0-20211020151524-b7c3a969101a google.golang.org/grpc v1.42.0 google.golang.org/protobuf v1.27.1 + gopkg.in/yaml.v2 v2.4.0 gotest.tools/v3 v3.0.3 stash.kopano.io/kgol/rndm v1.1.1 ) require ( + cloud.google.com/go v0.93.3 // indirect contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect github.com/Masterminds/goutils v1.1.1 // indirect @@ -137,16 +139,17 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/mock v1.6.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/gomodule/redigo v1.8.5 // indirect github.com/google/go-cmp v0.5.6 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/gookit/goutil v0.3.15 // indirect github.com/gorilla/schema v1.2.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/hashicorp/go-hclog v1.0.0 // indirect github.com/hashicorp/go-plugin v1.4.3 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect github.com/huandu/xstrings v1.3.2 // indirect github.com/imdario/mergo v0.3.12 // indirect @@ -160,7 +163,6 @@ require ( github.com/klauspost/compress v1.13.6 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/longsleep/go-metrics v1.0.0 // indirect - github.com/magiconair/properties v1.8.5 // indirect github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect github.com/mattn/go-colorable v0.1.11 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -189,7 +191,6 @@ require ( github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc // indirect github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect - github.com/pelletier/go-toml v1.9.4 // indirect github.com/pkg/xattr v0.4.4 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect @@ -213,13 +214,9 @@ require ( github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect github.com/sony/gobreaker v0.4.1 // indirect - github.com/spf13/afero v1.6.0 // indirect - github.com/spf13/cast v1.4.1 // indirect - github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/steveyen/gtreap v0.1.0 // indirect github.com/studio-b12/gowebdav v0.0.0-20210917133250-a3a86976a1df // indirect - github.com/subosito/gotenv v1.2.0 // indirect github.com/tus/tusd v1.6.0 // indirect github.com/wk8/go-ordered-map v0.2.0 // indirect github.com/xanzy/ssh-agent v0.3.1 // indirect @@ -241,7 +238,6 @@ require ( gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect stash.kopano.io/kgol/kcc-go/v5 v5.0.1 // indirect stash.kopano.io/kgol/oidc-go v0.3.2 // indirect diff --git a/go.sum b/go.sum index 0085d260999..587fc407c69 100644 --- a/go.sum +++ b/go.sum @@ -37,7 +37,6 @@ cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM7 cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= -cloud.google.com/go/firestore v1.6.0/go.mod h1:afJwI0vaXwAG54kI7A//lP/lSPDkQORQuMkv56TxEPU= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= @@ -106,6 +105,7 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/akamai/AkamaiOPEN-edgegrid-golang v1.1.0/go.mod h1:kX6YddBkXqqywAe8c9LyvgTCyFuZCTMF4cRPQhc3Fy8= @@ -121,12 +121,14 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= +github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/arl/statsviz v0.4.0/go.mod h1:+5inUy/dxy11x/KSmicG3ZrEEy0Yr81AFm3dn4QC04M= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= @@ -509,6 +511,7 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/gobs/pretty v0.0.0-20180724170744-09732c25a95b/go.mod h1:Xo4aNUOrJnVruqWQJBtW6+bTBDTniY8yZum5rF3b5jw= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= @@ -575,6 +578,7 @@ github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3K github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v0.0.0-20170622202551-6a1fa9404c0a/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -649,7 +653,15 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/googleapis/gax-go/v2 v2.1.0/go.mod h1:Q3nei7sK6ybPYH7twZdmQpAd1MKb7pfu6SK+H1/DsU0= +github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk= +github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= +github.com/gookit/config/v2 v2.0.27 h1:jCQSAe3qN8gFABz6h4qA9MNhTk0D4ipn6+1jeAD7g9E= +github.com/gookit/config/v2 v2.0.27/go.mod h1:q7I5c+hWOlzGh8jLff6CuNV6H2RDZ1QanaBEimGGtwE= +github.com/gookit/goutil v0.3.14/go.mod h1:YdGV0ObqRUlRq4/RzAQBHcd1Wzl/jKw7cppDBtD3q+U= +github.com/gookit/goutil v0.3.15 h1:nfMiE1nlBES16zOsLzNeR/vo6a7KlV58womgG6dB+JM= +github.com/gookit/goutil v0.3.15/go.mod h1:2w7h+/CB6n2m4qzECHj6+TOmMR8q7ierD9+LyybGy3I= +github.com/gookit/ini/v2 v2.0.11 h1:Wl651xN2AaJbFrb8daBwWo8kS+sQHL3TddFi0/PRNXs= +github.com/gookit/ini/v2 v2.0.11/go.mod h1:rIY8Uup5WDdPsrEE7VrF7fcMdGCCcPGA22Bk5R7roJQ= github.com/gophercloud/gophercloud v0.15.1-0.20210202035223-633d73521055/go.mod h1:wRtmUelyIIv3CSSDI47aUwbs075O6i+LY+pXsKCBsb4= github.com/gophercloud/gophercloud v0.16.0/go.mod h1:wRtmUelyIIv3CSSDI47aUwbs075O6i+LY+pXsKCBsb4= github.com/gophercloud/utils v0.0.0-20210216074907-f6de111f2eae/go.mod h1:wx8HMD8oQD0Ryhz6+6ykq75PJ79iPyEqYHfwZ4l7OsA= @@ -677,13 +689,10 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 h1:rgxjzoDmDXw5q8HONgyHhBas4to0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0/go.mod h1:qrJPVzv9YlhsrxJc3P/Q85nr0w1lIRikTl4JlhdDH5w= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v1.0.0 h1:bkKf0BeBXcSYa7f5Fyi9gMuQ8gNsxeiNpZjR6VxNZeo= @@ -691,12 +700,10 @@ github.com/hashicorp/go-hclog v1.0.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39E github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v6UZM= github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= @@ -706,16 +713,13 @@ github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/hcl/v2 v2.10.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/memberlist v0.2.4/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 h1:brI5vBRUlAlM34VFmnLPwjnCL/FxAJp9XvOdX6Zt+XE= github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= @@ -810,6 +814,7 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= @@ -831,7 +836,6 @@ github.com/m3o/m3o-go/client v0.0.0-20210421144725-8bfd7992ada3/go.mod h1:vmeaYr github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -850,7 +854,6 @@ github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxq github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -862,6 +865,7 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -897,7 +901,6 @@ github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -908,6 +911,7 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0= @@ -1020,8 +1024,6 @@ github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUr github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= -github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -1035,7 +1037,6 @@ github.com/pkg/xattr v0.4.4/go.mod h1:sBD3RAqlr8Q+RC3FutZcikpT8nyDrIEEBw2J744gVW github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc= github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= @@ -1128,7 +1129,6 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sacloud/libsacloud v1.36.2/go.mod h1:P7YAOVmnIn3DKHqCZcUKYUXmSwGBm3yS7IBEjKVSrjg= -github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYIR88KRMEuODE= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210127161313-bd30bebeac4f/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= @@ -1169,12 +1169,9 @@ github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= -github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= -github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= @@ -1183,10 +1180,10 @@ github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJ github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -1194,8 +1191,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= -github.com/spf13/viper v1.9.0 h1:yR6EXjTp0y0cLN8OZg1CRZmOBdI88UcGkhgyJhu6nZk= -github.com/spf13/viper v1.9.0/go.mod h1:+i6ajR7OX2XaiBkrcZJFK21htRk7eDeLg7+O6bhUPP4= github.com/steveyen/gtreap v0.1.0 h1:CjhzTa274PyJLJuMZwIzCO1PfC00oRa8d1Kc78bFXJM= github.com/steveyen/gtreap v0.1.0/go.mod h1:kl/5J7XbrOmlIbYIXdRHDDE5QxHqpk0cmkT7Z4dM9/Y= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -1212,7 +1207,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/studio-b12/gowebdav v0.0.0-20210917133250-a3a86976a1df h1:C+J/LwTqP8gRPt1MdSzBNZP0OYuDm5wsmDKgwpLjYzo= github.com/studio-b12/gowebdav v0.0.0-20210917133250-a3a86976a1df/go.mod h1:gCcfDlA1Y7GqOaeEKw5l9dOGx1VLdc/HuQSlQAaZ30s= -github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/thanhpk/randstr v1.0.4 h1:IN78qu/bR+My+gHCvMEXhR/i5oriVHcTB/BJJIRTsNo= @@ -1243,6 +1237,9 @@ github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPU github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/vimeo/go-util v1.2.0/go.mod h1:s13SMDTSO7AjH1nbgp707mfN5JFIWUFDU5MDDuRRtKs= github.com/vinyldns/go-vinyldns v0.0.0-20200917153823-148a5f6b8f14/go.mod h1:RWc47jtnVuQv6+lY3c768WtXCas/Xi+U5UFc5xULmYg= +github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= +github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/vultr/govultr/v2 v2.0.0/go.mod h1:2PsEeg+gs3p/Fo5Pw8F9mv+DUBEOlrNZ8GmCTGmhOhs= github.com/wk8/go-ordered-map v0.2.0 h1:KlvGyHstD1kkGZkPtHCyCfRYS0cz84uk6rrW/Dnhdtk= github.com/wk8/go-ordered-map v0.2.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= @@ -1259,11 +1256,14 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1: github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yaegashi/msgraph.go v0.1.1-0.20200221123608-2d438cf2a7cc/go.mod h1:tso14hwzqX4VbnWTNsxiL0DvMb2OwbGISFA7jDibdWc= github.com/yaegashi/msgraph.go v0.1.4 h1:leDXSczAbwBpYFSmmZrdByTiPoUw8dbTfNMetAjJvbw= github.com/yaegashi/msgraph.go v0.1.4/go.mod h1:vgeYhHa5skJt/3lTyjGXThTZhwbhRnGo6uUxzoJIGME= github.com/yaegashi/wtz.go v0.0.2/go.mod h1:nOLA5QXsmdkRxBkP5tljhua13ADHCKirLBrzPf4PEJc= +github.com/yosuke-furukawa/json5 v0.1.1/go.mod h1:sw49aWDqNdRJ6DYUtIQiaA3xyj2IL9tjeNYmX2ixwcU= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -1271,6 +1271,9 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= +github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= github.com/zenazn/goji v0.9.1-0.20160507202103-64eb34159fe5/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go-micro.dev/v4 v4.1.0/go.mod h1:XTEJj5ILOBW+2ndGDG56r8fBXZ8hmsVaIaS1K5zwj+s= go-micro.dev/v4 v4.2.1/go.mod h1:XTEJj5ILOBW+2ndGDG56r8fBXZ8hmsVaIaS1K5zwj+s= @@ -1351,6 +1354,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1375,7 +1379,6 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -1423,6 +1426,7 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1539,6 +1543,7 @@ golang.org/x/sys v0.0.0-20190415081028-16da32be82c5/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1565,7 +1570,6 @@ golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200120151820-655fe14d7479/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1615,7 +1619,6 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210921065528-437939a70204/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ= @@ -1758,7 +1761,6 @@ google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtuk google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/api v0.51.0/go.mod h1:t4HdrdoNgyN5cbEfm7Lum0lcLDLiise1F8qDKX00sOU= google.golang.org/api v0.54.0/go.mod h1:7C4bFFOvVDGXjfDTAsgGwDgAxRDeQ4X8NvUedIt6z3k= -google.golang.org/api v0.56.0/go.mod h1:38yMfeP1kfjsl8isn0tliTjIb1rJXcQi4UXlbqivdVE= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -1823,8 +1825,6 @@ google.golang.org/genproto v0.0.0-20210716133855-ce7ef5c701ea/go.mod h1:AxrInvYm google.golang.org/genproto v0.0.0-20210728212813-7823e685a01f/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= google.golang.org/genproto v0.0.0-20210805201207-89edb61ffb67/go.mod h1:ob2IJxKrgPT52GcgX759i1sleT07tiKowYBGbczaW48= google.golang.org/genproto v0.0.0-20210813162853-db860fec028c/go.mod h1:cFeNkxwySK631ADgubI+/XFU/xp8FD5KIVV4rj8UC5w= -google.golang.org/genproto v0.0.0-20210821163610-241b8fcbd6c8/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= -google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY= google.golang.org/genproto v0.0.0-20211020151524-b7c3a969101a h1:8maMHMQp9NroHXhc3HelFX9Ay2lWlXLcdH5mw5Biz0s= google.golang.org/genproto v0.0.0-20211020151524-b7c3a969101a/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= diff --git a/graph-explorer/cmd/graph-explorer/main.go b/graph-explorer/cmd/graph-explorer/main.go index f0d3cdcac7c..a8357cb1f2e 100644 --- a/graph-explorer/cmd/graph-explorer/main.go +++ b/graph-explorer/cmd/graph-explorer/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/graph-explorer/pkg/command/health.go b/graph-explorer/pkg/command/health.go index 2fc86dcc07d..60f4cc925b8 100644 --- a/graph-explorer/pkg/command/health.go +++ b/graph-explorer/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/graph-explorer/pkg/config" - "github.com/owncloud/ocis/graph-explorer/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 83cdcb1861f..2f5f679a4cb 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -3,15 +3,11 @@ package command import ( "context" "os" - "strings" "github.com/owncloud/ocis/graph-explorer/pkg/config" - "github.com/owncloud/ocis/graph-explorer/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -23,32 +19,25 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve Graph-Explorer for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Server.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), }, } - cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ Name: "version,v", Usage: "Print the version", @@ -68,49 +57,16 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads accounts configuration from Viper known paths. +// ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("GRAPH_EXPLORER") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("graph-explorer") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") - } - - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Info(). - Msg("Continue without config") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("Unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("Failed to read config") - } - } - - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") + conf, err := ociscfg.BindSourcesToStructs("graph-explorer", cfg) + if err != nil { + return err } - return nil + conf.LoadOSEnv(config.GetEnv(), false) + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the graph-explorer command to be embedded and supervised by a suture supervisor tree. @@ -120,10 +76,7 @@ type SutureService struct { // NewSutureService creates a new graph-explorer.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.GraphExplorer.Supervised = true - } - cfg.GraphExplorer.Log.File = cfg.Log.File + cfg.GraphExplorer.Log = cfg.Log return SutureService{ cfg: cfg.GraphExplorer, } diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index fa15eaf3607..f97daa3b8ed 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -6,7 +6,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/graph-explorer/pkg/config" - "github.com/owncloud/ocis/graph-explorer/pkg/flagset" "github.com/owncloud/ocis/graph-explorer/pkg/metrics" "github.com/owncloud/ocis/graph-explorer/pkg/server/debug" "github.com/owncloud/ocis/graph-explorer/pkg/server/http" @@ -20,24 +19,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - // When running on single binary mode the before hook from the root command won't get called. We manually - // call this before hook from ocis command, so the configuration can be loaded. - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - logger.Debug().Str("service", "graph-explorer").Msg("ignoring config file parsing when running supervised") - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) - tracing.Configure(cfg) var ( diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 12653c78c2e..c25d415de51 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -1,62 +1,58 @@ package config -import "context" +import ( + "context" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - Namespace string + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` } // Server configures a server. type Server struct { - Version string - Name string + Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // GraphExplorer defines the available graph-explorer configuration. type GraphExplorer struct { - ClientID string - Issuer string - GraphURLBase string - GraphURLPath string + ClientID string `ocisConfig:"client_id"` + Issuer string `ocisConfig:"issuer"` + GraphURLBase string `ocisConfig:"graph_url_base"` + GraphURLPath string `ocisConfig:"graph_url_path"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Server Server - Tracing Tracing - GraphExplorer GraphExplorer + File string `ocisConfig:"file"` + Log shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Server Server `ocisConfig:"server"` + Tracing Tracing `ocisConfig:"tracing"` + GraphExplorer GraphExplorer `ocisConfig:"graph_explorer"` Context context.Context Supervised bool @@ -66,3 +62,45 @@ type Config struct { func New() *Config { return &Config{} } + +// DefaultConfig provides with a working version of a config. +func DefaultConfig() *Config { + return &Config{ + Log: shared.Log{}, + 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", + }, + Server: Server{}, + Tracing: Tracing{ + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "graph-explorer", + }, + GraphExplorer: GraphExplorer{ + ClientID: "ocis-explorer.js", + Issuer: "https://localhost:9200", + GraphURLBase: "https://localhost:9200", + GraphURLPath: "/graph", + }, + } +} + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv() []string { + var r = make([]string, len(structMappings(&Config{}))) + for i := range structMappings(&Config{}) { + r = append(r, structMappings(&Config{})[i].EnvVars...) + } + + return r +} diff --git a/graph-explorer/pkg/config/mappings.go b/graph-explorer/pkg/config/mappings.go new file mode 100644 index 00000000000..85014e61b6e --- /dev/null +++ b/graph-explorer/pkg/config/mappings.go @@ -0,0 +1,96 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_EXPLORER_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_EXPLORER_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_EXPLORER_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_EXPLORER_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_EXPLORER_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_EXPLORER_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_EXPLORER_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_EXPLORER_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, + }, + { + EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_ISSUER"}, + Destination: &cfg.GraphExplorer.Issuer, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_CLIENT_ID"}, + Destination: &cfg.GraphExplorer.ClientID, + }, + { + EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_GRAPH_URL_BASE"}, + Destination: &cfg.GraphExplorer.GraphURLBase, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_PATH"}, + Destination: &cfg.GraphExplorer.GraphURLPath, + }, + } +} diff --git a/graph-explorer/pkg/flagset/flagset.go b/graph-explorer/pkg/flagset/flagset.go deleted file mode 100644 index 06acd9502a2..00000000000 --- a/graph-explorer/pkg/flagset/flagset.go +++ /dev/null @@ -1,169 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/graph-explorer/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"GRAPH_EXPLORER_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"GRAPH_EXPLORER_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"GRAPH_EXPLORER_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9136"), - Usage: "Address to debug endpoint", - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"GRAPH_EXPLORER_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"GRAPH_EXPLORER_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"GRAPH_EXPLORER_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"GRAPH_EXPLORER_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "graph-explorer"), - Usage: "Service name for tracing", - EnvVars: []string{"GRAPH_EXPLORER_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9136"), - Usage: "Address to bind debug server", - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"GRAPH_EXPLORER_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9135"), - Usage: "Address to bind http server", - EnvVars: []string{"GRAPH_EXPLORER_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/graph-explorer"), - Usage: "Root path of http server", - EnvVars: []string{"GRAPH_EXPLORER_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.HTTP.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http namespace", - EnvVars: []string{"GRAPH_EXPLORER_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - &cli.StringFlag{ - Name: "issuer", - Value: flags.OverrideDefaultString(cfg.GraphExplorer.Issuer, "https://localhost:9200"), - Usage: "Set the OpenID Connect Provider", - EnvVars: []string{"GRAPH_EXPLORER_ISSUER", "OCIS_URL"}, - Destination: &cfg.GraphExplorer.Issuer, - }, - &cli.StringFlag{ - Name: "client-id", - Value: flags.OverrideDefaultString(cfg.GraphExplorer.ClientID, "ocis-explorer.js"), - Usage: "Set the OpenID Client ID to send to the issuer", - EnvVars: []string{"GRAPH_EXPLORER_CLIENT_ID"}, - Destination: &cfg.GraphExplorer.ClientID, - }, - &cli.StringFlag{ - Name: "graph-url-base", - Value: flags.OverrideDefaultString(cfg.GraphExplorer.GraphURLBase, "https://localhost:9200"), - Usage: "Set the base url to the graph api service", - EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_BASE", "OCIS_URL"}, - Destination: &cfg.GraphExplorer.GraphURLBase, - }, - &cli.StringFlag{ - Name: "graph-url-path", - Value: flags.OverrideDefaultString(cfg.GraphExplorer.GraphURLPath, "/graph"), - Usage: "Set the url path to the graph api service", - EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_PATH"}, - Destination: &cfg.GraphExplorer.GraphURLPath, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} diff --git a/graph/pkg/command/health.go b/graph/pkg/command/health.go index 8fd0bef9c0a..509146e3fa6 100644 --- a/graph/pkg/command/health.go +++ b/graph/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/graph/pkg/config" - "github.com/owncloud/ocis/graph/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index c342d81b55b..20d07c88ea2 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -3,17 +3,15 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/thejerf/suture/v4" "github.com/owncloud/ocis/graph/pkg/config" - "github.com/owncloud/ocis/graph/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/spf13/viper" "github.com/urfave/cli/v2" ) @@ -24,32 +22,25 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve Graph API for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Server.Version = version.String return ParseConfig(c, cfg) }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), }, } - cli.HelpFlag = &cli.BoolFlag{ Name: "help,h", Usage: "Show the help", } - cli.VersionFlag = &cli.BoolFlag{ Name: "version,v", Usage: "Print the version", @@ -69,49 +60,28 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig reads graph configuration from fs. +// ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("GRAPH") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("graph") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("graph", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Info(). - Msg("Continue without config") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("Unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("Failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") - } - - return nil + conf.LoadOSEnv(config.GetEnv(cfg), false) + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree. @@ -121,10 +91,7 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Graph.Supervised = true - } - cfg.Graph.Log.File = cfg.Log.File + cfg.Graph.Commons = cfg.Commons return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index fb649db7b92..1c4341bcc73 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -6,7 +6,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/graph/pkg/config" - "github.com/owncloud/ocis/graph/pkg/flagset" "github.com/owncloud/ocis/graph/pkg/metrics" "github.com/owncloud/ocis/graph/pkg/server/debug" "github.com/owncloud/ocis/graph/pkg/server/http" @@ -20,19 +19,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - // When running on single binary mode the before hook from the root command won't get called. We manually - // call this before hook from ocis command, so the configuration can be loaded. - if !cfg.Supervised { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "graph").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index d766029dbfb..71a52845518 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -1,72 +1,70 @@ package config -import "context" +import ( + "context" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Root string `ocisConfig:"root"` } // Server configures a server. type Server struct { - Version string - Name string + Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Reva defines all available REVA configuration. type Reva struct { - Address string + Address string `ocisConfig:"address"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `ocisConfig:"jwt_secret"` } type Spaces struct { - WebDavBase string - WebDavPath string - DefaultQuota string + WebDavBase string `ocisConfig:"webdav_base"` + WebDavPath string `ocisConfig:"webdav_path"` + DefaultQuota string `ocisConfig:"default_quota"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Server Server - Tracing Tracing - Reva Reva - TokenManager TokenManager - Spaces Spaces + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Server Server `ocisConfig:"server"` + Tracing Tracing `ocisConfig:"tracing"` + Reva Reva `ocisConfig:"reva"` + TokenManager TokenManager `ocisConfig:"token_manager"` + Spaces Spaces `ocisConfig:"spaces"` Context context.Context Supervised bool @@ -76,3 +74,34 @@ type Config struct { func New() *Config { return &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.web", + Root: "/graph", + }, + Server: Server{}, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Service: "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", + }, + } +} diff --git a/graph/pkg/config/mappings.go b/graph/pkg/config/mappings.go new file mode 100644 index 00000000000..2c74cc9f17b --- /dev/null +++ b/graph/pkg/config/mappings.go @@ -0,0 +1,115 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"GRAPH_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"GRAPH_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"GRAPH_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"GRAPH_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"GRAPH_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"GRAPH_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"GRAPH_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"GRAPH_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"GRAPH_HTTP_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, + }, + { + EnvVars: []string{"OCIS_URL", "GRAPH_SPACES_WEBDAV_BASE"}, + Destination: &cfg.Spaces.WebDavBase, + }, + { + EnvVars: []string{"GRAPH_SPACES_WEBDAV_PATH"}, + Destination: &cfg.Spaces.WebDavPath, + }, + { + EnvVars: []string{"GRAPH_SPACES_DEFAULT_QUOTA"}, + Destination: &cfg.Spaces.DefaultQuota, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET", "GRAPH_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.Address, + }, + } +} diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go deleted file mode 100644 index 39326e8789d..00000000000 --- a/graph/pkg/flagset/flagset.go +++ /dev/null @@ -1,186 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/graph/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "config-file", - Value: flags.OverrideDefaultString(cfg.File, ""), - Usage: "Path to config file", - EnvVars: []string{"GRAPH_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"GRAPH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"GRAPH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"GRAPH_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9124"), - Usage: "Address to debug endpoint", - EnvVars: []string{"GRAPH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"GRAPH_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"GRAPH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"GRAPH_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"GRAPH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"GRAPH_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "graph"), - Usage: "Service name for tracing", - EnvVars: []string{"GRAPH_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9124"), - Usage: "Address to bind debug server", - EnvVars: []string{"GRAPH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"GRAPH_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"GRAPH_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"GRAPH_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9120"), - Usage: "Address to bind http server", - EnvVars: []string{"GRAPH_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/graph"), - Usage: "Root path of http server", - EnvVars: []string{"GRAPH_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.HTTP.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http service for service discovery", - EnvVars: []string{"GRAPH_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - - &cli.StringFlag{ - Name: "spaces-webdav-base", - Value: flags.OverrideDefaultString(cfg.Spaces.WebDavBase, "https://localhost:9200"), - Usage: "spaces webdav base URL to use when rendering drive WabDAV URLs", - EnvVars: []string{"GRAPH_SPACES_WEBDAV_BASE", "OCIS_URL"}, - Destination: &cfg.Spaces.WebDavBase, - }, - &cli.StringFlag{ - Name: "spaces-webdav-path", - Value: flags.OverrideDefaultString(cfg.Spaces.WebDavPath, "/dav/spaces/"), - Usage: "spaces webdav path to use when rendering drive WabDAV URLs", - EnvVars: []string{"GRAPH_SPACES_WEBDAV_PATH"}, - Destination: &cfg.Spaces.WebDavPath, - }, - - &cli.StringFlag{ - Name: "default-space-quota", - Value: flags.OverrideDefaultString(cfg.Spaces.DefaultQuota, "1000000000"), - Usage: "default quota used for all spaces if no custom quota was given", - EnvVars: []string{"GRAPH_SPACES_DEFAULT_QUOTA"}, - Destination: &cfg.Spaces.DefaultQuota, - }, - - &cli.StringFlag{ - Name: "jwt-secret", - Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"), - Usage: "Used to validate the reva access JWT, should equal reva's jwt-secret", - EnvVars: []string{"GRAPH_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Address, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Address, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} diff --git a/idp/cmd/idp/main.go b/idp/cmd/idp/main.go index 10bf21ffe88..c60ac2f401a 100644 --- a/idp/cmd/idp/main.go +++ b/idp/cmd/idp/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/idp/pkg/command/health.go b/idp/pkg/command/health.go index 7e03cabc723..813470bd483 100644 --- a/idp/pkg/command/health.go +++ b/idp/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 640e750356b..e0d5ba775f7 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" + + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/flagset" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -23,16 +21,12 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve IDP API for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Service.Version = version.String return nil @@ -69,49 +63,30 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig load configuration for every extension +// ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("IDP") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("idp") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("idp", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(cfg), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the idp command to be embedded and supervised by a suture supervisor tree. @@ -121,10 +96,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.IDP.Supervised = true - } - cfg.IDP.Log.File = cfg.Log.File + cfg.IDP.Commons = cfg.Commons return SutureService{ cfg: cfg.IDP, } diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index 425fc8ad133..c9f943ebca2 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -6,7 +6,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/flagset" "github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" @@ -20,31 +19,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + if err := ParseConfig(ctx, cfg); err != nil { + return err } - // StringSliceFlag doesn't support Destination - // UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli - if len(ctx.StringSlice("trusted-proxy")) > 0 { - cfg.IDP.TrustedProxy = ctx.StringSlice("trusted-proxy") - } - - if len(ctx.StringSlice("allow-scope")) > 0 { - cfg.IDP.AllowScope = ctx.StringSlice("allow-scope") - } - - if len(ctx.StringSlice("signing-private-key")) > 0 { - cfg.IDP.SigningPrivateKeyFiles = ctx.StringSlice("signing-private-key") + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - logger.Debug().Str("service", "idp").Msg("ignoring config file parsing when running supervised") return nil }, Action: func(c *cli.Context) error { diff --git a/idp/pkg/command/version.go b/idp/pkg/command/version.go index 5f43da13215..7408d59f617 100644 --- a/idp/pkg/command/version.go +++ b/idp/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListIDPWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 3fac9d0d1ee..ffb7e781e4d 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -2,82 +2,113 @@ package config import ( "context" + "path" - "github.com/libregraph/lico/bootstrap" -) + "github.com/owncloud/ocis/ocis-pkg/shared" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - TLSCert string - TLSKey string - TLS bool + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + TLSCert string `ocisConfig:"tls_cert"` + TLSKey string `ocisConfig:"tls_key"` + TLS bool `ocisConfig:"tls"` } // Ldap defines the available LDAP configuration. type Ldap struct { - URI string - BindDN string - BindPassword string - BaseDN string - Scope string - LoginAttribute string - EmailAttribute string - NameAttribute string - UUIDAttribute string - UUIDAttributeType string - Filter string + URI string `ocisConfig:"uri"` + BindDN string `ocisConfig:"bind_dn"` + BindPassword string `ocisConfig:"bind_password"` + BaseDN string `ocisConfig:"base_dn"` + Scope string `ocisConfig:"scope"` + LoginAttribute string `ocisConfig:"login_attribute"` + EmailAttribute string `ocisConfig:"email_attribute"` + NameAttribute string `ocisConfig:"name_attribute"` + UUIDAttribute string `ocisConfig:"uuid_attribute"` + UUIDAttributeType string `ocisConfig:"uuid_attribute_type"` + Filter string `ocisConfig:"filter"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `ocisConfig:"asset"` +} + +type Settings struct { + Iss string `ocisConfig:"iss"` + IdentityManager string `ocisConfig:"identity_manager"` + URIBasePath string `ocisConfig:"uri_base_path"` + SignInURI string `ocisConfig:"sign_in_uri"` + SignedOutURI string `ocisConfig:"signed_out_uri"` + AuthorizationEndpointURI string `ocisConfig:"authorization_endpoint_uri"` + EndsessionEndpointURI string `ocisConfig:"end_session_endpoint_uri"` + Insecure bool `ocisConfig:"insecure"` + TrustedProxy []string `ocisConfig:"trusted_proxy"` + AllowScope []string `ocisConfig:"allow_scope"` + AllowClientGuests bool `ocisConfig:"allow_client_guests"` + AllowDynamicClientRegistration bool `ocisConfig:"allow_dynamic_client_registration"` + EncryptionSecretFile string `ocisConfig:"encrypt_secret_file"` + Listen string `ocisConfig:"listen"` + IdentifierClientDisabled bool `ocisConfig:"identifier_client_disabled"` + IdentifierClientPath string `ocisConfig:"identifier_client_path"` + IdentifierRegistrationConf string `ocisConfig:"identifier_registration_conf"` + IdentifierScopesConf string `ocisConfig:"identifier_scopes_conf"` + IdentifierDefaultBannerLogo string `ocisConfig:"identifier_default_banner_logo"` + IdentifierDefaultSignInPageText string `ocisConfig:"identifier_default_sign_in_page_text"` + IdentifierDefaultUsernameHintText string `ocisConfig:"identifier_default_username_hint_text"` + SigningKid string `ocisConfig:"sign_in_kid"` + SigningMethod string `ocisConfig:"sign_in_method"` + SigningPrivateKeyFiles []string `ocisConfig:"sign_in_private_key_files"` + ValidationKeysPath string `ocisConfig:"validation_keys_path"` + CookieBackendURI string `ocisConfig:"cookie_backend_uri"` + CookieNames []string `ocisConfig:"cookie_names"` + AccessTokenDurationSeconds uint64 `ocisConfig:"access_token_duration_seconds"` + IDTokenDurationSeconds uint64 `ocisConfig:"id_token_duration_seconds"` + RefreshTokenDurationSeconds uint64 `ocisConfig:"refresh_token_duration_seconds"` + DyamicClientSecretDurationSeconds uint64 `ocisConfig:"dynamic_client_secret_duration_seconds"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Tracing Tracing - Asset Asset - IDP bootstrap.Settings - Ldap Ldap - Service Service + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Tracing Tracing `ocisConfig:"tracing"` + Asset Asset `ocisConfig:"asset"` + IDP Settings `ocisConfig:"idp"` + Ldap Ldap `ocisConfig:"ldap"` + Service Service `ocisConfig:"service"` Context context.Context Supervised bool @@ -87,3 +118,75 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9134", + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9130", + Root: "/", + TLSCert: path.Join(defaults.BaseDataPath(), "idp", "server.crt"), + TLSKey: path.Join(defaults.BaseDataPath(), "idp", "server.key"), + TLS: false, + }, + Tracing: Tracing{ + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "idp", + }, + Asset: Asset{}, + IDP: Settings{ + Iss: "https://localhost:9200", + IdentityManager: "ldap", + URIBasePath: "", + SignInURI: "", + SignedOutURI: "", + AuthorizationEndpointURI: "", + EndsessionEndpointURI: "", + Insecure: false, + TrustedProxy: nil, + AllowScope: nil, + AllowClientGuests: false, + AllowDynamicClientRegistration: false, + EncryptionSecretFile: "", + Listen: "", + IdentifierClientDisabled: true, + IdentifierClientPath: path.Join(defaults.BaseDataPath(), "idp"), + IdentifierRegistrationConf: path.Join(defaults.BaseDataPath(), "idp", "identifier-registration.yaml"), + IdentifierScopesConf: "", + IdentifierDefaultBannerLogo: "", + IdentifierDefaultSignInPageText: "", + IdentifierDefaultUsernameHintText: "", + SigningKid: "", + SigningMethod: "PS256", + SigningPrivateKeyFiles: nil, + ValidationKeysPath: "", + CookieBackendURI: "", + CookieNames: nil, + AccessTokenDurationSeconds: 60 * 10, // 10 minutes + IDTokenDurationSeconds: 60 * 60, // 1 hour + RefreshTokenDurationSeconds: 60 * 60 * 24 * 365 * 3, // 1 year + DyamicClientSecretDurationSeconds: 0, + }, + Ldap: Ldap{ + URI: "ldap://localhost:9125", + BindDN: "cn=idp,ou=sysusers,dc=ocis,dc=test", + BindPassword: "idp", + BaseDN: "ou=users,dc=ocis,dc=test", + Scope: "sub", + LoginAttribute: "cn", + EmailAttribute: "mail", + NameAttribute: "sn", + UUIDAttribute: "uid", + UUIDAttributeType: "text", + Filter: "(objectClass=posixaccount)", + }, + Service: Service{ + Name: "idp", + Namespace: "com.owncloud.web", + }, + } +} diff --git a/idp/pkg/config/mappings.go b/idp/pkg/config/mappings.go new file mode 100644 index 00000000000..68383fe5c78 --- /dev/null +++ b/idp/pkg/config/mappings.go @@ -0,0 +1,243 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL", "IDP_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "IDP_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "IDP_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "IDP_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"IDP_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "IDP_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "IDP_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "IDP_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "IDP_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"IDP_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"IDP_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"IDP_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"IDP_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"IDP_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"IDP_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"IDP_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"IDP_HTTP_NAMESPACE"}, + Destination: &cfg.Service.Namespace, + }, + { + EnvVars: []string{"IDP_NAME"}, + Destination: &cfg.Service.Name, + }, + { + EnvVars: []string{"IDP_IDENTITY_MANAGER"}, + Destination: &cfg.IDP.IdentityManager, + }, + { + EnvVars: []string{"IDP_LDAP_URI"}, + Destination: &cfg.Ldap.URI, + }, + { + EnvVars: []string{"IDP_LDAP_BIND_DN"}, + Destination: &cfg.Ldap.BindDN, + }, + { + EnvVars: []string{"IDP_LDAP_BIND_PASSWORD"}, + Destination: &cfg.Ldap.BindPassword, + }, + { + EnvVars: []string{"IDP_LDAP_BASE_DN"}, + Destination: &cfg.Ldap.BaseDN, + }, + { + EnvVars: []string{"IDP_LDAP_SCOPE"}, + Destination: &cfg.Ldap.Scope, + }, + { + EnvVars: []string{"IDP_LDAP_LOGIN_ATTRIBUTE"}, + Destination: &cfg.Ldap.LoginAttribute, + }, + { + EnvVars: []string{"IDP_LDAP_EMAIL_ATTRIBUTE"}, + Destination: &cfg.Ldap.EmailAttribute, + }, + { + EnvVars: []string{"IDP_LDAP_NAME_ATTRIBUTE"}, + Destination: &cfg.Ldap.NameAttribute, + }, + { + EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE"}, + Destination: &cfg.Ldap.UUIDAttribute, + }, + { + EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE_TYPE"}, + Destination: &cfg.Ldap.UUIDAttributeType, + }, + { + EnvVars: []string{"IDP_LDAP_FILTER"}, + Destination: &cfg.Ldap.Filter, + }, + { + EnvVars: []string{"IDP_TRANSPORT_TLS_CERT"}, + Destination: &cfg.HTTP.TLSCert, + }, + { + EnvVars: []string{"IDP_TRANSPORT_TLS_KEY"}, + Destination: &cfg.HTTP.TLSKey, + }, + { + EnvVars: []string{"OCIS_URL", "IDP_ISS"}, // IDP_ISS takes precedence over OCIS_URL + Destination: &cfg.IDP.Iss, + }, + { + EnvVars: []string{"IDP_SIGNING_KID"}, + Destination: &cfg.IDP.SigningKid, + }, + { + EnvVars: []string{"IDP_VALIDATION_KEYS_PATH"}, + Destination: &cfg.IDP.ValidationKeysPath, + }, + { + EnvVars: []string{"IDP_ENCRYPTION_SECRET"}, + Destination: &cfg.IDP.EncryptionSecretFile, + }, + { + EnvVars: []string{"IDP_SIGNING_METHOD"}, + Destination: &cfg.IDP.SigningMethod, + }, + { + EnvVars: []string{"IDP_URI_BASE_PATH"}, + Destination: &cfg.IDP.URIBasePath, + }, + { + EnvVars: []string{"IDP_SIGN_IN_URI"}, + Destination: &cfg.IDP.SignInURI, + }, + { + EnvVars: []string{"IDP_SIGN_OUT_URI"}, + Destination: &cfg.IDP.SignedOutURI, + }, + { + EnvVars: []string{"IDP_ENDPOINT_URI"}, + Destination: &cfg.IDP.AuthorizationEndpointURI, + }, + { + EnvVars: []string{"IDP_ENDSESSION_ENDPOINT_URI"}, + Destination: &cfg.IDP.EndsessionEndpointURI, + }, + { + EnvVars: []string{"IDP_ASSET_PATH"}, + Destination: &cfg.Asset.Path, + }, + { + EnvVars: []string{"IDP_IDENTIFIER_CLIENT_PATH"}, + Destination: &cfg.IDP.IdentifierClientPath, + }, + { + EnvVars: []string{"IDP_IDENTIFIER_REGISTRATION_CONF"}, + Destination: &cfg.IDP.IdentifierRegistrationConf, + }, + { + EnvVars: []string{"IDP_IDENTIFIER_SCOPES_CONF"}, + Destination: &cfg.IDP.IdentifierScopesConf, + }, + { + EnvVars: []string{"IDP_INSECURE"}, + Destination: &cfg.IDP.Insecure, + }, + { + EnvVars: []string{"IDP_TLS"}, + Destination: &cfg.HTTP.TLS, + }, + { + EnvVars: []string{"IDP_ALLOW_CLIENT_GUESTS"}, + Destination: &cfg.IDP.AllowClientGuests, + }, + { + EnvVars: []string{"IDP_ALLOW_DYNAMIC_CLIENT_REGISTRATION"}, + Destination: &cfg.IDP.AllowDynamicClientRegistration, + }, + { + EnvVars: []string{"IDP_DISABLE_IDENTIFIER_WEBAPP"}, + Destination: &cfg.IDP.IdentifierClientDisabled, + }, + { + EnvVars: []string{"IDP_ACCESS_TOKEN_EXPIRATION"}, + Destination: &cfg.IDP.AccessTokenDurationSeconds, + }, + { + EnvVars: []string{"IDP_ID_TOKEN_EXPIRATION"}, + Destination: &cfg.IDP.IDTokenDurationSeconds, + }, + { + EnvVars: []string{"IDP_REFRESH_TOKEN_EXPIRATION"}, + Destination: &cfg.IDP.RefreshTokenDurationSeconds, + }, + } +} diff --git a/idp/pkg/flagset/flagset.go b/idp/pkg/flagset/flagset.go deleted file mode 100644 index d9c9af81bfa..00000000000 --- a/idp/pkg/flagset/flagset.go +++ /dev/null @@ -1,446 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"IDP_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"IDP_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"IDP_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9134"), - Usage: "Address to debug endpoint", - EnvVars: []string{"IDP_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"IDP_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "config-file", - Value: flags.OverrideDefaultString(cfg.File, ""), - Usage: "Path to config file", - EnvVars: []string{"IDP_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"IDP_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"IDP_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"IDP_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"IDP_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "idp"), - Usage: "Service name for tracing", - EnvVars: []string{"IDP_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9134"), - Usage: "Address to bind debug server", - EnvVars: []string{"IDP_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"IDP_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"IDP_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"IDP_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9130"), - Usage: "Address to bind http server", - EnvVars: []string{"IDP_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/"), - Usage: "Root path of http server", - EnvVars: []string{"IDP_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for service discovery", - EnvVars: []string{"IDP_HTTP_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "idp"), - Usage: "Service name", - EnvVars: []string{"IDP_NAME"}, - Destination: &cfg.Service.Name, - }, - &cli.StringFlag{ - Name: "identity-manager", - Value: flags.OverrideDefaultString(cfg.IDP.IdentityManager, "ldap"), - Usage: "Identity manager (one of ldap,kc,cookie,dummy)", - EnvVars: []string{"IDP_IDENTITY_MANAGER"}, - Destination: &cfg.IDP.IdentityManager, - }, - &cli.StringFlag{ - Name: "ldap-uri", - Value: flags.OverrideDefaultString(cfg.Ldap.URI, "ldap://localhost:9125"), - Usage: "URI of the LDAP server (glauth)", - EnvVars: []string{"IDP_LDAP_URI"}, - Destination: &cfg.Ldap.URI, - }, - &cli.StringFlag{ - Name: "ldap-bind-dn", - Value: flags.OverrideDefaultString(cfg.Ldap.BindDN, "cn=idp,ou=sysusers,dc=ocis,dc=test"), - Usage: "Bind DN for the LDAP server (glauth)", - EnvVars: []string{"IDP_LDAP_BIND_DN"}, - Destination: &cfg.Ldap.BindDN, - }, - &cli.StringFlag{ - Name: "ldap-bind-password", - Value: flags.OverrideDefaultString(cfg.Ldap.BindPassword, "idp"), - Usage: "Password for the Bind DN of the LDAP server (glauth)", - EnvVars: []string{"IDP_LDAP_BIND_PASSWORD"}, - Destination: &cfg.Ldap.BindPassword, - }, - &cli.StringFlag{ - Name: "ldap-base-dn", - Value: flags.OverrideDefaultString(cfg.Ldap.BaseDN, "ou=users,dc=ocis,dc=test"), - Usage: "LDAP base DN of the oCIS users", - EnvVars: []string{"IDP_LDAP_BASE_DN"}, - Destination: &cfg.Ldap.BaseDN, - }, - &cli.StringFlag{ - Name: "ldap-scope", - Value: flags.OverrideDefaultString(cfg.Ldap.Scope, "sub"), - Usage: "LDAP scope of the oCIS users", - EnvVars: []string{"IDP_LDAP_SCOPE"}, - Destination: &cfg.Ldap.Scope, - }, - &cli.StringFlag{ - Name: "ldap-login-attribute", - Value: flags.OverrideDefaultString(cfg.Ldap.LoginAttribute, "cn"), - Usage: "LDAP login attribute of the oCIS users", - EnvVars: []string{"IDP_LDAP_LOGIN_ATTRIBUTE"}, - Destination: &cfg.Ldap.LoginAttribute, - }, - &cli.StringFlag{ - Name: "ldap-email-attribute", - Value: flags.OverrideDefaultString(cfg.Ldap.EmailAttribute, "mail"), - Usage: "LDAP email attribute of the oCIS users", - EnvVars: []string{"IDP_LDAP_EMAIL_ATTRIBUTE"}, - Destination: &cfg.Ldap.EmailAttribute, - }, - &cli.StringFlag{ - Name: "ldap-name-attribute", - Value: flags.OverrideDefaultString(cfg.Ldap.NameAttribute, "sn"), - Usage: "LDAP name attribute of the oCIS users", - EnvVars: []string{"IDP_LDAP_NAME_ATTRIBUTE"}, - Destination: &cfg.Ldap.NameAttribute, - }, - &cli.StringFlag{ - Name: "ldap-uuid-attribute", - Value: flags.OverrideDefaultString(cfg.Ldap.UUIDAttribute, "uid"), - Usage: "LDAP UUID attribute of the oCIS users", - EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE"}, - Destination: &cfg.Ldap.UUIDAttribute, - }, - &cli.StringFlag{ - Name: "ldap-uuid-attribute-type", - Value: flags.OverrideDefaultString(cfg.Ldap.UUIDAttributeType, "text"), - Usage: "LDAP UUID attribute type of the oCIS users", - EnvVars: []string{"IDP_LDAP_UUID_ATTRIBUTE_TYPE"}, - Destination: &cfg.Ldap.UUIDAttributeType, - }, - &cli.StringFlag{ - Name: "ldap-filter", - Value: flags.OverrideDefaultString(cfg.Ldap.Filter, "(objectClass=posixaccount)"), - Usage: "LDAP filter of the oCIS users", - EnvVars: []string{"IDP_LDAP_FILTER"}, - Destination: &cfg.Ldap.Filter, - }, - &cli.StringFlag{ - Name: "transport-tls-cert", - Value: flags.OverrideDefaultString(cfg.HTTP.TLSCert, path.Join(defaults.BaseDataPath(), "idp", "server.crt")), - Usage: "Certificate file for transport encryption", - EnvVars: []string{"IDP_TRANSPORT_TLS_CERT"}, - Destination: &cfg.HTTP.TLSCert, - }, - &cli.StringFlag{ - Name: "transport-tls-key", - Value: flags.OverrideDefaultString(cfg.HTTP.TLSKey, path.Join(defaults.BaseDataPath(), "idp", "server.key")), - Usage: "Secret file for transport encryption", - EnvVars: []string{"IDP_TRANSPORT_TLS_KEY"}, - Destination: &cfg.HTTP.TLSKey, - }, - &cli.StringFlag{ - Name: "iss", - Value: flags.OverrideDefaultString(cfg.IDP.Iss, "https://localhost:9200"), - Usage: "OIDC issuer URL", - EnvVars: []string{"IDP_ISS", "OCIS_URL"}, // IDP_ISS takes precedence over OCIS_URL - Destination: &cfg.IDP.Iss, - }, - &cli.StringSliceFlag{ - Name: "signing-private-key", - Usage: "Full path to PEM encoded private key file (must match the --signing-method algorithm)", - EnvVars: []string{"IDP_SIGNING_PRIVATE_KEY"}, - Value: nil, - }, - &cli.StringFlag{ - Name: "signing-kid", - Usage: "Value of kid field to use in created tokens (uniquely identifying the signing-private-key)", - EnvVars: []string{"IDP_SIGNING_KID"}, - Value: flags.OverrideDefaultString(cfg.IDP.SigningKid, ""), - Destination: &cfg.IDP.SigningKid, - }, - &cli.StringFlag{ - Name: "validation-keys-path", - Usage: "Full path to a folder containing PEM encoded private or public key files used for token validation (file name without extension is used as kid)", - EnvVars: []string{"IDP_VALIDATION_KEYS_PATH"}, - Value: flags.OverrideDefaultString(cfg.IDP.ValidationKeysPath, ""), - Destination: &cfg.IDP.ValidationKeysPath, - }, - &cli.StringFlag{ - Name: "encryption-secret", - Usage: "Full path to a file containing a %d bytes secret key", - EnvVars: []string{"IDP_ENCRYPTION_SECRET"}, - Value: flags.OverrideDefaultString(cfg.IDP.EncryptionSecretFile, ""), - Destination: &cfg.IDP.EncryptionSecretFile, - }, - &cli.StringFlag{ - Name: "signing-method", - Usage: "JWT default signing method", - EnvVars: []string{"IDP_SIGNING_METHOD"}, - Value: flags.OverrideDefaultString(cfg.IDP.SigningMethod, "PS256"), - Destination: &cfg.IDP.SigningMethod, - }, - &cli.StringFlag{ - Name: "uri-base-path", - Usage: "Custom base path for URI endpoints", - EnvVars: []string{"IDP_URI_BASE_PATH"}, - Value: flags.OverrideDefaultString(cfg.IDP.URIBasePath, ""), - Destination: &cfg.IDP.URIBasePath, - }, - &cli.StringFlag{ - Name: "sign-in-uri", - Usage: "Custom redirection URI to sign-in form", - EnvVars: []string{"IDP_SIGN_IN_URI"}, - Value: flags.OverrideDefaultString(cfg.IDP.SignInURI, ""), - Destination: &cfg.IDP.SignInURI, - }, - &cli.StringFlag{ - Name: "signed-out-uri", - Usage: "Custom redirection URI to signed-out goodbye page", - EnvVars: []string{"IDP_SIGN_OUT_URI"}, - Value: flags.OverrideDefaultString(cfg.IDP.SignedOutURI, ""), - Destination: &cfg.IDP.SignedOutURI, - }, - &cli.StringFlag{ - Name: "authorization-endpoint-uri", - Usage: "Custom authorization endpoint URI", - EnvVars: []string{"IDP_ENDPOINT_URI"}, - Value: flags.OverrideDefaultString(cfg.IDP.AuthorizationEndpointURI, ""), - Destination: &cfg.IDP.AuthorizationEndpointURI, - }, - &cli.StringFlag{ - Name: "endsession-endpoint-uri", - Usage: "Custom endsession endpoint URI", - EnvVars: []string{"IDP_ENDSESSION_ENDPOINT_URI"}, - Value: flags.OverrideDefaultString(cfg.IDP.EndsessionEndpointURI, ""), - Destination: &cfg.IDP.EndsessionEndpointURI, - }, - &cli.StringFlag{ - Name: "asset-path", - Value: flags.OverrideDefaultString(cfg.Asset.Path, ""), - Usage: "Path to custom assets", - EnvVars: []string{"IDP_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - &cli.StringFlag{ - Name: "identifier-client-path", - Usage: "Path to the identifier web client base folder", - EnvVars: []string{"IDP_IDENTIFIER_CLIENT_PATH"}, - Value: flags.OverrideDefaultString(cfg.IDP.IdentifierClientPath, path.Join(defaults.BaseDataPath(), "idp")), - Destination: &cfg.IDP.IdentifierClientPath, - }, - &cli.StringFlag{ - Name: "identifier-registration-conf", - Usage: "Path to a identifier-registration.yaml configuration file", - EnvVars: []string{"IDP_IDENTIFIER_REGISTRATION_CONF"}, - Value: flags.OverrideDefaultString(cfg.IDP.IdentifierRegistrationConf, path.Join(defaults.BaseDataPath(), "idp", "identifier-registration.yaml")), - Destination: &cfg.IDP.IdentifierRegistrationConf, - }, - &cli.StringFlag{ - Name: "identifier-scopes-conf", - Usage: "Path to a scopes.yaml configuration file", - EnvVars: []string{"IDP_IDENTIFIER_SCOPES_CONF"}, - Value: flags.OverrideDefaultString(cfg.IDP.IdentifierScopesConf, ""), - Destination: &cfg.IDP.IdentifierScopesConf, - }, - &cli.BoolFlag{ - Name: "insecure", - Usage: "Disable TLS certificate and hostname validation", - Value: flags.OverrideDefaultBool(cfg.IDP.Insecure, false), - EnvVars: []string{"IDP_INSECURE"}, - Destination: &cfg.IDP.Insecure, - }, - &cli.BoolFlag{ - Name: "tls", - Usage: "Use TLS (disable only if idp is behind a TLS-terminating reverse-proxy).", - EnvVars: []string{"IDP_TLS"}, - Value: flags.OverrideDefaultBool(cfg.HTTP.TLS, false), - Destination: &cfg.HTTP.TLS, - }, - &cli.StringSliceFlag{ - Name: "trusted-proxy", - Usage: "Trusted proxy IP or IP network (can be used multiple times)", - EnvVars: []string{"IDP_TRUSTED_PROXY"}, - Value: nil, - }, - &cli.StringSliceFlag{ - Name: "allow-scope", - Usage: "Allow OAuth 2 scope (can be used multiple times, if not set default scopes are allowed)", - EnvVars: []string{"IDP_ALLOW_SCOPE"}, - Value: nil, - }, - &cli.BoolFlag{ - Name: "allow-client-guests", - Usage: "Allow sign in of client controlled guest users", - EnvVars: []string{"IDP_ALLOW_CLIENT_GUESTS"}, - Destination: &cfg.IDP.AllowClientGuests, - }, - &cli.BoolFlag{ - Name: "allow-dynamic-client-registration", - Usage: "Allow dynamic OAuth2 client registration", - EnvVars: []string{"IDP_ALLOW_DYNAMIC_CLIENT_REGISTRATION"}, - Value: flags.OverrideDefaultBool(cfg.IDP.AllowDynamicClientRegistration, false), - Destination: &cfg.IDP.AllowDynamicClientRegistration, - }, - &cli.BoolFlag{ - Name: "disable-identifier-webapp", - Usage: "Disable built-in identifier-webapp to use a frontend hosted elsewhere.", - EnvVars: []string{"IDP_DISABLE_IDENTIFIER_WEBAPP"}, - Value: flags.OverrideDefaultBool(cfg.IDP.IdentifierClientDisabled, true), - Destination: &cfg.IDP.IdentifierClientDisabled, - }, - &cli.Uint64Flag{ - Name: "access-token-expiration", - Usage: "Expiration time of access tokens in seconds since generated", - EnvVars: []string{"IDP_ACCESS_TOKEN_EXPIRATION"}, - Destination: &cfg.IDP.AccessTokenDurationSeconds, - Value: flags.OverrideDefaultUint64(cfg.IDP.AccessTokenDurationSeconds, 60*10), // 10 minutes - }, - &cli.Uint64Flag{ - Name: "id-token-expiration", - Usage: "Expiration time of id tokens in seconds since generated", - EnvVars: []string{"IDP_ID_TOKEN_EXPIRATION"}, - Destination: &cfg.IDP.IDTokenDurationSeconds, - Value: flags.OverrideDefaultUint64(cfg.IDP.IDTokenDurationSeconds, 60*60), // 1 hour - }, - &cli.Uint64Flag{ - Name: "refresh-token-expiration", - Usage: "Expiration time of refresh tokens in seconds since generated", - EnvVars: []string{"IDP_REFRESH_TOKEN_EXPIRATION"}, - Destination: &cfg.IDP.RefreshTokenDurationSeconds, - Value: flags.OverrideDefaultUint64(cfg.IDP.RefreshTokenDurationSeconds, 60*60*24*365*3), // 1 year - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} - -// ListIDPWithConfig applies the config to the list commands flags -func ListIDPWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{&cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for service discovery", - EnvVars: []string{"IDP_HTTP_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "idp"), - Usage: "Service name", - EnvVars: []string{"IDP_NAME"}, - Destination: &cfg.Service.Name, - }, - } -} diff --git a/idp/pkg/service/v0/service.go b/idp/pkg/service/v0/service.go index c149b11af47..0f949a91a1b 100644 --- a/idp/pkg/service/v0/service.go +++ b/idp/pkg/service/v0/service.go @@ -55,7 +55,10 @@ func NewService(opts ...Option) Service { dummyBackendSupport.MustRegister() kcBackendSupport.MustRegister() - bs, err := bootstrap.Boot(ctx, &options.Config.IDP, &licoconfig.Config{ + // https://play.golang.org/p/Mh8AVJCd593 + idpSettings := bootstrap.Settings(options.Config.IDP) + + bs, err := bootstrap.Boot(ctx, &idpSettings, &licoconfig.Config{ Logger: logw.Wrap(logger), }) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 01ca3187f18..c2c78541e9d 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -1,6 +1,8 @@ package config import ( + "github.com/owncloud/ocis/ocis-pkg/shared" + accounts "github.com/owncloud/ocis/accounts/pkg/config" glauth "github.com/owncloud/ocis/glauth/pkg/config" graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/config" @@ -16,45 +18,37 @@ import ( webdav "github.com/owncloud/ocis/webdav/pkg/config" ) -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} - // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string + Addr string `ocisConfig:"addr"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `ocisConfig:"jwt_secret"` } const ( @@ -69,58 +63,206 @@ type Mode int // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { - Port string - Host string - Extensions string + Port string `ocisConfig:"port"` + Host string `ocisConfig:"host"` + Extensions string `ocisConfig:"extensions"` } // Config combines all available configuration parts. type Config struct { - // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regards of - // what it does. Supervised (0) loads configuration from a unified config file because of known limitations of Viper; whereas - // Unsupervised (1) MUST parse config from all known sources. - Mode Mode - File string - - Registry string - Log Log - Debug Debug - HTTP HTTP - GRPC GRPC - Tracing Tracing - TokenManager TokenManager - Runtime Runtime - - Accounts *accounts.Config - GLAuth *glauth.Config - Graph *graph.Config - GraphExplorer *graphExplorer.Config - IDP *idp.Config - OCS *ocs.Config - Web *web.Config - Proxy *proxy.Config - Settings *settings.Config - Storage *storage.Config - Store *store.Config - Thumbnails *thumbnails.Config - WebDAV *webdav.Config + *shared.Commons `ocisConfig:"shared"` + + Mode Mode // DEPRECATED + File string + OcisURL string `ocisConfig:"ocis_url"` + + Registry string `ocisConfig:"registry"` + Log shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` + Tracing Tracing `ocisConfig:"tracing"` + TokenManager TokenManager `ocisConfig:"token_manager"` + Runtime Runtime `ocisConfig:"runtime"` + + Accounts *accounts.Config `ocisConfig:"accounts"` + GLAuth *glauth.Config `ocisConfig:"glauth"` + Graph *graph.Config `ocisConfig:"graph"` + GraphExplorer *graphExplorer.Config `ocisConfig:"graph_explorer"` + IDP *idp.Config `ocisConfig:"idp"` + OCS *ocs.Config `ocisConfig:"ocs"` + Web *web.Config `ocisConfig:"web"` + Proxy *proxy.Config `ocisConfig:"proxy"` + Settings *settings.Config `ocisConfig:"settings"` + Storage *storage.Config `ocisConfig:"storage"` + Store *store.Config `ocisConfig:"store"` + Thumbnails *thumbnails.Config `ocisConfig:"thumbnails"` + WebDAV *webdav.Config `ocisConfig:"webdav"` } // New initializes a new configuration with or without defaults. func New() *Config { return &Config{ - Accounts: accounts.New(), - GLAuth: glauth.New(), - Graph: graph.New(), - GraphExplorer: graphExplorer.New(), - IDP: idp.New(), - OCS: ocs.New(), - Web: web.New(), - Proxy: proxy.New(), - Settings: settings.New(), - Storage: storage.New(), - Store: store.New(), - Thumbnails: thumbnails.New(), - WebDAV: webdav.New(), + Accounts: accounts.DefaultConfig(), + GLAuth: glauth.DefaultConfig(), + Graph: graph.DefaultConfig(), + IDP: idp.DefaultConfig(), + Proxy: proxy.DefaultConfig(), + GraphExplorer: graphExplorer.DefaultConfig(), + OCS: ocs.DefaultConfig(), + Settings: settings.DefaultConfig(), + Web: web.DefaultConfig(), + Store: store.DefaultConfig(), + Thumbnails: thumbnails.DefaultConfig(), + WebDAV: webdav.DefaultConfig(), + Storage: storage.DefaultConfig(), + } +} + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9010", + Token: "", + Pprof: false, + Zpages: false, + }, + HTTP: HTTP{ + Addr: "127.0.0.1:9000", + Root: "/", + }, + GRPC: GRPC{ + Addr: "127.0.0.1:9001", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "ocis", + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Runtime: Runtime{ + Port: "9250", + Host: "localhost", + }, + Accounts: accounts.DefaultConfig(), + GLAuth: glauth.DefaultConfig(), + Graph: graph.DefaultConfig(), + IDP: idp.DefaultConfig(), + Proxy: proxy.DefaultConfig(), + GraphExplorer: graphExplorer.DefaultConfig(), + OCS: ocs.DefaultConfig(), + Settings: settings.DefaultConfig(), + Web: web.DefaultConfig(), + Store: store.DefaultConfig(), + Thumbnails: thumbnails.DefaultConfig(), + WebDAV: webdav.DefaultConfig(), + Storage: storage.DefaultConfig(), + } +} + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv() []string { + var r = make([]string, len(structMappings(&Config{}))) + for i := range structMappings(&Config{}) { + r = append(r, structMappings(&Config{})[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"OCIS_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + { + EnvVars: []string{"OCIS_RUNTIME_PORT"}, + Destination: &cfg.Runtime.Port, + }, + { + EnvVars: []string{"OCIS_RUNTIME_HOST"}, + Destination: &cfg.Runtime.Host, + }, + { + EnvVars: []string{"OCIS_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"OCIS_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"OCIS_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"OCIS_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"OCIS_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"OCIS_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"OCIS_GRPC_ADDR"}, + Destination: &cfg.GRPC.Addr, + }, + { + EnvVars: []string{"OCIS_RUN_EXTENSIONS"}, + Destination: &cfg.Runtime.Extensions, + }, } } diff --git a/ocis-pkg/config/config_test.go b/ocis-pkg/config/config_test.go new file mode 100644 index 00000000000..6a77d3cda97 --- /dev/null +++ b/ocis-pkg/config/config_test.go @@ -0,0 +1,17 @@ +package config + +import ( + "fmt" + "testing" + + "gopkg.in/yaml.v2" +) + +func TestDefaultConfig(t *testing.T) { + cfg := DefaultConfig() + yBytes, err := yaml.Marshal(cfg) + if err != nil { + panic(err) + } + fmt.Println(string(yBytes)) +} diff --git a/ocis-pkg/config/environment.go b/ocis-pkg/config/environment.go new file mode 100644 index 00000000000..c713d92e40c --- /dev/null +++ b/ocis-pkg/config/environment.go @@ -0,0 +1,47 @@ +package config + +import ( + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" +) + +// BindEnv takes a config `c` and a EnvBinding and binds the values from the environment to the address location in cfg. +func BindEnv(c *gofig.Config, bindings []shared.EnvBinding) error { + return bindEnv(c, bindings) +} + +func bindEnv(c *gofig.Config, bindings []shared.EnvBinding) error { + for i := range bindings { + for j := range bindings[i].EnvVars { + // we need to guard against v != "" because this is the condition that checks that the value is set from the environment. + // the `ok` guard is not enough, apparently. + if v, ok := c.GetValue(bindings[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(bindings[i].Destination).Type().String() { + case "*bool": + r := c.Bool(bindings[i].EnvVars[j]) + *bindings[i].Destination.(*bool) = r + case "*string": + r := c.String(bindings[i].EnvVars[j]) + *bindings[i].Destination.(*string) = r + case "*int": + r := c.Int(bindings[i].EnvVars[j]) + *bindings[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := c.Float(bindings[i].EnvVars[j]) + *bindings[i].Destination.(*float64) = r + default: + // it is unlikely we will ever get here. Let this serve more as a runtime check for when debugging. + return fmt.Errorf("invalid type for env var: `%v`", bindings[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go new file mode 100644 index 00000000000..f89cdc5ddc3 --- /dev/null +++ b/ocis-pkg/config/helpers.go @@ -0,0 +1,85 @@ +package config + +import ( + "io/fs" + "os" + "path/filepath" + "strings" + + gofig "github.com/gookit/config/v2" + goojson "github.com/gookit/config/v2/json" + gooyaml "github.com/gookit/config/v2/yaml" +) + +var ( + defaultLocations = []string{ + filepath.Join(os.Getenv("HOME"), "/.ocis/config/"), + "/etc/ocis/", + ".config/", + } + + // supportedExtensions is determined by gookit/config. + supportedExtensions = []string{ + "yaml", + "yml", + "json", + } +) + +// DefaultConfigSources returns a slice with matched expected config files. It sugars coat several aspects of config file +// management by assuming there are 3 default locations a config file could be. +// It uses globbing to match a config file by name, and retrieve any supported extension supported by our drivers. +// It sanitizes the output depending on the list of drivers provided. +func DefaultConfigSources(filename string, drivers []string) []string { + var sources []string + + for i := range defaultLocations { + dirFS := os.DirFS(defaultLocations[i]) + pattern := filename + ".*" + matched, _ := fs.Glob(dirFS, pattern) + if len(matched) > 0 { + // prepend path to results + for j := 0; j < len(matched); j++ { + matched[j] = filepath.Join(defaultLocations[i], matched[j]) + } + } + sources = append(sources, matched...) + } + + return sanitizeExtensions(sources, drivers, func(a, b string) bool { + return strings.HasSuffix(filepath.Base(a), b) + }) +} + +// sanitizeExtensions removes elements from "set" which extensions are not in "ext". +func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) []string { + var r []string + for i := 0; i < len(set); i++ { + for j := 0; j < len(ext); j++ { + if f(filepath.Base(set[i]), ext[j]) { + r = append(r, set[i]) + } + } + } + return r +} + +// BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. Its only purpose +// is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner. +func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) { + sources := DefaultConfigSources(extension, supportedExtensions) + cnf := gofig.NewWithOptions(extension, gofig.ParseEnv) + cnf.WithOptions(func(options *gofig.Options) { + options.DecoderConfig.TagName = "ocisConfig" + }) + cnf.AddDriver(gooyaml.Driver) + cnf.AddDriver(goojson.Driver) + _ = cnf.LoadFiles(sources...) + + err := cnf.BindStruct("", &dst) + if err != nil { + return nil, err + } + + return cnf, nil +} diff --git a/ocis-pkg/log/log.go b/ocis-pkg/log/log.go index 04363919556..42ae508f825 100644 --- a/ocis-pkg/log/log.go +++ b/ocis-pkg/log/log.go @@ -6,6 +6,8 @@ import ( "strings" "time" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" mdlog "go-micro.dev/v4/debug/log" @@ -18,6 +20,17 @@ type Logger struct { zerolog.Logger } +// LoggerFromConfig initializes a service-specific logger instance. +func LoggerFromConfig(name string, cfg shared.Log) Logger { + return NewLogger( + Name(name), + Level(cfg.Level), + Pretty(cfg.Pretty), + Color(cfg.Color), + File(cfg.File), + ) +} + // NewLogger initializes a new logger instance. func NewLogger(opts ...Option) Logger { options := newOptions(opts...) diff --git a/ocis-pkg/service/debug/option.go b/ocis-pkg/service/debug/option.go index ef39d9ce42a..d33420ca492 100644 --- a/ocis-pkg/service/debug/option.go +++ b/ocis-pkg/service/debug/option.go @@ -20,6 +20,7 @@ type Options struct { Zpages bool Health func(http.ResponseWriter, *http.Request) Ready func(http.ResponseWriter, *http.Request) + ConfigDump func(http.ResponseWriter, *http.Request) CorsAllowedOrigins []string CorsAllowedMethods []string CorsAllowedHeaders []string @@ -100,6 +101,13 @@ func Ready(r func(http.ResponseWriter, *http.Request)) Option { } } +// ConfigDump to be documented. +func ConfigDump(r func(http.ResponseWriter, *http.Request)) Option { + return func(o *Options) { + o.ConfigDump = r + } +} + // CorsAllowedOrigins provides a function to set the CorsAllowedOrigin option. func CorsAllowedOrigins(origins []string) Option { return func(o *Options) { diff --git a/ocis-pkg/service/debug/service.go b/ocis-pkg/service/debug/service.go index a89ea0c53cc..8112618a53a 100644 --- a/ocis-pkg/service/debug/service.go +++ b/ocis-pkg/service/debug/service.go @@ -15,12 +15,6 @@ import ( // NewService initializes a new debug service. func NewService(opts ...Option) *http.Server { dopts := newOptions(opts...) - - dopts.Logger.Info(). - Str("transport", "debug"). - Str("addr", dopts.Address). - Msg("starting server") - mux := http.NewServeMux() mux.Handle("/metrics", alice.New( @@ -34,6 +28,10 @@ func NewService(opts ...Option) *http.Server { mux.HandleFunc("/healthz", dopts.Health) mux.HandleFunc("/readyz", dopts.Ready) + if dopts.ConfigDump != nil { + mux.HandleFunc("/config", dopts.ConfigDump) + } + if dopts.Pprof { mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 34c20c8264b..c21609b53b3 100644 --- a/ocis-pkg/service/grpc/service.go +++ b/ocis-pkg/service/grpc/service.go @@ -32,11 +32,6 @@ type Service struct { func NewService(opts ...Option) Service { sopts := newOptions(opts...) - sopts.Logger.Info(). - Str("transport", "grpc"). - Str("addr", sopts.Address). - Msg("starting server") - mopts := []micro.Option{ // first add a server because it will reset any options micro.Server(mgrpcs.NewServer()), diff --git a/ocis-pkg/service/http/service.go b/ocis-pkg/service/http/service.go index f23bf7a885b..2af5e9d7e51 100644 --- a/ocis-pkg/service/http/service.go +++ b/ocis-pkg/service/http/service.go @@ -1,7 +1,6 @@ package http import ( - "crypto/tls" "strings" "time" @@ -20,11 +19,6 @@ type Service struct { // NewService initializes a new http service. func NewService(opts ...Option) Service { sopts := newOptions(opts...) - sopts.Logger.Info(). - Str("transport", transport(sopts.TLSConfig)). - Str("addr", sopts.Address). - Msg("starting server") - wopts := []micro.Option{ micro.Server(mhttps.NewServer(server.TLSConfig(sopts.TLSConfig))), micro.Address(sopts.Address), @@ -39,11 +33,3 @@ func NewService(opts ...Option) Service { return Service{micro.NewService(wopts...)} } - -func transport(secure *tls.Config) string { - if secure != nil { - return "https" - } - - return "http" -} diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go new file mode 100644 index 00000000000..fc655e73df2 --- /dev/null +++ b/ocis-pkg/shared/shared_types.go @@ -0,0 +1,24 @@ +package shared + +// EnvBinding represents a direct binding from an env variable to a go kind. Along with gookit/config, its primal goal +// is to unpack environment variables into a Go value. We do so with reflection, and this data structure is just a step +// in between. +type EnvBinding struct { + EnvVars []string // name of the environment var. + Destination interface{} // pointer to the original config value to modify. +} + +// Log defines the available logging configuration. +type Log struct { + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` +} + +// Commons holds configuration that are common to all extensions. Each extension can then decide whether +// to overwrite its values. +type Commons struct { + *Log `mapstructure:"log"` + OcisURL string `mapstructure:"ocis_url"` +} diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index a89afa655a9..1cacd70d0a7 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -5,10 +5,7 @@ package command import ( "github.com/owncloud/ocis/accounts/pkg/command" - svcconfig "github.com/owncloud/ocis/accounts/pkg/config" - "github.com/owncloud/ocis/accounts/pkg/flagset" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -19,7 +16,6 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Name: "accounts", Usage: "Start accounts server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Accounts), Subcommands: []*cli.Command{ command.ListAccounts(cfg.Accounts), command.AddAccount(cfg.Accounts), @@ -29,36 +25,23 @@ func AccountsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Accounts), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Accounts.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureAccounts(cfg)) + origCmd := command.Server(cfg.Accounts) return handleOriginalAction(c, origCmd) }, } } -func configureAccounts(cfg *config.Config) *svcconfig.Config { - cfg.Accounts.Log.Level = cfg.Log.Level - cfg.Accounts.Log.Pretty = cfg.Log.Pretty - cfg.Accounts.Log.Color = cfg.Log.Color - cfg.Accounts.Server.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Accounts.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Accounts.Tracing.Type = cfg.Tracing.Type - cfg.Accounts.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Accounts.Tracing.Collector = cfg.Tracing.Collector - } - - if cfg.TokenManager.JWTSecret != "" { - cfg.Accounts.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret - cfg.Accounts.Repo.CS3.JWTSecret = cfg.TokenManager.JWTSecret - } - - return cfg.Accounts -} - func init() { register.AddCommand(AccountsCommand) } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 6a69699e548..c6baacfdeb5 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -2,10 +2,7 @@ package command import ( "github.com/owncloud/ocis/glauth/pkg/command" - svcconfig "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/glauth/pkg/flagset" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -16,33 +13,24 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Name: "glauth", Usage: "Start glauth server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.GLAuth), Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.GLAuth.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureGLAuth(cfg)) + origCmd := command.Server(cfg.GLAuth) return handleOriginalAction(c, origCmd) }, } } -func configureGLAuth(cfg *config.Config) *svcconfig.Config { - cfg.GLAuth.Log.Level = cfg.Log.Level - cfg.GLAuth.Log.Pretty = cfg.Log.Pretty - cfg.GLAuth.Log.Color = cfg.Log.Color - cfg.GLAuth.Version = version.String - - if cfg.Tracing.Enabled { - cfg.GLAuth.Tracing.Enabled = cfg.Tracing.Enabled - cfg.GLAuth.Tracing.Type = cfg.Tracing.Type - cfg.GLAuth.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.GLAuth.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.GLAuth -} - func init() { register.AddCommand(GLAuthCommand) } diff --git a/ocis/pkg/command/health.go b/ocis/pkg/command/health.go index c65e2958298..f293dbf8faa 100644 --- a/ocis/pkg/command/health.go +++ b/ocis/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis/pkg/flagset" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -15,7 +14,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 46f24ec7b73..7b35c15ba89 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -2,10 +2,7 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" - svcconfig "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/idp/pkg/flagset" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) @@ -16,16 +13,22 @@ func IDPCommand(cfg *config.Config) *cli.Command { Name: "idp", Usage: "Start idp server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.IDP), Subcommands: []*cli.Command{ command.PrintVersion(cfg.IDP), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.IDP.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - idpCommand := command.Server(configureIDP(cfg)) - + idpCommand := command.Server(cfg.IDP) if err := idpCommand.Before(c); err != nil { return err } @@ -35,23 +38,6 @@ func IDPCommand(cfg *config.Config) *cli.Command { } } -func configureIDP(cfg *config.Config) *svcconfig.Config { - cfg.IDP.Log.Level = cfg.Log.Level - cfg.IDP.Log.Pretty = cfg.Log.Pretty - cfg.IDP.Log.Color = cfg.Log.Color - cfg.IDP.HTTP.TLS = false - cfg.IDP.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.IDP.Tracing.Enabled = cfg.Tracing.Enabled - cfg.IDP.Tracing.Type = cfg.Tracing.Type - cfg.IDP.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.IDP.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.IDP -} - func init() { register.AddCommand(IDPCommand) } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 12d39be9222..17f2d927e69 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -5,11 +5,8 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocs/pkg/command" - svcconfig "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/owncloud/ocis/ocs/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -19,40 +16,27 @@ func OCSCommand(cfg *config.Config) *cli.Command { Name: "ocs", Usage: "Start ocs server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.OCS), - Subcommands: []*cli.Command{ - command.PrintVersion(cfg.OCS), - }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.OCS.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureOCS(cfg)) + origCmd := command.Server(cfg.OCS) return handleOriginalAction(c, origCmd) }, + Subcommands: []*cli.Command{ + command.PrintVersion(cfg.OCS), + }, } } -func configureOCS(cfg *config.Config) *svcconfig.Config { - cfg.OCS.Log.Level = cfg.Log.Level - cfg.OCS.Log.Pretty = cfg.Log.Pretty - cfg.OCS.Log.Color = cfg.Log.Color - cfg.OCS.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.OCS.Tracing.Enabled = cfg.Tracing.Enabled - cfg.OCS.Tracing.Type = cfg.Tracing.Type - cfg.OCS.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.OCS.Tracing.Collector = cfg.Tracing.Collector - } - - if cfg.TokenManager.JWTSecret != "" { - cfg.OCS.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret - } - - return cfg.OCS -} - func init() { register.AddCommand(OCSCommand) } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 8ac4816c53c..321298689b5 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -5,11 +5,8 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/proxy/pkg/command" - svcconfig "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/owncloud/ocis/proxy/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -19,40 +16,27 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: "proxy", Usage: "Start proxy server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Proxy), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Proxy), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Proxy.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureProxy(cfg)) + origCmd := command.Server(cfg.Proxy) return handleOriginalAction(c, origCmd) }, } } -func configureProxy(cfg *config.Config) *svcconfig.Config { - cfg.Proxy.Log.Level = cfg.Log.Level - cfg.Proxy.Log.Pretty = cfg.Log.Pretty - cfg.Proxy.Log.Color = cfg.Log.Color - cfg.Proxy.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Proxy.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Proxy.Tracing.Type = cfg.Tracing.Type - cfg.Proxy.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Proxy.Tracing.Collector = cfg.Tracing.Collector - } - - if cfg.TokenManager.JWTSecret != "" { - cfg.Proxy.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret - } - - return cfg.Proxy -} - func init() { register.AddCommand(ProxyCommand) } diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index e132e26506b..7272c357f5f 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -2,41 +2,33 @@ package command import ( "os" - "strings" - - "github.com/owncloud/ocis/ocis-pkg/sync" - - "github.com/owncloud/ocis/ocis-pkg/log" - "github.com/urfave/cli/v2" "github.com/owncloud/ocis/ocis-pkg/config" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/owncloud/ocis/ocis/pkg/flagset" "github.com/owncloud/ocis/ocis/pkg/register" - "github.com/spf13/viper" + "github.com/urfave/cli/v2" ) // Execute is the entry point for the ocis command. func Execute() error { - cfg := config.New() + cfg := config.DefaultConfig() app := &cli.App{ Name: "ocis", Version: version.String, Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), - Before: func(c *cli.Context) error { return ParseConfig(c, cfg) }, - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - Flags: flagset.RootWithConfig(cfg), } for _, fn := range register.Commands { @@ -70,47 +62,15 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig load configuration for every extension +// ParseConfig loads ocis configuration. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("OCIS") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("ocis") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read config") - } - } - - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } + conf.LoadOSEnv(config.GetEnv(), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index acd66bc2681..336a39e87a4 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -6,8 +6,9 @@ package command import ( "strings" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis/pkg/flagset" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocis/pkg/runtime" "github.com/urfave/cli/v2" @@ -19,15 +20,19 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start fullstack server", Category: "Fullstack", - Flags: flagset.ServerWithConfig(cfg), Before: func(c *cli.Context) error { if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return nil + return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { + + cfg.Commons = &shared.Commons{ + Log: &cfg.Log, + } + r := runtime.New(cfg) return r.Start() }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 7970d406a1d..adb37be5b09 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -5,11 +5,8 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/settings/pkg/command" - svcconfig "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -19,40 +16,27 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Name: "settings", Usage: "Start settings server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Settings), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Settings), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Settings.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureSettings(cfg)) + origCmd := command.Server(cfg.Settings) return handleOriginalAction(c, origCmd) }, } } -func configureSettings(cfg *config.Config) *svcconfig.Config { - cfg.Settings.Log.Level = cfg.Log.Level - cfg.Settings.Log.Pretty = cfg.Log.Pretty - cfg.Settings.Log.Color = cfg.Log.Color - cfg.Settings.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Settings.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Settings.Tracing.Type = cfg.Tracing.Type - cfg.Settings.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Settings.Tracing.Collector = cfg.Tracing.Collector - } - - if cfg.TokenManager.JWTSecret != "" { - cfg.Settings.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret - } - - return cfg.Settings -} - func init() { register.AddCommand(SettingsCommand) } diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index cb60828d06e..5202959659a 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageAppProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-app-provider", Usage: "Start storage app-provider service", Category: "Extensions", - Flags: flagset.AppProviderWithConfig(cfg.Storage), + //Flags: flagset.AppProviderWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.AppProvider(configureStorageAppProvider(cfg)) + origCmd := command.AppProvider(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageAppProvider(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageAppProviderCommand) } diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index fe7a87eb1f5..62cddc5c80f 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageAuthBasicCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-basic", Usage: "Start storage auth-basic service", Category: "Extensions", - Flags: flagset.AuthBasicWithConfig(cfg.Storage), + //Flags: flagset.AuthBasicWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.AuthBasic(configureStorageAuthBasic(cfg)) + origCmd := command.AuthBasic(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageAuthBasic(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageAuthBasicCommand) } diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index 004d0b79362..329e6446721 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-bearer", Usage: "Start storage auth-bearer service", Category: "Extensions", - Flags: flagset.AuthBearerWithConfig(cfg.Storage), + //Flags: flagset.AuthBearerWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.AuthBearer(configureStorageAuthBearer(cfg)) + origCmd := command.AuthBearer(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageAuthBearer(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageAuthBearerCommand) } diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 220eabc7441..29fb13ee21c 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command { Name: "storage-frontend", Usage: "Start storage frontend", Category: "Extensions", - Flags: flagset.FrontendWithConfig(cfg.Storage), + //Flags: flagset.FrontendWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.Frontend(configureStorageFrontend(cfg)) + origCmd := command.Frontend(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageFrontend(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageFrontendCommand) } diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index d0e4e61fa01..4f24f3e4948 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageGatewayCommand(cfg *config.Config) *cli.Command { Name: "storage-gateway", Usage: "Start storage gateway", Category: "Extensions", - Flags: flagset.GatewayWithConfig(cfg.Storage), + //Flags: flagset.GatewayWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.Gateway(configureStorageGateway(cfg)) + origCmd := command.Gateway(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageGateway(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageGatewayCommand) } diff --git a/ocis/pkg/command/storagegroupprovider.go b/ocis/pkg/command/storagegroupprovider.go index 3f77796e382..530e8148ce0 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageGroupProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-groupprovider", Usage: "Start storage groupprovider service", Category: "Extensions", - Flags: flagset.GroupsWithConfig(cfg.Storage), + //Flags: flagset.GroupsWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.Groups(configureStorageGroupProvider(cfg)) + origCmd := command.Groups(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageGroupProvider(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageGroupProviderCommand) } diff --git a/ocis/pkg/command/storagehome.go b/ocis/pkg/command/storagehome.go index 9e025b28562..bae5c1c674a 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storagehome.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageHomeCommand(cfg *config.Config) *cli.Command { Name: "storage-home", Usage: "Start storage and data provider for /home mount", Category: "Extensions", - Flags: flagset.StorageHomeWithConfig(cfg.Storage), + //Flags: flagset.StorageHomeWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.StorageHome(configureStorageHome(cfg)) + origCmd := command.StorageHome(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageHome(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageHomeCommand) } diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index 90c56da0077..d475da582d3 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -4,8 +4,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -15,29 +13,17 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command { Name: "storage-metadata", Usage: "Start storage and data service for metadata", Category: "Extensions", - Flags: flagset.StorageMetadata(cfg.Storage), + //Flags: flagset.StorageMetadata(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.StorageMetadata(configureStorageMetadata(cfg)) + origCmd := command.StorageMetadata(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageMetadata(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageMetadataCommand) } diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index 0d94d5afb6c..e4d9dc75013 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { Name: "storage-public-link", Usage: "Start storage public link storage", Category: "Extensions", - Flags: flagset.StoragePublicLink(cfg.Storage), + //Flags: flagset.StoragePublicLink(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.StoragePublicLink(configureStoragePublicLink(cfg)) + origCmd := command.StoragePublicLink(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStoragePublicLink(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StoragePublicLinkCommand) } diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index d712f9e9a3d..3a15d90eea9 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageSharingCommand(cfg *config.Config) *cli.Command { Name: "storage-sharing", Usage: "Start storage sharing service", Category: "Extensions", - Flags: flagset.SharingWithConfig(cfg.Storage), + //Flags: flagset.SharingWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.Sharing(configureStorageSharing(cfg)) + origCmd := command.Sharing(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageSharing(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageSharingCommand) } diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index ea701a1c3be..fc423737a3f 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageUserProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-userprovider", Usage: "Start storage userprovider service", Category: "Extensions", - Flags: flagset.UsersWithConfig(cfg.Storage), + //Flags: flagset.UsersWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.Users(configureStorageUserProvider(cfg)) + origCmd := command.Users(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageUserProvider(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageUserProviderCommand) } diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index 80f32e796b9..a7978fb69ce 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -7,8 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - svcconfig "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -18,29 +16,17 @@ func StorageUsersCommand(cfg *config.Config) *cli.Command { Name: "storage-users", Usage: "Start storage and data provider for /users mount", Category: "Extensions", - Flags: flagset.StorageUsersWithConfig(cfg.Storage), + //Flags: flagset.StorageUsersWithConfig(cfg.Storage), + Before: func(ctx *cli.Context) error { + return ParseStorageCommon(ctx, cfg) + }, Action: func(c *cli.Context) error { - origCmd := command.StorageUsers(configureStorageUsers(cfg)) + origCmd := command.StorageUsers(cfg.Storage) return handleOriginalAction(c, origCmd) }, } } -func configureStorageUsers(cfg *config.Config) *svcconfig.Config { - cfg.Storage.Log.Level = cfg.Log.Level - cfg.Storage.Log.Pretty = cfg.Log.Pretty - cfg.Storage.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Storage.Tracing.Type = cfg.Tracing.Type - cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Storage.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Storage -} - func init() { register.AddCommand(StorageUsersCommand) } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 74d2a84fed6..63946211797 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -5,50 +5,45 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/store/pkg/command" - svcconfig "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/flagset" "github.com/urfave/cli/v2" ) // StoreCommand is the entrypoint for the ocs command. func StoreCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "store", Usage: "Start a go-micro store", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Store), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Store), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureStore(cfg)) + // if accounts logging is empty in ocis.yaml + if (cfg.Store.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Store.Log = globalLog + } + + origCmd := command.Server(cfg.Store) return handleOriginalAction(c, origCmd) }, } } -func configureStore(cfg *config.Config) *svcconfig.Config { - cfg.Store.Log.Level = cfg.Log.Level - cfg.Store.Log.Pretty = cfg.Log.Pretty - cfg.Store.Log.Color = cfg.Log.Color - cfg.Store.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Store.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Store.Tracing.Type = cfg.Tracing.Type - cfg.Store.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Store.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Store -} - func init() { register.AddCommand(StoreCommand) } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 083442f8af4..0562b5d617d 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -5,13 +5,9 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/thumbnails/pkg/command" - "github.com/owncloud/ocis/thumbnails/pkg/flagset" "github.com/urfave/cli/v2" - - svcconfig "github.com/owncloud/ocis/thumbnails/pkg/config" ) // ThumbnailsCommand is the entrypoint for the thumbnails command. @@ -20,36 +16,27 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Name: "thumbnails", Usage: "Start thumbnails server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Thumbnails), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Thumbnails), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Thumbnails.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureThumbnails(cfg)) + origCmd := command.Server(cfg.Thumbnails) return handleOriginalAction(c, origCmd) }, } } -func configureThumbnails(cfg *config.Config) *svcconfig.Config { - cfg.Thumbnails.Log.Level = cfg.Log.Level - cfg.Thumbnails.Log.Pretty = cfg.Log.Pretty - cfg.Thumbnails.Log.Color = cfg.Log.Color - cfg.Thumbnails.Server.Version = version.String - - if cfg.Tracing.Enabled { - cfg.Thumbnails.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Thumbnails.Tracing.Type = cfg.Tracing.Type - cfg.Thumbnails.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Thumbnails.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Thumbnails -} - func init() { register.AddCommand(ThumbnailsCommand) } diff --git a/ocis/pkg/command/util.go b/ocis/pkg/command/util.go new file mode 100644 index 00000000000..a2e9b1abc0e --- /dev/null +++ b/ocis/pkg/command/util.go @@ -0,0 +1,26 @@ +package command + +import ( + "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/urfave/cli/v2" +) + +func ParseStorageCommon(ctx *cli.Context, cfg *config.Config) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Storage.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Storage.Log = &shared.Log{ + Level: cfg.Commons.Log.Level, + Pretty: cfg.Commons.Log.Pretty, + Color: cfg.Commons.Log.Color, + File: cfg.Commons.Log.File, + } + } else if cfg.Storage.Log == nil && cfg.Commons == nil { + cfg.Storage.Log = &shared.Log{} + } + + return nil +} diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 431443cadaa..c3f2df2eafe 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -4,8 +4,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/web/pkg/command" - svcconfig "github.com/owncloud/ocis/web/pkg/config" - "github.com/owncloud/ocis/web/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -15,32 +13,24 @@ func WebCommand(cfg *config.Config) *cli.Command { Name: "web", Usage: "Start web server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Web), Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.Web.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureWeb(cfg)) + origCmd := command.Server(cfg.Web) return handleOriginalAction(c, origCmd) }, } } -func configureWeb(cfg *config.Config) *svcconfig.Config { - cfg.Web.Log.Level = cfg.Log.Level - cfg.Web.Log.Pretty = cfg.Log.Pretty - cfg.Web.Log.Color = cfg.Log.Color - - if cfg.Tracing.Enabled { - cfg.Web.Tracing.Enabled = cfg.Tracing.Enabled - cfg.Web.Tracing.Type = cfg.Tracing.Type - cfg.Web.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.Web.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.Web -} - func init() { register.AddCommand(WebCommand) } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index b84453a5163..0502642bb24 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -5,50 +5,39 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/webdav/pkg/command" - svcconfig "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/owncloud/ocis/webdav/pkg/flagset" "github.com/urfave/cli/v2" ) // WebDAVCommand is the entrypoint for the webdav command. func WebDAVCommand(cfg *config.Config) *cli.Command { + return &cli.Command{ Name: "webdav", Usage: "Start webdav server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.WebDAV), Subcommands: []*cli.Command{ command.PrintVersion(cfg.WebDAV), }, Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Commons != nil { + cfg.WebDAV.Commons = cfg.Commons + } + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureWebDAV(cfg)) + origCmd := command.Server(cfg.WebDAV) return handleOriginalAction(c, origCmd) }, } } -func configureWebDAV(cfg *config.Config) *svcconfig.Config { - cfg.WebDAV.Log.Level = cfg.Log.Level - cfg.WebDAV.Log.Pretty = cfg.Log.Pretty - cfg.WebDAV.Log.Color = cfg.Log.Color - cfg.WebDAV.Service.Version = version.String - - if cfg.Tracing.Enabled { - cfg.WebDAV.Tracing.Enabled = cfg.Tracing.Enabled - cfg.WebDAV.Tracing.Type = cfg.Tracing.Type - cfg.WebDAV.Tracing.Endpoint = cfg.Tracing.Endpoint - cfg.WebDAV.Tracing.Collector = cfg.Tracing.Collector - } - - return cfg.WebDAV -} - func init() { register.AddCommand(WebDAVCommand) } diff --git a/ocis/pkg/config/config.go b/ocis/pkg/config/config.go deleted file mode 100644 index f02f06b4abf..00000000000 --- a/ocis/pkg/config/config.go +++ /dev/null @@ -1,104 +0,0 @@ -package config - -import ( - accounts "github.com/owncloud/ocis/accounts/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" - idp "github.com/owncloud/ocis/idp/pkg/config" - pman "github.com/owncloud/ocis/ocis/pkg/runtime/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" -) - -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool -} - -// Debug defines the available debug configuration. -type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool -} - -// HTTP defines the available http configuration. -type HTTP struct { - Addr string - Root string -} - -// GRPC defines the available grpc configuration. -type GRPC struct { - Addr string -} - -// Tracing defines the available tracing configuration. -type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string -} - -// TokenManager is the config for using the reva token manager -type TokenManager struct { - JWTSecret string -} - -// Config combines all available configuration parts. -type Config struct { - Registry string - Log Log - Debug Debug - HTTP HTTP - GRPC GRPC - Tracing Tracing - TokenManager TokenManager - - Accounts *accounts.Config - GLAuth *glauth.Config - Graph *graph.Config - GraphExplorer *graphExplorer.Config - IDP *idp.Config - OCS *ocs.Config - Web *web.Config - Proxy *proxy.Config - Settings *settings.Config - Storage *storage.Config - Store *store.Config - Thumbnails *thumbnails.Config - WebDAV *webdav.Config - Runtime *pman.Config -} - -// New initializes a new configuration with or without defaults. -func New() *Config { - return &Config{ - Accounts: accounts.New(), - GLAuth: glauth.New(), - Graph: graph.New(), - GraphExplorer: graphExplorer.New(), - IDP: idp.New(), - OCS: ocs.New(), - Web: web.New(), - Proxy: proxy.New(), - Settings: settings.New(), - Storage: storage.New(), - Store: store.New(), - Thumbnails: thumbnails.New(), - WebDAV: webdav.New(), - Runtime: pman.NewConfig(), - } -} diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go deleted file mode 100644 index 68bcdb14a62..00000000000 --- a/ocis/pkg/flagset/flagset.go +++ /dev/null @@ -1,181 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - // this is just a dummy config flag do document the existence - // of this environment variable - // the environment variable itself is used in `ocis-pkg/config/defaults/paths.go` - Name: "ocis-base-data-path", - Usage: "Set the base path where oCIS stores data", - EnvVars: []string{"OCIS_BASE_DATA_PATH"}, - }, - &cli.StringFlag{ - Name: "config-file", - Usage: "Load config file from a non standard location.", - EnvVars: []string{"OCIS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.StringFlag{ - Name: "ocis-log-level", - Value: "info", - Usage: "Set logging level", - EnvVars: []string{"OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Value: false, - Name: "ocis-log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Value: true, - Name: "ocis-log-color", - Usage: "Enable colored logging", - EnvVars: []string{"OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - &cli.StringFlag{ - Name: "ocis-log-file", - Usage: "Enable log to file", - EnvVars: []string{"OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: "jaeger", - Usage: "Tracing backend type", - EnvVars: []string{"OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: "", - Usage: "Endpoint for the agent", - EnvVars: []string{"OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: "", - Usage: "Endpoint for the collector", - EnvVars: []string{"OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: "ocis", - Usage: "Service name for tracing", - EnvVars: []string{"OCIS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "jwt-secret", - Value: "Pive-Fumkiu4", - Usage: "Used to dismantle the access token, should equal reva's jwt-secret", - EnvVars: []string{"OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - &cli.StringFlag{ - Name: "runtime-port", - Value: "9250", - Usage: "Configures which port the runtime starts", - EnvVars: []string{"OCIS_RUNTIME_PORT"}, - Destination: &cfg.Runtime.Port, - }, - &cli.StringFlag{ - Name: "runtime-host", - Value: "localhost", - Usage: "Configures the host where the runtime process is running", - EnvVars: []string{"OCIS_RUNTIME_HOST"}, - Destination: &cfg.Runtime.Host, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: "127.0.0.1:9010", - Usage: "Address to debug endpoint", - EnvVars: []string{"OCIS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: "127.0.0.1:9010", - Usage: "Address to bind debug server", - EnvVars: []string{"OCIS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: "", - Usage: "Token to grant metrics access", - EnvVars: []string{"OCIS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"OCIS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"OCIS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: "127.0.0.1:9000", - Usage: "Address to bind http server", - EnvVars: []string{"OCIS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: "/", - Usage: "Root path of http server", - EnvVars: []string{"OCIS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: "127.0.0.1:9001", - Usage: "Address to bind grpc server", - EnvVars: []string{"OCIS_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - &cli.StringFlag{ - Name: "extensions", - Aliases: []string{"e"}, - Usage: "Run specific extensions during supervised mode", - EnvVars: []string{"OCIS_RUN_EXTENSIONS"}, - Destination: &cfg.Runtime.Extensions, - }, - } -} diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 78e8350eddf..a725b04bf88 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -13,6 +13,8 @@ import ( "syscall" "time" + "github.com/owncloud/ocis/ocis-pkg/shared" + mzlog "github.com/asim/go-micro/plugins/logger/zerolog/v4" "github.com/mohae/deepcopy" "github.com/olekukonko/tablewriter" @@ -159,13 +161,22 @@ func Start(o ...Option) error { FailureBackoff: 3 * time.Second, }) - // reva storages have their own logging. For consistency sake the top level logging will cascade to reva. - s.cfg.Storage.Log.Color = s.cfg.Log.Color - s.cfg.Storage.Log.Level = s.cfg.Log.Level - s.cfg.Storage.Log.Pretty = s.cfg.Log.Pretty - s.cfg.Storage.Log.File = s.cfg.Log.File + if s.cfg.Commons == nil { + s.cfg.Commons = &shared.Commons{ + Log: &shared.Log{}, + } + } + + if s.cfg.Storage.Log == nil { + s.cfg.Storage.Log = &shared.Log{} + } + + s.cfg.Storage.Log.Color = s.cfg.Commons.Color + s.cfg.Storage.Log.Level = s.cfg.Commons.Level + s.cfg.Storage.Log.Pretty = s.cfg.Commons.Pretty + s.cfg.Storage.Log.File = s.cfg.Commons.File - if err := rpc.Register(s); err != nil { + if err = rpc.Register(s); err != nil { if s != nil { s.Log.Fatal().Err(err) } diff --git a/ocs/cmd/ocs/main.go b/ocs/cmd/ocs/main.go index aac75b441f1..ca3ea14b364 100644 --- a/ocs/cmd/ocs/main.go +++ b/ocs/cmd/ocs/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/ocs/pkg/command/health.go b/ocs/pkg/command/health.go index c84b6d24496..51474a3da2d 100644 --- a/ocs/pkg/command/health.go +++ b/ocs/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/owncloud/ocis/ocs/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index d7921b159c6..19c53801c6f 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/shared" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -67,49 +65,30 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig reads ocs configuration from fs. +// ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("OCS") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("ocs") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("ocs", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(cfg), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the ocs command to be embedded and supervised by a suture supervisor tree. @@ -119,10 +98,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.OCS.Supervised = true - } - cfg.OCS.Log.File = cfg.Log.File + cfg.OCS.Commons = cfg.Commons return SutureService{ cfg: cfg.OCS, } diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 0e66aa9aa41..722673cd136 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -10,7 +10,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/owncloud/ocis/ocs/pkg/flagset" "github.com/owncloud/ocis/ocs/pkg/metrics" "github.com/owncloud/ocis/ocs/pkg/server/debug" "github.com/owncloud/ocis/ocs/pkg/server/http" @@ -22,26 +21,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - if origins := ctx.StringSlice("cors-allowed-origins"); len(origins) != 0 { - cfg.HTTP.CORS.AllowedOrigins = origins - } - if methods := ctx.StringSlice("cors-allowed-methods"); len(methods) != 0 { - cfg.HTTP.CORS.AllowedMethods = methods - } - if headers := ctx.StringSlice("cors-allowed-headers"); len(headers) != 0 { - cfg.HTTP.CORS.AllowedOrigins = headers + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "ocs").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { diff --git a/ocs/pkg/command/version.go b/ocs/pkg/command/version.go index 10c1c17df75..2c1b64e0e7a 100644 --- a/ocs/pkg/command/version.go +++ b/ocs/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/owncloud/ocis/ocs/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListOcsWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 5b3e9affc22..01f2d65bbd1 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -1,85 +1,83 @@ package config -import "context" +import ( + "context" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allow_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - CORS CORS + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Reva defines all available REVA configuration. type Reva struct { - Address string + Address string `ocisConfig:"address"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `ocisConfig:"jwt_secret"` } // IdentityManagement keeps track of the OIDC address. This is because Reva requisite of uniqueness for users // is based in the combination of IDP hostname + UserID. For more information see: // https://github.com/cs3org/reva/blob/4fd0229f13fae5bc9684556a82dbbd0eced65ef9/pkg/storage/utils/decomposedfs/node/node.go#L856-L865 type IdentityManagement struct { - Address string + Address string `ocisConfig:"address"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Tracing Tracing - TokenManager TokenManager - Service Service - AccountBackend string - Reva Reva - StorageUsersDriver string - MachineAuthAPIKey string - IdentityManagement IdentityManagement + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Tracing Tracing `ocisConfig:"tracing"` + TokenManager TokenManager `ocisConfig:"token_manager"` + Service Service `ocisConfig:"service"` + AccountBackend string `ocisConfig:"account_backend"` + Reva Reva `ocisConfig:"reva"` + StorageUsersDriver string `ocisConfig:"storage_users_driver"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"` + IdentityManagement IdentityManagement `ocisConfig:"identity_management"` Context context.Context Supervised bool @@ -89,3 +87,46 @@ type Config struct { func New() *Config { return &Config{} } + +// DefaultConfig provides default values for a config struct. +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", + CORS: CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "ocs", + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + Service: Service{ + Name: "ocs", + Namespace: "com.owncloud.web", + }, + 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/mappings.go b/ocs/pkg/config/mappings.go new file mode 100644 index 00000000000..2aab7b910ce --- /dev/null +++ b/ocs/pkg/config/mappings.go @@ -0,0 +1,123 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_FILE", "OCS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_LOG_LEVEL", "OCS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "OCS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "OCS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCS_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "OCS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "OCS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "OCS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "OCS_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"OCS_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"OCS_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"OCS_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"OCS_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"OCS_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"OCS_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"OCS_NAMESPACE"}, + Destination: &cfg.Service.Namespace, + }, + { + EnvVars: []string{"OCS_NAME"}, + Destination: &cfg.Service.Name, + }, + { + EnvVars: []string{"OCS_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET", "OCS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + { + EnvVars: []string{"OCS_ACCOUNT_BACKEND_TYPE"}, + Destination: &cfg.AccountBackend, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.Address, + }, + { + EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "OCS_MACHINE_AUTH_API_KEY"}, + Destination: &cfg.MachineAuthAPIKey, + }, + { + EnvVars: []string{"OCIS_URL", "OCS_IDM_ADDRESS"}, + Destination: &cfg.IdentityManagement.Address, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER", "OCS_STORAGE_USERS_DRIVER"}, + Destination: &cfg.StorageUsersDriver, + }, + } +} diff --git a/ocs/pkg/flagset/flagset.go b/ocs/pkg/flagset/flagset.go deleted file mode 100644 index 4eef288e2e9..00000000000 --- a/ocs/pkg/flagset/flagset.go +++ /dev/null @@ -1,238 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/ocs/pkg/config" - "github.com/urfave/cli/v2" -) - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9114"), - Usage: "Address to debug endpoint", - EnvVars: []string{"OCS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"OCS_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"OCS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"OCS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"OCS_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"OCS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Value: flags.OverrideDefaultBool(cfg.Tracing.Enabled, false), - Usage: "Enable sending traces", - EnvVars: []string{"OCS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"OCS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"OCS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"OCS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "ocs"), - Usage: "Service name for tracing", - EnvVars: []string{"OCS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9114"), - Usage: "Address to bind debug server", - EnvVars: []string{"OCS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"OCS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"OCS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"OCS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9110"), - Usage: "Address to bind http server", - EnvVars: []string{"OCS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http namespace", - EnvVars: []string{"OCS_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-origins", - Value: cli.NewStringSlice("*"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"OCS_CORS_ALLOW_ORIGINS", "OCIS_CORS_ALLOW_ORIGINS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-methods", - Value: cli.NewStringSlice("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"OCS_CORS_ALLOW_METHODS", "OCIS_CORS_ALLOW_METHODS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-headers", - Value: cli.NewStringSlice("Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"OCS_CORS_ALLOW_HEADERS", "OCIS_CORS_ALLOW_HEADERS"}, - }, - &cli.BoolFlag{ - Name: "cors-allow-credentials", - Value: flags.OverrideDefaultBool(cfg.HTTP.CORS.AllowCredentials, true), - Usage: "Allow credentials for CORS", - EnvVars: []string{"OCS_CORS_ALLOW_CREDENTIALS", "OCIS_CORS_ALLOW_CREDENTIALS"}, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "ocs"), - Usage: "Service name", - EnvVars: []string{"OCS_NAME"}, - Destination: &cfg.Service.Name, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/ocs"), - Usage: "Root path of http server", - EnvVars: []string{"OCS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - - &cli.StringFlag{ - Name: "jwt-secret", - Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"), - Usage: "Used to dismantle the access token, should equal reva's jwt-secret", - EnvVars: []string{"OCS_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - - &cli.StringFlag{ - Name: "account-backend-type", - Value: flags.OverrideDefaultString(cfg.AccountBackend, "accounts"), - Usage: "account-backend-type", - EnvVars: []string{"OCS_ACCOUNT_BACKEND_TYPE"}, - Destination: &cfg.AccountBackend, - }, - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Address, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Address, - }, - &cli.StringFlag{ - Name: "machine-auth-api-key", - Value: flags.OverrideDefaultString(cfg.MachineAuthAPIKey, "change-me-please"), - Usage: "the API key to be used for the machine auth driver in reva", - EnvVars: []string{"OCS_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, - Destination: &cfg.MachineAuthAPIKey, - }, - &cli.StringFlag{ - Name: "idm-address", - Value: flags.OverrideDefaultString(cfg.IdentityManagement.Address, "https://localhost:9200"), - EnvVars: []string{"OCS_IDM_ADDRESS", "OCIS_URL"}, - Usage: "keeps track of the IDM Address. Needed because of Reva requisite of uniqueness for users", - Destination: &cfg.IdentityManagement.Address, - }, - &cli.StringFlag{ - Name: "users-driver", - Value: flags.OverrideDefaultString(cfg.StorageUsersDriver, "ocis"), - Usage: "storage driver for users mount: eg. local, eos, owncloud, ocis or s3", - EnvVars: []string{"OCS_STORAGE_USERS_DRIVER", "STORAGE_USERS_DRIVER"}, - Destination: &cfg.StorageUsersDriver, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, - } -} - -// ListOcsWithConfig applies the config to the list commands flagset. -func ListOcsWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http namespace", - EnvVars: []string{"OCS_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "ocs"), - Usage: "Service name", - EnvVars: []string{"OCS_NAME"}, - Destination: &cfg.Service.Name, - }, - } -} diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index cdcb2eee9a5..0e432054bb2 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -14,17 +14,19 @@ import ( "strings" "testing" + "github.com/owncloud/ocis/ocis-pkg/shared" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/auth/scope" "github.com/cs3org/reva/pkg/token" "github.com/cs3org/reva/pkg/token/manager/jwt" "github.com/golang/protobuf/ptypes/empty" - accountsCmd "github.com/owncloud/ocis/accounts/pkg/command" accountsCfg "github.com/owncloud/ocis/accounts/pkg/config" accountsProto "github.com/owncloud/ocis/accounts/pkg/proto/v0" accountsSvc "github.com/owncloud/ocis/accounts/pkg/service/v0" ocisLog "github.com/owncloud/ocis/ocis-pkg/log" + oclog "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/service/grpc" "github.com/owncloud/ocis/ocs/pkg/config" svc "github.com/owncloud/ocis/ocs/pkg/service/v0" @@ -549,7 +551,7 @@ func init() { Path: dataPath, }, }, - Log: accountsCfg.Log{ + Log: &shared.Log{ Level: "info", Pretty: true, Color: true, @@ -560,7 +562,7 @@ func init() { var err error if hdlr, err = accountsSvc.New( - accountsSvc.Logger(accountsCmd.NewLogger(c)), + accountsSvc.Logger(oclog.LoggerFromConfig("accounts", *c.Log)), accountsSvc.Config(c), accountsSvc.RoleService(buildRoleServiceMock()), ); err != nil { @@ -696,7 +698,7 @@ func getService() svc.Service { TokenManager: config.TokenManager{ JWTSecret: jwtSecret, }, - Log: config.Log{ + Log: &shared.Log{ Level: "debug", }, } diff --git a/proxy/cmd/proxy/main.go b/proxy/cmd/proxy/main.go index fbc6a6d7448..f67b685f344 100644 --- a/proxy/cmd/proxy/main.go +++ b/proxy/cmd/proxy/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/proxy/pkg/command/health.go b/proxy/pkg/command/health.go index 4dbe95aa7d7..adb3f0a77bd 100644 --- a/proxy/pkg/command/health.go +++ b/proxy/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/owncloud/ocis/proxy/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,7 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + //Flags: flagset.HealthWithConfig(cfg), Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 81a135d7fc3..13ea25e99d7 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -3,16 +3,12 @@ package command import ( "context" "os" - "strings" - - "github.com/owncloud/ocis/ocis-pkg/sync" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/owncloud/ocis/proxy/pkg/flagset" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -24,21 +20,16 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "proxy for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Service.Version = version.String return nil }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), @@ -59,60 +50,35 @@ func Execute(cfg *config.Config) error { return app.Run(os.Args) } -// NewLogger initializes a service-specific logger instance. -func NewLogger(cfg *config.Config) log.Logger { - return log.NewLogger( - log.Name("proxy"), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) -} - -// ParseConfig loads proxy configuration from Viper known paths. +// ParseConfig loads proxy configuration. Loading will first attempt to parse config files in the expected locations +// and then parses environment variables. In the context of oCIS env variables will always overwrite values set +// in a config file. +// If this extension is run as a subcommand (i.e: ocis proxy) then there are 2 levels of config parsing: +// 1. ocis.yaml (if any) +// 2. proxy.yaml (if any) +// 3. environment variables. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("PROXY") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("proxy") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("proxy", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") - } + conf.LoadOSEnv(config.GetEnv(cfg), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. @@ -122,10 +88,7 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Proxy.Supervised = true - } - cfg.Proxy.Log.File = cfg.Log.File + cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.Proxy, } @@ -139,3 +102,14 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// NewLogger initializes a service-specific logger instance. +func NewLogger(cfg *config.Config) log.Logger { + return log.NewLogger( + log.Name("proxy"), + log.Level(cfg.Log.Level), + log.Pretty(cfg.Log.Pretty), + log.Color(cfg.Log.Color), + log.File(cfg.Log.File), + ) +} diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 50376b362c9..fbc26bc39d6 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -21,7 +21,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/owncloud/ocis/proxy/pkg/cs3" - "github.com/owncloud/ocis/proxy/pkg/flagset" "github.com/owncloud/ocis/proxy/pkg/metrics" "github.com/owncloud/ocis/proxy/pkg/middleware" "github.com/owncloud/ocis/proxy/pkg/proxy" @@ -40,14 +39,19 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if cfg.Policies == nil { + cfg.Policies = config.DefaultPolicies() + } + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - // StringSliceFlag doesn't support Destination - // UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli + if len(ctx.StringSlice("presignedurl-allow-method")) > 0 { cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method") } @@ -56,10 +60,6 @@ func Server(cfg *config.Config) *cli.Command { return err } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - logger.Debug().Str("service", "ocs").Msg("ignoring config file parsing when running supervised") return nil }, Action: func(c *cli.Context) error { diff --git a/proxy/pkg/command/version.go b/proxy/pkg/command/version.go index 273db559cc9..469abc6efe7 100644 --- a/proxy/pkg/command/version.go +++ b/proxy/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/owncloud/ocis/proxy/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListProxyWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 9dd370118ec..bd21ee1e320 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -2,61 +2,65 @@ package config import ( "context" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `ocisConfig:"level"` + Pretty bool `ocisConfig:"pretty"` + Color bool `ocisConfig:"color"` + File string `ocisConfig:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - TLSCert string - TLSKey string - TLS bool + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + TLSCert string `ocisConfig:"tls_cert"` + TLSKey string `ocisConfig:"tls_key"` + TLS bool `ocisConfig:"tls"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Policy enables us to use multiple directors. type Policy struct { - Name string - Routes []Route + Name string `ocisConfig:"name"` + Routes []Route `ocisConfig:"routes"` } // Route define forwarding routes type Route struct { - Type RouteType - Endpoint string - Backend string - ApacheVHost bool `mapstructure:"apache-vhost"` + Type RouteType `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Backend string `ocisConfig:"backend"` + ApacheVHost bool `ocisConfig:"apache-vhost"` } // RouteType defines the type of a route @@ -75,52 +79,53 @@ const ( var ( // RouteTypes is an array of the available route types - RouteTypes []RouteType = []RouteType{QueryRoute, RegexRoute, PrefixRoute} + RouteTypes = []RouteType{QueryRoute, RegexRoute, PrefixRoute} ) // Reva defines all available REVA configuration. type Reva struct { - Address string - Middleware Middleware + Address string `ocisConfig:"address"` + Middleware Middleware `ocisConfig:"middleware"` } // Middleware configures proxy middlewares. type Middleware struct { - Auth Auth + Auth Auth `ocisConfig:"middleware"` } // Auth configures proxy http auth middleware. type Auth struct { - CredentialsByUserAgent map[string]string + CredentialsByUserAgent map[string]string `ocisConfig:""` } // Cache is a TTL cache configuration. type Cache struct { - Size int - TTL int + Size int `ocisConfig:"size"` + TTL int `ocisConfig:"ttl"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Service Service - Tracing Tracing - Policies []Policy - OIDC OIDC - TokenManager TokenManager - PolicySelector *PolicySelector `mapstructure:"policy_selector"` - Reva Reva - PreSignedURL PreSignedURL - AccountBackend string - UserOIDCClaim string - UserCS3Claim string - MachineAuthAPIKey string - AutoprovisionAccounts bool - EnableBasicAuth bool - InsecureBackends bool + *shared.Commons + + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Service Service `ocisConfig:"service"` + Tracing Tracing `ocisConfig:"tracing"` + Policies []Policy `ocisConfig:"policies"` + OIDC OIDC `ocisConfig:"oidc"` + TokenManager TokenManager `ocisConfig:"token_manager"` + PolicySelector *PolicySelector `ocisConfig:"policy_selector"` + Reva Reva `ocisConfig:"reva"` + PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"` + AccountBackend string `ocisConfig:"account_backend"` + UserOIDCClaim string `ocisConfig:"user_oidc_claim"` + UserCS3Claim string `ocisConfig:"user_cs3_claim"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"` + AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts"` + EnableBasicAuth bool `ocisConfig:"enable_basic_auth"` + InsecureBackends bool `ocisConfig:"insecure_backends"` Context context.Context Supervised bool @@ -129,61 +134,62 @@ type Config struct { // OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request // with the configured oidc-provider type OIDC struct { - Issuer string - Insecure bool - UserinfoCache Cache + Issuer string `ocisConfig:"issuer"` + Insecure bool `ocisConfig:"insecure"` + UserinfoCache Cache `ocisConfig:"user_info_cache"` } // PolicySelector is the toplevel-configuration for different selectors type PolicySelector struct { - Static *StaticSelectorConf - Migration *MigrationSelectorConf - Claims *ClaimsSelectorConf - Regex *RegexSelectorConf + Static *StaticSelectorConf `ocisConfig:"static"` + Migration *MigrationSelectorConf `ocisConfig:"migration"` + Claims *ClaimsSelectorConf `ocisConfig:"claims"` + Regex *RegexSelectorConf `ocisConfig:"regex"` } // StaticSelectorConf is the config for the static-policy-selector type StaticSelectorConf struct { - Policy string + Policy string `ocisConfig:"policy"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `ocisConfig:"jwt_secret"` } // PreSignedURL is the config for the presigned url middleware type PreSignedURL struct { - AllowedHTTPMethods []string - Enabled bool + AllowedHTTPMethods []string `ocisConfig:"allowed_http_methods"` + Enabled bool `ocisConfig:"enabled"` } // MigrationSelectorConf is the config for the migration-selector type MigrationSelectorConf struct { - AccFoundPolicy string `mapstructure:"acc_found_policy"` - AccNotFoundPolicy string `mapstructure:"acc_not_found_policy"` - UnauthenticatedPolicy string `mapstructure:"unauthenticated_policy"` + AccFoundPolicy string `ocisConfig:"acc_found_policy"` + AccNotFoundPolicy string `ocisConfig:"acc_not_found_policy"` + UnauthenticatedPolicy string `ocisConfig:"unauthenticated_policy"` } // ClaimsSelectorConf is the config for the claims-selector type ClaimsSelectorConf struct { - DefaultPolicy string `mapstructure:"default_policy"` - UnauthenticatedPolicy string `mapstructure:"unauthenticated_policy"` - SelectorCookieName string `mapstructure:"selector_cookie_name"` + DefaultPolicy string `ocisConfig:"default_policy"` + UnauthenticatedPolicy string `ocisConfig:"unauthenticated_policy"` + SelectorCookieName string `ocisConfig:"selector_cookie_name"` } // RegexSelectorConf is the config for the regex-selector type RegexSelectorConf struct { - DefaultPolicy string `mapstructure:"default_policy"` - MatchesPolicies []RegexRuleConf `mapstructure:"matches_policies"` - UnauthenticatedPolicy string `mapstructure:"unauthenticated_policy"` - SelectorCookieName string `mapstructure:"selector_cookie_name"` + DefaultPolicy string `ocisConfig:"default_policy"` + MatchesPolicies []RegexRuleConf `ocisConfig:"matches_policies"` + UnauthenticatedPolicy string `ocisConfig:"unauthenticated_policy"` + SelectorCookieName string `ocisConfig:"selector_cookie_name"` } + type RegexRuleConf struct { - Priority int `mapstructure:"priority"` - Property string `mapstructure:"property"` - Match string `mapstructure:"match"` - Policy string `mapstructure:"policy"` + Priority int `ocisConfig:"priority"` + Property string `ocisConfig:"property"` + Match string `ocisConfig:"match"` + Policy string `ocisConfig:"policy"` } // New initializes a new configuration @@ -192,3 +198,217 @@ func New() *Config { HTTP: HTTP{}, } } + +// DefaultConfig provides with a working local configuration for a proxy service. +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "0.0.0.0:9205", + Token: "", + }, + HTTP: HTTP{ + Addr: "0.0.0.0:9200", + Root: "/", + TLSCert: path.Join(defaults.BaseDataPath(), "proxy", "server.crt"), + TLSKey: path.Join(defaults.BaseDataPath(), "proxy", "server.key"), + TLS: true, + }, + Service: Service{ + Name: "proxy", + Namespace: "com.owncloud.web", + }, + Tracing: Tracing{ + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "proxy", + }, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: true, + //Insecure: true, + UserinfoCache: Cache{ + Size: 1024, + TTL: 10, + }, + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + PolicySelector: nil, + Reva: Reva{ + Address: "127.0.0.1:9142", + }, + PreSignedURL: PreSignedURL{ + AllowedHTTPMethods: []string{"GET"}, + Enabled: true, + }, + AccountBackend: "accounts", + UserOIDCClaim: "email", + UserCS3Claim: "mail", + MachineAuthAPIKey: "change-me-please", + //AutoprovisionAccounts: false, + //EnableBasicAuth: false, + //InsecureBackends: false, + Context: nil, + //Policies: defaultPolicies(), + } +} + +func DefaultPolicies() []Policy { + return []Policy{ + { + Name: "ocis", + Routes: []Route{ + { + Endpoint: "/", + Backend: "http://localhost:9100", + }, + { + Endpoint: "/.well-known/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/konnect/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/signin/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/archiver", + Backend: "http://localhost:9140", + }, + { + Type: RegexRoute, + Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs + Backend: "http://localhost:9110", + }, + { + Endpoint: "/ocs/", + Backend: "http://localhost:9140", + }, + { + Type: QueryRoute, + Endpoint: "/remote.php/?preview=1", + Backend: "http://localhost:9115", + }, + { + Endpoint: "/remote.php/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/dav/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/webdav/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/status.php", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/index.php/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/data", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/app/", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/graph/", + Backend: "http://localhost:9120", + }, + { + Endpoint: "/graph-explorer", + Backend: "http://localhost:9135", + }, + // if we were using the go micro api gateway we could look up the endpoint in the registry dynamically + { + Endpoint: "/api/v0/accounts", + Backend: "http://localhost:9181", + }, + // TODO the lookup needs a better mechanism + { + Endpoint: "/accounts.js", + Backend: "http://localhost:9181", + }, + { + Endpoint: "/api/v0/settings", + Backend: "http://localhost:9190", + }, + { + Endpoint: "/settings.js", + Backend: "http://localhost:9190", + }, + }, + }, + { + Name: "oc10", + Routes: []Route{ + { + Endpoint: "/", + Backend: "http://localhost:9100", + }, + { + Endpoint: "/.well-known/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/konnect/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/signin/", + Backend: "http://localhost:9130", + }, + { + Endpoint: "/archiver", + Backend: "http://localhost:9140", + }, + { + Endpoint: "/ocs/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/remote.php/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/dav/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/webdav/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/status.php", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/index.php/", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + { + Endpoint: "/data", + Backend: "https://demo.owncloud.com", + ApacheVHost: true, + }, + }, + }, + } +} diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go new file mode 100644 index 00000000000..582e391b4e5 --- /dev/null +++ b/proxy/pkg/config/mappings.go @@ -0,0 +1,186 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + // Logging + { + EnvVars: []string{"OCIS_LOG_LEVEL", "PROXY_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "PROXY_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "PROXY_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "PROXY_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + + // Basic auth + { + EnvVars: []string{"PROXY_ENABLE_BASIC_AUTH"}, + Destination: &cfg.EnableBasicAuth, + }, + + // Debug (health) + { + EnvVars: []string{"PROXY_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + + // Tracing + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "PROXY_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "PROXY_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "PROXY_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "PROXY_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"PROXY_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + + // Debug + { + EnvVars: []string{"PROXY_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"PROXY_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"PROXY_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"PROXY_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + + // HTTP + { + EnvVars: []string{"PROXY_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"PROXY_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + + // Service + { + EnvVars: []string{"PROXY_SERVICE_NAMESPACE"}, + Destination: &cfg.Service.Namespace, + }, + { + EnvVars: []string{"PROXY_SERVICE_NAME"}, + Destination: &cfg.Service.Name, + }, + { + EnvVars: []string{"PROXY_TRANSPORT_TLS_CERT"}, + Destination: &cfg.HTTP.TLSCert, + }, + { + EnvVars: []string{"PROXY_TRANSPORT_TLS_KEY"}, + Destination: &cfg.HTTP.TLSKey, + }, + { + EnvVars: []string{"PROXY_TLS"}, + Destination: &cfg.HTTP.TLS, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET", "PROXY_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.Address, + }, + { + EnvVars: []string{"PROXY_INSECURE_BACKENDS"}, + Destination: &cfg.InsecureBackends, + }, + { + EnvVars: []string{"OCIS_URL", "PROXY_OIDC_ISSUER"}, + Destination: &cfg.OIDC.Issuer, + }, + { + EnvVars: []string{"OCIS_INSECURE", "PROXY_OIDC_INSECURE"}, + Destination: &cfg.OIDC.Insecure, + }, + { + EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_TTL"}, + Destination: &cfg.OIDC.UserinfoCache.TTL, + }, + { + EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_SIZE"}, + Destination: &cfg.OIDC.UserinfoCache.Size, + }, + { + EnvVars: []string{"PROXY_AUTOPROVISION_ACCOUNTS"}, + Destination: &cfg.AutoprovisionAccounts, + }, + { + EnvVars: []string{"PROXY_USER_OIDC_CLAIM"}, + Destination: &cfg.UserOIDCClaim, + }, + { + EnvVars: []string{"PROXY_USER_CS3_CLAIM"}, + Destination: &cfg.UserCS3Claim, + }, + { + EnvVars: []string{"PROXY_ENABLE_PRESIGNEDURLS"}, + Destination: &cfg.PreSignedURL.Enabled, + }, + { + EnvVars: []string{"PROXY_ACCOUNT_BACKEND_TYPE"}, + Destination: &cfg.AccountBackend, + }, + { + EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "PROXY_MACHINE_AUTH_API_KEY"}, + Destination: &cfg.MachineAuthAPIKey, + }, + // there are 2 missing bindings: + // EnvVars: []string{"PROXY_MIDDLEWARE_AUTH_CREDENTIALS_BY_USER_AGENT"}, + // EnvVars: []string{"PRESIGNEDURL_ALLOWED_METHODS"}, + // since they both have no destination + // see https://github.com/owncloud/ocis/blob/52e5effa4fa05a1626d46f7d4cb574dde3a54593/proxy/pkg/flagset/flagset.go#L256-L261 + // and https://github.com/owncloud/ocis/blob/52e5effa4fa05a1626d46f7d4cb574dde3a54593/proxy/pkg/flagset/flagset.go#L295-L300 + } +} diff --git a/proxy/pkg/flagset/flagset.go b/proxy/pkg/flagset/flagset.go deleted file mode 100644 index 62e5f0d375d..00000000000 --- a/proxy/pkg/flagset/flagset.go +++ /dev/null @@ -1,322 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9109"), - Usage: "Address to debug endpoint", - EnvVars: []string{"PROXY_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"PROXY_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"PROXY_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"PROXY_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: "", - Usage: "Endpoint for the agent", - EnvVars: []string{"PROXY_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: "", - Usage: "Endpoint for the collector", - EnvVars: []string{"PROXY_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "proxy"), - Usage: "Service name for tracing", - EnvVars: []string{"PROXY_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9205"), - Usage: "Address to bind debug server", - EnvVars: []string{"PROXY_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: "", - Usage: "Token to grant metrics access", - EnvVars: []string{"PROXY_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"PROXY_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"PROXY_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "0.0.0.0:9200"), - Usage: "Address to bind http server", - EnvVars: []string{"PROXY_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/"), - Usage: "Root path of http server", - EnvVars: []string{"PROXY_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "service-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the service namespace", - EnvVars: []string{"PROXY_SERVICE_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "service-name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "proxy"), - Usage: "Service name", - EnvVars: []string{"PROXY_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, - &cli.StringFlag{ - Name: "transport-tls-cert", - Value: flags.OverrideDefaultString(cfg.HTTP.TLSCert, path.Join(defaults.BaseDataPath(), "proxy", "server.crt")), - Usage: "Certificate file for transport encryption", - EnvVars: []string{"PROXY_TRANSPORT_TLS_CERT"}, - Destination: &cfg.HTTP.TLSCert, - }, - &cli.StringFlag{ - Name: "transport-tls-key", - Value: flags.OverrideDefaultString(cfg.HTTP.TLSKey, path.Join(defaults.BaseDataPath(), "proxy", "server.key")), - Usage: "Secret file for transport encryption", - EnvVars: []string{"PROXY_TRANSPORT_TLS_KEY"}, - Destination: &cfg.HTTP.TLSKey, - }, - &cli.BoolFlag{ - Name: "tls", - Value: flags.OverrideDefaultBool(cfg.HTTP.TLS, true), - Usage: "Use TLS (disable only if proxy is behind a TLS-terminating reverse-proxy).", - EnvVars: []string{"PROXY_TLS"}, - Destination: &cfg.HTTP.TLS, - }, - &cli.StringFlag{ - Name: "jwt-secret", - Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"), - Usage: "Used to create JWT to talk to reva, should equal reva's jwt-secret", - EnvVars: []string{"PROXY_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Address, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Address, - }, - &cli.BoolFlag{ - Name: "insecure", - Value: flags.OverrideDefaultBool(cfg.InsecureBackends, false), - Usage: "allow insecure communication to upstream servers", - EnvVars: []string{"PROXY_INSECURE_BACKENDS"}, - Destination: &cfg.InsecureBackends, - }, - - // OIDC - - &cli.StringFlag{ - Name: "oidc-issuer", - Value: flags.OverrideDefaultString(cfg.OIDC.Issuer, "https://localhost:9200"), - Usage: "OIDC issuer", - EnvVars: []string{"PROXY_OIDC_ISSUER", "OCIS_URL"}, // PROXY_OIDC_ISSUER takes precedence over OCIS_URL - Destination: &cfg.OIDC.Issuer, - }, - &cli.BoolFlag{ - Name: "oidc-insecure", - Value: flags.OverrideDefaultBool(cfg.OIDC.Insecure, false), - Usage: "OIDC allow insecure communication", - EnvVars: []string{"PROXY_OIDC_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.OIDC.Insecure, - }, - &cli.IntFlag{ - Name: "oidc-userinfo-cache-tll", - Value: flags.OverrideDefaultInt(cfg.OIDC.UserinfoCache.TTL, 10), - Usage: "Fallback TTL in seconds for caching userinfo, when no token lifetime can be identified", - EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_TTL"}, - Destination: &cfg.OIDC.UserinfoCache.TTL, - }, - &cli.IntFlag{ - Name: "oidc-userinfo-cache-size", - Value: flags.OverrideDefaultInt(cfg.OIDC.UserinfoCache.Size, 1024), - Usage: "Max entries for caching userinfo", - EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_SIZE"}, - Destination: &cfg.OIDC.UserinfoCache.Size, - }, - - // account related config - - &cli.BoolFlag{ - Name: "autoprovision-accounts", - Value: flags.OverrideDefaultBool(cfg.AutoprovisionAccounts, false), - Usage: "create accounts from OIDC access tokens to learn new users", - EnvVars: []string{"PROXY_AUTOPROVISION_ACCOUNTS"}, - Destination: &cfg.AutoprovisionAccounts, - }, - &cli.StringFlag{ - Name: "user-oidc-claim", - Value: flags.OverrideDefaultString(cfg.UserOIDCClaim, "email"), - Usage: "The OIDC claim that is used to identify users, eg. 'ownclouduuid', 'uid', 'cn' or 'email'", - EnvVars: []string{"PROXY_USER_OIDC_CLAIM"}, - Destination: &cfg.UserOIDCClaim, - }, - &cli.StringFlag{ - Name: "user-cs3-claim", - Value: flags.OverrideDefaultString(cfg.UserCS3Claim, "mail"), - Usage: "The CS3 claim to use when looking up a user in the CS3 users API, eg. 'userid', 'username' or 'mail'", - EnvVars: []string{"PROXY_USER_CS3_CLAIM"}, - Destination: &cfg.UserCS3Claim, - }, - - // Pre Signed URLs - &cli.StringSliceFlag{ - Name: "presignedurl-allow-method", - Value: cli.NewStringSlice("GET"), - Usage: "--presignedurl-allow-method GET [--presignedurl-allow-method POST]", - EnvVars: []string{"PRESIGNEDURL_ALLOWED_METHODS"}, - }, - &cli.BoolFlag{ - Name: "enable-presignedurls", - Value: flags.OverrideDefaultBool(cfg.PreSignedURL.Enabled, true), - Usage: "Enable or disable handling the presigned urls in the proxy", - EnvVars: []string{"PROXY_ENABLE_PRESIGNEDURLS"}, - Destination: &cfg.PreSignedURL.Enabled, - }, - - // Basic auth - &cli.BoolFlag{ - Name: "enable-basic-auth", - Value: flags.OverrideDefaultBool(cfg.EnableBasicAuth, false), - Usage: "enable basic authentication", - EnvVars: []string{"PROXY_ENABLE_BASIC_AUTH"}, - Destination: &cfg.EnableBasicAuth, - }, - - &cli.StringFlag{ - Name: "account-backend-type", - Value: flags.OverrideDefaultString(cfg.AccountBackend, "accounts"), - Usage: "account-backend-type", - EnvVars: []string{"PROXY_ACCOUNT_BACKEND_TYPE"}, - Destination: &cfg.AccountBackend, - }, - - &cli.StringFlag{ - Name: "machine-auth-api-key", - Value: flags.OverrideDefaultString(cfg.MachineAuthAPIKey, "change-me-please"), - Usage: "the API key to be used for the machine auth driver in reva", - EnvVars: []string{"PROXY_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, - Destination: &cfg.MachineAuthAPIKey, - }, - - // Reva Middlewares Config - &cli.StringSliceFlag{ - Name: "proxy-user-agent-lock-in", - Usage: "--user-agent-whitelist-lock-in=mirall:basic,foo:bearer Given a tuple of [UserAgent:challenge] it locks a given user agent to the authentication challenge. Particularly useful for old clients whose USer-Agent is known and only support one authentication challenge. When this flag is set in the proxy it configures the authentication middlewares.", - EnvVars: []string{"PROXY_MIDDLEWARE_AUTH_CREDENTIALS_BY_USER_AGENT"}, - }, - } -} - -// ListProxyWithConfig applies the config to the list commands flags. -func ListProxyWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "service-namespace", - Value: flags.OverrideDefaultString(cfg.OIDC.Issuer, "com.owncloud.web"), - Usage: "Set the base namespace for the service namespace", - EnvVars: []string{"PROXY_SERVICE_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "service-name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "proxy"), - Usage: "Service name", - EnvVars: []string{"PROXY_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, - } -} diff --git a/proxy/pkg/proxy/proxy.go b/proxy/pkg/proxy/proxy.go index a863fd5e9f1..7681defb80c 100644 --- a/proxy/pkg/proxy/proxy.go +++ b/proxy/pkg/proxy/proxy.go @@ -62,13 +62,6 @@ func NewMultiHostReverseProxy(opts ...Option) *MultiHostReverseProxy { }, } - if options.Config.Policies == nil { - rp.logger.Info().Str("source", "runtime").Msg("Policies") - options.Config.Policies = defaultPolicies() - } else { - rp.logger.Info().Str("source", "file").Str("src", options.Config.File).Msg("policies") - } - if options.Config.PolicySelector == nil { firstPolicy := options.Config.Policies[0].Name rp.logger.Warn().Str("policy", firstPolicy).Msg("policy-selector not configured. Will always use first policy") @@ -93,20 +86,15 @@ func NewMultiHostReverseProxy(opts ...Option) *MultiHostReverseProxy { for _, pol := range options.Config.Policies { for _, route := range pol.Routes { rp.logger.Debug().Str("fwd: ", route.Endpoint) - uri, err := url.Parse(route.Backend) - if err != nil { + uri, err2 := url.Parse(route.Backend) + if err2 != nil { rp.logger. Fatal(). // fail early on misconfiguration - Err(err). + Err(err2). Str("backend", route.Backend). Msg("malformed url") } - rp.logger. - Debug(). - Interface("route", route). - Msg("adding route") - rp.AddHost(pol.Name, uri, route) } } @@ -268,161 +256,3 @@ func (p *MultiHostReverseProxy) regexRouteMatcher(pattern string, target url.URL func (p *MultiHostReverseProxy) prefixRouteMatcher(prefix string, target url.URL) bool { return strings.HasPrefix(target.Path, prefix) && prefix != "/" } - -func defaultPolicies() []config.Policy { - return []config.Policy{ - { - Name: "ocis", - Routes: []config.Route{ - { - Endpoint: "/", - Backend: "http://localhost:9100", - }, - { - Endpoint: "/.well-known/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/konnect/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/signin/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/archiver", - Backend: "http://localhost:9140", - }, - { - Type: config.RegexRoute, - Endpoint: "/ocs/v[12].php/cloud/(users?|groups)", // we have `user`, `users` and `groups` in ocis-ocs - Backend: "http://localhost:9110", - }, - { - Endpoint: "/ocs/", - Backend: "http://localhost:9140", - }, - { - Type: config.QueryRoute, - Endpoint: "/remote.php/?preview=1", - Backend: "http://localhost:9115", - }, - { - Endpoint: "/remote.php/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/dav/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/webdav/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/status.php", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/index.php/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/data", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/app/", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/graph/", - Backend: "http://localhost:9120", - }, - { - Endpoint: "/graph-explorer", - Backend: "http://localhost:9135", - }, - // if we were using the go micro api gateway we could look up the endpoint in the registry dynamically - { - Endpoint: "/api/v0/accounts", - Backend: "http://localhost:9181", - }, - // TODO the lookup needs a better mechanism - { - Endpoint: "/accounts.js", - Backend: "http://localhost:9181", - }, - { - Endpoint: "/api/v0/settings", - Backend: "http://localhost:9190", - }, - { - Endpoint: "/settings.js", - Backend: "http://localhost:9190", - }, - }, - }, - { - Name: "oc10", - Routes: []config.Route{ - { - Endpoint: "/", - Backend: "http://localhost:9100", - }, - { - Endpoint: "/.well-known/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/konnect/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/signin/", - Backend: "http://localhost:9130", - }, - { - Endpoint: "/archiver", - Backend: "http://localhost:9140", - }, - { - Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - { - Endpoint: "/data", - Backend: "https://demo.owncloud.com", - ApacheVHost: true, - }, - }, - }, - } -} diff --git a/proxy/pkg/proxy/proxy_integration_test.go b/proxy/pkg/proxy/proxy_integration_test.go index 3b439e7c096..9809383a67e 100644 --- a/proxy/pkg/proxy/proxy_integration_test.go +++ b/proxy/pkg/proxy/proxy_integration_test.go @@ -10,6 +10,8 @@ import ( "net/url" "testing" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/proxy/pkg/config" ) @@ -213,8 +215,7 @@ func (tc *testCase) expectProxyTo(strURL string) testCase { func testConfig(policy []config.Policy) *config.Config { return &config.Config{ - File: "", - Log: config.Log{}, + Log: &shared.Log{}, Debug: config.Debug{}, HTTP: config.HTTP{}, Tracing: config.Tracing{}, diff --git a/proxy/pkg/proxy/proxy_test.go b/proxy/pkg/proxy/proxy_test.go index 8eefe3143b7..a0300e64d18 100644 --- a/proxy/pkg/proxy/proxy_test.go +++ b/proxy/pkg/proxy/proxy_test.go @@ -13,7 +13,8 @@ type matchertest struct { } func TestPrefixRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() + cfg.Policies = config.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -32,7 +33,8 @@ func TestPrefixRouteMatcher(t *testing.T) { } func TestQueryRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() + cfg.Policies = config.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -59,7 +61,8 @@ func TestQueryRouteMatcher(t *testing.T) { } func TestRegexRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() + cfg.Policies = config.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 2d8bfb7382a..b4106f2a8c4 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -1,6 +1,7 @@ package debug import ( + "encoding/json" "io" "net/http" @@ -22,6 +23,7 @@ func Server(opts ...Option) (*http.Server, error) { debug.Zpages(options.Config.Debug.Zpages), debug.Health(health(options.Config)), debug.Ready(ready(options.Config)), + debug.ConfigDump(configDump(options.Config)), ), nil } @@ -52,3 +54,17 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { } } } + +// configDump implements the config dump +func configDump(cfg *config.Config) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + b, err := json.Marshal(cfg) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + } + + _, _ = w.Write(b) + } +} diff --git a/settings/cmd/settings/main.go b/settings/cmd/settings/main.go index 56ced7764fb..cfee45c6987 100644 --- a/settings/cmd/settings/main.go +++ b/settings/cmd/settings/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/settings/pkg/command/health.go b/settings/pkg/command/health.go index 72e9ea7f7db..9b475f5e7ac 100644 --- a/settings/pkg/command/health.go +++ b/settings/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index de90398455f..74c09626e38 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -3,16 +3,13 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/shared" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/flagset" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -32,8 +29,6 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Service.Version = version.String return nil @@ -70,49 +65,28 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads settings configuration from Viper known paths. +// ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("SETTINGS") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("settings") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("settings", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } - - return nil + conf.LoadOSEnv(config.GetEnv(cfg), false) + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree. @@ -122,10 +96,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Settings.Supervised = true - } - cfg.Settings.Log.File = cfg.Log.File + cfg.Settings.Commons = cfg.Commons return SutureService{ cfg: cfg.Settings, } diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 630930a8575..894b159ff75 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -7,7 +7,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/flagset" "github.com/owncloud/ocis/settings/pkg/metrics" "github.com/owncloud/ocis/settings/pkg/server/debug" "github.com/owncloud/ocis/settings/pkg/server/grpc" @@ -21,28 +20,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - // When running on single binary mode the before hook from the root command won't get called. We manually - // call this before hook from ocis command, so the configuration can be loaded. - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - if origins := ctx.StringSlice("cors-allowed-origins"); len(origins) != 0 { - cfg.HTTP.CORS.AllowedOrigins = origins - } - if methods := ctx.StringSlice("cors-allowed-methods"); len(methods) != 0 { - cfg.HTTP.CORS.AllowedMethods = methods - } - if headers := ctx.StringSlice("cors-allowed-headers"); len(headers) != 0 { - cfg.HTTP.CORS.AllowedOrigins = headers + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "settings").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { diff --git a/settings/pkg/command/version.go b/settings/pkg/command/version.go index fda866b626b..55091cf81a1 100644 --- a/settings/pkg/command/version.go +++ b/settings/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/settings/pkg/config" - "github.com/owncloud/ocis/settings/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListSettingsWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 71053c421f5..4d91088b965 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -1,83 +1,84 @@ package config -import "context" - -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} +import ( + "context" + "path" + + "github.com/owncloud/ocis/ocis-pkg/shared" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allow_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string - CacheTTL int - CORS CORS + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Root string `ocisConfig:"root"` + CacheTTL int `ocisConfig:"cache_ttl"` + CORS CORS `ocisConfig:"cors"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string - Namespace string + Addr string `ocisConfig:"grpc"` + Namespace string `ocisConfig:"namespace"` } // Service provides configuration options for the service type Service struct { - Name string - Version string - DataPath string + Name string `ocisConfig:"name"` + Version string `ocisConfig:"version"` + DataPath string `ocisConfig:"data_path"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Asset undocumented type Asset struct { - Path string + Path string `ocisConfig:"asset"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `ocisConfig:"jwt_secret"` } // Config combines all available configuration parts. type Config struct { - File string - Service Service - Log Log - Debug Debug - HTTP HTTP - GRPC GRPC - Tracing Tracing - Asset Asset - TokenManager TokenManager + *shared.Commons + + File string `ocisConfig:"file"` + Service Service `ocisConfig:"service"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + GRPC GRPC `ocisConfig:"grpc"` + Tracing Tracing `ocisConfig:"tracing"` + Asset Asset `ocisConfig:"asset"` + TokenManager TokenManager `ocisConfig:"token_manager"` Context context.Context Supervised bool @@ -87,3 +88,48 @@ type Config struct { func New() *Config { return &Config{} } + +// DefaultConfig provides sane bootstrapping defaults. +func DefaultConfig() *Config { + return &Config{ + Service: Service{ + Name: "settings", + DataPath: path.Join(defaults.BaseDataPath(), "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", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "settings", + }, + Asset: Asset{ + Path: "", + }, + TokenManager: TokenManager{ + JWTSecret: "Pive-Fumkiu4", + }, + } +} diff --git a/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go new file mode 100644 index 00000000000..0fd5a9f2d6b --- /dev/null +++ b/settings/pkg/config/mappings.go @@ -0,0 +1,119 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL", "SETTINGS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "SETTINGS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "SETTINGS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"SETTINGS_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "SETTINGS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "SETTINGS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "SETTINGS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "SETTINGS_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"SETTINGS_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"SETTINGS_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"SETTINGS_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"SETTINGS_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"SETTINGS_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"SETTINGS_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"SETTINGS_HTTP_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, + }, + { + EnvVars: []string{"SETTINGS_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"SETTINGS_CACHE_TTL"}, + Destination: &cfg.HTTP.CacheTTL, + }, + { + EnvVars: []string{"SETTINGS_GRPC_ADDR"}, + Destination: &cfg.GRPC.Addr, + }, + { + EnvVars: []string{"SETTINGS_ASSET_PATH"}, + Destination: &cfg.Asset.Path, + }, + { + EnvVars: []string{"SETTINGS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + { + EnvVars: []string{"SETTINGS_NAME"}, + Destination: &cfg.Service.Name, + }, + { + EnvVars: []string{"SETTINGS_DATA_PATH"}, + Destination: &cfg.Service.DataPath, + }, + { + EnvVars: []string{"OCIS_JWT_SECRET", "SETTINGS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + } +} diff --git a/settings/pkg/flagset/flagset.go b/settings/pkg/flagset/flagset.go deleted file mode 100644 index 585cfcecfa0..00000000000 --- a/settings/pkg/flagset/flagset.go +++ /dev/null @@ -1,238 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/settings/pkg/config" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"SETTINGS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"SETTINGS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"SETTINGS_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9194"), - Usage: "Address to debug endpoint", - EnvVars: []string{"SETTINGS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"SETTINGS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"SETTINGS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"SETTINGS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"SETTINGS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"SETTINGS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "settings"), - Usage: "Service name for tracing", - EnvVars: []string{"SETTINGS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9194"), - Usage: "Address to bind debug server", - EnvVars: []string{"SETTINGS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"SETTINGS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"SETTINGS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"SETTINGS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9190"), - Usage: "Address to bind http server", - EnvVars: []string{"SETTINGS_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.HTTP.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http namespace", - EnvVars: []string{"SETTINGS_HTTP_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/"), - Usage: "Root path of http server", - EnvVars: []string{"SETTINGS_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.IntFlag{ - Name: "http-cache-ttl", - Value: flags.OverrideDefaultInt(cfg.HTTP.CacheTTL, 604800), // 10 days - Usage: "Set the static assets caching duration in seconds", - EnvVars: []string{"SETTINGS_CACHE_TTL"}, - Destination: &cfg.HTTP.CacheTTL, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-origins", - Value: cli.NewStringSlice("*"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"SETTINGS_CORS_ALLOW_ORIGINS", "OCIS_CORS_ALLOW_ORIGINS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-methods", - Value: cli.NewStringSlice("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"SETTINGS_CORS_ALLOW_METHODS", "OCIS_CORS_ALLOW_METHODS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-headers", - Value: cli.NewStringSlice("Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"SETTINGS_CORS_ALLOW_HEADERS", "OCIS_CORS_ALLOW_HEADERS"}, - }, - &cli.BoolFlag{ - Name: "cors-allow-credentials", - Value: flags.OverrideDefaultBool(cfg.HTTP.CORS.AllowCredentials, true), - Usage: "Allow credentials for CORS", - EnvVars: []string{"SETTINGS_CORS_ALLOW_CREDENTIALS", "OCIS_CORS_ALLOW_CREDENTIALS"}, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.GRPC.Addr, "127.0.0.1:9191"), - Usage: "Address to bind grpc server", - EnvVars: []string{"SETTINGS_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - &cli.StringFlag{ - Name: "asset-path", - Value: flags.OverrideDefaultString(cfg.Asset.Path, ""), - Usage: "Path to custom assets", - EnvVars: []string{"SETTINGS_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"SETTINGS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "settings"), - Usage: "service name", - EnvVars: []string{"SETTINGS_NAME"}, - Destination: &cfg.Service.Name, - }, - &cli.StringFlag{ - Name: "data-path", - Value: flags.OverrideDefaultString(cfg.Service.DataPath, path.Join(defaults.BaseDataPath(), "settings")), - Usage: "Mount path for the storage", - EnvVars: []string{"SETTINGS_DATA_PATH"}, - Destination: &cfg.Service.DataPath, - }, - &cli.StringFlag{ - Name: "jwt-secret", - Value: flags.OverrideDefaultString(cfg.TokenManager.JWTSecret, "Pive-Fumkiu4"), - Usage: "Used to create JWT to talk to reva, should equal reva's jwt-secret", - EnvVars: []string{"SETTINGS_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.TokenManager.JWTSecret, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} - -// ListSettingsWithConfig applies list command flags to cfg -func ListSettingsWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.GRPC.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"SETTINGS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "settings"), - Usage: "service name", - EnvVars: []string{"SETTINGS_NAME"}, - Destination: &cfg.Service.Name, - }, - } -} diff --git a/settings/pkg/store/filesystem/store.go b/settings/pkg/store/filesystem/store.go index 8eb3f034161..cf81638b9e5 100644 --- a/settings/pkg/store/filesystem/store.go +++ b/settings/pkg/store/filesystem/store.go @@ -24,17 +24,17 @@ type Store struct { // New creates a new store func New(cfg *config.Config) settings.Manager { s := Store{ - Logger: olog.NewLogger( - olog.Color(cfg.Log.Color), - olog.Pretty(cfg.Log.Pretty), - olog.Level(cfg.Log.Level), - olog.File(cfg.Log.File), - ), + //Logger: olog.NewLogger( + // olog.Color(cfg.Log.Color), + // olog.Pretty(cfg.Log.Pretty), + // olog.Level(cfg.Log.Level), + // olog.File(cfg.Log.File), + //), } if _, err := os.Stat(cfg.Service.DataPath); err != nil { s.Logger.Info().Msgf("creating container on %v", cfg.Service.DataPath) - err := os.MkdirAll(cfg.Service.DataPath, 0700) + err = os.MkdirAll(cfg.Service.DataPath, 0700) if err != nil { s.Logger.Err(err).Msgf("providing container on %v", cfg.Service.DataPath) diff --git a/storage/cmd/storage/main.go b/storage/cmd/storage/main.go index 2eaed0e9634..78ccf99eca9 100644 --- a/storage/cmd/storage/main.go +++ b/storage/cmd/storage/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 1a8b9e5d95c..80c8c523bac 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -24,11 +23,8 @@ func AppProvider(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "app-provider", Usage: "Start appprovider for providing apps", - Flags: flagset.AppProviderWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.AppProvider.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-app-provider") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -132,9 +128,7 @@ type AppProviderSutureService struct { // NewAppProvider creates a new store.AppProviderSutureService func NewAppProvider(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.AppProvider.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return AppProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 840963058d4..10268754a14 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -13,7 +13,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -25,11 +24,8 @@ func AuthBasic(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-basic", Usage: "Start authprovider for basic auth", - Flags: flagset.AuthBasicWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.AuthBasic.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-auth-basic") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -151,9 +147,7 @@ type AuthBasicSutureService struct { // NewAuthBasicSutureService creates a new store.AuthBasicSutureService func NewAuthBasic(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.AuthBasic.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return AuthBasicSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 4a2b43c05ed..af60ccbdac7 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -24,11 +23,8 @@ func AuthBearer(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-bearer", Usage: "Start authprovider for bearer auth", - Flags: flagset.AuthBearerWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.AuthBearer.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-auth-bearer") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -127,9 +123,7 @@ type AuthBearerSutureService struct { // NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService func NewAuthBearer(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.AuthBearer.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return AuthBearerSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 8bdb111014d..eaaa97cbf61 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -24,11 +23,8 @@ func AuthMachine(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-machine", Usage: "Start authprovider for machine auth", - Flags: flagset.AuthMachineWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.AuthMachine.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-auth-machine") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -123,9 +119,7 @@ type AuthMachineSutureService struct { // NewAuthMachineSutureService creates a new gateway.AuthMachineSutureService func NewAuthMachine(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.AuthMachine.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return AuthMachineSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 19822f7f28f..4161d35c9fc 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -16,7 +16,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/conversions" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -28,11 +27,11 @@ func Frontend(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "frontend", Usage: "Start frontend service", - Flags: flagset.FrontendWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Frontend.Services = c.StringSlice("service") - cfg.Reva.ChecksumSupportedTypes = c.StringSlice("checksum-supported-type") - return loadUserAgent(c, cfg) + if err := loadUserAgent(c, cfg); err != nil { + return err + } + return ParseConfig(c, cfg, "storage-frontend") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -335,11 +334,9 @@ type FrontendSutureService struct { cfg *config.Config } -// NewFrontendSutureService creates a new frontend.FrontendSutureService +// NewFrontend creates a new frontend.FrontendSutureService func NewFrontend(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.Frontend.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return FrontendSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 444a0fd6e7b..63f158da1ec 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -9,21 +9,19 @@ import ( "path" "strings" - "github.com/mitchellh/mapstructure" - "github.com/owncloud/ocis/storage/pkg/tracing" - - "github.com/owncloud/ocis/ocis-pkg/sync" - "github.com/owncloud/ocis/ocis-pkg/version" - "github.com/cs3org/reva/cmd/revad/runtime" "github.com/gofrs/uuid" + "github.com/mitchellh/mapstructure" "github.com/oklog/run" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/service/external" + "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -33,10 +31,10 @@ func Gateway(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "gateway", Usage: "Start gateway", - Flags: flagset.GatewayWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Gateway.Services = c.StringSlice("service") - cfg.Reva.StorageRegistry.Rules = c.StringSlice("storage-registry-rule") + if err := ParseConfig(c, cfg, "storage-gateway"); err != nil { + return err + } if cfg.Reva.DataGateway.PublicURL == "" { cfg.Reva.DataGateway.PublicURL = strings.TrimRight(cfg.Reva.Frontend.PublicURL, "/") + "/data" @@ -221,9 +219,9 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac } // generate rules based on default config - return map[string]map[string]interface{}{ + ret := map[string]map[string]interface{}{ cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint}, - cfg.Reva.StorageHome.MountID: {"address": cfg.Reva.StorageHome.Endpoint}, + cfg.Reva.StorageHome.AlternativeID: {"address": cfg.Reva.StorageHome.Endpoint}, cfg.Reva.StorageUsers.MountPath: {"address": cfg.Reva.StorageUsers.Endpoint}, cfg.Reva.StorageUsers.MountID + ".*": {"address": cfg.Reva.StorageUsers.Endpoint}, cfg.Reva.StoragePublicLink.MountPath: {"address": cfg.Reva.StoragePublicLink.Endpoint}, @@ -231,6 +229,8 @@ func rules(cfg *config.Config, logger log.Logger) map[string]map[string]interfac // public link storage returns the mount id of the actual storage // medatada storage not part of the global namespace } + + return ret } func mimetypes(cfg *config.Config, logger log.Logger) []map[string]interface{} { @@ -352,9 +352,7 @@ type GatewaySutureService struct { // NewGatewaySutureService creates a new gateway.GatewaySutureService func NewGateway(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.Gateway.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return GatewaySutureService{ cfg: cfg.Storage, } @@ -381,3 +379,29 @@ func (s GatewaySutureService) Serve(ctx context.Context) error { return nil } + +// ParseConfig loads accounts configuration from known paths. +func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) error { + conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg) + if err != nil { + 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} + } + + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(cfg), false) + + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) +} diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index e3758080f7f..043c96fdcdc 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -13,7 +13,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -25,11 +24,8 @@ func Groups(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "groups", Usage: "Start groups service", - Flags: flagset.GroupsWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Groups.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-groups") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -165,9 +161,7 @@ type GroupSutureService struct { // NewGroupProviderSutureService creates a new storage.GroupProvider func NewGroupProvider(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.Groups.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return GroupSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/health.go b/storage/pkg/command/health.go index 9398b3ba030..a3c3791a99c 100644 --- a/storage/pkg/command/health.go +++ b/storage/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg, "storage") + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 9d0ee792ae2..4ac235e8cc2 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -2,13 +2,10 @@ package command import ( "os" - "strings" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" - "github.com/spf13/viper" "github.com/urfave/cli/v2" ) @@ -26,49 +23,8 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, - - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("STORAGE") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("storage") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") - } - - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read config") - } - } - - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } - - return nil + return ParseConfig(c, cfg, "storage") }, Commands: []*cli.Command{ diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index 50f50c64b6e..abace4d50b2 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -16,7 +16,6 @@ import ( "github.com/oklog/run" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" @@ -27,11 +26,8 @@ func Sharing(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "sharing", Usage: "Start sharing service", - Flags: flagset.SharingWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Sharing.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-sharing") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -191,9 +187,7 @@ type SharingSutureService struct { // NewSharingSutureService creates a new store.SharingSutureService func NewSharing(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.Sharing.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return SharingSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index fff984b13c0..bbeca4d7058 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -14,7 +14,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/storage/pkg/command/storagedrivers" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -26,11 +25,8 @@ func StorageHome(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-home", Usage: "Start storage-home service", - Flags: flagset.StorageHomeWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.StorageHome.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-home") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -150,9 +146,7 @@ type StorageHomeSutureService struct { // NewStorageHomeSutureService creates a new storage.StorageHomeSutureService func NewStorageHome(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.StorageHome.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return StorageHomeSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 74af72911e9..1c84313a37e 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -15,7 +15,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/command/storagedrivers" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/service/external" "github.com/owncloud/ocis/storage/pkg/tracing" @@ -30,8 +29,9 @@ func StorageMetadata(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-metadata", Usage: "Start storage-metadata service", - // TODO(refs) at this point it might make sense delegate log flags to each individual storage command. - Flags: append(flagset.StorageMetadata(cfg), flagset.RootWithConfig(cfg)...), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg, "storage-metadata") + }, Category: "Extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -166,9 +166,7 @@ type MetadataSutureService struct { // NewSutureService creates a new storagemetadata.SutureService func NewStorageMetadata(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.StorageMetadata.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return MetadataSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 22dbf988528..edd73c9ad5d 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -12,7 +12,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -22,9 +21,11 @@ import ( // StoragePublicLink is the entrypoint for the reva-storage-public-link command. func StoragePublicLink(cfg *config.Config) *cli.Command { return &cli.Command{ - Name: "storage-public-link", - Usage: "Start storage-public-link service", - Flags: flagset.StoragePublicLink(cfg), + Name: "storage-public-link", + Usage: "Start storage-public-link service", + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg, "storage-public-link") + }, Category: "Extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -125,9 +126,7 @@ type StoragePublicLinkSutureService struct { // NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.StoragePublicLink.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return StoragePublicLinkSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 99ae03348c0..7bb7aa6c0ff 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -13,7 +13,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/command/storagedrivers" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -25,11 +24,8 @@ func StorageUsers(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-users", Usage: "Start storage-users service", - Flags: flagset.StorageUsersWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.StorageHome.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-userprovider") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -150,9 +146,7 @@ type StorageUsersSutureService struct { // NewStorageUsersSutureService creates a new storage.StorageUsersSutureService func NewStorageUsers(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.StorageUsers.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return StorageUsersSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 2f4c3e87cc8..34aee1d7c03 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -13,7 +13,6 @@ import ( ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/owncloud/ocis/storage/pkg/server/debug" "github.com/owncloud/ocis/storage/pkg/tracing" "github.com/thejerf/suture/v4" @@ -25,11 +24,8 @@ func Users(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "users", Usage: "Start users service", - Flags: flagset.UsersWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Users.Services = c.StringSlice("service") - - return nil + return ParseConfig(c, cfg, "storage-users") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -186,9 +182,7 @@ type UserProviderSutureService struct { // NewUserProviderSutureService creates a new storage.UserProvider func NewUserProvider(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Storage.Reva.Users.Supervised = true - } + cfg.Storage.Commons = cfg.Commons return UserProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 4797b77362a..a9f6b5967c3 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -1,235 +1,243 @@ package config -import "context" +import ( + "context" + "os" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `ocisConfig:"level"` + Pretty bool `ocisConfig:"pretty"` + Color bool `ocisConfig:"color"` + File string `ocisConfig:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // Gateway defines the available gateway configuration. type Gateway struct { Port - CommitShareToStorageGrant bool - CommitShareToStorageRef bool - DisableHomeCreationOnLogin bool - ShareFolder string - LinkGrants string - HomeMapping string - EtagCacheTTL int + CommitShareToStorageGrant bool `ocisConfig:"commit_share_to_storage_grant"` + CommitShareToStorageRef bool `ocisConfig:"commit_share_to_storage_ref"` + DisableHomeCreationOnLogin bool `ocisConfig:"disable_home_creation_on_login"` + ShareFolder string `ocisConfig:"share_folder"` + LinkGrants string `ocisConfig:"link_grants"` + HomeMapping string `ocisConfig:"home_mapping"` + EtagCacheTTL int `ocisConfig:"etag_cache_ttl"` } // StorageRegistry defines the available storage registry configuration type StorageRegistry struct { - Driver string + Driver string `ocisConfig:"driver"` // HomeProvider is the path in the global namespace that the static storage registry uses to determine the home storage - HomeProvider string - Rules []string - JSON string + HomeProvider string `ocisConfig:"home_provider"` + Rules []string `ocisConfig:"rules"` + JSON string `ocisConfig:"json"` } // AppRegistry defines the available app registry configuration type AppRegistry struct { - Driver string - MimetypesJSON string + Driver string `ocisConfig:"driver"` + MimetypesJSON string `ocisConfig:"mime_types_json"` } // AppProvider defines the available app provider configuration type AppProvider struct { Port - ExternalAddr string - Driver string - WopiDriver WopiDriver - AppsURL string - OpenURL string + ExternalAddr string `ocisConfig:"external_addr"` + Driver string `ocisConfig:"driver"` + WopiDriver WopiDriver `ocisConfig:"wopi_driver"` + AppsURL string `ocisConfig:"apps_url"` + OpenURL string `ocisConfig:"open_url"` } type WopiDriver struct { - AppAPIKey string - AppDesktopOnly bool - AppIconURI string - AppInternalURL string - AppName string - AppURL string - Insecure bool - IopSecret string - JWTSecret string - WopiURL string + AppAPIKey string `ocisConfig:"app_api_key"` + AppDesktopOnly bool `ocisConfig:"app_desktop_only"` + AppIconURI string `ocisConfig:"app_icon_uri"` + AppInternalURL string `ocisConfig:"app_internal_url"` + AppName string `ocisConfig:"app_name"` + AppURL string `ocisConfig:"app_url"` + Insecure bool `ocisConfig:"insecure"` + IopSecret string `ocisConfig:"ipo_secret"` + JWTSecret string `ocisConfig:"jwt_secret"` + WopiURL string `ocisConfig:"wopi_url"` } // Sharing defines the available sharing configuration. type Sharing struct { Port - UserDriver string - UserJSONFile string - UserSQLUsername string - UserSQLPassword string - UserSQLHost string - UserSQLPort int - UserSQLName string - PublicDriver string - PublicJSONFile string - PublicPasswordHashCost int - PublicEnableExpiredSharesCleanup bool - PublicJanitorRunInterval int - UserStorageMountID string + UserDriver string `ocisConfig:"user_driver"` + UserJSONFile string `ocisConfig:"user_json_file"` + UserSQLUsername string `ocisConfig:"user_sql_username"` + UserSQLPassword string `ocisConfig:"user_sql_password"` + UserSQLHost string `ocisConfig:"user_sql_host"` + UserSQLPort int `ocisConfig:"user_sql_port"` + UserSQLName string `ocisConfig:"user_sql_name"` + PublicDriver string `ocisConfig:"public_driver"` + PublicJSONFile string `ocisConfig:"public_json_file"` + PublicPasswordHashCost int `ocisConfig:"public_password_hash_cost"` + PublicEnableExpiredSharesCleanup bool `ocisConfig:"public_enable_expired_shares_cleanup"` + PublicJanitorRunInterval int `ocisConfig:"public_janitor_run_interval"` + UserStorageMountID string `ocisConfig:"user_storage_mount_id"` } // Port defines the available port configuration. type Port struct { // MaxCPUs can be a number or a percentage - MaxCPUs string - LogLevel string + MaxCPUs string `ocisConfig:"max_cpus"` + LogLevel string `ocisConfig:"log_level"` // GRPCNetwork can be tcp, udp or unix - GRPCNetwork string + GRPCNetwork string `ocisConfig:"grpc_network"` // GRPCAddr to listen on, hostname:port (0.0.0.0:9999 for all interfaces) or socket (/var/run/reva/sock) - GRPCAddr string + GRPCAddr string `ocisConfig:"grpc_addr"` // Protocol can be grpc or http // HTTPNetwork can be tcp, udp or unix - HTTPNetwork string + HTTPNetwork string `ocisConfig:"http_network"` // HTTPAddr to listen on, hostname:port (0.0.0.0:9100 for all interfaces) or socket (/var/run/reva/sock) - HTTPAddr string + HTTPAddr string `ocisConfig:"http_addr"` // Protocol can be grpc or http - Protocol string + Protocol string `ocisConfig:"protocol"` // Endpoint is used by the gateway and registries (eg localhost:9100 or cloud.example.com) - Endpoint string + Endpoint string `ocisConfig:"endpoint"` // DebugAddr for the debug endpoint to bind to - DebugAddr string + DebugAddr string `ocisConfig:"debug_addr"` // Services can be used to give a list of services that should be started on this port - Services []string + Services []string `ocisConfig:"services"` // Config can be used to configure the reva instance. // Services and Protocol will be ignored if this is used - Config map[string]interface{} + Config map[string]interface{} `ocisConfig:"config"` // Context allows for context cancellation and propagation Context context.Context // Supervised is used when running under an oCIS runtime supervision tree - Supervised bool + Supervised bool // deprecated } // Users defines the available users configuration. type Users struct { Port - Driver string - JSON string - UserGroupsCacheExpiration int + Driver string `ocisConfig:"driver"` + JSON string `ocisConfig:"json"` + UserGroupsCacheExpiration int `ocisConfig:"user_groups_cache_expiration"` } // AuthMachineConfig defines the available configuration for the machine auth driver. type AuthMachineConfig struct { - MachineAuthAPIKey string + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"` } // Groups defines the available groups configuration. type Groups struct { Port - Driver string - JSON string - GroupMembersCacheExpiration int + Driver string `ocisConfig:"driver"` + JSON string `ocisConfig:"json"` + GroupMembersCacheExpiration int `ocisConfig:"group_members_cache_expiration"` } // FrontendPort defines the available frontend configuration. type FrontendPort struct { Port - AppProviderInsecure bool - AppProviderPrefix string - ArchiverInsecure bool - ArchiverPrefix string - DatagatewayPrefix string - Favorites bool - OCDavInsecure bool - OCDavPrefix string - OCSPrefix string - OCSSharePrefix string - OCSHomeNamespace string - PublicURL string - OCSCacheWarmupDriver string - OCSAdditionalInfoAttribute string - OCSResourceInfoCacheTTL int - Middleware Middleware + AppProviderInsecure bool `ocisConfig:"app_provider_insecure"` + AppProviderPrefix string `ocisConfig:"app_provider_prefix"` + ArchiverInsecure bool `ocisConfig:"archiver_insecure"` + ArchiverPrefix string `ocisConfig:"archiver_prefix"` + DatagatewayPrefix string `ocisConfig:"data_gateway_prefix"` + Favorites bool `ocisConfig:"favorites"` + OCDavInsecure bool `ocisConfig:"ocdav_insecure"` + OCDavPrefix string `ocisConfig:"ocdav_prefix"` + OCSPrefix string `ocisConfig:"ocs_prefix"` + OCSSharePrefix string `ocisConfig:"ocs_share_prefix"` + OCSHomeNamespace string `ocisConfig:"ocs_home_namespace"` + PublicURL string `ocisConfig:"public_url"` + OCSCacheWarmupDriver string `ocisConfig:"ocs_cache_warmup_driver"` + OCSAdditionalInfoAttribute string `ocisConfig:"ocs_additional_info_attribute"` + OCSResourceInfoCacheTTL int `ocisConfig:"ocs_resource_info_cache_ttl"` + Middleware Middleware `ocisConfig:"middleware"` } // Middleware configures reva middlewares. type Middleware struct { - Auth Auth + Auth Auth `ocisConfig:"auth"` } // Auth configures reva http auth middleware. type Auth struct { - CredentialsByUserAgent map[string]string + CredentialsByUserAgent map[string]string `ocisConfig:"credentials_by_user_agenr"` } // DataGatewayPort has a public url type DataGatewayPort struct { Port - PublicURL string + PublicURL string `ocisConfig:""` } type DataProvider struct { - Insecure bool + Insecure bool `ocisConfig:"insecure"` } // StoragePort defines the available storage configuration. type StoragePort struct { Port - Driver string - MountPath string - MountID string - ExposeDataServer bool + Driver string `ocisConfig:"driver"` + MountPath string `ocisConfig:"mount_path"` + MountID string `ocisConfig:"mount_id"` + AlternativeID string `ocisConfig:"alternative_id"` + ExposeDataServer bool `ocisConfig:"expose_data_server"` // url the data gateway will use to route requests - DataServerURL string + DataServerURL string `ocisConfig:"data_server_url"` // for HTTP ports with only one http service - HTTPPrefix string - TempFolder string - ReadOnly bool - DataProvider DataProvider + HTTPPrefix string `ocisConfig:"http_prefix"` + TempFolder string `ocisConfig:"temp_folder"` + ReadOnly bool `ocisConfig:"read_only"` + DataProvider DataProvider `ocisConfig:"data_provider"` } // PublicStorage configures a public storage provider type PublicStorage struct { StoragePort - PublicShareProviderAddr string - UserProviderAddr string + PublicShareProviderAddr string `ocisConfig:"public_share_provider_addr"` + UserProviderAddr string `ocisConfig:"user_provider_addr"` } // StorageConfig combines all available storage driver configuration parts. type StorageConfig struct { - EOS DriverEOS - Local DriverCommon - OwnCloud DriverOwnCloud - OwnCloudSQL DriverOwnCloudSQL - S3 DriverS3 - S3NG DriverS3NG - OCIS DriverOCIS - // TODO checksums ... figure out what that is supposed to do + EOS DriverEOS `ocisConfig:"eos"` + Local DriverCommon `ocisConfig:"local"` + OwnCloud DriverOwnCloud `ocisConfig:"owncloud"` + OwnCloudSQL DriverOwnCloudSQL `ocisConfig:"owncloud_sql"` + S3 DriverS3 `ocisConfig:"s3"` + S3NG DriverS3NG `ocisConfig:"s3ng"` + OCIS DriverOCIS `ocisConfig:"ocis"` } // DriverCommon defines common driver configuration options. type DriverCommon struct { // Root is the absolute path to the location of the data - Root string + Root string `ocisConfig:"root"` //ShareFolder defines the name of the folder jailing all shares - ShareFolder string + ShareFolder string `ocisConfig:"share_folder"` // UserLayout contains the template used to construct // the internal path, eg: `{{substr 0 1 .Username}}/{{.Username}}` - UserLayout string + UserLayout string `ocisConfig:"user_layout"` // EnableHome enables the creation of home directories. - EnableHome bool + EnableHome bool `ocisConfig:"enable_home"` } // DriverEOS defines the available EOS driver configuration. @@ -237,274 +245,2012 @@ type DriverEOS struct { DriverCommon // ShadowNamespace for storing shadow data - ShadowNamespace string + ShadowNamespace string `ocisConfig:"shadow_namespace"` // UploadsNamespace for storing upload data - UploadsNamespace string + UploadsNamespace string `ocisConfig:"uploads_namespace"` // Location of the eos binary. // Default is /usr/bin/eos. - EosBinary string + EosBinary string `ocisConfig:"eos_binary"` // Location of the xrdcopy binary. // Default is /usr/bin/xrdcopy. - XrdcopyBinary string + XrdcopyBinary string `ocisConfig:"xrd_copy_binary"` // URL of the Master EOS MGM. // Default is root://eos-example.org - MasterURL string + MasterURL string `ocisConfig:"master_url"` // URI of the EOS MGM grpc server // Default is empty - GrpcURI string + GrpcURI string `ocisConfig:"grpc_uri"` // URL of the Slave EOS MGM. // Default is root://eos-example.org - SlaveURL string + SlaveURL string `ocisConfig:"slave_url"` // Location on the local fs where to store reads. // Defaults to os.TempDir() - CacheDirectory string + CacheDirectory string `ocisConfig:"cache_directory"` // Enables logging of the commands executed // Defaults to false - EnableLogging bool + EnableLogging bool `ocisConfig:"enable_logging"` // ShowHiddenSysFiles shows internal EOS files like // .sys.v# and .sys.a# files. - ShowHiddenSysFiles bool + ShowHiddenSysFiles bool `ocisConfig:"shadow_hidden_files"` // ForceSingleUserMode will force connections to EOS to use SingleUsername - ForceSingleUserMode bool + ForceSingleUserMode bool `ocisConfig:"force_single_user_mode"` // UseKeyTabAuth changes will authenticate requests by using an EOS keytab. - UseKeytab bool + UseKeytab bool `ocisConfig:"user_keytab"` // SecProtocol specifies the xrootd security protocol to use between the server and EOS. - SecProtocol string + SecProtocol string `ocisConfig:"sec_protocol"` // Keytab specifies the location of the keytab to use to authenticate to EOS. - Keytab string + Keytab string `ocisConfig:"keytab"` // SingleUsername is the username to use when SingleUserMode is enabled - SingleUsername string + SingleUsername string `ocisConfig:"single_username"` // gateway service to use for uid lookups - GatewaySVC string + GatewaySVC string `ocisConfig:"gateway_svc"` } // DriverOCIS defines the available oCIS storage driver configuration. type DriverOCIS struct { DriverCommon - ServiceUserUUID string + ServiceUserUUID string `ocisConfig:"service_user_uuid"` } // DriverOwnCloud defines the available ownCloud storage driver configuration. type DriverOwnCloud struct { DriverCommon - UploadInfoDir string - Redis string - Scan bool + UploadInfoDir string `ocisConfig:"upload_info_dir"` + Redis string `ocisConfig:"redis"` + Scan bool `ocisConfig:"scan"` } // DriverOwnCloudSQL defines the available ownCloudSQL storage driver configuration. type DriverOwnCloudSQL struct { DriverCommon - UploadInfoDir string - DBUsername string - DBPassword string - DBHost string - DBPort int - DBName string + UploadInfoDir string `ocisConfig:"upload_info_dir"` + DBUsername string `ocisConfig:"db_username"` + DBPassword string `ocisConfig:"db_password"` + DBHost string `ocisConfig:"db_host"` + DBPort int `ocisConfig:"db_port"` + DBName string `ocisConfig:"db_name"` } // DriverS3 defines the available S3 storage driver configuration. type DriverS3 struct { DriverCommon - Region string - AccessKey string - SecretKey string - Endpoint string - Bucket string + Region string `ocisConfig:"region"` + AccessKey string `ocisConfig:"access_key"` + SecretKey string `ocisConfig:"secret_key"` + Endpoint string `ocisConfig:"endpoint"` + Bucket string `ocisConfig:"bucket"` } // DriverS3NG defines the available s3ng storage driver configuration. type DriverS3NG struct { DriverCommon - Region string - AccessKey string - SecretKey string - Endpoint string - Bucket string + Region string `ocisConfig:"region"` + AccessKey string `ocisConfig:"access_key"` + SecretKey string `ocisConfig:"secret_key"` + Endpoint string `ocisConfig:"endpoint"` + Bucket string `ocisConfig:"bucket"` } // OIDC defines the available OpenID Connect configuration. type OIDC struct { - Issuer string - Insecure bool - IDClaim string - UIDClaim string - GIDClaim string + Issuer string `ocisConfig:"issuer"` + Insecure bool `ocisConfig:"insecure"` + IDClaim string `ocisConfig:"id_claim"` + UIDClaim string `ocisConfig:"uid_claim"` + GIDClaim string `ocisConfig:"gid_claim"` } // LDAP defines the available ldap configuration. type LDAP struct { - Hostname string - Port int - CACert string - Insecure bool - BaseDN string - LoginFilter string - UserFilter string - UserAttributeFilter string - UserFindFilter string - UserGroupFilter string - GroupFilter string - GroupAttributeFilter string - GroupFindFilter string - GroupMemberFilter string - BindDN string - BindPassword string - IDP string - UserSchema LDAPUserSchema - GroupSchema LDAPGroupSchema + Hostname string `ocisConfig:"hostname"` + Port int `ocisConfig:"port"` + CACert string `ocisConfig:"ca_cert"` + Insecure bool `ocisConfig:"insecure"` + BaseDN string `ocisConfig:"base_dn"` + LoginFilter string `ocisConfig:"login_filter"` + UserFilter string `ocisConfig:"user_filter"` + UserAttributeFilter string `ocisConfig:"user_attribute_filter"` + UserFindFilter string `ocisConfig:"user_find_filter"` + UserGroupFilter string `ocisConfig:"user_group_filter"` + GroupFilter string `ocisConfig:"group_filter"` + GroupAttributeFilter string `ocisConfig:"group_attribute_filter"` + GroupFindFilter string `ocisConfig:"group_finder_filter"` + GroupMemberFilter string `ocisConfig:"group_member_filter"` + BindDN string `ocisConfig:"bind_dn"` + BindPassword string `ocisConfig:"bind_password"` + IDP string `ocisConfig:"idp"` + UserSchema LDAPUserSchema `ocisConfig:"user_schema"` + GroupSchema LDAPGroupSchema `ocisConfig:"group_schema"` } // UserGroupRest defines the REST driver specification for user and group resolution. type UserGroupRest struct { - ClientID string - ClientSecret string - RedisAddress string - RedisUsername string - RedisPassword string - IDProvider string - APIBaseURL string - OIDCTokenEndpoint string - TargetAPI string + ClientID string `ocisConfig:"client_id"` + ClientSecret string `ocisConfig:"client_secret"` + RedisAddress string `ocisConfig:"redis_address"` + RedisUsername string `ocisConfig:"redis_username"` + RedisPassword string `ocisConfig:"redis_password"` + IDProvider string `ocisConfig:"idp_provider"` + APIBaseURL string `ocisConfig:"api_base_url"` + OIDCTokenEndpoint string `ocisConfig:"oidc_token_endpoint"` + TargetAPI string `ocisConfig:"target_api"` } // UserOwnCloudSQL defines the available ownCloudSQL user provider configuration. type UserOwnCloudSQL struct { - DBUsername string - DBPassword string - DBHost string - DBPort int - DBName string - Idp string - Nobody int64 - JoinUsername bool - JoinOwnCloudUUID bool - EnableMedialSearch bool + DBUsername string `ocisConfig:"db_username"` + DBPassword string `ocisConfig:"db_password"` + DBHost string `ocisConfig:"db_host"` + DBPort int `ocisConfig:"db_port"` + DBName string `ocisConfig:"db_name"` + Idp string `ocisConfig:"idp"` + Nobody int64 `ocisConfig:"nobody"` + JoinUsername bool `ocisConfig:"join_username"` + JoinOwnCloudUUID bool `ocisConfig:"join_owncloud_uuid"` + EnableMedialSearch bool `ocisConfig:"enable_medial_search"` } // LDAPUserSchema defines the available ldap user schema configuration. type LDAPUserSchema struct { - UID string - Mail string - DisplayName string - CN string - UIDNumber string - GIDNumber string + UID string `ocisConfig:"uid"` + Mail string `ocisConfig:"mail"` + DisplayName string `ocisConfig:"display_name"` + CN string `ocisConfig:"cn"` + UIDNumber string `ocisConfig:"uid_number"` + GIDNumber string `ocisConfig:"gid_number"` } // LDAPGroupSchema defines the available ldap group schema configuration. type LDAPGroupSchema struct { - GID string - Mail string - DisplayName string - CN string - GIDNumber string + GID string `ocisConfig:"gid"` + Mail string `ocisConfig:"mail"` + DisplayName string `ocisConfig:"display_name"` + CN string `ocisConfig:"cn"` + GIDNumber string `ocisConfig:"gid_number"` } // OCDav defines the available ocdav configuration. type OCDav struct { - WebdavNamespace string - DavFilesNamespace string + WebdavNamespace string `ocisConfig:"webdav_namespace"` + DavFilesNamespace string `ocisConfig:"dav_files_namespace"` } // Archiver defines the available archiver configuration. type Archiver struct { - MaxNumFiles int64 - MaxSize int64 - ArchiverURL string + MaxNumFiles int64 `ocisConfig:"max_num_files"` + MaxSize int64 `ocisConfig:"max_size"` + ArchiverURL string `ocisConfig:"archiver_url"` } // Reva defines the available reva configuration. type Reva struct { // JWTSecret used to sign jwt tokens between services - JWTSecret string - SkipUserGroupsInToken bool - TransferSecret string - TransferExpires int - OIDC OIDC - LDAP LDAP - UserGroupRest UserGroupRest - UserOwnCloudSQL UserOwnCloudSQL - OCDav OCDav - Archiver Archiver - UserStorage StorageConfig - MetadataStorage StorageConfig + JWTSecret string `ocisConfig:"jwt_secret"` + SkipUserGroupsInToken bool `ocisConfig:"skip_user_grooups_in_token"` + TransferSecret string `ocisConfig:"transfer_secret"` + TransferExpires int `ocisConfig:"transfer_expires"` + OIDC OIDC `ocisConfig:"oidc"` + LDAP LDAP `ocisConfig:"ldap"` + UserGroupRest UserGroupRest `ocisConfig:"user_group_rest"` + UserOwnCloudSQL UserOwnCloudSQL `ocisConfig:"user_owncloud_sql"` + OCDav OCDav `ocisConfig:"ocdav"` + Archiver Archiver `ocisConfig:"archiver"` + UserStorage StorageConfig `ocisConfig:"user_storage"` + MetadataStorage StorageConfig `ocisConfig:"metadata_storage"` // Ports are used to configure which services to start on which port - Frontend FrontendPort - DataGateway DataGatewayPort - Gateway Gateway - StorageRegistry StorageRegistry - AppRegistry AppRegistry - Users Users - Groups Groups - AuthProvider Users - AuthBasic Port - AuthBearer Port - AuthMachine Port - AuthMachineConfig AuthMachineConfig - Sharing Sharing - StorageHome StoragePort - StorageUsers StoragePort - StoragePublicLink PublicStorage - StorageMetadata StoragePort - AppProvider AppProvider + Frontend FrontendPort `ocisConfig:"frontend"` + DataGateway DataGatewayPort `ocisConfig:"data_gateway"` + Gateway Gateway `ocisConfig:"gateway"` + StorageRegistry StorageRegistry `ocisConfig:"storage_registry"` + AppRegistry AppRegistry `ocisConfig:"app_registry"` + Users Users `ocisConfig:"users"` + Groups Groups `ocisConfig:"groups"` + AuthProvider Users `ocisConfig:"auth_provider"` + AuthBasic Port `ocisConfig:"auth_basic"` + AuthBearer Port `ocisConfig:"auth_bearer"` + AuthMachine Port `ocisConfig:"auth_machine"` + AuthMachineConfig AuthMachineConfig `ocisConfig:"auth_machine_config"` + Sharing Sharing `ocisConfig:"sharing"` + StorageHome StoragePort `ocisConfig:"storage_home"` + StorageUsers StoragePort `ocisConfig:"storage_users"` + StoragePublicLink PublicStorage `ocisConfig:"storage_public_link"` + StorageMetadata StoragePort `ocisConfig:"storage_metadata"` + AppProvider AppProvider `ocisConfig:"app_provider"` // Configs can be used to configure the reva instance. // Services and Ports will be ignored if this is used - Configs map[string]interface{} + Configs map[string]interface{} `ocisConfig:"configs"` // chunking and resumable upload config (TUS) - UploadMaxChunkSize int - UploadHTTPMethodOverride string + UploadMaxChunkSize int `ocisConfig:"uppload_max_chunk_size"` + UploadHTTPMethodOverride string `ocisConfig:"upload_http_method_override"` // checksumming capabilities - ChecksumSupportedTypes []string - ChecksumPreferredUploadType string - DefaultUploadProtocol string + ChecksumSupportedTypes []string `ocisConfig:"checksum_supported_types"` + ChecksumPreferredUploadType string `ocisConfig:"checksum_preferred_upload_type"` + DefaultUploadProtocol string `ocisConfig:"default_upload_protocol"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `ocisConfig:"path"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - Reva Reva - Tracing Tracing - Asset Asset + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + Reva Reva `ocisConfig:"reva"` + Tracing Tracing `ocisConfig:"tracing"` + Asset Asset `ocisConfig:"asset"` } // New initializes a new configuration with or without defaults. func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + // log is inherited + Debug: Debug{ + Addr: "127.0.0.1:9109", + }, + Reva: Reva{ + JWTSecret: "Pive-Fumkiu4", + SkipUserGroupsInToken: false, + TransferSecret: "replace-me-with-a-transfer-secret", + TransferExpires: 24 * 60 * 60, + OIDC: OIDC{ + Issuer: "https://localhost:9200", + Insecure: false, + IDClaim: "preferred_username", + }, + LDAP: LDAP{ + Hostname: "localhost", + Port: 9126, + CACert: path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"), + Insecure: false, + BaseDN: "dc=ocis,dc=test", + LoginFilter: "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))", + UserFilter: "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + UserAttributeFilter: "(&(objectclass=posixAccount)({{attr}}={{value}}))", + UserFindFilter: "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + UserGroupFilter: "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))", + GroupFilter: "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))", + GroupAttributeFilter: "(&(objectclass=posixGroup)({{attr}}={{value}}))", + GroupFindFilter: "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))", + GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", + BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", + BindPassword: "reva", + IDP: "https://localhost:9200", + UserSchema: LDAPUserSchema{ + UID: "ownclouduuid", + Mail: "mail", + DisplayName: "displayname", + CN: "cn", + UIDNumber: "uidnumber", + GIDNumber: "gidnumber", + }, + GroupSchema: LDAPGroupSchema{ + GID: "cn", + Mail: "mail", + DisplayName: "cn", + CN: "cn", + GIDNumber: "gidnumber", + }, + }, + UserGroupRest: UserGroupRest{ + RedisAddress: "localhost:6379", + }, + UserOwnCloudSQL: UserOwnCloudSQL{ + DBUsername: "owncloud", + DBPassword: "secret", + DBHost: "mysql", + DBPort: 3306, + DBName: "owncloud", + Idp: "https://localhost:9200", + Nobody: 90, + JoinUsername: false, + JoinOwnCloudUUID: false, + EnableMedialSearch: false, + }, + OCDav: OCDav{ + WebdavNamespace: "/home/", + DavFilesNamespace: "/users/", + }, + Archiver: Archiver{ + MaxNumFiles: 10000, + MaxSize: 1073741824, + ArchiverURL: "/archiver", + }, + UserStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + }, + ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow") + UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads") + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + OwnCloud: DriverOwnCloud{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + Redis: ":6379", + Scan: true, + }, + OwnCloudSQL: DriverOwnCloudSQL{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), + ShareFolder: "/Shares", + UserLayout: "{{.Username}}", + EnableHome: false, + }, + UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), + DBUsername: "owncloud", + DBPassword: "owncloud", + DBHost: "", + DBPort: 3306, + DBName: "owncloud", + }, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + Region: "default", + AccessKey: "", + SecretKey: "", + Endpoint: "", + Bucket: "", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "users"), + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + MetadataStorage: StorageConfig{ + EOS: DriverEOS{ + DriverCommon: DriverCommon{ + Root: "/eos/dockertest/reva", + ShareFolder: "/Shares", + UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", + EnableHome: false, + }, + ShadowNamespace: "", + UploadsNamespace: "", + EosBinary: "/usr/bin/eos", + XrdcopyBinary: "/usr/bin/xrdcopy", + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + GrpcURI: "", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + CacheDirectory: os.TempDir(), + EnableLogging: false, + ShowHiddenSysFiles: false, + ForceSingleUserMode: false, + UseKeytab: false, + SecProtocol: "", + Keytab: "", + SingleUsername: "", + GatewaySVC: "127.0.0.1:9142", + }, + Local: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), + }, + OwnCloud: DriverOwnCloud{}, + OwnCloudSQL: DriverOwnCloudSQL{}, + S3: DriverS3{ + DriverCommon: DriverCommon{}, + Region: "default", + }, + S3NG: DriverS3NG{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + Region: "default", + }, + OCIS: DriverOCIS{ + DriverCommon: DriverCommon{ + Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), + ShareFolder: "", + UserLayout: "{{.Id.OpaqueId}}", + EnableHome: false, + }, + ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", + }, + }, + Frontend: FrontendPort{ + Port: Port{ + MaxCPUs: "", + LogLevel: "", + GRPCNetwork: "", + GRPCAddr: "", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9140", + Protocol: "", + Endpoint: "", + DebugAddr: "127.0.0.1:9141", + Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, + Config: nil, + Context: nil, + Supervised: false, + }, + AppProviderInsecure: false, + AppProviderPrefix: "", + ArchiverInsecure: false, + ArchiverPrefix: "archiver", + DatagatewayPrefix: "data", + Favorites: false, + OCDavInsecure: false, + OCDavPrefix: "", + OCSPrefix: "ocs", + OCSSharePrefix: "/Shares", + OCSHomeNamespace: "/home", + PublicURL: "https://localhost:9200", + OCSCacheWarmupDriver: "", + OCSAdditionalInfoAttribute: "{{.Mail}}", + OCSResourceInfoCacheTTL: 0, + Middleware: Middleware{}, + }, + DataGateway: DataGatewayPort{ + Port: Port{}, + PublicURL: "", + }, + Gateway: Gateway{ + Port: Port{ + Endpoint: "127.0.0.1:9142", + DebugAddr: "127.0.0.1:9143", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9142", + }, + CommitShareToStorageGrant: true, + CommitShareToStorageRef: true, + DisableHomeCreationOnLogin: false, + ShareFolder: "Shares", + LinkGrants: "", + HomeMapping: "", + EtagCacheTTL: 0, + }, + StorageRegistry: StorageRegistry{ + Driver: "static", + HomeProvider: "/home", + JSON: "", + }, + AppRegistry: AppRegistry{ + Driver: "static", + MimetypesJSON: "", + }, + Users: Users{ + Port: Port{ + Endpoint: "localhost:9144", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9144", + Services: []string{"userprovider"}, + }, + Driver: "ldap", + UserGroupsCacheExpiration: 5, + }, + Groups: Groups{ + Port: Port{ + Endpoint: "localhost:9160", + DebugAddr: "127.0.0.1:9161", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9160", + Services: []string{"groupprovider"}, + }, + Driver: "ldap", + GroupMembersCacheExpiration: 5, + }, + AuthProvider: Users{ + Port: Port{}, + Driver: "ldap", + UserGroupsCacheExpiration: 0, + }, + AuthBasic: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9146", + DebugAddr: "127.0.0.1:9147", + Services: []string{"authprovider"}, + Endpoint: "localhost:9146", + }, + AuthBearer: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9148", + DebugAddr: "127.0.0.1:9149", + Services: []string{"authprovider"}, + Endpoint: "localhost:9148", + }, + AuthMachine: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9166", + DebugAddr: "127.0.0.1:9167", + Services: []string{"authprovider"}, + Endpoint: "localhost:9166", + }, + AuthMachineConfig: AuthMachineConfig{ + MachineAuthAPIKey: "change-me-please", + }, + Sharing: Sharing{ + Port: Port{ + Endpoint: "localhost:9150", + DebugAddr: "127.0.0.1:9151", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9150", + Services: []string{"usershareprovider", "publicshareprovider"}, + }, + UserDriver: "json", + UserJSONFile: path.Join(defaults.BaseDataPath(), "storage", "shares.json"), + UserSQLUsername: "", + UserSQLPassword: "", + UserSQLHost: "", + UserSQLPort: 1433, + UserSQLName: "", + PublicDriver: "json", + PublicJSONFile: path.Join(defaults.BaseDataPath(), "storage", "publicshares.json"), + PublicPasswordHashCost: 11, + PublicEnableExpiredSharesCleanup: true, + PublicJanitorRunInterval: 60, + UserStorageMountID: "", + }, + StorageHome: StoragePort{ + Port: Port{ + Endpoint: "localhost:9154", + DebugAddr: "127.0.0.1:9156", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9154", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9155", + }, + Driver: "ocis", + ReadOnly: false, + MountPath: "/home", + AlternativeID: "1284d238-aa92-42ce-bdc4-0b0000009154", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + DataServerURL: "http://localhost:9155/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "home"), + }, + StorageUsers: StoragePort{ + Port: Port{ + Endpoint: "localhost:9157", + DebugAddr: "127.0.0.1:9159", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9157", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9158", + }, + MountPath: "/users", + MountID: "1284d238-aa92-42ce-bdc4-0b0000009157", + Driver: "ocis", + DataServerURL: "http://localhost:9158/data", + HTTPPrefix: "data", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "users"), + }, + StoragePublicLink: PublicStorage{ + StoragePort: StoragePort{ + Port: Port{ + Endpoint: "localhost:9178", + DebugAddr: "127.0.0.1:9179", + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9178", + }, + MountPath: "/public", + MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", + }, + PublicShareProviderAddr: "", + UserProviderAddr: "", + }, + StorageMetadata: StoragePort{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9215", + HTTPNetwork: "tcp", + HTTPAddr: "127.0.0.1:9216", + DebugAddr: "127.0.0.1:9217", + }, + Driver: "ocis", + ExposeDataServer: false, + DataServerURL: "http://localhost:9216", + TempFolder: path.Join(defaults.BaseDataPath(), "tmp", "metadata"), + DataProvider: DataProvider{}, + }, + AppProvider: AppProvider{ + Port: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9164", + DebugAddr: "127.0.0.1:9165", + Endpoint: "localhost:9164", + Services: []string{"appprovider"}, + }, + ExternalAddr: "127.0.0.1:9164", + WopiDriver: WopiDriver{}, + AppsURL: "/app/list", + OpenURL: "/app/open", + }, + Configs: nil, + UploadMaxChunkSize: 1e+8, + UploadHTTPMethodOverride: "", + ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, + ChecksumPreferredUploadType: "", + DefaultUploadProtocol: "tus", + }, + Tracing: Tracing{ + Service: "storage", + Type: "jaeger", + }, + Asset: Asset{}, + } +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + // Shared + { + EnvVars: []string{"OCIS_LOG_LEVEL", "STORAGE_FRONTEND_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "STORAGE_FRONTEND_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "STORAGE_FRONTEND_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_METADATA_DATAPROVIDER_INSECURE"}, + Destination: &cfg.Reva.StorageMetadata.DataProvider.Insecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_HOME_DATAPROVIDER_INSECURE"}, + Destination: &cfg.Reva.StorageHome.DataProvider.Insecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_FRONTEND_APPPROVIDER_INSECURE"}, + Destination: &cfg.Reva.Frontend.AppProviderInsecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_FRONTEND_ARCHIVER_INSECURE"}, + Destination: &cfg.Reva.Frontend.ArchiverInsecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_FRONTEND_OCDAV_INSECURE"}, + Destination: &cfg.Reva.Frontend.OCDavInsecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_OIDC_INSECURE"}, + Destination: &cfg.Reva.OIDC.Insecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "STORAGE_USERS_DATAPROVIDER_INSECURE"}, + Destination: &cfg.Reva.StorageUsers.DataProvider.Insecure, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_LOCAL_ROOT"}, + Destination: &cfg.Reva.UserStorage.Local.Root, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER"}, + Destination: &cfg.Reva.StorageUsers.Driver, + }, + { + EnvVars: []string{"STORAGE_HOME_DRIVER"}, + Destination: &cfg.Reva.StorageHome.Driver, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_DATADIR"}, + Destination: &cfg.Reva.UserStorage.OwnCloud.Root, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_ROOT"}, + Destination: &cfg.Reva.UserStorage.OCIS.Root, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_OCIS_ROOT"}, + Destination: &cfg.Reva.MetadataStorage.OCIS.Root, + }, + { + EnvVars: []string{"STORAGE_SHARING_USER_JSON_FILE"}, + Destination: &cfg.Reva.Sharing.UserJSONFile, + }, + { + EnvVars: []string{"OCIS_URL", "STORAGE_FRONTEND_PUBLIC_URL"}, + Destination: &cfg.Reva.Frontend.PublicURL, + }, + { + EnvVars: []string{"OCIS_URL", "STORAGE_OIDC_ISSUER"}, + Destination: &cfg.Reva.OIDC.Issuer, + }, + { + EnvVars: []string{"OCIS_URL", "STORAGE_LDAP_IDP"}, + Destination: &cfg.Reva.LDAP.IDP, + }, + { + EnvVars: []string{"OCIS_URL", "STORAGE_USERPROVIDER_OWNCLOUDSQL_IDP"}, + Destination: &cfg.Reva.UserOwnCloudSQL.Idp, + }, + { + EnvVars: []string{"STORAGE_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + + // debug + + { + EnvVars: []string{"STORAGE_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"STORAGE_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"STORAGE_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + + // app provider + + { + EnvVars: []string{"APP_PROVIDER_BASIC_DEBUG_ADDR"}, + Destination: &cfg.Reva.AppProvider.DebugAddr, + }, + { + EnvVars: []string{"APP_PROVIDER_BASIC_GRPC_NETWORK"}, + Destination: &cfg.Reva.AppProvider.GRPCNetwork, + }, + { + EnvVars: []string{"APP_PROVIDER_BASIC_GRPC_ADDR"}, + Destination: &cfg.Reva.AppProvider.GRPCAddr, + }, + { + EnvVars: []string{"APP_PROVIDER_BASIC_EXTERNAL_ADDR"}, + Destination: &cfg.Reva.AppProvider.ExternalAddr, + }, + { + EnvVars: []string{"APP_PROVIDER_DRIVER"}, + Destination: &cfg.Reva.AppProvider.Driver, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_API_KEY"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.AppAPIKey, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_DESKTOP_ONLY"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.AppDesktopOnly, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_ICON_URI"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.AppIconURI, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_INTERNAL_URL"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.AppInternalURL, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_NAME"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.AppName, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_URL"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.AppURL, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_INSECURE"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.Insecure, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_IOP_SECRET"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.IopSecret, + }, + { + EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_WOPI_URL"}, + Destination: &cfg.Reva.AppProvider.WopiDriver.WopiURL, + }, + + // authbasic + { + EnvVars: []string{"STORAGE_AUTH_BASIC_DEBUG_ADDR"}, + Destination: &cfg.Reva.AuthBasic.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_AUTH_DRIVER"}, + Destination: &cfg.Reva.AuthProvider.Driver, + }, + { + EnvVars: []string{"STORAGE_AUTH_JSON"}, + Destination: &cfg.Reva.AuthProvider.JSON, + }, + { + EnvVars: []string{"STORAGE_AUTH_BASIC_GRPC_NETWORK"}, + Destination: &cfg.Reva.AuthBasic.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_AUTH_BASIC_GRPC_ADDR"}, + Destination: &cfg.Reva.AuthBasic.GRPCAddr, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.Gateway.Endpoint, + }, + + // authbearer + { + EnvVars: []string{"STORAGE_AUTH_BEARER_DEBUG_ADDR"}, + Destination: &cfg.Reva.AuthBearer.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_OIDC_ID_CLAIM"}, + Destination: &cfg.Reva.OIDC.IDClaim, + }, + { + EnvVars: []string{"STORAGE_OIDC_UID_CLAIM"}, + Destination: &cfg.Reva.OIDC.UIDClaim, + }, + { + EnvVars: []string{"STORAGE_OIDC_GID_CLAIM"}, + Destination: &cfg.Reva.OIDC.GIDClaim, + }, + { + EnvVars: []string{"STORAGE_AUTH_BEARER_GRPC_NETWORK"}, + Destination: &cfg.Reva.AuthBearer.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_AUTH_BEARER_GRPC_ADDR"}, + Destination: &cfg.Reva.AuthBearer.GRPCAddr, + }, + + // auth-machine + { + EnvVars: []string{"STORAGE_AUTH_MACHINE_DEBUG_ADDR"}, + Destination: &cfg.Reva.AuthMachine.DebugAddr, + }, + { + EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "STORAGE_AUTH_MACHINE_AUTH_API_KEY"}, + Destination: &cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, + }, + { + EnvVars: []string{"STORAGE_AUTH_MACHINE_GRPC_NETWORK"}, + Destination: &cfg.Reva.AuthMachine.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_AUTH_MACHINE_GRPC_ADDR"}, + Destination: &cfg.Reva.AuthMachine.GRPCAddr, + }, + + // frontend + { + EnvVars: []string{"STORAGE_FRONTEND_DEBUG_ADDR"}, + Destination: &cfg.Reva.Frontend.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_TRANSFER_SECRET"}, + Destination: &cfg.Reva.TransferSecret, + }, + { + EnvVars: []string{"STORAGE_CHUNK_FOLDER"}, + Destination: &cfg.Reva.OCDav.WebdavNamespace, + }, + { + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.Reva.OCDav.WebdavNamespace, + }, + { + EnvVars: []string{"STORAGE_DAV_FILES_NAMESPACE"}, + Destination: &cfg.Reva.OCDav.DavFilesNamespace, + }, + { + EnvVars: []string{"STORAGE_ARCHIVER_MAX_NUM_FILES"}, + Destination: &cfg.Reva.Archiver.MaxNumFiles, + }, + { + EnvVars: []string{"STORAGE_ARCHIVER_MAX_SIZE"}, + Destination: &cfg.Reva.Archiver.MaxSize, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_HTTP_NETWORK"}, + Destination: &cfg.Reva.Frontend.HTTPNetwork, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_HTTP_ADDR"}, + Destination: &cfg.Reva.Frontend.HTTPAddr, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_APPPROVIDER_PREFIX"}, + Destination: &cfg.Reva.Frontend.AppProviderPrefix, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_ARCHIVER_PREFIX"}, + Destination: &cfg.Reva.Frontend.ArchiverPrefix, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_DATAGATEWAY_PREFIX"}, + Destination: &cfg.Reva.Frontend.DatagatewayPrefix, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_FAVORITES"}, + Destination: &cfg.Reva.Frontend.Favorites, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCDAV_PREFIX"}, + Destination: &cfg.Reva.Frontend.OCDavPrefix, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCS_PREFIX"}, + Destination: &cfg.Reva.Frontend.OCSPrefix, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCS_SHARE_PREFIX"}, + Destination: &cfg.Reva.Frontend.OCSSharePrefix, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCS_HOME_NAMESPACE"}, + Destination: &cfg.Reva.Frontend.OCSHomeNamespace, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCS_RESOURCE_INFO_CACHE_TTL"}, + Destination: &cfg.Reva.Frontend.OCSResourceInfoCacheTTL, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCS_CACHE_WARMUP_DRIVER"}, + Destination: &cfg.Reva.Frontend.OCSCacheWarmupDriver, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_OCS_ADDITIONAL_INFO_ATTRIBUTE"}, + Destination: &cfg.Reva.Frontend.OCSAdditionalInfoAttribute, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_DEFAULT_UPLOAD_PROTOCOL"}, + Destination: &cfg.Reva.DefaultUploadProtocol, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_UPLOAD_MAX_CHUNK_SIZE"}, + Destination: &cfg.Reva.UploadMaxChunkSize, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_UPLOAD_HTTP_METHOD_OVERRIDE"}, + Destination: &cfg.Reva.UploadHTTPMethodOverride, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_CHECKSUM_PREFERRED_UPLOAD_TYPE"}, + Destination: &cfg.Reva.ChecksumPreferredUploadType, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_ARCHIVER_URL"}, + Destination: &cfg.Reva.Archiver.ArchiverURL, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_APP_PROVIDER_APPS_URL"}, + Destination: &cfg.Reva.AppProvider.AppsURL, + }, + { + EnvVars: []string{"STORAGE_FRONTEND_APP_PROVIDER_OPEN_URL"}, + Destination: &cfg.Reva.AppProvider.OpenURL, + }, + + // gateway + { + EnvVars: []string{"STORAGE_GATEWAY_DEBUG_ADDR"}, + Destination: &cfg.Reva.Gateway.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_TRANSFER_EXPIRES"}, + Destination: &cfg.Reva.TransferExpires, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_GRPC_NETWORK"}, + Destination: &cfg.Reva.Gateway.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_GRPC_ADDR"}, + Destination: &cfg.Reva.Gateway.GRPCAddr, + }, + + { + EnvVars: []string{"STORAGE_GATEWAY_COMMIT_SHARE_TO_STORAGE_GRANT"}, + Destination: &cfg.Reva.Gateway.CommitShareToStorageGrant, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_COMMIT_SHARE_TO_STORAGE_REF"}, + Destination: &cfg.Reva.Gateway.CommitShareToStorageRef, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_SHARE_FOLDER"}, + Destination: &cfg.Reva.Gateway.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_DISABLE_HOME_CREATION_ON_LOGIN"}, + Destination: &cfg.Reva.Gateway.DisableHomeCreationOnLogin, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_HOME_MAPPING"}, + Destination: &cfg.Reva.Gateway.HomeMapping, + }, + { + EnvVars: []string{"STORAGE_GATEWAY_ETAG_CACHE_TTL"}, + Destination: &cfg.Reva.Gateway.EtagCacheTTL, + }, + { + EnvVars: []string{"STORAGE_AUTH_BASIC_ENDPOINT"}, + Destination: &cfg.Reva.AuthBasic.Endpoint, + }, + { + EnvVars: []string{"STORAGE_AUTH_BEARER_ENDPOINT"}, + Destination: &cfg.Reva.AuthBearer.Endpoint, + }, + { + EnvVars: []string{"STORAGE_AUTH_MACHINE_ENDPOINT"}, + Destination: &cfg.Reva.AuthMachine.Endpoint, + }, + { + EnvVars: []string{"STORAGE_STORAGE_REGISTRY_DRIVER"}, + Destination: &cfg.Reva.StorageRegistry.Driver, + }, + { + EnvVars: []string{"STORAGE_STORAGE_REGISTRY_HOME_PROVIDER"}, + Destination: &cfg.Reva.StorageRegistry.HomeProvider, + }, + { + EnvVars: []string{"STORAGE_STORAGE_REGISTRY_JSON"}, + Destination: &cfg.Reva.StorageRegistry.JSON, + }, + { + EnvVars: []string{"STORAGE_APP_REGISTRY_DRIVER"}, + Destination: &cfg.Reva.AppRegistry.Driver, + }, + { + EnvVars: []string{"STORAGE_APP_REGISTRY_MIMETYPES_JSON"}, + Destination: &cfg.Reva.AppRegistry.MimetypesJSON, + }, + { + EnvVars: []string{"STORAGE_DATAGATEWAY_PUBLIC_URL"}, + Destination: &cfg.Reva.DataGateway.PublicURL, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_ENDPOINT"}, + Destination: &cfg.Reva.Users.Endpoint, + }, + { + EnvVars: []string{"STORAGE_GROUPPROVIDER_ENDPOINT"}, + Destination: &cfg.Reva.Groups.Endpoint, + }, + { + EnvVars: []string{"STORAGE_SHARING_ENDPOINT"}, + Destination: &cfg.Reva.Sharing.Endpoint, + }, + { + EnvVars: []string{"STORAGE_APPPROVIDER_ENDPOINT"}, + Destination: &cfg.Reva.AppProvider.Endpoint, + }, + { + EnvVars: []string{"STORAGE_HOME_ENDPOINT"}, + Destination: &cfg.Reva.StorageHome.Endpoint, + }, + { + EnvVars: []string{"STORAGE_HOME_MOUNT_PATH"}, + Destination: &cfg.Reva.StorageHome.MountPath, + }, + { + EnvVars: []string{"STORAGE_HOME_MOUNT_ID"}, + Destination: &cfg.Reva.StorageHome.MountID, + }, + { + EnvVars: []string{"STORAGE_USERS_ENDPOINT"}, + Destination: &cfg.Reva.StorageUsers.Endpoint, + }, + { + EnvVars: []string{"STORAGE_USERS_MOUNT_PATH"}, + Destination: &cfg.Reva.StorageUsers.MountPath, + }, + { + EnvVars: []string{"STORAGE_USERS_MOUNT_ID"}, + Destination: &cfg.Reva.StorageUsers.MountID, + }, + { + EnvVars: []string{"STORAGE_PUBLIC_LINK_ENDPOINT"}, + Destination: &cfg.Reva.StoragePublicLink.Endpoint, + }, + { + EnvVars: []string{"STORAGE_PUBLIC_LINK_MOUNT_PATH"}, + Destination: &cfg.Reva.StoragePublicLink.MountPath, + }, + + // groups + { + EnvVars: []string{"STORAGE_GROUPPROVIDER_DEBUG_ADDR"}, + Destination: &cfg.Reva.Groups.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_GROUPPROVIDER_NETWORK"}, + Destination: &cfg.Reva.Groups.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_GROUPPROVIDER_ADDR"}, + Destination: &cfg.Reva.Groups.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_GROUPPROVIDER_DRIVER"}, + Destination: &cfg.Reva.Groups.Driver, + }, + { + EnvVars: []string{"STORAGE_GROUPPROVIDER_JSON"}, + Destination: &cfg.Reva.Groups.JSON, + }, + { + EnvVars: []string{"STORAGE_GROUP_CACHE_EXPIRATION"}, + Destination: &cfg.Reva.Groups.GroupMembersCacheExpiration, + }, + + // ldap + { + EnvVars: []string{"STORAGE_LDAP_HOSTNAME"}, + Destination: &cfg.Reva.LDAP.Hostname, + }, + { + EnvVars: []string{"STORAGE_LDAP_PORT"}, + Destination: &cfg.Reva.LDAP.Port, + }, + { + EnvVars: []string{"STORAGE_LDAP_CACERT"}, + Destination: &cfg.Reva.LDAP.CACert, + }, + { + EnvVars: []string{"STORAGE_LDAP_INSECURE"}, + Destination: &cfg.Reva.LDAP.Insecure, + }, + { + EnvVars: []string{"STORAGE_LDAP_BASE_DN"}, + Destination: &cfg.Reva.LDAP.BaseDN, + }, + { + EnvVars: []string{"STORAGE_LDAP_LOGINFILTER"}, + Destination: &cfg.Reva.LDAP.LoginFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_USERFILTER"}, + Destination: &cfg.Reva.LDAP.UserFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_USERATTRIBUTEFILTER"}, + Destination: &cfg.Reva.LDAP.UserAttributeFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_USERFINDFILTER"}, + Destination: &cfg.Reva.LDAP.UserFindFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_USERGROUPFILTER"}, + Destination: &cfg.Reva.LDAP.UserGroupFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUPFILTER"}, + Destination: &cfg.Reva.LDAP.GroupFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUPATTRIBUTEFILTER"}, + Destination: &cfg.Reva.LDAP.GroupAttributeFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUPFINDFILTER"}, + Destination: &cfg.Reva.LDAP.GroupFindFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUPMEMBERFILTER"}, + Destination: &cfg.Reva.LDAP.GroupMemberFilter, + }, + { + EnvVars: []string{"STORAGE_LDAP_BIND_DN"}, + Destination: &cfg.Reva.LDAP.BindDN, + }, + { + EnvVars: []string{"STORAGE_LDAP_BIND_PASSWORD"}, + Destination: &cfg.Reva.LDAP.BindPassword, + }, + { + EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_UID"}, + Destination: &cfg.Reva.LDAP.UserSchema.UID, + }, + { + EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_MAIL"}, + Destination: &cfg.Reva.LDAP.UserSchema.Mail, + }, + { + EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_DISPLAYNAME"}, + Destination: &cfg.Reva.LDAP.UserSchema.DisplayName, + }, + { + EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_CN"}, + Destination: &cfg.Reva.LDAP.UserSchema.CN, + }, + { + EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_UID_NUMBER"}, + Destination: &cfg.Reva.LDAP.UserSchema.UIDNumber, + }, + { + EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_GID_NUMBER"}, + Destination: &cfg.Reva.LDAP.UserSchema.GIDNumber, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_GID"}, + Destination: &cfg.Reva.LDAP.GroupSchema.GID, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_MAIL"}, + Destination: &cfg.Reva.LDAP.GroupSchema.Mail, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_DISPLAYNAME"}, + Destination: &cfg.Reva.LDAP.GroupSchema.DisplayName, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_CN"}, + Destination: &cfg.Reva.LDAP.GroupSchema.CN, + }, + { + EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_GID_NUMBER"}, + Destination: &cfg.Reva.LDAP.GroupSchema.GIDNumber, + }, + + // rest + { + EnvVars: []string{"STORAGE_REST_CLIENT_ID"}, + Destination: &cfg.Reva.UserGroupRest.ClientID, + }, + { + EnvVars: []string{"STORAGE_REST_CLIENT_SECRET"}, + Destination: &cfg.Reva.UserGroupRest.ClientSecret, + }, + { + EnvVars: []string{"STORAGE_REST_REDIS_ADDRESS"}, + Destination: &cfg.Reva.UserGroupRest.RedisAddress, + }, + { + EnvVars: []string{"STORAGE_REST_REDIS_USERNAME"}, + Destination: &cfg.Reva.UserGroupRest.RedisUsername, + }, + { + EnvVars: []string{"STORAGE_REST_REDIS_PASSWORD"}, + Destination: &cfg.Reva.UserGroupRest.RedisPassword, + }, + { + EnvVars: []string{"STORAGE_REST_ID_PROVIDER"}, + Destination: &cfg.Reva.UserGroupRest.IDProvider, + }, + { + EnvVars: []string{"STORAGE_REST_API_BASE_URL"}, + Destination: &cfg.Reva.UserGroupRest.APIBaseURL, + }, + { + EnvVars: []string{"STORAGE_REST_OIDC_TOKEN_ENDPOINT"}, + Destination: &cfg.Reva.UserGroupRest.OIDCTokenEndpoint, + }, + { + EnvVars: []string{"STORAGE_REST_TARGET_API"}, + Destination: &cfg.Reva.UserGroupRest.TargetAPI, + }, + + // secret + { + EnvVars: []string{"OCIS_JWT_SECRET", "STORAGE_JWT_SECRET"}, + Destination: &cfg.Reva.JWTSecret, + }, + { + EnvVars: []string{"STORAGE_SKIP_USER_GROUPS_IN_TOKEN"}, + Destination: &cfg.Reva.SkipUserGroupsInToken, + }, + + // sharing + { + EnvVars: []string{"STORAGE_SHARING_DEBUG_ADDR"}, + Destination: &cfg.Reva.Sharing.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_SHARING_GRPC_NETWORK"}, + Destination: &cfg.Reva.Sharing.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_SHARING_GRPC_ADDR"}, + Destination: &cfg.Reva.Sharing.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_SHARING_USER_DRIVER"}, + Destination: &cfg.Reva.Sharing.UserDriver, + }, + { + EnvVars: []string{"STORAGE_SHARING_PUBLIC_DRIVER"}, + Destination: &cfg.Reva.Sharing.PublicDriver, + }, + { + EnvVars: []string{"STORAGE_SHARING_PUBLIC_JSON_FILE"}, + Destination: &cfg.Reva.Sharing.PublicJSONFile, + }, + { + EnvVars: []string{"STORAGE_SHARING_PUBLIC_PASSWORD_HASH_COST"}, + Destination: &cfg.Reva.Sharing.PublicPasswordHashCost, + }, + { + EnvVars: []string{"STORAGE_SHARING_PUBLIC_ENABLE_EXPIRED_SHARES_CLEANUP"}, + Destination: &cfg.Reva.Sharing.PublicEnableExpiredSharesCleanup, + }, + { + EnvVars: []string{"STORAGE_SHARING_PUBLIC_JANITOR_RUN_INTERVAL"}, + Destination: &cfg.Reva.Sharing.PublicJanitorRunInterval, + }, + + // shqringsql + { + EnvVars: []string{"STORAGE_SHARING_USER_SQL_USERNAME"}, + Destination: &cfg.Reva.Sharing.UserSQLUsername, + }, + { + EnvVars: []string{"STORAGE_SHARING_USER_SQL_PASSWORD"}, + Destination: &cfg.Reva.Sharing.UserSQLPassword, + }, + { + EnvVars: []string{"STORAGE_SHARING_USER_SQL_HOST"}, + Destination: &cfg.Reva.Sharing.UserSQLHost, + }, + { + EnvVars: []string{"STORAGE_SHARING_USER_SQL_PORT"}, + Destination: &cfg.Reva.Sharing.UserSQLPort, + }, + { + EnvVars: []string{"STORAGE_SHARING_USER_SQL_NAME"}, + Destination: &cfg.Reva.Sharing.UserSQLName, + }, + + // storage home + { + EnvVars: []string{"STORAGE_HOME_DEBUG_ADDR"}, + Destination: &cfg.Reva.StorageHome.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_HOME_GRPC_NETWORK"}, + Destination: &cfg.Reva.StorageHome.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_HOME_GRPC_ADDR"}, + Destination: &cfg.Reva.StorageHome.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_HOME_HTTP_NETWORK"}, + Destination: &cfg.Reva.StorageHome.HTTPNetwork, + }, + { + EnvVars: []string{"STORAGE_HOME_HTTP_ADDR"}, + Destination: &cfg.Reva.StorageHome.HTTPAddr, + }, + { + EnvVars: []string{"OCIS_STORAGE_READ_ONLY", "STORAGE_HOME_READ_ONLY"}, + Destination: &cfg.Reva.StorageHome.ReadOnly, + }, + { + EnvVars: []string{"STORAGE_HOME_EXPOSE_DATA_SERVER"}, + Destination: &cfg.Reva.StorageHome.ExposeDataServer, + }, + { + EnvVars: []string{"STORAGE_HOME_DATA_SERVER_URL"}, + Destination: &cfg.Reva.StorageHome.DataServerURL, + }, + { + EnvVars: []string{"STORAGE_HOME_HTTP_PREFIX"}, + Destination: &cfg.Reva.StorageHome.HTTPPrefix, + }, + { + EnvVars: []string{"STORAGE_HOME_TMP_FOLDER"}, + Destination: &cfg.Reva.StorageHome.TempFolder, + }, + + // storage metadata + { + EnvVars: []string{"STORAGE_METADATA_DEBUG_ADDR"}, + Destination: &cfg.Reva.StorageMetadata.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_METADATA_GRPC_NETWORK"}, + Destination: &cfg.Reva.StorageMetadata.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_METADATA_GRPC_PROVIDER_ADDR"}, + Destination: &cfg.Reva.StorageMetadata.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_METADATA_DATA_SERVER_URL"}, + Destination: &cfg.Reva.StorageMetadata.DataServerURL, + }, + { + EnvVars: []string{"STORAGE_METADATA_HTTP_NETWORK"}, + Destination: &cfg.Reva.StorageMetadata.HTTPNetwork, + }, + { + EnvVars: []string{"STORAGE_METADATA_HTTP_ADDR"}, + Destination: &cfg.Reva.StorageMetadata.HTTPAddr, + }, + { + EnvVars: []string{"STORAGE_METADATA_TMP_FOLDER"}, + Destination: &cfg.Reva.StorageMetadata.TempFolder, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER"}, + Destination: &cfg.Reva.StorageMetadata.Driver, + }, + + // storage public link + { + EnvVars: []string{"STORAGE_PUBLIC_LINK_DEBUG_ADDR"}, + Destination: &cfg.Reva.StoragePublicLink.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_PUBLIC_LINK_GRPC_NETWORK"}, + Destination: &cfg.Reva.StoragePublicLink.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_PUBLIC_LINK_GRPC_ADDR"}, + Destination: &cfg.Reva.StoragePublicLink.GRPCAddr, + }, + + // storage users + { + EnvVars: []string{"STORAGE_USERS_DEBUG_ADDR"}, + Destination: &cfg.Reva.StorageUsers.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_USERS_GRPC_NETWORK"}, + Destination: &cfg.Reva.StorageUsers.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_USERS_GRPC_ADDR"}, + Destination: &cfg.Reva.StorageUsers.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_USERS_HTTP_NETWORK"}, + Destination: &cfg.Reva.StorageUsers.HTTPNetwork, + }, + { + EnvVars: []string{"STORAGE_USERS_HTTP_ADDR"}, + Destination: &cfg.Reva.StorageUsers.HTTPAddr, + }, + { + EnvVars: []string{"OCIS_STORAGE_READ_ONLY", "STORAGE_USERS_READ_ONLY"}, + Destination: &cfg.Reva.StorageUsers.ReadOnly, + }, + { + EnvVars: []string{"STORAGE_USERS_EXPOSE_DATA_SERVER"}, + Destination: &cfg.Reva.StorageUsers.ExposeDataServer, + }, + { + EnvVars: []string{"STORAGE_USERS_DATA_SERVER_URL"}, + Destination: &cfg.Reva.StorageUsers.DataServerURL, + }, + { + EnvVars: []string{"STORAGE_USERS_HTTP_PREFIX"}, + Destination: &cfg.Reva.StorageUsers.HTTPPrefix, + }, + { + EnvVars: []string{"STORAGE_USERS_TMP_FOLDER"}, + Destination: &cfg.Reva.StorageUsers.TempFolder, + }, + + // tracing + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "STORAGE_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "STORAGE_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "STORAGE_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "STORAGE_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"STORAGE_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + + // users + { + EnvVars: []string{"STORAGE_USERPROVIDER_DEBUG_ADDR"}, + Destination: &cfg.Reva.Users.DebugAddr, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_NETWORK"}, + Destination: &cfg.Reva.Users.GRPCNetwork, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_ADDR"}, + Destination: &cfg.Reva.Users.GRPCAddr, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_DRIVER"}, + Destination: &cfg.Reva.Users.Driver, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_JSON"}, + Destination: &cfg.Reva.Users.JSON, + }, + { + EnvVars: []string{"STORAGE_USER_CACHE_EXPIRATION"}, + Destination: &cfg.Reva.Users.UserGroupsCacheExpiration, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBHOST"}, + Destination: &cfg.Reva.UserOwnCloudSQL.DBHost, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBPORT"}, + Destination: &cfg.Reva.UserOwnCloudSQL.DBPort, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBNAME"}, + Destination: &cfg.Reva.UserOwnCloudSQL.DBName, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBUSER"}, + Destination: &cfg.Reva.UserOwnCloudSQL.DBUsername, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBPASS"}, + Destination: &cfg.Reva.UserOwnCloudSQL.DBPassword, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_NOBODY"}, + Destination: &cfg.Reva.UserOwnCloudSQL.Nobody, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_JOIN_USERNAME"}, + Destination: &cfg.Reva.UserOwnCloudSQL.JoinUsername, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_JOIN_OWNCLOUDUUID"}, + Destination: &cfg.Reva.UserOwnCloudSQL.JoinOwnCloudUUID, + }, + { + EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_ENABLE_MEDIAL_SEARCH"}, + Destination: &cfg.Reva.UserOwnCloudSQL.EnableMedialSearch, + }, + + // driver eos + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_NAMESPACE"}, + Destination: &cfg.Reva.UserStorage.EOS.Root, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SHADOW_NAMESPACE"}, + Destination: &cfg.Reva.UserStorage.EOS.ShadowNamespace, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_UPLOADS_NAMESPACE"}, + Destination: &cfg.Reva.UserStorage.EOS.UploadsNamespace, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SHARE_FOLDER"}, + Destination: &cfg.Reva.UserStorage.EOS.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_BINARY"}, + Destination: &cfg.Reva.UserStorage.EOS.EosBinary, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_XRDCOPY_BINARY"}, + Destination: &cfg.Reva.UserStorage.EOS.XrdcopyBinary, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_MASTER_URL"}, + Destination: &cfg.Reva.UserStorage.EOS.MasterURL, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SLAVE_URL"}, + Destination: &cfg.Reva.UserStorage.EOS.SlaveURL, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_CACHE_DIRECTORY"}, + Destination: &cfg.Reva.UserStorage.EOS.CacheDirectory, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_ENABLE_LOGGING"}, + Destination: &cfg.Reva.UserStorage.EOS.EnableLogging, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SHOW_HIDDEN_SYSFILES"}, + Destination: &cfg.Reva.UserStorage.EOS.ShowHiddenSysFiles, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_FORCE_SINGLEUSER_MODE"}, + Destination: &cfg.Reva.UserStorage.EOS.ForceSingleUserMode, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_USE_KEYTAB"}, + Destination: &cfg.Reva.UserStorage.EOS.UseKeytab, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SEC_PROTOCOL"}, + Destination: &cfg.Reva.UserStorage.EOS.SecProtocol, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_KEYTAB"}, + Destination: &cfg.Reva.UserStorage.EOS.Keytab, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SINGLE_USERNAME"}, + Destination: &cfg.Reva.UserStorage.EOS.SingleUsername, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_LAYOUT"}, + Destination: &cfg.Reva.UserStorage.EOS.UserLayout, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.UserStorage.EOS.GatewaySVC, + }, + + // driver local + { + EnvVars: []string{"STORAGE_USERS_DRIVER_LOCAL_SHARE_FOLDER"}, + Destination: &cfg.Reva.UserStorage.Local.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_LOCAL_USER_LAYOUT"}, + Destination: &cfg.Reva.UserStorage.Local.UserLayout, + }, + + // driver ocis + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_LAYOUT"}, + Destination: &cfg.Reva.UserStorage.OCIS.UserLayout, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_SHARE_FOLDER"}, + Destination: &cfg.Reva.UserStorage.OCIS.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_SERVICE_USER_UUID"}, + Destination: &cfg.Reva.UserStorage.OCIS.ServiceUserUUID, + }, + + // driver owncloud + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_UPLOADINFO_DIR"}, + Destination: &cfg.Reva.UserStorage.OwnCloud.UploadInfoDir, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_SHARE_FOLDER"}, + Destination: &cfg.Reva.UserStorage.OwnCloud.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_SCAN"}, + Destination: &cfg.Reva.UserStorage.OwnCloud.Scan, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_REDIS_ADDR"}, + Destination: &cfg.Reva.UserStorage.OwnCloud.Redis, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_LAYOUT"}, + Destination: &cfg.Reva.UserStorage.OwnCloud.UserLayout, + }, + + // driver owncloud sql + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DATADIR"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.Root, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_UPLOADINFO_DIR"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.UploadInfoDir, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_SHARE_FOLDER"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_LAYOUT"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.UserLayout, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBUSERNAME"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBUsername, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBPASSWORD"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBPassword, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBHOST"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBHost, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBPORT"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBPort, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBNAME"}, + Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBName, + }, + + // driver s3 + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3_REGION"}, + Destination: &cfg.Reva.UserStorage.S3.Region, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3_ACCESS_KEY"}, + Destination: &cfg.Reva.UserStorage.S3.AccessKey, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3_SECRET_KEY"}, + Destination: &cfg.Reva.UserStorage.S3.SecretKey, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3_ENDPOINT"}, + Destination: &cfg.Reva.UserStorage.S3.Endpoint, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3_BUCKET"}, + Destination: &cfg.Reva.UserStorage.S3.Bucket, + }, + + // driver s3ng + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_ROOT"}, + Destination: &cfg.Reva.UserStorage.S3NG.Root, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_LAYOUT"}, + Destination: &cfg.Reva.UserStorage.S3NG.UserLayout, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_SHARE_FOLDER"}, + Destination: &cfg.Reva.UserStorage.S3NG.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_REGION"}, + Destination: &cfg.Reva.UserStorage.S3NG.Region, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_ACCESS_KEY"}, + Destination: &cfg.Reva.UserStorage.S3NG.AccessKey, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_SECRET_KEY"}, + Destination: &cfg.Reva.UserStorage.S3NG.SecretKey, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_ENDPOINT"}, + Destination: &cfg.Reva.UserStorage.S3NG.Endpoint, + }, + { + EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_BUCKET"}, + Destination: &cfg.Reva.UserStorage.S3NG.Bucket, + }, + + // metadata driver eos + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_NAMESPACE"}, + Destination: &cfg.Reva.MetadataStorage.EOS.Root, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SHADOW_NAMESPACE"}, + Destination: &cfg.Reva.MetadataStorage.EOS.ShadowNamespace, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_UPLOADS_NAMESPACE"}, + Destination: &cfg.Reva.MetadataStorage.EOS.UploadsNamespace, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SHARE_FOLDER"}, + Destination: &cfg.Reva.MetadataStorage.EOS.ShareFolder, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_BINARY"}, + Destination: &cfg.Reva.MetadataStorage.EOS.EosBinary, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_XRDCOPY_BINARY"}, + Destination: &cfg.Reva.MetadataStorage.EOS.XrdcopyBinary, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_MASTER_URL"}, + Destination: &cfg.Reva.MetadataStorage.EOS.MasterURL, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SLAVE_URL"}, + Destination: &cfg.Reva.MetadataStorage.EOS.SlaveURL, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_CACHE_DIRECTORY"}, + Destination: &cfg.Reva.MetadataStorage.EOS.CacheDirectory, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_ENABLE_LOGGING"}, + Destination: &cfg.Reva.MetadataStorage.EOS.EnableLogging, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SHOW_HIDDEN_SYSFILES"}, + Destination: &cfg.Reva.MetadataStorage.EOS.ShowHiddenSysFiles, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_FORCE_SINGLEUSER_MODE"}, + Destination: &cfg.Reva.MetadataStorage.EOS.ForceSingleUserMode, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_USE_KEYTAB"}, + Destination: &cfg.Reva.MetadataStorage.EOS.UseKeytab, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SEC_PROTOCOL"}, + Destination: &cfg.Reva.MetadataStorage.EOS.SecProtocol, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_KEYTAB"}, + Destination: &cfg.Reva.MetadataStorage.EOS.Keytab, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SINGLE_USERNAME"}, + Destination: &cfg.Reva.MetadataStorage.EOS.SingleUsername, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_LAYOUT"}, + Destination: &cfg.Reva.MetadataStorage.EOS.UserLayout, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.MetadataStorage.EOS.GatewaySVC, + }, + + // metadata local driver + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_LOCAL_ROOT"}, + Destination: &cfg.Reva.MetadataStorage.Local.Root, + }, + + // metadata ocis driver + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_OCIS_LAYOUT"}, + Destination: &cfg.Reva.MetadataStorage.OCIS.UserLayout, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_OCIS_SERVICE_USER_UUID"}, + Destination: &cfg.Reva.MetadataStorage.OCIS.ServiceUserUUID, + }, + + // metadata driver s3 + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_REGION"}, + Destination: &cfg.Reva.MetadataStorage.S3.Region, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_ACCESS_KEY"}, + Destination: &cfg.Reva.MetadataStorage.S3.AccessKey, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_SECRET_KEY"}, + Destination: &cfg.Reva.MetadataStorage.S3.SecretKey, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_ENDPOINT"}, + Destination: &cfg.Reva.MetadataStorage.S3.Endpoint, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_BUCKET"}, + Destination: &cfg.Reva.MetadataStorage.S3.Bucket, + }, + + // driver s3ng + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_ROOT"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.Root, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_LAYOUT"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.UserLayout, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_REGION"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.Region, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_ACCESS_KEY"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.AccessKey, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_SECRET_KEY"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.SecretKey, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_ENDPOINT"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.Endpoint, + }, + { + EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_BUCKET"}, + Destination: &cfg.Reva.MetadataStorage.S3NG.Bucket, + }, + } +} diff --git a/storage/pkg/flagset/appprovider.go b/storage/pkg/flagset/appprovider.go deleted file mode 100644 index 781705586d4..00000000000 --- a/storage/pkg/flagset/appprovider.go +++ /dev/null @@ -1,144 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// AppProviderWithConfig applies cfg to the root flagset -func AppProviderWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.DebugAddr, "127.0.0.1:9165"), - Usage: "Address to bind debug server", - EnvVars: []string{"APP_PROVIDER_BASIC_DEBUG_ADDR"}, - Destination: &cfg.Reva.AppProvider.DebugAddr, - }, - - // Auth - - // Services - - // AppProvider - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage auth-basic service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"APP_PROVIDER_BASIC_GRPC_NETWORK"}, - Destination: &cfg.Reva.AppProvider.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.GRPCAddr, "127.0.0.1:9164"), - Usage: "Address to bind storage service", - EnvVars: []string{"APP_PROVIDER_BASIC_GRPC_ADDR"}, - Destination: &cfg.Reva.AppProvider.GRPCAddr, - }, - &cli.StringFlag{ - Name: "external-addr", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.ExternalAddr, "127.0.0.1:9164"), - Usage: "Address to connect to the storage service for other services", - EnvVars: []string{"APP_PROVIDER_BASIC_EXTERNAL_ADDR"}, - Destination: &cfg.Reva.AppProvider.ExternalAddr, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("appprovider"), - Usage: "--service appprovider [--service otherservice]", - EnvVars: []string{"APP_PROVIDER_BASIC_SERVICES"}, - }, - - &cli.StringFlag{ - Name: "driver", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.Driver, ""), - Usage: "Driver to use for app provider", - EnvVars: []string{"APP_PROVIDER_DRIVER"}, - Destination: &cfg.Reva.AppProvider.Driver, - }, - - // WOPI driver - &cli.StringFlag{ - Name: "wopi-driver-app-apikey", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.AppAPIKey, ""), - Usage: "The API key used by the app, if applicable.", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_API_KEY"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.AppAPIKey, - }, - &cli.BoolFlag{ - Name: "wopi-driver-app-desktop-only", - Value: flags.OverrideDefaultBool(cfg.Reva.AppProvider.WopiDriver.AppDesktopOnly, false), - Usage: "Whether the app can be opened only on desktop", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_DESKTOP_ONLY"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.AppDesktopOnly, - }, - &cli.StringFlag{ - Name: "wopi-driver-app-icon-uri", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.AppIconURI, ""), - Usage: "IOP Secret (Shared with WOPI server)", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_ICON_URI"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.AppIconURI, - }, - &cli.StringFlag{ - Name: "wopi-driver-app-internal-url", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.AppInternalURL, ""), - Usage: "The internal app URL in case of dockerized deployments. Defaults to AppURL", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_INTERNAL_URL"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.AppInternalURL, - }, - &cli.StringFlag{ - Name: "wopi-driver-app-name", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.AppName, ""), - Usage: "The App user-friendly name.", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_NAME"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.AppName, - }, - &cli.StringFlag{ - Name: "wopi-driver-app-url", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.AppURL, ""), - Usage: "App server URL", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_APP_URL"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.AppURL, - }, - &cli.BoolFlag{ - Name: "wopi-driver-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.AppProvider.WopiDriver.Insecure, false), - Usage: "Disable SSL certificate verification of WOPI server and WOPI bridge", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_INSECURE"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.Insecure, - }, - &cli.StringFlag{ - Name: "wopi-driver-iopsecret", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.IopSecret, ""), - Usage: "IOP Secret (Shared with WOPI server)", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_IOP_SECRET"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.IopSecret, - }, - &cli.StringFlag{ - Name: "wopi-driver-wopiurl", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.WopiDriver.WopiURL, ""), - Usage: "WOPI server URL", - EnvVars: []string{"APP_PROVIDER_WOPI_DRIVER_WOPI_URL"}, - Destination: &cfg.Reva.AppProvider.WopiDriver.WopiURL, - }, - - // Gateway - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/authbasic.go b/storage/pkg/flagset/authbasic.go deleted file mode 100644 index bbfcae1ee3c..00000000000 --- a/storage/pkg/flagset/authbasic.go +++ /dev/null @@ -1,81 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// AuthBasicWithConfig applies cfg to the root flagset -func AuthBasicWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBasic.DebugAddr, "127.0.0.1:9147"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_AUTH_BASIC_DEBUG_ADDR"}, - Destination: &cfg.Reva.AuthBasic.DebugAddr, - }, - - // Auth - - &cli.StringFlag{ - Name: "auth-driver", - Value: flags.OverrideDefaultString(cfg.Reva.AuthProvider.Driver, "ldap"), - Usage: "auth driver: 'demo', 'json' or 'ldap'", - EnvVars: []string{"STORAGE_AUTH_DRIVER"}, - Destination: &cfg.Reva.AuthProvider.Driver, - }, - &cli.StringFlag{ - Name: "auth-json", - Value: flags.OverrideDefaultString(cfg.Reva.AuthProvider.JSON, ""), - Usage: "Path to users.json file", - EnvVars: []string{"STORAGE_AUTH_JSON"}, - Destination: &cfg.Reva.AuthProvider.JSON, - }, - - // Services - - // AuthBasic - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBasic.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage auth-basic service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_AUTH_BASIC_GRPC_NETWORK"}, - Destination: &cfg.Reva.AuthBasic.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBasic.GRPCAddr, "127.0.0.1:9146"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_AUTH_BASIC_GRPC_ADDR"}, - Destination: &cfg.Reva.AuthBasic.GRPCAddr, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("authprovider"), - Usage: "--service authprovider [--service otherservice]", - EnvVars: []string{"STORAGE_AUTH_BASIC_SERVICES"}, - }, - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, LDAPWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/authbearer.go b/storage/pkg/flagset/authbearer.go deleted file mode 100644 index d41a89558a2..00000000000 --- a/storage/pkg/flagset/authbearer.go +++ /dev/null @@ -1,107 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// AuthBearerWithConfig applies cfg to the root flagset -func AuthBearerWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBearer.DebugAddr, "127.0.0.1:9149"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_AUTH_BEARER_DEBUG_ADDR"}, - Destination: &cfg.Reva.AuthBearer.DebugAddr, - }, - - // OIDC - - &cli.StringFlag{ - Name: "oidc-issuer", - Value: flags.OverrideDefaultString(cfg.Reva.OIDC.Issuer, "https://localhost:9200"), - Usage: "OIDC issuer", - EnvVars: []string{"STORAGE_OIDC_ISSUER", "OCIS_URL"}, // STORAGE_OIDC_ISSUER takes precedence over OCIS_URL - Destination: &cfg.Reva.OIDC.Issuer, - }, - &cli.BoolFlag{ - Name: "oidc-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.OIDC.Insecure, false), - Usage: "OIDC allow insecure communication", - EnvVars: []string{"STORAGE_OIDC_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.OIDC.Insecure, - }, - &cli.StringFlag{ - Name: "oidc-id-claim", - // preferred_username is a workaround - // the user manager needs to take care of the sub to user metadata lookup, which ldap cannot do - // TODO sub is stable and defined as unique. - // AFAICT we want to use the account id from ocis-accounts - // TODO add an ocis middleware to storage that changes the users opaqueid? - // TODO add an ocis-accounts backed user manager - Value: flags.OverrideDefaultString(cfg.Reva.OIDC.IDClaim, "preferred_username"), - Usage: "OIDC id claim", - EnvVars: []string{"STORAGE_OIDC_ID_CLAIM"}, - Destination: &cfg.Reva.OIDC.IDClaim, - }, - &cli.StringFlag{ - Name: "oidc-uid-claim", - Value: flags.OverrideDefaultString(cfg.Reva.OIDC.UIDClaim, ""), - Usage: "OIDC uid claim", - EnvVars: []string{"STORAGE_OIDC_UID_CLAIM"}, - Destination: &cfg.Reva.OIDC.UIDClaim, - }, - &cli.StringFlag{ - Name: "oidc-gid-claim", - Value: flags.OverrideDefaultString(cfg.Reva.OIDC.GIDClaim, ""), - Usage: "OIDC gid claim", - EnvVars: []string{"STORAGE_OIDC_GID_CLAIM"}, - Destination: &cfg.Reva.OIDC.GIDClaim, - }, - - // Services - - // AuthBearer - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBearer.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_AUTH_BEARER_GRPC_NETWORK"}, - Destination: &cfg.Reva.AuthBearer.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBearer.GRPCAddr, "127.0.0.1:9148"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_AUTH_BEARER_GRPC_ADDR"}, - Destination: &cfg.Reva.AuthBearer.GRPCAddr, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("authprovider"), // TODO preferences - Usage: "--service authprovider [--service otherservice]", - EnvVars: []string{"STORAGE_AUTH_BEARER_SERVICES"}, - }, - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/authmachine.go b/storage/pkg/flagset/authmachine.go deleted file mode 100644 index f4a9d20f7af..00000000000 --- a/storage/pkg/flagset/authmachine.go +++ /dev/null @@ -1,73 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// AuthMachineWithConfig applies cfg to the root flagset -func AuthMachineWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.AuthMachine.DebugAddr, "127.0.0.1:9167"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_AUTH_MACHINE_DEBUG_ADDR"}, - Destination: &cfg.Reva.AuthMachine.DebugAddr, - }, - - // Machine Auth - - &cli.StringFlag{ - Name: "machine-auth-api-key", - Value: flags.OverrideDefaultString(cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, "change-me-please"), - Usage: "the API key to be used for the machine auth driver in reva", - EnvVars: []string{"STORAGE_AUTH_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, - Destination: &cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, - }, - - // Services - - // AuthMachine - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.AuthMachine.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_AUTH_MACHINE_GRPC_NETWORK"}, - Destination: &cfg.Reva.AuthMachine.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.AuthMachine.GRPCAddr, "127.0.0.1:9166"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_AUTH_MACHINE_GRPC_ADDR"}, - Destination: &cfg.Reva.AuthMachine.GRPCAddr, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("authprovider"), // TODO preferences - Usage: "--service authprovider [--service otherservice]", - EnvVars: []string{"STORAGE_AUTH_MACHINE_SERVICES"}, - }, - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/debug.go b/storage/pkg/flagset/debug.go deleted file mode 100644 index 4273f088658..00000000000 --- a/storage/pkg/flagset/debug.go +++ /dev/null @@ -1,32 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DebugWithConfig applies common debug config cfg to the flagset -func DebugWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"STORAGE_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"STORAGE_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"STORAGE_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - } -} diff --git a/storage/pkg/flagset/frontend.go b/storage/pkg/flagset/frontend.go deleted file mode 100644 index 3baa80ae292..00000000000 --- a/storage/pkg/flagset/frontend.go +++ /dev/null @@ -1,299 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset/userdrivers" - "github.com/urfave/cli/v2" -) - -// FrontendWithConfig applies cfg to the root flagset -func FrontendWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.DebugAddr, "127.0.0.1:9141"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_FRONTEND_DEBUG_ADDR"}, - Destination: &cfg.Reva.Frontend.DebugAddr, - }, - - // REVA - - &cli.StringFlag{ - Name: "transfer-secret", - Value: flags.OverrideDefaultString(cfg.Reva.TransferSecret, "replace-me-with-a-transfer-secret"), - Usage: "Transfer secret for datagateway", - EnvVars: []string{"STORAGE_TRANSFER_SECRET"}, - Destination: &cfg.Reva.TransferSecret, - }, - - // OCDav - - &cli.StringFlag{ - Name: "chunk-folder", - Value: flags.OverrideDefaultString(cfg.Reva.OCDav.WebdavNamespace, path.Join(defaults.BaseDataPath(), "tmp", "chunks")), - Usage: "temp directory for chunked uploads", - EnvVars: []string{"STORAGE_CHUNK_FOLDER"}, - Destination: &cfg.Reva.OCDav.WebdavNamespace, - }, - - &cli.StringFlag{ - Name: "webdav-namespace", - Value: flags.OverrideDefaultString(cfg.Reva.OCDav.WebdavNamespace, "/home/"), - Usage: "Namespace prefix for the /webdav endpoint", - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, - Destination: &cfg.Reva.OCDav.WebdavNamespace, - }, - - // th/dav/files endpoint expects a username as the first path segment - // this can eg. be set to /eos/users - &cli.StringFlag{ - Name: "dav-files-namespace", - Value: flags.OverrideDefaultString(cfg.Reva.OCDav.DavFilesNamespace, "/users/"), - Usage: "Namespace prefix for the webdav /dav/files endpoint", - EnvVars: []string{"STORAGE_DAV_FILES_NAMESPACE"}, - Destination: &cfg.Reva.OCDav.DavFilesNamespace, - }, - - // Archiver - - &cli.Int64Flag{ - Name: "archiver-max-num-files", - Value: flags.OverrideDefaultInt64(cfg.Reva.Archiver.MaxNumFiles, 10000), - Usage: "Maximum number of files to be included in the archiver", - EnvVars: []string{"STORAGE_ARCHIVER_MAX_NUM_FILES"}, - Destination: &cfg.Reva.Archiver.MaxNumFiles, - }, - &cli.Int64Flag{ - Name: "archiver-max-size", - Value: flags.OverrideDefaultInt64(cfg.Reva.Archiver.MaxSize, 1073741824), // 1GB - Usage: "Maximum size for the sum of the sizes of all the files included in the archive", - EnvVars: []string{"STORAGE_ARCHIVER_MAX_SIZE"}, - Destination: &cfg.Reva.Archiver.MaxSize, - }, - - // Services - - // Frontend - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.HTTPNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_FRONTEND_HTTP_NETWORK"}, - Destination: &cfg.Reva.Frontend.HTTPNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.HTTPAddr, "127.0.0.1:9140"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_FRONTEND_HTTP_ADDR"}, - Destination: &cfg.Reva.Frontend.HTTPAddr, - }, - // please note that STORAGE_FRONTEND_PUBLIC_URL is also defined in - // storage/pkg/flagset/gateway.go because this setting may be consumed - // by both the gateway and frontend service - &cli.StringFlag{ - Name: "public-url", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.PublicURL, "https://localhost:9200"), - Usage: "URL to use for the storage service", - EnvVars: []string{"STORAGE_FRONTEND_PUBLIC_URL", "OCIS_URL"}, // STORAGE_FRONTEND_PUBLIC_URL takes precedence over OCIS_URL - Destination: &cfg.Reva.Frontend.PublicURL, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("datagateway", "ocdav", "ocs", "appprovider"), - Usage: "--service ocdav [--service ocs]", - EnvVars: []string{"STORAGE_FRONTEND_SERVICES"}, - }, - &cli.StringFlag{ - Name: "approvider-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.AppProviderPrefix, ""), - Usage: "approvider prefix", - EnvVars: []string{"STORAGE_FRONTEND_APPPROVIDER_PREFIX"}, - Destination: &cfg.Reva.Frontend.AppProviderPrefix, - }, - &cli.BoolFlag{ - Name: "approvider-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.Frontend.AppProviderInsecure, false), - Usage: "approvider insecure", - EnvVars: []string{"STORAGE_FRONTEND_APPPROVIDER_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.Frontend.AppProviderInsecure, - }, - &cli.StringFlag{ - Name: "archiver-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.ArchiverPrefix, "archiver"), - Usage: "archiver prefix", - EnvVars: []string{"STORAGE_FRONTEND_ARCHIVER_PREFIX"}, - Destination: &cfg.Reva.Frontend.ArchiverPrefix, - }, - &cli.BoolFlag{ - Name: "archiver-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.Frontend.ArchiverInsecure, false), - Usage: "archiver insecure", - EnvVars: []string{"STORAGE_FRONTEND_ARCHIVER_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.Frontend.ArchiverInsecure, - }, - &cli.StringFlag{ - Name: "datagateway-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.DatagatewayPrefix, "data"), - Usage: "datagateway prefix", - EnvVars: []string{"STORAGE_FRONTEND_DATAGATEWAY_PREFIX"}, - Destination: &cfg.Reva.Frontend.DatagatewayPrefix, - }, - &cli.BoolFlag{ - Name: "favorites", - Value: flags.OverrideDefaultBool(cfg.Reva.Frontend.Favorites, false), - Usage: "announces favorites support to clients", - EnvVars: []string{"STORAGE_FRONTEND_FAVORITES"}, - Destination: &cfg.Reva.Frontend.Favorites, - }, - &cli.StringFlag{ - Name: "ocdav-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCDavPrefix, ""), - Usage: "owncloud webdav endpoint prefix", - EnvVars: []string{"STORAGE_FRONTEND_OCDAV_PREFIX"}, - Destination: &cfg.Reva.Frontend.OCDavPrefix, - }, - &cli.BoolFlag{ - Name: "ocdav-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.Frontend.OCDavInsecure, false), - Usage: "owncloud webdav insecure", - EnvVars: []string{"STORAGE_FRONTEND_OCDAV_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.Frontend.OCDavInsecure, - }, - &cli.StringFlag{ - Name: "ocs-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCSPrefix, "ocs"), - Usage: "open collaboration services endpoint prefix", - EnvVars: []string{"STORAGE_FRONTEND_OCS_PREFIX"}, - Destination: &cfg.Reva.Frontend.OCSPrefix, - }, - &cli.StringFlag{ - Name: "ocs-share-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCSSharePrefix, "/Shares"), - Usage: "the prefix prepended to the path of shared files", - EnvVars: []string{"STORAGE_FRONTEND_OCS_SHARE_PREFIX"}, - Destination: &cfg.Reva.Frontend.OCSSharePrefix, - }, - &cli.StringFlag{ - Name: "ocs-home-namespace", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCSHomeNamespace, "/home"), - Usage: "the prefix prepended to the incoming requests in OCS", - EnvVars: []string{"STORAGE_FRONTEND_OCS_HOME_NAMESPACE"}, - Destination: &cfg.Reva.Frontend.OCSHomeNamespace, - }, - &cli.IntFlag{ - Name: "ocs-resource-info-cache-ttl", - Value: flags.OverrideDefaultInt(cfg.Reva.Frontend.OCSResourceInfoCacheTTL, 0), - Usage: "the TTL for statted resources in the share cache", - EnvVars: []string{"STORAGE_FRONTEND_OCS_RESOURCE_INFO_CACHE_TTL"}, - Destination: &cfg.Reva.Frontend.OCSResourceInfoCacheTTL, - }, - &cli.StringFlag{ - Name: "ocs-cache-warmup-driver", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCSCacheWarmupDriver, ""), - Usage: "the driver to be used for warming up the share cache", - EnvVars: []string{"STORAGE_FRONTEND_OCS_CACHE_WARMUP_DRIVER"}, - Destination: &cfg.Reva.Frontend.OCSCacheWarmupDriver, - }, - &cli.StringFlag{ - Name: "ocs-additional-info-attribute", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.OCSAdditionalInfoAttribute, "{{.Mail}}"), - Usage: "the additional info to be returned when searching for users", - EnvVars: []string{"STORAGE_FRONTEND_OCS_ADDITIONAL_INFO_ATTRIBUTE"}, - Destination: &cfg.Reva.Frontend.OCSAdditionalInfoAttribute, - }, - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - - // Chunking - &cli.StringFlag{ - Name: "default-upload-protocol", - Value: flags.OverrideDefaultString(cfg.Reva.DefaultUploadProtocol, "tus"), - Usage: "Default upload chunking protocol to be used out of tus/v1/ng", - EnvVars: []string{"STORAGE_FRONTEND_DEFAULT_UPLOAD_PROTOCOL"}, - Destination: &cfg.Reva.DefaultUploadProtocol, - }, - &cli.IntFlag{ - Name: "upload-max-chunk-size", - Value: flags.OverrideDefaultInt(cfg.Reva.UploadMaxChunkSize, 1e+8), // 0.1 GB - Usage: "Max chunk size in bytes to advertise to clients through capabilities, or 0 for unlimited", - EnvVars: []string{"STORAGE_FRONTEND_UPLOAD_MAX_CHUNK_SIZE"}, - Destination: &cfg.Reva.UploadMaxChunkSize, - }, - &cli.StringFlag{ - Name: "upload-http-method-override", - Value: flags.OverrideDefaultString(cfg.Reva.UploadHTTPMethodOverride, ""), - Usage: "Specify an HTTP method (ex: POST) that clients should to use when uploading instead of PATCH", - EnvVars: []string{"STORAGE_FRONTEND_UPLOAD_HTTP_METHOD_OVERRIDE"}, - Destination: &cfg.Reva.UploadHTTPMethodOverride, - }, - &cli.StringSliceFlag{ - Name: "checksum-supported-type", - Value: cli.NewStringSlice("sha1", "md5", "adler32"), - Usage: "--checksum-supported-type sha1 [--checksum-supported-type adler32]", - EnvVars: []string{"STORAGE_FRONTEND_CHECKSUM_SUPPORTED_TYPES"}, - }, - &cli.StringFlag{ - Name: "checksum-preferred-upload-type", - Value: flags.OverrideDefaultString(cfg.Reva.ChecksumPreferredUploadType, ""), - Usage: "Specify the preferred checksum algorithm used for uploads", - EnvVars: []string{"STORAGE_FRONTEND_CHECKSUM_PREFERRED_UPLOAD_TYPE"}, - Destination: &cfg.Reva.ChecksumPreferredUploadType, - }, - - // Archiver - &cli.StringFlag{ - Name: "archiver-url", - Value: flags.OverrideDefaultString(cfg.Reva.Archiver.ArchiverURL, "/archiver"), - Usage: "URL where the archiver is reachable", - EnvVars: []string{"STORAGE_FRONTEND_ARCHIVER_URL"}, - Destination: &cfg.Reva.Archiver.ArchiverURL, - }, - - // App Provider - &cli.StringFlag{ - Name: "appprovider-apps-url", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.AppsURL, "/app/list"), - Usage: "URL where the app listing of the app provider is reachable", - EnvVars: []string{"STORAGE_FRONTEND_APP_PROVIDER_APPS_URL"}, - Destination: &cfg.Reva.AppProvider.AppsURL, - }, - &cli.StringFlag{ - Name: "appprovider-open-url", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.OpenURL, "/app/open"), - Usage: "URL where files can be handed over to an application from the app provider", - EnvVars: []string{"STORAGE_FRONTEND_APP_PROVIDER_OPEN_URL"}, - Destination: &cfg.Reva.AppProvider.OpenURL, - }, - - // Reva Middlewares Config - &cli.StringSliceFlag{ - Name: "user-agent-whitelist-lock-in", - Usage: "--user-agent-whitelist-lock-in=mirall:basic,foo:bearer Given a tuple of comma separated [UserAgent:challenge] values, it locks a given user agent to the authentication challenge. Particularly useful for old clients whose USer-Agent is known and only support one authentication challenge. When this flag is set in the storage-frontend it configures Reva.", - EnvVars: []string{"STORAGE_FRONTEND_MIDDLEWARE_AUTH_CREDENTIALS_BY_USER_AGENT"}, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, SharingSQLWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverEOSWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/gateway.go b/storage/pkg/flagset/gateway.go deleted file mode 100644 index 416fac641cf..00000000000 --- a/storage/pkg/flagset/gateway.go +++ /dev/null @@ -1,306 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// GatewayWithConfig applies cfg to the root flagset -func GatewayWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.DebugAddr, "127.0.0.1:9143"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_GATEWAY_DEBUG_ADDR"}, - Destination: &cfg.Reva.Gateway.DebugAddr, - }, - - // REVA - - &cli.StringFlag{ - Name: "transfer-secret", - Value: flags.OverrideDefaultString(cfg.Reva.TransferSecret, "replace-me-with-a-transfer-secret"), - Usage: "Transfer secret for datagateway", - EnvVars: []string{"STORAGE_TRANSFER_SECRET"}, - Destination: &cfg.Reva.TransferSecret, - }, - &cli.IntFlag{ - Name: "transfer-expires", - Value: flags.OverrideDefaultInt(cfg.Reva.TransferExpires, 24*60*60), // one day - Usage: "Transfer token ttl in seconds", - EnvVars: []string{"STORAGE_TRANSFER_EXPIRES"}, - Destination: &cfg.Reva.TransferExpires, - }, - - // Services - - // Gateway - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_GATEWAY_GRPC_NETWORK"}, - Destination: &cfg.Reva.Gateway.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.GRPCAddr, "127.0.0.1:9142"), - Usage: "Address to bind REVA service", - EnvVars: []string{"STORAGE_GATEWAY_GRPC_ADDR"}, - Destination: &cfg.Reva.Gateway.GRPCAddr, - }, - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("gateway", "authregistry", "storageregistry", "appregistry"), - Usage: "--service gateway [--service authregistry]", - EnvVars: []string{"STORAGE_GATEWAY_SERVICES"}, - }, - &cli.BoolFlag{ - Name: "commit-share-to-storage-grant", - Value: flags.OverrideDefaultBool(cfg.Reva.Gateway.CommitShareToStorageGrant, true), - Usage: "Commit shares to the share manager", - EnvVars: []string{"STORAGE_GATEWAY_COMMIT_SHARE_TO_STORAGE_GRANT"}, - Destination: &cfg.Reva.Gateway.CommitShareToStorageGrant, - }, - &cli.BoolFlag{ - Name: "commit-share-to-storage-ref", - Value: flags.OverrideDefaultBool(cfg.Reva.Gateway.CommitShareToStorageRef, true), - Usage: "Commit shares to the storage", - EnvVars: []string{"STORAGE_GATEWAY_COMMIT_SHARE_TO_STORAGE_REF"}, - Destination: &cfg.Reva.Gateway.CommitShareToStorageRef, - }, - &cli.StringFlag{ - Name: "share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.ShareFolder, "Shares"), - Usage: "mount shares in this folder of the home storage provider", - EnvVars: []string{"STORAGE_GATEWAY_SHARE_FOLDER"}, - Destination: &cfg.Reva.Gateway.ShareFolder, - }, - &cli.BoolFlag{ - Name: "disable-home-creation-on-login", - Usage: "Disable creation of home folder on login", - EnvVars: []string{"STORAGE_GATEWAY_DISABLE_HOME_CREATION_ON_LOGIN"}, - Destination: &cfg.Reva.Gateway.DisableHomeCreationOnLogin, - }, - &cli.StringFlag{ - Name: "storage-home-mapping", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.HomeMapping, ""), - Usage: "mapping template for user home paths to user-specific mount points, e.g. /home/{{substr 0 1 .Username}}", - EnvVars: []string{"STORAGE_GATEWAY_HOME_MAPPING"}, - Destination: &cfg.Reva.Gateway.HomeMapping, - }, - &cli.IntFlag{ - Name: "etag-cache-ttl", - Value: flags.OverrideDefaultInt(cfg.Reva.Gateway.EtagCacheTTL, 0), - Usage: "TTL for the home and shares directory etags cache", - EnvVars: []string{"STORAGE_GATEWAY_ETAG_CACHE_TTL"}, - Destination: &cfg.Reva.Gateway.EtagCacheTTL, - }, - - // other services - - &cli.StringFlag{ - Name: "auth-basic-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBasic.Endpoint, "localhost:9146"), - Usage: "endpoint to use for the basic auth provider", - EnvVars: []string{"STORAGE_AUTH_BASIC_ENDPOINT"}, - Destination: &cfg.Reva.AuthBasic.Endpoint, - }, - &cli.StringFlag{ - Name: "auth-bearer-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.AuthBearer.Endpoint, "localhost:9148"), - Usage: "endpoint to use for the bearer auth provider", - EnvVars: []string{"STORAGE_AUTH_BEARER_ENDPOINT"}, - Destination: &cfg.Reva.AuthBearer.Endpoint, - }, - &cli.StringFlag{ - Name: "auth-machine-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.AuthMachine.Endpoint, "localhost:9166"), - Usage: "endpoint to use for the machine auth provider", - EnvVars: []string{"STORAGE_AUTH_MACHINE_ENDPOINT"}, - Destination: &cfg.Reva.AuthMachine.Endpoint, - }, - - // storage registry - - &cli.StringFlag{ - Name: "storage-registry-driver", - Value: flags.OverrideDefaultString(cfg.Reva.StorageRegistry.Driver, "static"), - Usage: "driver of the storage registry", - EnvVars: []string{"STORAGE_STORAGE_REGISTRY_DRIVER"}, - Destination: &cfg.Reva.StorageRegistry.Driver, - }, - &cli.StringSliceFlag{ - Name: "storage-registry-rule", - Value: cli.NewStringSlice(), - Usage: `Replaces the generated storage registry rules with this set: --storage-registry-rule "/eos=localhost:9158" [--storage-registry-rule "1284d238-aa92-42ce-bdc4-0b0000009162=localhost:9162"]`, - EnvVars: []string{"STORAGE_STORAGE_REGISTRY_RULES"}, - }, - &cli.StringFlag{ - Name: "storage-home-provider", - Value: flags.OverrideDefaultString(cfg.Reva.StorageRegistry.HomeProvider, "/home"), - Usage: "mount point of the storage provider for user homes in the global namespace", - EnvVars: []string{"STORAGE_STORAGE_REGISTRY_HOME_PROVIDER"}, - Destination: &cfg.Reva.StorageRegistry.HomeProvider, - }, - &cli.StringFlag{ - Name: "storage-registry-json", - Value: flags.OverrideDefaultString(cfg.Reva.StorageRegistry.JSON, ""), - Usage: "JSON file containing the storage registry rules", - EnvVars: []string{"STORAGE_STORAGE_REGISTRY_JSON"}, - Destination: &cfg.Reva.StorageRegistry.JSON, - }, - - // app registry - - &cli.StringFlag{ - Name: "app-registry-driver", - Value: flags.OverrideDefaultString(cfg.Reva.AppRegistry.Driver, "static"), - Usage: "driver of the app registry", - EnvVars: []string{"STORAGE_APP_REGISTRY_DRIVER"}, - Destination: &cfg.Reva.AppRegistry.Driver, - }, - &cli.StringFlag{ - Name: "app-registry-mimetypes-json", - Value: flags.OverrideDefaultString(cfg.Reva.AppRegistry.MimetypesJSON, ""), - Usage: "JSON file containing the storage registry rules", - EnvVars: []string{"STORAGE_APP_REGISTRY_MIMETYPES_JSON"}, - Destination: &cfg.Reva.AppRegistry.MimetypesJSON, - }, - - // please note that STORAGE_FRONTEND_PUBLIC_URL is also defined in - // storage/pkg/flagset/frontend.go because this setting may be consumed - // by both the gateway and frontend service - &cli.StringFlag{ - Name: "public-url", - Value: flags.OverrideDefaultString(cfg.Reva.Frontend.PublicURL, "https://localhost:9200"), - Usage: "URL to use for the storage service", - EnvVars: []string{"STORAGE_FRONTEND_PUBLIC_URL", "OCIS_URL"}, // STORAGE_FRONTEND_PUBLIC_URL takes precedence over OCIS_URL - Destination: &cfg.Reva.Frontend.PublicURL, - }, - &cli.StringFlag{ - Name: "datagateway-url", - Value: flags.OverrideDefaultString(cfg.Reva.DataGateway.PublicURL, ""), - Usage: "URL to use for the storage datagateway, defaults to /data", - EnvVars: []string{"STORAGE_DATAGATEWAY_PUBLIC_URL"}, - Destination: &cfg.Reva.DataGateway.PublicURL, - }, - &cli.StringFlag{ - Name: "userprovider-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Users.Endpoint, "localhost:9144"), - Usage: "endpoint to use for the userprovider", - EnvVars: []string{"STORAGE_USERPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Users.Endpoint, - }, - &cli.StringFlag{ - Name: "groupprovider-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.Endpoint, "localhost:9160"), - Usage: "endpoint to use for the groupprovider", - EnvVars: []string{"STORAGE_GROUPPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Groups.Endpoint, - }, - &cli.StringFlag{ - Name: "sharing-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.Endpoint, "localhost:9150"), - Usage: "endpoint to use for the storage service", - EnvVars: []string{"STORAGE_SHARING_ENDPOINT"}, - Destination: &cfg.Reva.Sharing.Endpoint, - }, - &cli.StringFlag{ - Name: "appprovider-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.AppProvider.Endpoint, "localhost:9164"), - Usage: "endpoint to use for the app provider", - EnvVars: []string{"STORAGE_APPPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.AppProvider.Endpoint, - }, - - // register home storage - - &cli.StringFlag{ - Name: "storage-home-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.Endpoint, "localhost:9154"), - Usage: "endpoint to use for the home storage", - EnvVars: []string{"STORAGE_HOME_ENDPOINT"}, - Destination: &cfg.Reva.StorageHome.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-home-mount-path", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.MountPath, "/home"), - Usage: "mount path", - EnvVars: []string{"STORAGE_HOME_MOUNT_PATH"}, - Destination: &cfg.Reva.StorageHome.MountPath, - }, - &cli.StringFlag{ - Name: "storage-home-mount-id", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.MountID, "1284d238-aa92-42ce-bdc4-0b0000009154"), - Usage: "mount id", - EnvVars: []string{"STORAGE_HOME_MOUNT_ID"}, - Destination: &cfg.Reva.StorageHome.MountID, - }, - - // register users storage - - &cli.StringFlag{ - Name: "storage-users-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.Endpoint, "localhost:9157"), - Usage: "endpoint to use for the users storage", - EnvVars: []string{"STORAGE_USERS_ENDPOINT"}, - Destination: &cfg.Reva.StorageUsers.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-users-mount-path", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.MountPath, "/users"), - Usage: "mount path", - EnvVars: []string{"STORAGE_USERS_MOUNT_PATH"}, - Destination: &cfg.Reva.StorageUsers.MountPath, - }, - &cli.StringFlag{ - Name: "storage-users-mount-id", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.MountID, "1284d238-aa92-42ce-bdc4-0b0000009157"), - Usage: "mount id", - EnvVars: []string{"STORAGE_USERS_MOUNT_ID"}, - Destination: &cfg.Reva.StorageUsers.MountID, - }, - - // register public link storage - - &cli.StringFlag{ - Name: "public-link-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.Endpoint, "localhost:9178"), - Usage: "endpoint to use for the public links service", - EnvVars: []string{"STORAGE_PUBLIC_LINK_ENDPOINT"}, - Destination: &cfg.Reva.StoragePublicLink.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-public-link-mount-path", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.MountPath, "/public"), - Usage: "mount path", - EnvVars: []string{"STORAGE_PUBLIC_LINK_MOUNT_PATH"}, - Destination: &cfg.Reva.StoragePublicLink.MountPath, - }, - &cli.StringFlag{ - Name: "storage-public-link-mount-id", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.MountID, "e1a73ede-549b-4226-abdf-40e69ca8230d"), - Usage: "mount id", - EnvVars: []string{"STORAGE_PUBLIC_LINK_MOUNT_ID"}, - Destination: &cfg.Reva.StoragePublicLink.MountID, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/groups.go b/storage/pkg/flagset/groups.go deleted file mode 100644 index 50dab10901b..00000000000 --- a/storage/pkg/flagset/groups.go +++ /dev/null @@ -1,94 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// GroupsWithConfig applies cfg to the root flagset -func GroupsWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.DebugAddr, "127.0.0.1:9161"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_GROUPPROVIDER_DEBUG_ADDR"}, - Destination: &cfg.Reva.Groups.DebugAddr, - }, - - // Services - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - - // Groupprovider - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_GROUPPROVIDER_NETWORK"}, - Destination: &cfg.Reva.Groups.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.GRPCAddr, "127.0.0.1:9160"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_GROUPPROVIDER_ADDR"}, - Destination: &cfg.Reva.Groups.GRPCAddr, - }, - &cli.StringFlag{ - Name: "endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.Endpoint, "localhost:9160"), - Usage: "URL to use for the storage service", - EnvVars: []string{"STORAGE_GROUPPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Groups.Endpoint, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("groupprovider"), // TODO preferences - Usage: "--service groupprovider [--service otherservice]", - EnvVars: []string{"STORAGE_GROUPPROVIDER_SERVICES"}, - }, - - &cli.StringFlag{ - Name: "driver", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.Driver, "ldap"), - Usage: "group driver: 'json', 'ldap', or 'rest'", - EnvVars: []string{"STORAGE_GROUPPROVIDER_DRIVER"}, - Destination: &cfg.Reva.Groups.Driver, - }, - &cli.StringFlag{ - Name: "json-config", - Value: flags.OverrideDefaultString(cfg.Reva.Groups.JSON, ""), - Usage: "Path to groups.json file", - EnvVars: []string{"STORAGE_GROUPPROVIDER_JSON"}, - Destination: &cfg.Reva.Groups.JSON, - }, - &cli.IntFlag{ - Name: "group-members-cache-expiration", - Value: flags.OverrideDefaultInt(cfg.Reva.Groups.GroupMembersCacheExpiration, 5), - Usage: "Time in minutes for redis cache expiration.", - EnvVars: []string{"STORAGE_GROUP_CACHE_EXPIRATION"}, - Destination: &cfg.Reva.Groups.GroupMembersCacheExpiration, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, LDAPWithConfig(cfg)...) - flags = append(flags, RestWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/health.go b/storage/pkg/flagset/health.go deleted file mode 100644 index 3333622e520..00000000000 --- a/storage/pkg/flagset/health.go +++ /dev/null @@ -1,20 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// HealthWithConfig applies cfg to the health flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9109"), - Usage: "Address to debug endpoint", - EnvVars: []string{"STORAGE_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} diff --git a/storage/pkg/flagset/ldap.go b/storage/pkg/flagset/ldap.go deleted file mode 100644 index 94848dce287..00000000000 --- a/storage/pkg/flagset/ldap.go +++ /dev/null @@ -1,229 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// LDAPWithConfig applies LDAP cfg to the flagset -func LDAPWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "ldap-hostname", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.Hostname, "localhost"), - Usage: "LDAP hostname", - EnvVars: []string{"STORAGE_LDAP_HOSTNAME"}, - Destination: &cfg.Reva.LDAP.Hostname, - }, - &cli.IntFlag{ - Name: "ldap-port", - Value: flags.OverrideDefaultInt(cfg.Reva.LDAP.Port, 9126), - Usage: "LDAP port", - EnvVars: []string{"STORAGE_LDAP_PORT"}, - Destination: &cfg.Reva.LDAP.Port, - }, - &cli.StringFlag{ - Name: "ldap-cacert", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.CACert, path.Join(defaults.BaseDataPath(), "ldap", "ldap.crt")), - Usage: "Path to a trusted Certificate file (in PEM format) for the LDAP Connection", - EnvVars: []string{"STORAGE_LDAP_CACERT"}, - Destination: &cfg.Reva.LDAP.CACert, - }, - &cli.BoolFlag{ - Name: "ldap-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.LDAP.Insecure, false), - Usage: "Disable TLS certificate and hostname validation", - EnvVars: []string{"STORAGE_LDAP_INSECURE"}, - Destination: &cfg.Reva.LDAP.Insecure, - }, - &cli.StringFlag{ - Name: "ldap-base-dn", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.BaseDN, "dc=ocis,dc=test"), - Usage: "LDAP basedn", - EnvVars: []string{"STORAGE_LDAP_BASE_DN"}, - Destination: &cfg.Reva.LDAP.BaseDN, - }, - &cli.StringFlag{ - Name: "ldap-loginfilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.LoginFilter, "(&(objectclass=posixAccount)(|(cn={{login}})(mail={{login}})))"), - Usage: "LDAP login filter", - EnvVars: []string{"STORAGE_LDAP_LOGINFILTER"}, - Destination: &cfg.Reva.LDAP.LoginFilter, - }, - - // User specific filters - - &cli.StringFlag{ - Name: "ldap-userfilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserFilter, "(&(objectclass=posixAccount)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))"), - Usage: "LDAP filter used when getting a user. The CS3 userid properties {{.OpaqueId}} and {{.Idp}} are available.", - EnvVars: []string{"STORAGE_LDAP_USERFILTER"}, - Destination: &cfg.Reva.LDAP.UserFilter, - }, - &cli.StringFlag{ - Name: "ldap-userattributefilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserAttributeFilter, "(&(objectclass=posixAccount)({{attr}}={{value}}))"), - Usage: "LDAP filter used when searching for a user by claim/attribute. {{attr}} will be replaced with the attribute, {{value}} with the value.", - EnvVars: []string{"STORAGE_LDAP_USERATTRIBUTEFILTER"}, - Destination: &cfg.Reva.LDAP.UserAttributeFilter, - }, - &cli.StringFlag{ - Name: "ldap-userfindfilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserFindFilter, "(&(objectclass=posixAccount)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))"), - Usage: "LDAP filter used when searching for user recipients. {{query}} will be replaced with the search query", - EnvVars: []string{"STORAGE_LDAP_USERFINDFILTER"}, - Destination: &cfg.Reva.LDAP.UserFindFilter, - }, - &cli.StringFlag{ - Name: "ldap-usergroupfilter", - // FIXME the storage implementation needs to use the memberof overlay to get the cn when it only has the uuid, - // because the ldap schema either uses the dn or the member(of) attributes to establish membership - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserGroupFilter, "(&(objectclass=posixGroup)(ownclouduuid={{.OpaqueId}}*))"), // This filter will never work - Usage: "LDAP filter used when getting the groups of a user. The CS3 userid properties {{.OpaqueId}} and {{.Idp}} are available.", - EnvVars: []string{"STORAGE_LDAP_USERGROUPFILTER"}, - Destination: &cfg.Reva.LDAP.UserGroupFilter, - }, - - // Group specific filters - // These might not work at the moment. Need to be fixed - - &cli.StringFlag{ - Name: "ldap-groupfilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupFilter, "(&(objectclass=posixGroup)(|(ownclouduuid={{.OpaqueId}})(cn={{.OpaqueId}})))"), - Usage: "LDAP filter used when getting a group. The CS3 groupid properties {{.OpaqueId}} and {{.Idp}} are available.", - EnvVars: []string{"STORAGE_LDAP_GROUPFILTER"}, - Destination: &cfg.Reva.LDAP.GroupFilter, - }, - &cli.StringFlag{ - Name: "ldap-groupattributefilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupAttributeFilter, "(&(objectclass=posixGroup)({{attr}}={{value}}))"), - Usage: "LDAP filter used when searching for a group by claim/attribute. {{attr}} will be replaced with the attribute, {{value}} with the value.", - EnvVars: []string{"STORAGE_LDAP_GROUPATTRIBUTEFILTER"}, - Destination: &cfg.Reva.LDAP.GroupAttributeFilter, - }, - &cli.StringFlag{ - Name: "ldap-groupfindfilter", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupFindFilter, "(&(objectclass=posixGroup)(|(cn={{query}}*)(displayname={{query}}*)(mail={{query}}*)))"), - Usage: "LDAP filter used when searching for group recipients. {{query}} will be replaced with the search query", - EnvVars: []string{"STORAGE_LDAP_GROUPFINDFILTER"}, - Destination: &cfg.Reva.LDAP.GroupFindFilter, - }, - &cli.StringFlag{ - Name: "ldap-groupmemberfilter", - // FIXME the storage implementation needs to use the members overlay to get the cn when it only has the uuid - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupMemberFilter, "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))"), // This filter will never work - Usage: "LDAP filter used when getting the members of a group. The CS3 groupid properties {{.OpaqueId}} and {{.Idp}} are available.", - EnvVars: []string{"STORAGE_LDAP_GROUPMEMBERFILTER"}, - Destination: &cfg.Reva.LDAP.GroupMemberFilter, - }, - &cli.StringFlag{ - Name: "ldap-bind-dn", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.BindDN, "cn=reva,ou=sysusers,dc=ocis,dc=test"), - Usage: "LDAP bind dn", - EnvVars: []string{"STORAGE_LDAP_BIND_DN"}, - Destination: &cfg.Reva.LDAP.BindDN, - }, - &cli.StringFlag{ - Name: "ldap-bind-password", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.BindPassword, "reva"), - Usage: "LDAP bind password", - EnvVars: []string{"STORAGE_LDAP_BIND_PASSWORD"}, - Destination: &cfg.Reva.LDAP.BindPassword, - }, - &cli.StringFlag{ - Name: "ldap-idp", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.IDP, "https://localhost:9200"), - Usage: "Identity provider to use for users", - EnvVars: []string{"STORAGE_LDAP_IDP", "OCIS_URL"}, // STORAGE_LDAP_IDP takes precedence over OCIS_URL - Destination: &cfg.Reva.LDAP.IDP, - }, - // ldap dn is always the dn - - // user schema - - &cli.StringFlag{ - Name: "ldap-user-schema-uid", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserSchema.UID, "ownclouduuid"), - Usage: "LDAP user schema uid", - EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_UID"}, - Destination: &cfg.Reva.LDAP.UserSchema.UID, - }, - &cli.StringFlag{ - Name: "ldap-user-schema-mail", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserSchema.Mail, "mail"), - Usage: "LDAP user schema mail", - EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_MAIL"}, - Destination: &cfg.Reva.LDAP.UserSchema.Mail, - }, - &cli.StringFlag{ - Name: "ldap-user-schema-displayName", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserSchema.DisplayName, "displayname"), - Usage: "LDAP user schema displayName", - EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_DISPLAYNAME"}, - Destination: &cfg.Reva.LDAP.UserSchema.DisplayName, - }, - &cli.StringFlag{ - Name: "ldap-user-schema-cn", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserSchema.CN, "cn"), - Usage: "LDAP user schema cn", - EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_CN"}, - Destination: &cfg.Reva.LDAP.UserSchema.CN, - }, - &cli.StringFlag{ - Name: "ldap-user-schema-uidnumber", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserSchema.UIDNumber, "uidnumber"), - Usage: "LDAP user schema uidnumber", - EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_UID_NUMBER"}, - Destination: &cfg.Reva.LDAP.UserSchema.UIDNumber, - }, - &cli.StringFlag{ - Name: "ldap-user-schema-gidnumber", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.UserSchema.GIDNumber, "gidnumber"), - Usage: "LDAP user schema gidnumber", - EnvVars: []string{"STORAGE_LDAP_USER_SCHEMA_GID_NUMBER"}, - Destination: &cfg.Reva.LDAP.UserSchema.GIDNumber, - }, - - // group schema - - &cli.StringFlag{ - Name: "ldap-group-schema-gid", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupSchema.GID, "cn"), - Usage: "LDAP group schema gid", - EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_GID"}, - Destination: &cfg.Reva.LDAP.GroupSchema.GID, - }, - &cli.StringFlag{ - Name: "ldap-group-schema-mail", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupSchema.Mail, "mail"), - Usage: "LDAP group schema mail", - EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_MAIL"}, - Destination: &cfg.Reva.LDAP.GroupSchema.Mail, - }, - &cli.StringFlag{ - Name: "ldap-group-schema-displayName", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupSchema.DisplayName, "cn"), - Usage: "LDAP group schema displayName", - EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_DISPLAYNAME"}, - Destination: &cfg.Reva.LDAP.GroupSchema.DisplayName, - }, - &cli.StringFlag{ - Name: "ldap-group-schema-cn", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupSchema.CN, "cn"), - Usage: "LDAP group schema cn", - EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_CN"}, - Destination: &cfg.Reva.LDAP.GroupSchema.CN, - }, - &cli.StringFlag{ - Name: "ldap-group-schema-gidnumber", - Value: flags.OverrideDefaultString(cfg.Reva.LDAP.GroupSchema.GIDNumber, "gidnumber"), - Usage: "LDAP group schema gidnumber", - EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_GID_NUMBER"}, - Destination: &cfg.Reva.LDAP.GroupSchema.GIDNumber, - }, - } -} diff --git a/storage/pkg/flagset/metadatadrivers/drivereos.go b/storage/pkg/flagset/metadatadrivers/drivereos.go deleted file mode 100644 index c734e6c1294..00000000000 --- a/storage/pkg/flagset/metadatadrivers/drivereos.go +++ /dev/null @@ -1,136 +0,0 @@ -package metadatadrivers - -import ( - "os" - - "github.com/owncloud/ocis/ocis-pkg/flags" - - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverEOSWithConfig applies cfg to the root flagset -func DriverEOSWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - - &cli.StringFlag{ - Name: "storage-eos-namespace", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.Root, "/eos/dockertest/reva"), - Usage: "Namespace for metadata operations", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_NAMESPACE"}, - Destination: &cfg.Reva.MetadataStorage.EOS.Root, - }, - &cli.StringFlag{ - Name: "storage-eos-shadow-namespace", - // Defaults to path.Join(c.Namespace, ".shadow") - Usage: "Shadow namespace where share references are stored", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SHADOW_NAMESPACE"}, - Destination: &cfg.Reva.MetadataStorage.EOS.ShadowNamespace, - }, - &cli.StringFlag{ - Name: "storage-eos-uploads-namespace", - // Defaults to path.Join(c.Namespace, ".uploads") - Usage: "Uploads namespace", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_UPLOADS_NAMESPACE"}, - Destination: &cfg.Reva.MetadataStorage.EOS.UploadsNamespace, - }, - &cli.StringFlag{ - Name: "storage-eos-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.ShareFolder, "/Shares"), - Usage: "name of the share folder", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SHARE_FOLDER"}, - Destination: &cfg.Reva.MetadataStorage.EOS.ShareFolder, - }, - &cli.StringFlag{ - Name: "storage-eos-binary", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.EosBinary, "/usr/bin/eos"), - Usage: "Location of the eos binary", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_BINARY"}, - Destination: &cfg.Reva.MetadataStorage.EOS.EosBinary, - }, - &cli.StringFlag{ - Name: "storage-eos-xrdcopy-binary", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.XrdcopyBinary, "/usr/bin/xrdcopy"), - Usage: "Location of the xrdcopy binary", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_XRDCOPY_BINARY"}, - Destination: &cfg.Reva.MetadataStorage.EOS.XrdcopyBinary, - }, - &cli.StringFlag{ - Name: "storage-eos-master-url", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.MasterURL, "root://eos-mgm1.eoscluster.cern.ch:1094"), - Usage: "URL of the Master EOS MGM", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_MASTER_URL"}, - Destination: &cfg.Reva.MetadataStorage.EOS.MasterURL, - }, - &cli.StringFlag{ - Name: "storage-eos-slave-url", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.SlaveURL, "root://eos-mgm1.eoscluster.cern.ch:1094"), - Usage: "URL of the Slave EOS MGM", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SLAVE_URL"}, - Destination: &cfg.Reva.MetadataStorage.EOS.SlaveURL, - }, - &cli.StringFlag{ - Name: "storage-eos-cache-directory", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.CacheDirectory, os.TempDir()), - Usage: "Location on the local fs where to store reads", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_CACHE_DIRECTORY"}, - Destination: &cfg.Reva.MetadataStorage.EOS.CacheDirectory, - }, - &cli.BoolFlag{ - Name: "storage-eos-enable-logging", - Usage: "Enables logging of the commands executed", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_ENABLE_LOGGING"}, - Destination: &cfg.Reva.MetadataStorage.EOS.EnableLogging, - }, - &cli.BoolFlag{ - Name: "storage-eos-show-hidden-sysfiles", - Usage: "show internal EOS files like .sys.v# and .sys.a# files.", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SHOW_HIDDEN_SYSFILES"}, - Destination: &cfg.Reva.MetadataStorage.EOS.ShowHiddenSysFiles, - }, - &cli.BoolFlag{ - Name: "storage-eos-force-singleuser-mode", - Usage: "force connections to EOS to use SingleUsername", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_FORCE_SINGLEUSER_MODE"}, - Destination: &cfg.Reva.MetadataStorage.EOS.ForceSingleUserMode, - }, - &cli.BoolFlag{ - Name: "storage-eos-use-keytab", - Usage: "authenticate requests by using an EOS keytab", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_USE_KEYTAB"}, - Destination: &cfg.Reva.MetadataStorage.EOS.UseKeytab, - }, - &cli.StringFlag{ - Name: "storage-eos-sec-protocol", - Usage: "the xrootd security protocol to use between the server and EOS", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SEC_PROTOCOL"}, - Destination: &cfg.Reva.MetadataStorage.EOS.SecProtocol, - }, - &cli.StringFlag{ - Name: "storage-eos-keytab", - Usage: "the location of the keytab to use to authenticate to EOS", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_KEYTAB"}, - Destination: &cfg.Reva.MetadataStorage.EOS.Keytab, - }, - &cli.StringFlag{ - Name: "storage-eos-single-username", - Usage: "the username to use when SingleUserMode is enabled", - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_SINGLE_USERNAME"}, - Destination: &cfg.Reva.MetadataStorage.EOS.SingleUsername, - }, - &cli.StringFlag{ - Name: "storage-eos-layout", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.UserLayout, "{{substr 0 1 .Username}}/{{.Username}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.UsernameLower}} and {{.Provider}} also supports prefixing dirs: "{{.UsernamePrefixCount.2}}/{{.UsernameLower}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_EOS_LAYOUT"}, - Destination: &cfg.Reva.MetadataStorage.EOS.UserLayout, - }, - &cli.StringFlag{ - Name: "storage-eos-reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.EOS.GatewaySVC, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.MetadataStorage.EOS.GatewaySVC, - }, - } -} diff --git a/storage/pkg/flagset/metadatadrivers/driverlocal.go b/storage/pkg/flagset/metadatadrivers/driverlocal.go deleted file mode 100644 index 7ef4ddac3fb..00000000000 --- a/storage/pkg/flagset/metadatadrivers/driverlocal.go +++ /dev/null @@ -1,23 +0,0 @@ -package metadatadrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverLocalWithConfig applies cfg to the root flagset -func DriverLocalWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-local-root", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.Local.Root, path.Join(defaults.BaseDataPath(), "storage", "local", "metadata")), - Usage: "the path to the local storage root", - EnvVars: []string{"STORAGE_METADATA_DRIVER_LOCAL_ROOT"}, - Destination: &cfg.Reva.MetadataStorage.Local.Root, - }, - } -} diff --git a/storage/pkg/flagset/metadatadrivers/driverocis.go b/storage/pkg/flagset/metadatadrivers/driverocis.go deleted file mode 100644 index 614b0bdaebe..00000000000 --- a/storage/pkg/flagset/metadatadrivers/driverocis.go +++ /dev/null @@ -1,37 +0,0 @@ -package metadatadrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverOCISWithConfig applies cfg to the root flagset -func DriverOCISWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-ocis-root", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.OCIS.Root, path.Join(defaults.BaseDataPath(), "storage", "metadata")), - Usage: "the path to the local storage root", - EnvVars: []string{"STORAGE_METADATA_DRIVER_OCIS_ROOT"}, - Destination: &cfg.Reva.MetadataStorage.OCIS.Root, - }, - &cli.StringFlag{ - Name: "storage-ocis-layout", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.OCIS.UserLayout, "{{.Id.OpaqueId}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.Mail}}, {{.Id.OpaqueId}}, {{.Id.Idp}} also supports prefixing dirs: "{{substr 0 1 .Username}}/{{.Username}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_OCIS_LAYOUT"}, - Destination: &cfg.Reva.MetadataStorage.OCIS.UserLayout, - }, - &cli.StringFlag{ - Name: "service-user-uuid", - Value: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Usage: "uuid of the internal service user", - EnvVars: []string{"STORAGE_METADATA_DRIVER_OCIS_SERVICE_USER_UUID"}, - Destination: &cfg.Reva.MetadataStorage.OCIS.ServiceUserUUID, - }, - } -} diff --git a/storage/pkg/flagset/metadatadrivers/drivers3.go b/storage/pkg/flagset/metadatadrivers/drivers3.go deleted file mode 100644 index 56047756042..00000000000 --- a/storage/pkg/flagset/metadatadrivers/drivers3.go +++ /dev/null @@ -1,48 +0,0 @@ -package metadatadrivers - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverS3NGWithConfig applies cfg to the root flagset -func DriverS3WithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-s3-region", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.S3.Region, "default"), - Usage: `"the s3 region" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_REGION"}, - Destination: &cfg.Reva.MetadataStorage.S3.Region, - }, - &cli.StringFlag{ - Name: "storage-s3-accesskey", - Value: "", - Usage: `"the s3 access key" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_ACCESS_KEY"}, - Destination: &cfg.Reva.MetadataStorage.S3.AccessKey, - }, - &cli.StringFlag{ - Name: "storage-s3-secretkey", - Value: "", - Usage: `"the secret s3 api key" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_SECRET_KEY"}, - Destination: &cfg.Reva.MetadataStorage.S3.SecretKey, - }, - &cli.StringFlag{ - Name: "storage-s3-endpoint", - Value: "", - Usage: `"s3 compatible API endpoint" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_ENDPOINT"}, - Destination: &cfg.Reva.MetadataStorage.S3.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-s3-bucket", - Value: "", - Usage: `"bucket where the data will be stored in`, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3_BUCKET"}, - Destination: &cfg.Reva.MetadataStorage.S3.Bucket, - }, - } -} diff --git a/storage/pkg/flagset/metadatadrivers/drivers3ng.go b/storage/pkg/flagset/metadatadrivers/drivers3ng.go deleted file mode 100644 index 81e394aaa83..00000000000 --- a/storage/pkg/flagset/metadatadrivers/drivers3ng.go +++ /dev/null @@ -1,65 +0,0 @@ -package metadatadrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverS3NGWithConfig applies cfg to the root flagset -func DriverS3NGWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-s3ng-root", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.S3NG.Root, path.Join(defaults.BaseDataPath(), "storage", "metadata")), - Usage: "the path to the local storage root", - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_ROOT"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.Root, - }, - &cli.StringFlag{ - Name: "storage-s3ng-layout", - Value: flags.OverrideDefaultString(cfg.Reva.MetadataStorage.S3NG.UserLayout, "{{.Id.OpaqueId}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.Mail}}, {{.Id.OpaqueId}}, {{.Id.Idp}} also supports prefixing dirs: "{{substr 0 1 .Username}}/{{.Username}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_LAYOUT"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.UserLayout, - }, - &cli.StringFlag{ - Name: "storage-s3ng-region", - Value: "default", - Usage: `"the s3 region" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_REGION"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.Region, - }, - &cli.StringFlag{ - Name: "storage-s3ng-accesskey", - Value: "", - Usage: `"the s3 access key" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_ACCESS_KEY"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.AccessKey, - }, - &cli.StringFlag{ - Name: "storage-s3ng-secretkey", - Value: "", - Usage: `"the secret s3 api key" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_SECRET_KEY"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.SecretKey, - }, - &cli.StringFlag{ - Name: "storage-s3ng-endpoint", - Value: "", - Usage: `"s3 compatible API endpoint" `, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_ENDPOINT"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-s3ng-bucket", - Value: "", - Usage: `"bucket where the data will be stored in`, - EnvVars: []string{"STORAGE_METADATA_DRIVER_S3NG_BUCKET"}, - Destination: &cfg.Reva.MetadataStorage.S3NG.Bucket, - }, - } -} diff --git a/storage/pkg/flagset/rest.go b/storage/pkg/flagset/rest.go deleted file mode 100644 index 1755b0e0f2a..00000000000 --- a/storage/pkg/flagset/rest.go +++ /dev/null @@ -1,76 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// RestWithConfig applies REST user/group provider cfg to the flagset -func RestWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "rest-client-id", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.ClientID, ""), - Usage: "User/group rest driver Client ID", - EnvVars: []string{"STORAGE_REST_CLIENT_ID"}, - Destination: &cfg.Reva.UserGroupRest.ClientID, - }, - &cli.StringFlag{ - Name: "rest-client-secret", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.ClientSecret, ""), - Usage: "User/group rest driver Client Secret", - EnvVars: []string{"STORAGE_REST_CLIENT_SECRET"}, - Destination: &cfg.Reva.UserGroupRest.ClientSecret, - }, - &cli.StringFlag{ - Name: "rest-redis-address", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.RedisAddress, "localhost:6379"), - Usage: "Address for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_ADDRESS"}, - Destination: &cfg.Reva.UserGroupRest.RedisAddress, - }, - &cli.StringFlag{ - Name: "rest-redis-username", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.RedisUsername, ""), - Usage: "Username for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_USERNAME"}, - Destination: &cfg.Reva.UserGroupRest.RedisUsername, - }, - &cli.StringFlag{ - Name: "rest-redis-password", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.RedisPassword, ""), - Usage: "Password for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_PASSWORD"}, - Destination: &cfg.Reva.UserGroupRest.RedisPassword, - }, - &cli.StringFlag{ - Name: "rest-id-provider", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.IDProvider, ""), - Usage: "The OIDC Provider", - EnvVars: []string{"STORAGE_REST_ID_PROVIDER"}, - Destination: &cfg.Reva.UserGroupRest.IDProvider, - }, - &cli.StringFlag{ - Name: "rest-api-base-url", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.APIBaseURL, ""), - Usage: "Base API Endpoint", - EnvVars: []string{"STORAGE_REST_API_BASE_URL"}, - Destination: &cfg.Reva.UserGroupRest.APIBaseURL, - }, - &cli.StringFlag{ - Name: "rest-oidc-token-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.OIDCTokenEndpoint, ""), - Usage: "Endpoint to generate token to access the API", - EnvVars: []string{"STORAGE_REST_OIDC_TOKEN_ENDPOINT"}, - Destination: &cfg.Reva.UserGroupRest.OIDCTokenEndpoint, - }, - &cli.StringFlag{ - Name: "rest-target-api", - Value: flags.OverrideDefaultString(cfg.Reva.UserGroupRest.TargetAPI, ""), - Usage: "The target application", - EnvVars: []string{"STORAGE_REST_TARGET_API"}, - Destination: &cfg.Reva.UserGroupRest.TargetAPI, - }, - } -} diff --git a/storage/pkg/flagset/root.go b/storage/pkg/flagset/root.go deleted file mode 100644 index dce2fc58184..00000000000 --- a/storage/pkg/flagset/root.go +++ /dev/null @@ -1,37 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"STORAGE_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"STORAGE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"STORAGE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"STORAGE_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} diff --git a/storage/pkg/flagset/secret.go b/storage/pkg/flagset/secret.go deleted file mode 100644 index 8504bd56b1e..00000000000 --- a/storage/pkg/flagset/secret.go +++ /dev/null @@ -1,27 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// SecretWithConfig applies cfg to the root flagset -func SecretWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "jwt-secret", - Value: flags.OverrideDefaultString(cfg.Reva.JWTSecret, "Pive-Fumkiu4"), - Usage: "Shared jwt secret for reva service communication", - EnvVars: []string{"STORAGE_JWT_SECRET", "OCIS_JWT_SECRET"}, - Destination: &cfg.Reva.JWTSecret, - }, - &cli.BoolFlag{ - Name: "skip-user-groups-in-token", - Value: flags.OverrideDefaultBool(cfg.Reva.SkipUserGroupsInToken, false), - Usage: "Whether to skip encoding user groups in reva's JWT token", - EnvVars: []string{"STORAGE_SKIP_USER_GROUPS_IN_TOKEN"}, - Destination: &cfg.Reva.SkipUserGroupsInToken, - }, - } -} diff --git a/storage/pkg/flagset/sharing.go b/storage/pkg/flagset/sharing.go deleted file mode 100644 index 1f54a2f6ec7..00000000000 --- a/storage/pkg/flagset/sharing.go +++ /dev/null @@ -1,116 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// SharingWithConfig applies cfg to the root flagset -func SharingWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.DebugAddr, "127.0.0.1:9151"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_SHARING_DEBUG_ADDR"}, - Destination: &cfg.Reva.Sharing.DebugAddr, - }, - - // Services - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - - // Sharing - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_SHARING_GRPC_NETWORK"}, - Destination: &cfg.Reva.Sharing.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.GRPCAddr, "127.0.0.1:9150"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_SHARING_GRPC_ADDR"}, - Destination: &cfg.Reva.Sharing.GRPCAddr, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("usershareprovider", "publicshareprovider"), // TODO osmshareprovider - Usage: "--service usershareprovider [--service publicshareprovider]", - EnvVars: []string{"STORAGE_SHARING_SERVICES"}, - }, - &cli.StringFlag{ - Name: "user-driver", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.UserDriver, "json"), - Usage: "driver to use for the UserShareProvider", - EnvVars: []string{"STORAGE_SHARING_USER_DRIVER"}, - Destination: &cfg.Reva.Sharing.UserDriver, - }, - &cli.StringFlag{ - Name: "user-json-file", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.UserJSONFile, path.Join(defaults.BaseDataPath(), "storage", "shares.json")), - Usage: "file used to persist shares for the UserShareProvider", - EnvVars: []string{"STORAGE_SHARING_USER_JSON_FILE"}, - Destination: &cfg.Reva.Sharing.UserJSONFile, - }, - &cli.StringFlag{ - Name: "public-driver", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.PublicDriver, "json"), - Usage: "driver to use for the PublicShareProvider", - EnvVars: []string{"STORAGE_SHARING_PUBLIC_DRIVER"}, - Destination: &cfg.Reva.Sharing.PublicDriver, - }, - &cli.StringFlag{ - Name: "public-json-file", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.PublicJSONFile, path.Join(defaults.BaseDataPath(), "storage", "publicshares.json")), - Usage: "file used to persist shares for the PublicShareProvider", - EnvVars: []string{"STORAGE_SHARING_PUBLIC_JSON_FILE"}, - Destination: &cfg.Reva.Sharing.PublicJSONFile, - }, - &cli.IntFlag{ - Name: "public-password-hash-cost", - Value: flags.OverrideDefaultInt(cfg.Reva.Sharing.PublicPasswordHashCost, 11), - Usage: "the cost of hashing the public shares passwords", - EnvVars: []string{"STORAGE_SHARING_PUBLIC_PASSWORD_HASH_COST"}, - Destination: &cfg.Reva.Sharing.PublicPasswordHashCost, - }, - &cli.BoolFlag{ - Name: "public-enable-expired-shares-cleanup", - Value: flags.OverrideDefaultBool(cfg.Reva.Sharing.PublicEnableExpiredSharesCleanup, true), - Usage: "whether to periodically delete expired public shares", - EnvVars: []string{"STORAGE_SHARING_PUBLIC_ENABLE_EXPIRED_SHARES_CLEANUP"}, - Destination: &cfg.Reva.Sharing.PublicEnableExpiredSharesCleanup, - }, - &cli.IntFlag{ - Name: "public-janitor-run-interval", - Value: flags.OverrideDefaultInt(cfg.Reva.Sharing.PublicJanitorRunInterval, 60), - Usage: "the time period in seconds after which to start a janitor run", - EnvVars: []string{"STORAGE_SHARING_PUBLIC_JANITOR_RUN_INTERVAL"}, - Destination: &cfg.Reva.Sharing.PublicJanitorRunInterval, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, SharingSQLWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/sharingsql.go b/storage/pkg/flagset/sharingsql.go deleted file mode 100644 index b152380fa77..00000000000 --- a/storage/pkg/flagset/sharingsql.go +++ /dev/null @@ -1,48 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// SharingSQLWithConfig applies the Sharing SQL driver cfg to the flagset -func SharingSQLWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "user-sql-username", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.UserSQLUsername, ""), - Usage: "Username to be used to connect to the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_USERNAME"}, - Destination: &cfg.Reva.Sharing.UserSQLUsername, - }, - &cli.StringFlag{ - Name: "user-sql-password", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.UserSQLPassword, ""), - Usage: "Password to be used to connect to the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_PASSWORD"}, - Destination: &cfg.Reva.Sharing.UserSQLPassword, - }, - &cli.StringFlag{ - Name: "user-sql-host", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.UserSQLHost, ""), - Usage: "Hostname of the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_HOST"}, - Destination: &cfg.Reva.Sharing.UserSQLHost, - }, - &cli.IntFlag{ - Name: "user-sql-port", - Value: flags.OverrideDefaultInt(cfg.Reva.Sharing.UserSQLPort, 1433), - Usage: "The port on which the SQL database is exposed", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_PORT"}, - Destination: &cfg.Reva.Sharing.UserSQLPort, - }, - &cli.StringFlag{ - Name: "user-sql-name", - Value: flags.OverrideDefaultString(cfg.Reva.Sharing.UserSQLName, ""), - Usage: "Name of the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_NAME"}, - Destination: &cfg.Reva.Sharing.UserSQLName, - }, - } -} diff --git a/storage/pkg/flagset/storagehome.go b/storage/pkg/flagset/storagehome.go deleted file mode 100644 index 76eb53d70bb..00000000000 --- a/storage/pkg/flagset/storagehome.go +++ /dev/null @@ -1,175 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset/userdrivers" - "github.com/urfave/cli/v2" -) - -// StorageHomeWithConfig applies cfg to the root flagset -func StorageHomeWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.DebugAddr, "127.0.0.1:9156"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_HOME_DEBUG_ADDR"}, - Destination: &cfg.Reva.StorageHome.DebugAddr, - }, - - // Services - - // Storage home - - &cli.StringFlag{ - Name: "grpc-network", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_HOME_GRPC_NETWORK"}, - Destination: &cfg.Reva.StorageHome.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.GRPCAddr, "127.0.0.1:9154"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_HOME_GRPC_ADDR"}, - Destination: &cfg.Reva.StorageHome.GRPCAddr, - }, - &cli.StringFlag{ - Name: "http-network", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.HTTPNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_HOME_HTTP_NETWORK"}, - Destination: &cfg.Reva.StorageHome.HTTPNetwork, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.HTTPAddr, "127.0.0.1:9155"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_HOME_HTTP_ADDR"}, - Destination: &cfg.Reva.StorageHome.HTTPAddr, - }, - - // TODO allow disabling grpc / http services - /* - &cli.StringSliceFlag{ - Name: "grpc-service", - Value: cli.NewStringSlice("storageprovider"), - Usage: "--service storageprovider [--service otherservice]", - EnvVars: []string{"STORAGE_HOME_GRPC_SERVICES"}, - }, - &cli.StringSliceFlag{ - Name: "http-service", - Value: cli.NewStringSlice("dataprovider"), - Usage: "--service dataprovider [--service otherservice]", - EnvVars: []string{"STORAGE_HOME_HTTP_SERVICES"}, - }, - */ - - &cli.StringFlag{ - Name: "driver", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.Driver, "ocis"), - Usage: "storage driver for home mount: eg. local, eos, owncloud, ocis or s3", - EnvVars: []string{"STORAGE_HOME_DRIVER"}, - Destination: &cfg.Reva.StorageHome.Driver, - }, - &cli.BoolFlag{ - Name: "read-only", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageHome.ReadOnly, false), - Usage: "use storage driver in read-only mode", - EnvVars: []string{"STORAGE_HOME_READ_ONLY", "OCIS_STORAGE_READ_ONLY"}, - Destination: &cfg.Reva.StorageHome.ReadOnly, - }, - &cli.StringFlag{ - Name: "mount-path", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.MountPath, "/home"), - Usage: "mount path", - EnvVars: []string{"STORAGE_HOME_MOUNT_PATH"}, - Destination: &cfg.Reva.StorageHome.MountPath, - }, - &cli.StringFlag{ - Name: "mount-id", - // This is the mount id of the storage provider using the same storage driver - // as /home but without home enabled. - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.MountID, "1284d238-aa92-42ce-bdc4-0b0000009157"), - Usage: "mount id", - EnvVars: []string{"STORAGE_HOME_MOUNT_ID"}, - Destination: &cfg.Reva.StorageHome.MountID, - }, - &cli.BoolFlag{ - Name: "expose-data-server", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageHome.ExposeDataServer, false), - Usage: "exposes a dedicated data server", - EnvVars: []string{"STORAGE_HOME_EXPOSE_DATA_SERVER"}, - Destination: &cfg.Reva.StorageHome.ExposeDataServer, - }, - &cli.StringFlag{ - Name: "data-server-url", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.DataServerURL, "http://localhost:9155/data"), - Usage: "data server url", - EnvVars: []string{"STORAGE_HOME_DATA_SERVER_URL"}, - Destination: &cfg.Reva.StorageHome.DataServerURL, - }, - &cli.StringFlag{ - Name: "http-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.HTTPPrefix, "data"), - Usage: "prefix for the http endpoint, without leading slash", - EnvVars: []string{"STORAGE_HOME_HTTP_PREFIX"}, - Destination: &cfg.Reva.StorageHome.HTTPPrefix, - }, - &cli.StringFlag{ - Name: "tmp-folder", - Value: flags.OverrideDefaultString(cfg.Reva.StorageHome.TempFolder, path.Join(defaults.BaseDataPath(), "tmp", "home")), - Usage: "path to tmp folder", - EnvVars: []string{"STORAGE_HOME_TMP_FOLDER"}, - Destination: &cfg.Reva.StorageHome.TempFolder, - }, - &cli.BoolFlag{ - Name: "dataprovider-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageHome.DataProvider.Insecure, false), - Usage: "dataprovider insecure", - EnvVars: []string{"STORAGE_HOME_DATAPROVIDER_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.StorageHome.DataProvider.Insecure, - }, - - // some drivers need to look up users at the gateway - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - // User provider - - &cli.StringFlag{ - Name: "users-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Users.Endpoint, "localhost:9144"), - Usage: "endpoint to use for the storage service", - EnvVars: []string{"STORAGE_USERPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Users.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverEOSWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverLocalWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverOwnCloudWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverOwnCloudSQLWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverOCISWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverS3NGWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverS3WithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/storagemetadata.go b/storage/pkg/flagset/storagemetadata.go deleted file mode 100644 index 4b80756f0a6..00000000000 --- a/storage/pkg/flagset/storagemetadata.go +++ /dev/null @@ -1,114 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset/metadatadrivers" - "github.com/urfave/cli/v2" -) - -// StorageMetadata applies cfg to the root flagset -func StorageMetadata(cfg *config.Config) []cli.Flag { - f := []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.DebugAddr, "127.0.0.1:9217"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_METADATA_DEBUG_ADDR"}, - Destination: &cfg.Reva.StorageMetadata.DebugAddr, - }, - &cli.StringFlag{ - Name: "grpc-network", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_METADATA_GRPC_NETWORK"}, - Destination: &cfg.Reva.StorageMetadata.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.GRPCAddr, "127.0.0.1:9215"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_METADATA_GRPC_PROVIDER_ADDR"}, - Destination: &cfg.Reva.StorageMetadata.GRPCAddr, - }, - &cli.StringFlag{ - Name: "data-server-url", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.DataServerURL, "http://localhost:9216"), - Usage: "URL of the data-provider the storage-provider uses", - EnvVars: []string{"STORAGE_METADATA_DATA_SERVER_URL"}, - Destination: &cfg.Reva.StorageMetadata.DataServerURL, - }, - &cli.StringFlag{ - Name: "http-network", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.HTTPNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_METADATA_HTTP_NETWORK"}, - Destination: &cfg.Reva.StorageMetadata.HTTPNetwork, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.HTTPAddr, "127.0.0.1:9216"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_METADATA_HTTP_ADDR"}, - Destination: &cfg.Reva.StorageMetadata.HTTPAddr, - }, - &cli.StringFlag{ - Name: "tmp-folder", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.TempFolder, path.Join(defaults.BaseDataPath(), "tmp", "metadata")), - Usage: "path to tmp folder", - EnvVars: []string{"STORAGE_METADATA_TMP_FOLDER"}, - Destination: &cfg.Reva.StorageMetadata.TempFolder, - }, - &cli.StringFlag{ - Name: "driver", - Value: flags.OverrideDefaultString(cfg.Reva.StorageMetadata.Driver, "ocis"), - Usage: "storage driver for metadata mount: eg. local, eos, owncloud, ocis or s3", - EnvVars: []string{"STORAGE_METADATA_DRIVER"}, - Destination: &cfg.Reva.StorageMetadata.Driver, - }, - &cli.BoolFlag{ - Name: "dataprovider-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageMetadata.DataProvider.Insecure, false), - Usage: "dataprovider insecure", - EnvVars: []string{"STORAGE_METADATA_DATAPROVIDER_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.StorageMetadata.DataProvider.Insecure, - }, - - // some drivers need to look up users at the gateway - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - - // User provider - - &cli.StringFlag{ - Name: "userprovider-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Users.Endpoint, "localhost:9144"), - Usage: "endpoint to use for the userprovider service", - EnvVars: []string{"STORAGE_USERPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Users.Endpoint, - }, - } - - f = append(f, TracingWithConfig(cfg)...) - f = append(f, DebugWithConfig(cfg)...) - f = append(f, SecretWithConfig(cfg)...) - f = append(f, metadatadrivers.DriverEOSWithConfig(cfg)...) - f = append(f, metadatadrivers.DriverLocalWithConfig(cfg)...) - f = append(f, metadatadrivers.DriverOCISWithConfig(cfg)...) - f = append(f, metadatadrivers.DriverS3NGWithConfig(cfg)...) - f = append(f, metadatadrivers.DriverS3WithConfig(cfg)...) - - return f - -} diff --git a/storage/pkg/flagset/storagepubliclink.go b/storage/pkg/flagset/storagepubliclink.go deleted file mode 100644 index 8d730be4188..00000000000 --- a/storage/pkg/flagset/storagepubliclink.go +++ /dev/null @@ -1,65 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// StoragePublicLink applies cfg to the root flagset -func StoragePublicLink(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.DebugAddr, "127.0.0.1:9179"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_PUBLIC_LINK_DEBUG_ADDR"}, - Destination: &cfg.Reva.StoragePublicLink.DebugAddr, - }, - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_PUBLIC_LINK_GRPC_NETWORK"}, - Destination: &cfg.Reva.StoragePublicLink.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.GRPCAddr, "127.0.0.1:9178"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_PUBLIC_LINK_GRPC_ADDR"}, - Destination: &cfg.Reva.StoragePublicLink.GRPCAddr, - }, - - &cli.StringFlag{ - Name: "mount-path", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.MountPath, "/public"), - Usage: "mount path", - EnvVars: []string{"STORAGE_PUBLIC_LINK_MOUNT_PATH"}, - Destination: &cfg.Reva.StoragePublicLink.MountPath, - }, - &cli.StringFlag{ - Name: "mount-id", - Value: flags.OverrideDefaultString(cfg.Reva.StoragePublicLink.MountID, "e1a73ede-549b-4226-abdf-40e69ca8230d"), - Usage: "mount id", - EnvVars: []string{"STORAGE_PUBLIC_LINK_MOUNT_ID"}, - Destination: &cfg.Reva.StoragePublicLink.MountID, - }, - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/storageusers.go b/storage/pkg/flagset/storageusers.go deleted file mode 100644 index 6be58bc33ba..00000000000 --- a/storage/pkg/flagset/storageusers.go +++ /dev/null @@ -1,172 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/owncloud/ocis/storage/pkg/flagset/userdrivers" - "github.com/urfave/cli/v2" -) - -// StorageUsersWithConfig applies cfg to the root flagset -func StorageUsersWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.DebugAddr, "127.0.0.1:9159"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_USERS_DEBUG_ADDR"}, - Destination: &cfg.Reva.StorageUsers.DebugAddr, - }, - - // Services - - // Storage home - - &cli.StringFlag{ - Name: "grpc-network", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.GRPCNetwork, "tcp"), - Usage: "Network to use for the users storage, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_USERS_GRPC_NETWORK"}, - Destination: &cfg.Reva.StorageUsers.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.GRPCAddr, "127.0.0.1:9157"), - Usage: "GRPC Address to bind users storage", - EnvVars: []string{"STORAGE_USERS_GRPC_ADDR"}, - Destination: &cfg.Reva.StorageUsers.GRPCAddr, - }, - &cli.StringFlag{ - Name: "http-network", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.HTTPNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_USERS_HTTP_NETWORK"}, - Destination: &cfg.Reva.StorageUsers.HTTPNetwork, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.HTTPAddr, "127.0.0.1:9158"), - Usage: "HTTP Address to bind users storage", - EnvVars: []string{"STORAGE_USERS_HTTP_ADDR"}, - Destination: &cfg.Reva.StorageUsers.HTTPAddr, - }, - // TODO allow disabling grpc / http services - /* - &cli.StringSliceFlag{ - Name: "grpc-service", - Value: cli.NewStringSlice("storageprovider"), - Usage: "--service storageprovider [--service otherservice]", - EnvVars: []string{"STORAGE_USERS_GRPC_SERVICES"}, - }, - &cli.StringSliceFlag{ - Name: "http-service", - Value: cli.NewStringSlice("dataprovider"), - Usage: "--service dataprovider [--service otherservice]", - EnvVars: []string{"STORAGE_USERS_HTTP_SERVICES"}, - }, - */ - - &cli.StringFlag{ - Name: "driver", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.Driver, "ocis"), - Usage: "storage driver for users mount: eg. local, eos, owncloud, ocis or s3", - EnvVars: []string{"STORAGE_USERS_DRIVER"}, - Destination: &cfg.Reva.StorageUsers.Driver, - }, - &cli.BoolFlag{ - Name: "dataprovider-insecure", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageUsers.DataProvider.Insecure, false), - Usage: "dataprovider insecure", - EnvVars: []string{"STORAGE_USERS_DATAPROVIDER_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Reva.StorageUsers.DataProvider.Insecure, - }, - &cli.BoolFlag{ - Name: "read-only", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageUsers.ReadOnly, false), - Usage: "use storage driver in read-only mode", - EnvVars: []string{"STORAGE_USERS_READ_ONLY", "OCIS_STORAGE_READ_ONLY"}, - Destination: &cfg.Reva.StorageUsers.ReadOnly, - }, - &cli.StringFlag{ - Name: "mount-path", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.MountPath, "/users"), - Usage: "mount path", - EnvVars: []string{"STORAGE_USERS_MOUNT_PATH"}, - Destination: &cfg.Reva.StorageUsers.MountPath, - }, - &cli.StringFlag{ - Name: "mount-id", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.MountID, "1284d238-aa92-42ce-bdc4-0b0000009157"), - Usage: "mount id", - EnvVars: []string{"STORAGE_USERS_MOUNT_ID"}, - Destination: &cfg.Reva.StorageUsers.MountID, - }, - &cli.BoolFlag{ - Name: "expose-data-server", - Value: flags.OverrideDefaultBool(cfg.Reva.StorageUsers.ExposeDataServer, false), - Usage: "exposes a dedicated data server", - EnvVars: []string{"STORAGE_USERS_EXPOSE_DATA_SERVER"}, - Destination: &cfg.Reva.StorageUsers.ExposeDataServer, - }, - &cli.StringFlag{ - Name: "data-server-url", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.DataServerURL, "http://localhost:9158/data"), - Usage: "data server url", - EnvVars: []string{"STORAGE_USERS_DATA_SERVER_URL"}, - Destination: &cfg.Reva.StorageUsers.DataServerURL, - }, - &cli.StringFlag{ - Name: "http-prefix", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.HTTPPrefix, "data"), - Usage: "prefix for the http endpoint, without leading slash", - EnvVars: []string{"STORAGE_USERS_HTTP_PREFIX"}, - Destination: &cfg.Reva.StorageUsers.HTTPPrefix, - }, - &cli.StringFlag{ - Name: "tmp-folder", - Value: flags.OverrideDefaultString(cfg.Reva.StorageUsers.TempFolder, path.Join(defaults.BaseDataPath(), "tmp", "users")), - Usage: "path to tmp folder", - EnvVars: []string{"STORAGE_USERS_TMP_FOLDER"}, - Destination: &cfg.Reva.StorageUsers.TempFolder, - }, - - // some drivers need to look up users at the gateway - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - // User provider - - &cli.StringFlag{ - Name: "users-endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Users.Endpoint, "localhost:9144"), - Usage: "endpoint to use for the storage service", - EnvVars: []string{"STORAGE_USERPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Users.Endpoint, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverEOSWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverLocalWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverOwnCloudWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverOwnCloudSQLWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverOCISWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverS3NGWithConfig(cfg)...) - flags = append(flags, userdrivers.DriverS3WithConfig(cfg)...) - - return flags -} diff --git a/storage/pkg/flagset/tracing.go b/storage/pkg/flagset/tracing.go deleted file mode 100644 index 67c7eb0baeb..00000000000 --- a/storage/pkg/flagset/tracing.go +++ /dev/null @@ -1,48 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// TracingWithConfig applies cfg to the root flagset -func TracingWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"STORAGE_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"STORAGE_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"STORAGE_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"STORAGE_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "storage"), - Usage: "Service name for tracing", - EnvVars: []string{"STORAGE_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/drivereos.go b/storage/pkg/flagset/userdrivers/drivereos.go deleted file mode 100644 index a937307ef5d..00000000000 --- a/storage/pkg/flagset/userdrivers/drivereos.go +++ /dev/null @@ -1,136 +0,0 @@ -package userdrivers - -import ( - "os" - - "github.com/owncloud/ocis/ocis-pkg/flags" - - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverEOSWithConfig applies cfg to the root flagset -func DriverEOSWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - - &cli.StringFlag{ - Name: "storage-eos-namespace", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.Root, "/eos/dockertest/reva"), - Usage: "Namespace for metadata operations", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_NAMESPACE"}, - Destination: &cfg.Reva.UserStorage.EOS.Root, - }, - &cli.StringFlag{ - Name: "storage-eos-shadow-namespace", - // Defaults to path.Join(c.Namespace, ".shadow") - Usage: "Shadow namespace where share references are stored", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SHADOW_NAMESPACE"}, - Destination: &cfg.Reva.UserStorage.EOS.ShadowNamespace, - }, - &cli.StringFlag{ - Name: "storage-eos-uploads-namespace", - // Defaults to path.Join(c.Namespace, ".uploads") - Usage: "Uploads namespace", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_UPLOADS_NAMESPACE"}, - Destination: &cfg.Reva.UserStorage.EOS.UploadsNamespace, - }, - &cli.StringFlag{ - Name: "storage-eos-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.ShareFolder, "/Shares"), - Usage: "name of the share folder", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SHARE_FOLDER"}, - Destination: &cfg.Reva.UserStorage.EOS.ShareFolder, - }, - &cli.StringFlag{ - Name: "storage-eos-binary", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.EosBinary, "/usr/bin/eos"), - Usage: "Location of the eos binary", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_BINARY"}, - Destination: &cfg.Reva.UserStorage.EOS.EosBinary, - }, - &cli.StringFlag{ - Name: "storage-eos-xrdcopy-binary", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.XrdcopyBinary, "/usr/bin/xrdcopy"), - Usage: "Location of the xrdcopy binary", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_XRDCOPY_BINARY"}, - Destination: &cfg.Reva.UserStorage.EOS.XrdcopyBinary, - }, - &cli.StringFlag{ - Name: "storage-eos-master-url", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.MasterURL, "root://eos-mgm1.eoscluster.cern.ch:1094"), - Usage: "URL of the Master EOS MGM", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_MASTER_URL"}, - Destination: &cfg.Reva.UserStorage.EOS.MasterURL, - }, - &cli.StringFlag{ - Name: "storage-eos-slave-url", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.SlaveURL, "root://eos-mgm1.eoscluster.cern.ch:1094"), - Usage: "URL of the Slave EOS MGM", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SLAVE_URL"}, - Destination: &cfg.Reva.UserStorage.EOS.SlaveURL, - }, - &cli.StringFlag{ - Name: "storage-eos-cache-directory", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.CacheDirectory, os.TempDir()), - Usage: "Location on the local fs where to store reads", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_CACHE_DIRECTORY"}, - Destination: &cfg.Reva.UserStorage.EOS.CacheDirectory, - }, - &cli.BoolFlag{ - Name: "storage-eos-enable-logging", - Usage: "Enables logging of the commands executed", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_ENABLE_LOGGING"}, - Destination: &cfg.Reva.UserStorage.EOS.EnableLogging, - }, - &cli.BoolFlag{ - Name: "storage-eos-show-hidden-sysfiles", - Usage: "show internal EOS files like .sys.v# and .sys.a# files.", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SHOW_HIDDEN_SYSFILES"}, - Destination: &cfg.Reva.UserStorage.EOS.ShowHiddenSysFiles, - }, - &cli.BoolFlag{ - Name: "storage-eos-force-singleuser-mode", - Usage: "force connections to EOS to use SingleUsername", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_FORCE_SINGLEUSER_MODE"}, - Destination: &cfg.Reva.UserStorage.EOS.ForceSingleUserMode, - }, - &cli.BoolFlag{ - Name: "storage-eos-use-keytab", - Usage: "authenticate requests by using an EOS keytab", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_USE_KEYTAB"}, - Destination: &cfg.Reva.UserStorage.EOS.UseKeytab, - }, - &cli.StringFlag{ - Name: "storage-eos-sec-protocol", - Usage: "the xrootd security protocol to use between the server and EOS", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SEC_PROTOCOL"}, - Destination: &cfg.Reva.UserStorage.EOS.SecProtocol, - }, - &cli.StringFlag{ - Name: "storage-eos-keytab", - Usage: "the location of the keytab to use to authenticate to EOS", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_KEYTAB"}, - Destination: &cfg.Reva.UserStorage.EOS.Keytab, - }, - &cli.StringFlag{ - Name: "storage-eos-single-username", - Usage: "the username to use when SingleUserMode is enabled", - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_SINGLE_USERNAME"}, - Destination: &cfg.Reva.UserStorage.EOS.SingleUsername, - }, - &cli.StringFlag{ - Name: "storage-eos-layout", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.UserLayout, "{{substr 0 1 .Username}}/{{.Username}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.UsernameLower}} and {{.Provider}} also supports prefixing dirs: "{{.UsernamePrefixCount.2}}/{{.UsernameLower}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_EOS_LAYOUT"}, - Destination: &cfg.Reva.UserStorage.EOS.UserLayout, - }, - &cli.StringFlag{ - Name: "storage-eos-reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.EOS.GatewaySVC, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.UserStorage.EOS.GatewaySVC, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/driverlocal.go b/storage/pkg/flagset/userdrivers/driverlocal.go deleted file mode 100644 index 212b202e743..00000000000 --- a/storage/pkg/flagset/userdrivers/driverlocal.go +++ /dev/null @@ -1,37 +0,0 @@ -package userdrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverLocalWithConfig applies cfg to the root flagset -func DriverLocalWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-local-root", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.Local.Root, path.Join(defaults.BaseDataPath(), "storage", "local", "users")), - Usage: "the path to the local storage root", - EnvVars: []string{"STORAGE_USERS_DRIVER_LOCAL_ROOT"}, - Destination: &cfg.Reva.UserStorage.Local.Root, - }, - &cli.StringFlag{ - Name: "storage-local-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.Local.ShareFolder, "/Shares"), - Usage: "the path to the local share folder", - EnvVars: []string{"STORAGE_USERS_DRIVER_LOCAL_SHARE_FOLDER"}, - Destination: &cfg.Reva.UserStorage.Local.ShareFolder, - }, - &cli.StringFlag{ - Name: "storage-local-user-layout", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.Local.UserLayout, "{{.Username}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.UsernameLower}} and {{.Provider}} also supports prefixing dirs: "{{.UsernamePrefixCount.2}}/{{.UsernameLower}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_LOCAL_USER_LAYOUT"}, - Destination: &cfg.Reva.UserStorage.Local.UserLayout, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/driverocis.go b/storage/pkg/flagset/userdrivers/driverocis.go deleted file mode 100644 index 35aa9868359..00000000000 --- a/storage/pkg/flagset/userdrivers/driverocis.go +++ /dev/null @@ -1,44 +0,0 @@ -package userdrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverOCISWithConfig applies cfg to the root flagset -func DriverOCISWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-ocis-root", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OCIS.Root, path.Join(defaults.BaseDataPath(), "storage", "users")), - Usage: "the path to the local storage root", - EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_ROOT"}, - Destination: &cfg.Reva.UserStorage.OCIS.Root, - }, - &cli.StringFlag{ - Name: "storage-ocis-layout", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OCIS.UserLayout, "{{.Id.OpaqueId}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.Mail}}, {{.Id.OpaqueId}}, {{.Id.Idp}} also supports prefixing dirs: "{{substr 0 1 .Username}}/{{.Username}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_LAYOUT"}, - Destination: &cfg.Reva.UserStorage.OCIS.UserLayout, - }, - &cli.StringFlag{ - Name: "storage-ocis-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OCIS.ShareFolder, "/Shares"), - Usage: "name of the shares folder", - EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_SHARE_FOLDER"}, - Destination: &cfg.Reva.UserStorage.OCIS.ShareFolder, - }, - &cli.StringFlag{ - Name: "service-user-uuid", - Value: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", - Usage: "uuid of the internal service user", - EnvVars: []string{"STORAGE_USERS_DRIVER_OCIS_SERVICE_USER_UUID"}, - Destination: &cfg.Reva.UserStorage.OCIS.ServiceUserUUID, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/driverowncloud.go b/storage/pkg/flagset/userdrivers/driverowncloud.go deleted file mode 100644 index 395b28325c3..00000000000 --- a/storage/pkg/flagset/userdrivers/driverowncloud.go +++ /dev/null @@ -1,58 +0,0 @@ -package userdrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverOwnCloudWithConfig applies cfg to the root flagset -func DriverOwnCloudWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-owncloud-datadir", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloud.Root, path.Join(defaults.BaseDataPath(), "storage", "owncloud")), - Usage: "the path to the owncloud data directory", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_DATADIR"}, - Destination: &cfg.Reva.UserStorage.OwnCloud.Root, - }, - &cli.StringFlag{ - Name: "storage-owncloud-uploadinfo-dir", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloud.UploadInfoDir, path.Join(defaults.BaseDataPath(), "storage", "uploadinfo")), - Usage: "the path to the tus upload info directory", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_UPLOADINFO_DIR"}, - Destination: &cfg.Reva.UserStorage.OwnCloud.UploadInfoDir, - }, - &cli.StringFlag{ - Name: "storage-owncloud-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloud.ShareFolder, "/Shares"), - Usage: "name of the shares folder", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_SHARE_FOLDER"}, - Destination: &cfg.Reva.UserStorage.OwnCloud.ShareFolder, - }, - &cli.BoolFlag{ - Name: "storage-owncloud-scan", - Value: flags.OverrideDefaultBool(cfg.Reva.UserStorage.OwnCloud.Scan, true), - Usage: "scan files on startup to add fileids", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_SCAN"}, - Destination: &cfg.Reva.UserStorage.OwnCloud.Scan, - }, - &cli.StringFlag{ - Name: "storage-owncloud-redis", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloud.Redis, ":6379"), - Usage: "the address of the redis server", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_REDIS_ADDR"}, - Destination: &cfg.Reva.UserStorage.OwnCloud.Redis, - }, - &cli.StringFlag{ - Name: "storage-owncloud-layout", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloud.UserLayout, "{{.Id.OpaqueId}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.Mail}}, {{.Id.OpaqueId}}, {{.Id.Idp}} also supports prefixing dirs: "{{substr 0 1 .Username}}/{{.Username}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUD_LAYOUT"}, - Destination: &cfg.Reva.UserStorage.OwnCloud.UserLayout, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/driverowncloudsql.go b/storage/pkg/flagset/userdrivers/driverowncloudsql.go deleted file mode 100644 index c0adb07dc22..00000000000 --- a/storage/pkg/flagset/userdrivers/driverowncloudsql.go +++ /dev/null @@ -1,79 +0,0 @@ -package userdrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverOwnCloudSQLWithConfig applies cfg to the root flagset -func DriverOwnCloudSQLWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-owncloudsql-datadir", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.Root, path.Join(defaults.BaseDataPath(), "storage", "owncloud")), - Usage: "the path to the owncloudsql data directory", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DATADIR"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.Root, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-uploadinfo-dir", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.UploadInfoDir, path.Join(defaults.BaseDataPath(), "storage", "uploadinfo")), - Usage: "the path to the tus upload info directory", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_UPLOADINFO_DIR"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.UploadInfoDir, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.ShareFolder, "/Shares"), - Usage: "name of the shares folder", - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_SHARE_FOLDER"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.ShareFolder, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-layout", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.UserLayout, "{{.Username}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.Mail}}, {{.Id.OpaqueId}}, {{.Id.Idp}} also supports prefixing dirs: "{{substr 0 1 .Username}}/{{.Username}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_LAYOUT"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.UserLayout, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-dbusername", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.DBUsername, "owncloud"), - Usage: `"username for accessing the database" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBUSERNAME"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBUsername, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-dbpassword", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.DBPassword, "owncloud"), - Usage: `"password for accessing the database" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBPASSWORD"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBPassword, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-dbhost", - Value: cfg.Reva.UserStorage.OwnCloudSQL.DBHost, - Usage: `"the database hostname or IP address" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBHOST"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBHost, - }, - &cli.IntFlag{ - Name: "storage-owncloudsql-dbport", - Value: flags.OverrideDefaultInt(cfg.Reva.UserStorage.OwnCloudSQL.DBPort, 3306), - Usage: `"port the database listens on" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBPORT"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBPort, - }, - &cli.StringFlag{ - Name: "storage-owncloudsql-dbname", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.OwnCloudSQL.DBName, "owncloud"), - Usage: `"the database name" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_OWNCLOUDSQL_DBNAME"}, - Destination: &cfg.Reva.UserStorage.OwnCloudSQL.DBName, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/drivers3.go b/storage/pkg/flagset/userdrivers/drivers3.go deleted file mode 100644 index 72984e684bb..00000000000 --- a/storage/pkg/flagset/userdrivers/drivers3.go +++ /dev/null @@ -1,48 +0,0 @@ -package userdrivers - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverS3NGWithConfig applies cfg to the root flagset -func DriverS3WithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-s3-region", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.S3.Region, "default"), - Usage: `"the s3 region" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3_REGION"}, - Destination: &cfg.Reva.UserStorage.S3.Region, - }, - &cli.StringFlag{ - Name: "storage-s3-accesskey", - Value: "", - Usage: `"the s3 access key" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3_ACCESS_KEY"}, - Destination: &cfg.Reva.UserStorage.S3.AccessKey, - }, - &cli.StringFlag{ - Name: "storage-s3-secretkey", - Value: "", - Usage: `"the secret s3 api key" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3_SECRET_KEY"}, - Destination: &cfg.Reva.UserStorage.S3.SecretKey, - }, - &cli.StringFlag{ - Name: "storage-s3-endpoint", - Value: "", - Usage: `"s3 compatible API endpoint" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3_ENDPOINT"}, - Destination: &cfg.Reva.UserStorage.S3.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-s3-bucket", - Value: "", - Usage: `"bucket where the data will be stored in`, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3_BUCKET"}, - Destination: &cfg.Reva.UserStorage.S3.Bucket, - }, - } -} diff --git a/storage/pkg/flagset/userdrivers/drivers3ng.go b/storage/pkg/flagset/userdrivers/drivers3ng.go deleted file mode 100644 index 1b21e2a9cda..00000000000 --- a/storage/pkg/flagset/userdrivers/drivers3ng.go +++ /dev/null @@ -1,72 +0,0 @@ -package userdrivers - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// DriverS3NGWithConfig applies cfg to the root flagset -func DriverS3NGWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "storage-s3ng-root", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.S3NG.Root, path.Join(defaults.BaseDataPath(), "storage", "users")), - Usage: "the path to the local storage root", - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_ROOT"}, - Destination: &cfg.Reva.UserStorage.S3NG.Root, - }, - &cli.StringFlag{ - Name: "storage-s3ng-layout", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.S3NG.UserLayout, "{{.Id.OpaqueId}}"), - Usage: `"layout of the users home dir path on disk, in addition to {{.Username}}, {{.Mail}}, {{.Id.OpaqueId}}, {{.Id.Idp}} also supports prefixing dirs: "{{substr 0 1 .Username}}/{{.Username}}" will turn "Einstein" into "Ei/Einstein" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_LAYOUT"}, - Destination: &cfg.Reva.UserStorage.S3NG.UserLayout, - }, - &cli.StringFlag{ - Name: "storage-s3ng-share-folder", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.S3NG.ShareFolder, "/Shares"), - Usage: "name of the shares folder", - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_SHARE_FOLDER"}, - Destination: &cfg.Reva.UserStorage.S3NG.ShareFolder, - }, - &cli.StringFlag{ - Name: "storage-s3ng-region", - Value: flags.OverrideDefaultString(cfg.Reva.UserStorage.S3NG.Region, "default"), - Usage: `"the s3 region" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_REGION"}, - Destination: &cfg.Reva.UserStorage.S3NG.Region, - }, - &cli.StringFlag{ - Name: "storage-s3ng-accesskey", - Value: "", - Usage: `"the s3 access key" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_ACCESS_KEY"}, - Destination: &cfg.Reva.UserStorage.S3NG.AccessKey, - }, - &cli.StringFlag{ - Name: "storage-s3ng-secretkey", - Value: "", - Usage: `"the secret s3 api key" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_SECRET_KEY"}, - Destination: &cfg.Reva.UserStorage.S3NG.SecretKey, - }, - &cli.StringFlag{ - Name: "storage-s3ng-endpoint", - Value: "", - Usage: `"s3 compatible API endpoint" `, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_ENDPOINT"}, - Destination: &cfg.Reva.UserStorage.S3NG.Endpoint, - }, - &cli.StringFlag{ - Name: "storage-s3ng-bucket", - Value: "", - Usage: `"bucket where the data will be stored in`, - EnvVars: []string{"STORAGE_USERS_DRIVER_S3NG_BUCKET"}, - Destination: &cfg.Reva.UserStorage.S3NG.Bucket, - }, - } -} diff --git a/storage/pkg/flagset/users.go b/storage/pkg/flagset/users.go deleted file mode 100644 index 182882ecd33..00000000000 --- a/storage/pkg/flagset/users.go +++ /dev/null @@ -1,167 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/storage/pkg/config" - "github.com/urfave/cli/v2" -) - -// UsersWithConfig applies cfg to the root flagset -func UsersWithConfig(cfg *config.Config) []cli.Flag { - flags := []cli.Flag{ - - // debug ports are the odd ports - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Users.DebugAddr, "127.0.0.1:9145"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORAGE_USERPROVIDER_DEBUG_ADDR"}, - Destination: &cfg.Reva.Users.DebugAddr, - }, - - // Services - - // Gateway - - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Reva.Gateway.Endpoint, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Reva.Gateway.Endpoint, - }, - - // Userprovider - - &cli.StringFlag{ - Name: "network", - Value: flags.OverrideDefaultString(cfg.Reva.Users.GRPCNetwork, "tcp"), - Usage: "Network to use for the storage service, can be 'tcp', 'udp' or 'unix'", - EnvVars: []string{"STORAGE_USERPROVIDER_NETWORK"}, - Destination: &cfg.Reva.Users.GRPCNetwork, - }, - &cli.StringFlag{ - Name: "addr", - Value: flags.OverrideDefaultString(cfg.Reva.Users.GRPCAddr, "127.0.0.1:9144"), - Usage: "Address to bind storage service", - EnvVars: []string{"STORAGE_USERPROVIDER_ADDR"}, - Destination: &cfg.Reva.Users.GRPCAddr, - }, - &cli.StringFlag{ - Name: "endpoint", - Value: flags.OverrideDefaultString(cfg.Reva.Users.Endpoint, "localhost:9144"), - Usage: "URL to use for the storage service", - EnvVars: []string{"STORAGE_USERPROVIDER_ENDPOINT"}, - Destination: &cfg.Reva.Users.Endpoint, - }, - &cli.StringSliceFlag{ - Name: "service", - Value: cli.NewStringSlice("userprovider"), // TODO preferences - Usage: "--service userprovider [--service otherservice]", - EnvVars: []string{"STORAGE_USERPROVIDER_SERVICES"}, - }, - - &cli.StringFlag{ - Name: "driver", - Value: flags.OverrideDefaultString(cfg.Reva.Users.Driver, "ldap"), - Usage: "user driver: 'demo', 'json', 'ldap', 'owncloudsql' or 'rest'", - EnvVars: []string{"STORAGE_USERPROVIDER_DRIVER"}, - Destination: &cfg.Reva.Users.Driver, - }, - &cli.StringFlag{ - Name: "json-config", - Value: flags.OverrideDefaultString(cfg.Reva.Users.JSON, ""), - Usage: "Path to users.json file", - EnvVars: []string{"STORAGE_USERPROVIDER_JSON"}, - Destination: &cfg.Reva.Users.JSON, - }, - &cli.IntFlag{ - Name: "user-groups-cache-expiration", - Value: flags.OverrideDefaultInt(cfg.Reva.Users.UserGroupsCacheExpiration, 5), - Usage: "Time in minutes for redis cache expiration.", - EnvVars: []string{"STORAGE_USER_CACHE_EXPIRATION"}, - Destination: &cfg.Reva.Users.UserGroupsCacheExpiration, - }, - - // user owncloudsql - - &cli.StringFlag{ - Name: "owncloudsql-dbhost", - Value: flags.OverrideDefaultString(cfg.Reva.UserOwnCloudSQL.DBHost, "mysql"), - Usage: "hostname of the mysql db", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBHOST"}, - Destination: &cfg.Reva.UserOwnCloudSQL.DBHost, - }, - &cli.IntFlag{ - Name: "owncloudsql-dbport", - Value: flags.OverrideDefaultInt(cfg.Reva.UserOwnCloudSQL.DBPort, 3306), - Usage: "port of the mysql db", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBPORT"}, - Destination: &cfg.Reva.UserOwnCloudSQL.DBPort, - }, - &cli.StringFlag{ - Name: "owncloudsql-dbname", - Value: flags.OverrideDefaultString(cfg.Reva.UserOwnCloudSQL.DBName, "owncloud"), - Usage: "database name of the owncloud db", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBNAME"}, - Destination: &cfg.Reva.UserOwnCloudSQL.DBName, - }, - &cli.StringFlag{ - Name: "owncloudsql-dbuser", - Value: flags.OverrideDefaultString(cfg.Reva.UserOwnCloudSQL.DBUsername, "owncloud"), - Usage: "user name to use when connecting to the mysql owncloud db", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBUSER"}, - Destination: &cfg.Reva.UserOwnCloudSQL.DBUsername, - }, - &cli.StringFlag{ - Name: "owncloudsql-dbpass", - Value: flags.OverrideDefaultString(cfg.Reva.UserOwnCloudSQL.DBPassword, "secret"), - Usage: "password to use when connecting to the mysql owncloud db", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_DBPASS"}, - Destination: &cfg.Reva.UserOwnCloudSQL.DBPassword, - }, - &cli.StringFlag{ - Name: "owncloudsql-idp", - Value: flags.OverrideDefaultString(cfg.Reva.UserOwnCloudSQL.Idp, "https://localhost:9200"), - Usage: "Identity provider to use for users", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_IDP", "OCIS_URL"}, - Destination: &cfg.Reva.UserOwnCloudSQL.Idp, - }, - &cli.Int64Flag{ - Name: "owncloudsql-nobody", - Value: flags.OverrideDefaultInt64(cfg.Reva.UserOwnCloudSQL.Nobody, 99), - Usage: "fallback user id to use when user has no id", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_NOBODY"}, - Destination: &cfg.Reva.UserOwnCloudSQL.Nobody, - }, - &cli.BoolFlag{ - Name: "owncloudsql-join-username", - Value: flags.OverrideDefaultBool(cfg.Reva.UserOwnCloudSQL.JoinUsername, false), - Usage: "join the username from the oc_preferences table", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_JOIN_USERNAME"}, - Destination: &cfg.Reva.UserOwnCloudSQL.JoinUsername, - }, - &cli.BoolFlag{ - Name: "owncloudsql-join-ownclouduuid", - Value: flags.OverrideDefaultBool(cfg.Reva.UserOwnCloudSQL.JoinOwnCloudUUID, false), - Usage: "join the ownclouduuid from the oc_preferences table", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_JOIN_OWNCLOUDUUID"}, - Destination: &cfg.Reva.UserOwnCloudSQL.JoinOwnCloudUUID, - }, - &cli.BoolFlag{ - Name: "owncloudsql-enable-medial-search", - Value: flags.OverrideDefaultBool(cfg.Reva.UserOwnCloudSQL.EnableMedialSearch, false), - Usage: "enable medial search when finding users", - EnvVars: []string{"STORAGE_USERPROVIDER_OWNCLOUDSQL_ENABLE_MEDIAL_SEARCH"}, - Destination: &cfg.Reva.UserOwnCloudSQL.EnableMedialSearch, - }, - } - - flags = append(flags, TracingWithConfig(cfg)...) - flags = append(flags, DebugWithConfig(cfg)...) - flags = append(flags, SecretWithConfig(cfg)...) - flags = append(flags, LDAPWithConfig(cfg)...) - flags = append(flags, RestWithConfig(cfg)...) - - return flags -} diff --git a/store/cmd/store/main.go b/store/cmd/store/main.go index ad2549012a2..f20f59258ee 100644 --- a/store/cmd/store/main.go +++ b/store/cmd/store/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/store/pkg/command/health.go b/store/pkg/command/health.go index 5768b00ecbb..38461c9ac5b 100644 --- a/store/pkg/command/health.go +++ b/store/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index a875d5a1bf7..49584e63cc3 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -3,16 +3,11 @@ package command import ( "context" "os" - "strings" - - "github.com/owncloud/ocis/ocis-pkg/sync" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/flagset" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -32,8 +27,6 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Service.Version = version.String return ParseConfig(c, cfg) @@ -70,49 +63,18 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads store configuration from Viper known paths. +// ParseConfig loads idp configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("STORE") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("store") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") - } - - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("Unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("Failed to read config") - } + conf, err := ociscfg.BindSourcesToStructs("store", cfg) + if err != nil { + return err } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the store command to be embedded and supervised by a suture supervisor tree. @@ -122,10 +84,6 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Store.Supervised = true - } - cfg.Store.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Store, } diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 1fec4e195ef..62271987424 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,13 +3,16 @@ package command import ( "context" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/store/pkg/tracing" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/oklog/run" "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/flagset" "github.com/owncloud/ocis/store/pkg/metrics" "github.com/owncloud/ocis/store/pkg/server/debug" "github.com/owncloud/ocis/store/pkg/server/grpc" @@ -21,15 +24,26 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) - // When running on single binary mode the before hook from the root command won't get called. We manually - // call this before hook from ocis command, so the configuration can be loaded. - if !cfg.Supervised { - return ParseConfig(ctx, cfg) + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) { + // set the default to the parent config + cfg.Log = inLog + + // and parse the environment + conf := &gofig.Config{} + conf.LoadOSEnv(config.GetEnv(), false) + bindings := config.StructMappings(cfg) + if err := ociscfg.BindEnv(conf, bindings); err != nil { + return err + } } - logger.Debug().Str("service", "store").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { diff --git a/store/pkg/command/version.go b/store/pkg/command/version.go index 22b9997bbaf..b5bfef3b266 100644 --- a/store/pkg/command/version.go +++ b/store/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/store/pkg/config" - "github.com/owncloud/ocis/store/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListStoreWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index ce9c852521e..a39cae29b54 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -1,54 +1,52 @@ package config -import "context" +import ( + "context" + "path" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string - Root string + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - GRPC GRPC - Tracing Tracing - Datapath string - Service Service + File string `ocisConfig:"file"` + Log shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + GRPC GRPC `ocisConfig:"grpc"` + Tracing Tracing `ocisConfig:"tracing"` + Datapath string `ocisConfig:"data_path"` + Service Service `ocisConfig:"service"` Context context.Context Supervised bool @@ -58,3 +56,41 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: shared.Log{}, + Debug: Debug{ + Addr: "127.0.0.1:9464", + Token: "", + Pprof: false, + Zpages: false, + }, + GRPC: GRPC{ + Addr: "127.0.0.1:9460", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "store", + }, + Datapath: path.Join(defaults.BaseDataPath(), "store"), + Service: Service{ + Name: "store", + Namespace: "com.owncloud.api", + }, + } +} + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv() []string { + var r = make([]string, len(structMappings(&Config{}))) + for i := range structMappings(&Config{}) { + r = append(r, structMappings(&Config{})[i].EnvVars...) + } + + return r +} diff --git a/store/pkg/config/mappings.go b/store/pkg/config/mappings.go new file mode 100644 index 00000000000..62eea4e71e5 --- /dev/null +++ b/store/pkg/config/mappings.go @@ -0,0 +1,84 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL", "STORE_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "STORE_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "STORE_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "STORE_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "STORE_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "STORE_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "STORE_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "STORE_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"STORE_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"STORE_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"STORE_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"STORE_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"STORE_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"STORE_GRPC_NAMESPACE"}, + Destination: &cfg.Service.Namespace, + }, + { + EnvVars: []string{"STORE_GRPC_ADDR"}, + Destination: &cfg.GRPC.Addr, + }, + { + EnvVars: []string{"STORE_NAME"}, + Destination: &cfg.Service.Name, + }, + { + EnvVars: []string{"STORE_DATA_PATH"}, + Destination: &cfg.Datapath, + }, + } +} diff --git a/store/pkg/flagset/flagset.go b/store/pkg/flagset/flagset.go deleted file mode 100644 index 2651bbf9834..00000000000 --- a/store/pkg/flagset/flagset.go +++ /dev/null @@ -1,177 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/store/pkg/config" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"STORE_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"STORE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"STORE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"STORE_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9464"), - Usage: "Address to debug endpoint", - EnvVars: []string{"STORE_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"STORE_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"STORE_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"STORE_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"STORE_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"STORE_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "store"), - Usage: "Service name for tracing", - EnvVars: []string{"STORE_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9464"), - Usage: "Address to bind debug server", - EnvVars: []string{"STORE_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"STORE_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"STORE_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"STORE_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"STORE_GRPC_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.GRPC.Addr, "127.0.0.1:9460"), - Usage: "Address to bind grpc server", - EnvVars: []string{"STORE_GRPC_ADDR"}, - Destination: &cfg.GRPC.Addr, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "store"), - Usage: "Service name", - EnvVars: []string{"STORE_NAME"}, - Destination: &cfg.Service.Name, - }, - &cli.StringFlag{ - Name: "data-path", - Value: flags.OverrideDefaultString(cfg.Datapath, path.Join(defaults.BaseDataPath(), "store")), - Usage: "location of the store data path", - EnvVars: []string{"STORE_DATA_PATH"}, - Destination: &cfg.Datapath, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} - -// ListStoreWithConfig applies the config to the list commands flags. -func ListStoreWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{&cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"STORE_GRPC_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "store"), - Usage: "Service name", - EnvVars: []string{"STORE_NAME"}, - Destination: &cfg.Service.Name, - }, - } -} diff --git a/thumbnails/cmd/thumbnails/main.go b/thumbnails/cmd/thumbnails/main.go index 7d89ce29f18..2098a63413b 100644 --- a/thumbnails/cmd/thumbnails/main.go +++ b/thumbnails/cmd/thumbnails/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/thumbnails/pkg/command/health.go b/thumbnails/pkg/command/health.go index babd7d20aab..6b5c84939c3 100644 --- a/thumbnails/pkg/command/health.go +++ b/thumbnails/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/thumbnails/pkg/config" - "github.com/owncloud/ocis/thumbnails/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 0e297c5ea5e..5136f0df0ca 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/shared" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/thumbnails/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -68,48 +66,28 @@ func NewLogger(cfg *config.Config) log.Logger { } // ParseConfig loads configuration from Viper known paths. +// ParseConfig loads glauth configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("THUMBNAILS") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("thumbnails") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("thumbnails", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } - - return nil + conf.LoadOSEnv(config.GetEnv(cfg), false) + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the thumbnails command to be embedded and supervised by a suture supervisor tree. @@ -119,10 +97,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Thumbnails.Supervised = true - } - cfg.Thumbnails.Log.File = cfg.Log.File + cfg.Thumbnails.Commons = cfg.Commons return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 856b7a5a8d4..e929245a47f 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -7,7 +7,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/thumbnails/pkg/config" - "github.com/owncloud/ocis/thumbnails/pkg/flagset" "github.com/owncloud/ocis/thumbnails/pkg/metrics" "github.com/owncloud/ocis/thumbnails/pkg/server/debug" "github.com/owncloud/ocis/thumbnails/pkg/server/grpc" @@ -20,20 +19,10 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) - - // StringSliceFlag doesn't support Destination - // UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli - if len(ctx.StringSlice("thumbnail-resolution")) > 0 { - cfg.Thumbnail.Resolutions = ctx.StringSlice("thumbnail-resolution") - } - - if !cfg.Supervised { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "thumbnails").Msg("ignoring config file parsing when running supervised") return nil }, Action: func(c *cli.Context) error { diff --git a/thumbnails/pkg/command/version.go b/thumbnails/pkg/command/version.go index 9a861db9720..df3c0230f02 100644 --- a/thumbnails/pkg/command/version.go +++ b/thumbnails/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/thumbnails/pkg/config" - "github.com/owncloud/ocis/thumbnails/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListThumbnailsWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.Server.Namespace + "." + cfg.Server.Name) diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 4a19e13f436..60350383497 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -1,48 +1,48 @@ package config -import "context" +import ( + "context" + "path" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // Server defines the available server configuration. type Server struct { - Name string - Namespace string - Address string - Version string + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Address string `ocisConfig:"address"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - Server Server - Tracing Tracing - Thumbnail Thumbnail + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + Server Server `ocisConfig:"server"` + Tracing Tracing `ocisConfig:"tracing"` + Thumbnail Thumbnail `ocisConfig:"thumbnail"` Context context.Context Supervised bool @@ -50,25 +50,58 @@ type Config struct { // FileSystemStorage defines the available filesystem storage configuration. type FileSystemStorage struct { - RootDirectory string + RootDirectory string `ocisConfig:"root_directory"` } // FileSystemSource defines the available filesystem source configuration. type FileSystemSource struct { - BasePath string + BasePath string `ocisConfig:"base_path"` } // Thumbnail defines the available thumbnail related configuration. type Thumbnail struct { - Resolutions []string - FileSystemStorage FileSystemStorage - WebdavAllowInsecure bool - CS3AllowInsecure bool - RevaGateway string - WebdavNamespace string + Resolutions []string `ocisConfig:"resolutions"` + FileSystemStorage FileSystemStorage `ocisConfig:"filesystem_storage"` + WebdavAllowInsecure bool `ocisConfig:"webdav_allow_insecure"` + CS3AllowInsecure bool `ocisConfig:"cs3_allow_insecure"` + RevaGateway string `ocisConfig:"reva_gateway"` + WebdavNamespace string `ocisConfig:"webdav_namespace"` } // New initializes a new configuration with or without defaults. func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Debug: Debug{ + Addr: "127.0.0.1:9189", + Token: "", + Pprof: false, + Zpages: false, + }, + Server: Server{ + Name: "thumbnails", + Namespace: "com.owncloud.api", + Address: "127.0.0.1:9185", + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "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", + WebdavNamespace: "/home", + CS3AllowInsecure: false, + }, + } +} diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go new file mode 100644 index 00000000000..3a75427c061 --- /dev/null +++ b/thumbnails/pkg/config/mappings.go @@ -0,0 +1,115 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_FILE", "THUMBNAILS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_LOG_LEVEL", "THUMBNAILS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "THUMBNAILS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "THUMBNAILS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"THUMBNAILS_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "THUMBNAILS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "THUMBNAILS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "THUMBNAILS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "THUMBNAILS_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"THUMBNAILS_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"THUMBNAILS_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"THUMBNAILS_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"THUMBNAILS_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"THUMBNAILS_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"THUMBNAILS_GRPC_NAME"}, + Destination: &cfg.Server.Name, + }, + { + EnvVars: []string{"THUMBNAILS_GRPC_ADDR"}, + Destination: &cfg.Server.Address, + }, + { + EnvVars: []string{"THUMBNAILS_GRPC_NAMESPACE"}, + Destination: &cfg.Server.Namespace, + }, + { + EnvVars: []string{"THUMBNAILS_FILESYSTEMSTORAGE_ROOT"}, + Destination: &cfg.Thumbnail.FileSystemStorage.RootDirectory, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Thumbnail.RevaGateway, + }, + { + EnvVars: []string{"OCIS_INSECURE", "THUMBNAILS_WEBDAVSOURCE_INSECURE"}, + Destination: &cfg.Thumbnail.WebdavAllowInsecure, + }, + { + EnvVars: []string{"OCIS_INSECURE", "THUMBNAILS_CS3SOURCE_INSECURE"}, + Destination: &cfg.Thumbnail.CS3AllowInsecure, + }, + { + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.Thumbnail.WebdavNamespace, + }, + } +} diff --git a/thumbnails/pkg/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go deleted file mode 100644 index 9efd680a11b..00000000000 --- a/thumbnails/pkg/flagset/flagset.go +++ /dev/null @@ -1,207 +0,0 @@ -package flagset - -import ( - "path" - - "github.com/owncloud/ocis/ocis-pkg/config/defaults" - "github.com/owncloud/ocis/ocis-pkg/flags" - - "github.com/owncloud/ocis/thumbnails/pkg/config" - "github.com/urfave/cli/v2" -) - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9189"), - Usage: "Address to debug endpoint", - EnvVars: []string{"THUMBNAILS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"THUMBNAILS_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"THUMBNAILS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"THUMBNAILS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"THUMBNAILS_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"THUMBNAILS_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"THUMBNAILS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"THUMBNAILS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"THUMBNAILS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"THUMBNAILS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "thumbnails"), - Usage: "Service name for tracing", - EnvVars: []string{"THUMBNAILS_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9189"), - Usage: "Address to bind debug server", - EnvVars: []string{"THUMBNAILS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"THUMBNAILS_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"THUMBNAILS_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"THUMBNAILS_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "grpc-name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "thumbnails"), - Usage: "Name of the service", - EnvVars: []string{"THUMBNAILS_GRPC_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.StringFlag{ - Name: "grpc-addr", - Value: flags.OverrideDefaultString(cfg.Server.Address, "127.0.0.1:9185"), - Usage: "Address to bind grpc server", - EnvVars: []string{"THUMBNAILS_GRPC_ADDR"}, - Destination: &cfg.Server.Address, - }, - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.Server.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"THUMBNAILS_GRPC_NAMESPACE"}, - Destination: &cfg.Server.Namespace, - }, - &cli.StringFlag{ - Name: "filesystemstorage-root", - Value: flags.OverrideDefaultString(cfg.Thumbnail.FileSystemStorage.RootDirectory, path.Join(defaults.BaseDataPath(), "thumbnails")), - Usage: "Root path of the filesystem storage directory", - EnvVars: []string{"THUMBNAILS_FILESYSTEMSTORAGE_ROOT"}, - Destination: &cfg.Thumbnail.FileSystemStorage.RootDirectory, - }, - &cli.StringFlag{ - Name: "reva-gateway-addr", - Value: flags.OverrideDefaultString(cfg.Thumbnail.RevaGateway, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.Thumbnail.RevaGateway, - }, - &cli.BoolFlag{ - Name: "webdavsource-insecure", - Value: flags.OverrideDefaultBool(cfg.Thumbnail.WebdavAllowInsecure, false), - Usage: "Whether to skip certificate checks", - EnvVars: []string{"THUMBNAILS_WEBDAVSOURCE_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Thumbnail.WebdavAllowInsecure, - }, - &cli.BoolFlag{ - Name: "cs3source-insecure", - Value: flags.OverrideDefaultBool(cfg.Thumbnail.CS3AllowInsecure, false), - Usage: "Whether to skip certificate checks", - EnvVars: []string{"THUMBNAILS_CS3SOURCE_INSECURE", "OCIS_INSECURE"}, - Destination: &cfg.Thumbnail.CS3AllowInsecure, - }, - &cli.StringSliceFlag{ - Name: "thumbnail-resolution", - Value: cli.NewStringSlice("16x16", "32x32", "64x64", "128x128", "1920x1080", "3840x2160", "7680x4320"), - Usage: "--thumbnail-resolution 16x16 [--thumbnail-resolution 32x32]", - EnvVars: []string{"THUMBNAILS_RESOLUTIONS"}, - }, - &cli.StringFlag{ - Name: "webdav-namespace", - Value: flags.OverrideDefaultString(cfg.Thumbnail.WebdavNamespace, "/home"), - Usage: "Namespace prefix for the webdav endpoint", - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, - Destination: &cfg.Thumbnail.WebdavNamespace, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, - } -} - -// ListThumbnailsWithConfig applies the config to the flagset for listing thumbnails services. -func ListThumbnailsWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "grpc-name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "thumbnails"), - Usage: "Name of the service", - EnvVars: []string{"THUMBNAILS_GRPC_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.StringFlag{ - Name: "grpc-namespace", - Value: flags.OverrideDefaultString(cfg.Server.Namespace, "com.owncloud.api"), - Usage: "Set the base namespace for the grpc namespace", - EnvVars: []string{"THUMBNAILS_GRPC_NAMESPACE"}, - Destination: &cfg.Server.Namespace, - }, - } -} diff --git a/web/cmd/web/main.go b/web/cmd/web/main.go index 50ca749a73f..7334862feef 100644 --- a/web/cmd/web/main.go +++ b/web/cmd/web/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/web/pkg/command/health.go b/web/pkg/command/health.go index 4719442e309..97206879bf4 100644 --- a/web/pkg/command/health.go +++ b/web/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/web/pkg/config" - "github.com/owncloud/ocis/web/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index a7b5bbba8af..8c99ecad628 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/shared" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/web/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -59,49 +57,28 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from Viper known paths. +// ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("WEB") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("web") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("web", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") - } - - return nil + conf.LoadOSEnv(config.GetEnv(cfg), false) + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the web command to be embedded and supervised by a suture supervisor tree. @@ -111,10 +88,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.Web.Supervised = true - } - cfg.Web.Log.File = cfg.Log.File + cfg.Web.Commons = cfg.Commons return SutureService{ cfg: cfg.Web, } diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 287507628ea..a0a11f37d6a 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -9,7 +9,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/web/pkg/config" - "github.com/owncloud/ocis/web/pkg/flagset" "github.com/owncloud/ocis/web/pkg/metrics" "github.com/owncloud/ocis/web/pkg/server/debug" "github.com/owncloud/ocis/web/pkg/server/http" @@ -22,30 +21,20 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") } - // StringSliceFlag doesn't support Destination - // UPDATE Destination on string flags supported. Wait for https://github.com/urfave/cli/pull/1078 to get to micro/cli - if len(ctx.StringSlice("web-config-app")) > 0 { - cfg.Web.Config.Apps = ctx.StringSlice("web-config-app") - } - - if !cfg.Supervised { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "web").Msg("ignoring config file parsing when running supervised") // 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" } + return nil }, Action: func(c *cli.Context) error { @@ -62,7 +51,7 @@ func Server(cfg *config.Config) *cli.Command { logger.Err(err).Msg("error opening config file") return err } - if err := json.Unmarshal(contents, &cfg.Web.Config); err != nil { + if err = json.Unmarshal(contents, &cfg.Web.Config); err != nil { logger.Fatal().Err(err).Msg("error unmarshalling config file") return err } diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 64a03838bdc..0054c9331ac 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -1,63 +1,59 @@ package config -import "context" - -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} +import ( + "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - Namespace string - CacheTTL int + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` + CacheTTL int `ocisConfig:"cache_ttl"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `ocisConfig:"path"` } // WebConfig defines the available web configuration for a dynamically rendered config.json. type WebConfig struct { - Server string `json:"server,omitempty"` - Theme string `json:"theme,omitempty"` - Version string `json:"version,omitempty"` // TODO what is version used for? - OpenIDConnect OIDC `json:"openIdConnect,omitempty"` - Apps []string `json:"apps"` // TODO add nilasempty when https://go-review.googlesource.com/c/go/+/205897/ is released - ExternalApps []ExternalApp `json:"external_apps,omitempty"` - Options map[string]interface{} `json:"options,omitempty"` + Server string `json:"server,omitempty" ocisConfig:"server"` + Theme string `json:"theme,omitempty" ocisConfig:"theme"` + Version string `json:"version,omitempty" ocisConfig:"version"` + OpenIDConnect OIDC `json:"openIdConnect,omitempty" ocisConfig:"oids"` + Apps []string `json:"apps" ocisConfig:"apps"` + ExternalApps []ExternalApp `json:"external_apps,omitempty" ocisConfig:"external_apps"` + Options map[string]interface{} `json:"options,omitempty" ocisConfig:"options"` } // OIDC defines the available oidc configuration type OIDC struct { - MetadataURL string `json:"metadata_url,omitempty"` - Authority string `json:"authority,omitempty"` - ClientID string `json:"client_id,omitempty"` - ResponseType string `json:"response_type,omitempty"` - Scope string `json:"scope,omitempty"` + MetadataURL string `json:"metadata_url,omitempty" ocisConfig:"metadata_url"` + Authority string `json:"authority,omitempty" ocisConfig:"authority"` + ClientID string `json:"client_id,omitempty" ocisConfig:"client_id"` + ResponseType string `json:"response_type,omitempty" ocisConfig:"response_type"` + Scope string `json:"scope,omitempty" ocisConfig:"scope"` } // ExternalApp defines an external web app. @@ -69,35 +65,36 @@ type OIDC struct { // } // } type ExternalApp struct { - ID string `json:"id,omitempty"` - Path string `json:"path,omitempty"` + ID string `json:"id,omitempty" ocisConfig:"id"` + Path string `json:"path,omitempty" ocisConfig:"path"` // Config is completely dynamic, because it depends on the extension - Config map[string]interface{} `json:"config,omitempty"` + Config map[string]interface{} `json:"config,omitempty" ocisConfig:"config"` } // ExternalAppConfig defines an external web app configuration. type ExternalAppConfig struct { - URL string `json:"url,omitempty"` + URL string `json:"url,omitempty" ocisConfig:"url"` } // Web defines the available web configuration. type Web struct { - Path string - ThemeServer string // used to build Theme in WebConfig - ThemePath string // used to build Theme in WebConfig - Config WebConfig + Path string `ocisConfig:"path"` + ThemeServer string `ocisConfig:"theme_server"` // used to build Theme in WebConfig + ThemePath string `ocisConfig:"theme_path"` // used to build Theme in WebConfig + Config WebConfig `ocisConfig:"config"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Tracing Tracing - Asset Asset - OIDC OIDC - Web Web + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Tracing Tracing `ocisConfig:"tracing"` + Asset Asset `ocisConfig:"asset"` + Web Web `ocisConfig:"web"` Context context.Context Supervised bool @@ -107,3 +104,48 @@ type Config struct { func New() *Config { return &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 + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "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/mappings.go b/web/pkg/config/mappings.go new file mode 100644 index 00000000000..3957c225ed0 --- /dev/null +++ b/web/pkg/config/mappings.go @@ -0,0 +1,143 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_LEVEL", "WEB_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "WEB_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "WEB_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCIS_LOG_FILE", "WEB_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"WEB_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "WEB_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "WEB_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "WEB_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "WEB_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"WEB_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"WEB_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"WEB_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"WEB_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"WEB_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"WEB_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"WEB_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"WEB_NAMESPACE"}, + Destination: &cfg.HTTP.Namespace, + }, + { + EnvVars: []string{"WEB_CACHE_TTL"}, + Destination: &cfg.HTTP.CacheTTL, + }, + { + EnvVars: []string{"WEB_ASSET_PATH"}, + Destination: &cfg.Asset.Path, + }, + { + EnvVars: []string{"WEB_UI_CONFIG"}, + Destination: &cfg.Web.Path, + }, + { + EnvVars: []string{"OCIS_URL", "WEB_UI_CONFIG_SERVER"}, // WEB_UI_CONFIG_SERVER takes precedence over OCIS_URL + Destination: &cfg.Web.Config.Server, + }, + { + EnvVars: []string{"OCIS_URL", "WEB_UI_THEME_SERVER"}, // WEB_UI_THEME_SERVER takes precedence over OCIS_URL + Destination: &cfg.Web.ThemeServer, + }, + { + EnvVars: []string{"WEB_UI_THEME_PATH"}, + Destination: &cfg.Web.ThemePath, + }, + { + EnvVars: []string{"WEB_UI_CONFIG_VERSION"}, + Destination: &cfg.Web.Config.Version, + }, + { + EnvVars: []string{"WEB_OIDC_METADATA_URL"}, + Destination: &cfg.Web.Config.OpenIDConnect.MetadataURL, + }, + { + EnvVars: []string{"OCIS_URL", "WEB_OIDC_AUTHORITY"}, // WEB_OIDC_AUTHORITY takes precedence over OCIS_URL + Destination: &cfg.Web.Config.OpenIDConnect.Authority, + }, + { + EnvVars: []string{"WEB_OIDC_CLIENT_ID"}, + Destination: &cfg.Web.Config.OpenIDConnect.ClientID, + }, + { + EnvVars: []string{"WEB_OIDC_RESPONSE_TYPE"}, + Destination: &cfg.Web.Config.OpenIDConnect.ResponseType, + }, + { + EnvVars: []string{"WEB_OIDC_SCOPE"}, + Destination: &cfg.Web.Config.OpenIDConnect.Scope, + }, + } +} diff --git a/web/pkg/flagset/flagset.go b/web/pkg/flagset/flagset.go deleted file mode 100644 index 2b3d77d1a8d..00000000000 --- a/web/pkg/flagset/flagset.go +++ /dev/null @@ -1,238 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/web/pkg/config" - "github.com/urfave/cli/v2" -) - -// RootWithConfig applies cfg to the root flagset -func RootWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"WEB_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"WEB_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"WEB_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - } -} - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9104"), - Usage: "Address to debug endpoint", - EnvVars: []string{"WEB_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"WEB_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"WEB_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"WEB_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"WEB_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"WEB_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"WEB_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "web"), - Usage: "Service name for tracing", - EnvVars: []string{"WEB_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9104"), - Usage: "Address to bind debug server", - EnvVars: []string{"WEB_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"WEB_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"WEB_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"WEB_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9100"), - Usage: "Address to bind http server", - EnvVars: []string{"WEB_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/"), - Usage: "Root path of http server", - EnvVars: []string{"WEB_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.HTTP.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for the http namespace", - EnvVars: []string{"WEB_NAMESPACE"}, - Destination: &cfg.HTTP.Namespace, - }, - &cli.IntFlag{ - Name: "http-cache-ttl", - Value: flags.OverrideDefaultInt(cfg.HTTP.CacheTTL, 604800), // 7 days - Usage: "Set the static assets caching duration in seconds", - EnvVars: []string{"WEB_CACHE_TTL"}, - Destination: &cfg.HTTP.CacheTTL, - }, - &cli.StringFlag{ - Name: "asset-path", - Value: flags.OverrideDefaultString(cfg.Asset.Path, ""), - Usage: "Path to custom assets", - EnvVars: []string{"WEB_ASSET_PATH"}, - Destination: &cfg.Asset.Path, - }, - &cli.StringFlag{ - Name: "web-config", - Value: flags.OverrideDefaultString(cfg.Web.Path, ""), - Usage: "Path to web config", - EnvVars: []string{"WEB_UI_CONFIG"}, - Destination: &cfg.Web.Path, - }, - &cli.StringFlag{ - Name: "web-config-server", - Value: flags.OverrideDefaultString(cfg.Web.Config.Server, "https://localhost:9200"), - Usage: "Configuration server URL", - EnvVars: []string{"WEB_UI_CONFIG_SERVER", "OCIS_URL"}, // WEB_UI_CONFIG_SERVER takes precedence over OCIS_URL - Destination: &cfg.Web.Config.Server, - }, - &cli.StringFlag{ - Name: "web-theme-server", - Value: flags.OverrideDefaultString(cfg.Web.ThemeServer, "https://localhost:9200"), - Usage: "Theme server URL", - EnvVars: []string{"WEB_UI_THEME_SERVER", "OCIS_URL"}, // WEB_UI_THEME_SERVER takes precedence over OCIS_URL - Destination: &cfg.Web.ThemeServer, - }, - &cli.StringFlag{ - Name: "web-config-theme", - Value: flags.OverrideDefaultString(cfg.Web.ThemePath, "/themes/owncloud/theme.json"), - Usage: "Theme path on the theme server", - EnvVars: []string{"WEB_UI_THEME_PATH"}, - Destination: &cfg.Web.ThemePath, - }, - &cli.StringFlag{ - Name: "web-config-version", - Value: flags.OverrideDefaultString(cfg.Web.Config.Version, "0.1.0"), - Usage: "Version", - EnvVars: []string{"WEB_UI_CONFIG_VERSION"}, - Destination: &cfg.Web.Config.Version, - }, - &cli.StringSliceFlag{ - Name: "web-config-app", - Value: cli.NewStringSlice("files", "search", "media-viewer", "external"), - Usage: `--web-config-app files [--web-config-app draw-io]`, - EnvVars: []string{"WEB_UI_CONFIG_APPS"}, - }, - &cli.StringFlag{ - Name: "oidc-metadata-url", - Value: flags.OverrideDefaultString(cfg.Web.Config.OpenIDConnect.MetadataURL, ""), - Usage: "OpenID Connect metadata URL, defaults to /.well-known/openid-configuration", - EnvVars: []string{"WEB_OIDC_METADATA_URL"}, - Destination: &cfg.Web.Config.OpenIDConnect.MetadataURL, - }, - &cli.StringFlag{ - Name: "oidc-authority", - Value: flags.OverrideDefaultString(cfg.Web.Config.OpenIDConnect.Authority, "https://localhost:9200"), - Usage: "OpenID Connect authority", // TODO rename to Issuer - EnvVars: []string{"WEB_OIDC_AUTHORITY", "OCIS_URL"}, // WEB_OIDC_AUTHORITY takes precedence over OCIS_URL - Destination: &cfg.Web.Config.OpenIDConnect.Authority, - }, - &cli.StringFlag{ - Name: "oidc-client-id", - Value: flags.OverrideDefaultString(cfg.Web.Config.OpenIDConnect.ClientID, "web"), - Usage: "OpenID Connect client ID", - EnvVars: []string{"WEB_OIDC_CLIENT_ID"}, - Destination: &cfg.Web.Config.OpenIDConnect.ClientID, - }, - &cli.StringFlag{ - Name: "oidc-response-type", - Value: flags.OverrideDefaultString(cfg.Web.Config.OpenIDConnect.ResponseType, "code"), - Usage: "OpenID Connect response type", - EnvVars: []string{"WEB_OIDC_RESPONSE_TYPE"}, - Destination: &cfg.Web.Config.OpenIDConnect.ResponseType, - }, - &cli.StringFlag{ - Name: "oidc-scope", - Value: flags.OverrideDefaultString(cfg.Web.Config.OpenIDConnect.Scope, "openid profile email"), - Usage: "OpenID Connect scope", - EnvVars: []string{"WEB_OIDC_SCOPE"}, - Destination: &cfg.Web.Config.OpenIDConnect.Scope, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} diff --git a/webdav/cmd/webdav/main.go b/webdav/cmd/webdav/main.go index fe242ff533a..f03fd520c88 100644 --- a/webdav/cmd/webdav/main.go +++ b/webdav/cmd/webdav/main.go @@ -8,7 +8,7 @@ import ( ) func main() { - if err := command.Execute(config.New()); err != nil { + if err := command.Execute(config.DefaultConfig()); err != nil { os.Exit(1) } } diff --git a/webdav/pkg/command/health.go b/webdav/pkg/command/health.go index 42aa7964c3c..58aca1e1d2e 100644 --- a/webdav/pkg/command/health.go +++ b/webdav/pkg/command/health.go @@ -5,7 +5,6 @@ import ( "net/http" "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/owncloud/ocis/webdav/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - Flags: flagset.HealthWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 99c902e89ef..f221de83283 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + "github.com/owncloud/ocis/ocis-pkg/shared" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -65,49 +63,30 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads webdav configuration from Viper known paths. +// ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) - - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("WEBDAV") - viper.AutomaticEnv() - - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName("webdav") - - viper.AddConfigPath("/etc/ocis") - viper.AddConfigPath("$HOME/.ocis") - viper.AddConfigPath("./config") + conf, err := ociscfg.BindSourcesToStructs("webdav", cfg) + if err != nil { + return err } - if err := viper.ReadInConfig(); err != nil { - switch err.(type) { - case viper.ConfigFileNotFoundError: - logger.Debug(). - Msg("no config found on preconfigured location") - case viper.UnsupportedConfigError: - logger.Fatal(). - Err(err). - Msg("Unsupported config type") - default: - logger.Fatal(). - Err(err). - Msg("Failed to read 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 = &shared.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.Commons == nil { + cfg.Log = &shared.Log{} } - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(cfg), false) - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the webdav command to be embedded and supervised by a suture supervisor tree. @@ -117,10 +96,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if cfg.Mode == 0 { - cfg.WebDAV.Supervised = true - } - cfg.WebDAV.Log.File = cfg.Log.File + cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.WebDAV, } diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 47a50909934..c0248c5a078 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -7,7 +7,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/owncloud/ocis/webdav/pkg/flagset" "github.com/owncloud/ocis/webdav/pkg/metrics" "github.com/owncloud/ocis/webdav/pkg/server/debug" "github.com/owncloud/ocis/webdav/pkg/server/http" @@ -20,26 +19,15 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - if origins := ctx.StringSlice("cors-allowed-origins"); len(origins) != 0 { - cfg.HTTP.CORS.AllowedOrigins = origins - } - if methods := ctx.StringSlice("cors-allowed-methods"); len(methods) != 0 { - cfg.HTTP.CORS.AllowedMethods = methods - } - if headers := ctx.StringSlice("cors-allowed-headers"); len(headers) != 0 { - cfg.HTTP.CORS.AllowedOrigins = headers + if err := ParseConfig(ctx, cfg); err != nil { + return err } - logger.Debug().Str("service", "webdav").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { @@ -83,7 +71,8 @@ func Server(cfg *config.Config) *cli.Command { gr.Add(func() error { return server.Run() - }, func(_ error) { + }, func(err error) { + logger.Error().Err(err).Msg("error ") logger.Info(). Str("transport", "http"). Msg("Shutting down server") @@ -104,7 +93,8 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { + gr.Add(server.ListenAndServe, func(err error) { + logger.Error().Err(err) _ = server.Shutdown(ctx) cancel() }) diff --git a/webdav/pkg/command/version.go b/webdav/pkg/command/version.go index 03ef51278d6..813cc1c08c2 100644 --- a/webdav/pkg/command/version.go +++ b/webdav/pkg/command/version.go @@ -8,7 +8,6 @@ import ( tw "github.com/olekukonko/tablewriter" "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/owncloud/ocis/webdav/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListWebdavWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { reg := registry.GetRegistry() services, err := reg.GetService(cfg.Service.Namespace + "." + cfg.Service.Name) diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index dfd4f46c6f0..c08c8ea0f9e 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -1,64 +1,62 @@ package config -import "context" +import ( + "context" -// Log defines the available logging configuration. -type Log struct { - Level string - Pretty bool - Color bool - File string -} + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `ocisConfig:"addr"` + Token string `ocisConfig:"token"` + Pprof bool `ocisConfig:"pprof"` + Zpages bool `ocisConfig:"zpages"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `ocisConfig:"allowed_origins"` + AllowedMethods []string `ocisConfig:"allowed_methods"` + AllowedHeaders []string `ocisConfig:"allowed_headers"` + AllowCredentials bool `ocisConfig:"allow_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - CORS CORS + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `ocisConfig:"enabled"` + Type string `ocisConfig:"type"` + Endpoint string `ocisConfig:"endpoint"` + Collector string `ocisConfig:"collector"` + Service string `ocisConfig:"service"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Tracing Tracing - Service Service - OcisPublicURL string - WebdavNamespace string + *shared.Commons + + File string `ocisConfig:"file"` + Log *shared.Log `ocisConfig:"log"` + Debug Debug `ocisConfig:"debug"` + HTTP HTTP `ocisConfig:"http"` + Tracing Tracing `ocisConfig:"tracing"` + Service Service `ocisConfig:"service"` + OcisPublicURL string `ocisConfig:"ocis_public_url"` + WebdavNamespace string `ocisConfig:"webdav_namespace"` Context context.Context Supervised bool @@ -68,3 +66,37 @@ type Config struct { func New() *Config { return &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: "/", + CORS: CORS{ + AllowedOrigins: []string{"*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"}, + AllowCredentials: true, + }, + }, + Tracing: Tracing{ + Enabled: false, + Type: "jaeger", + Endpoint: "", + Collector: "", + Service: "webdav", + }, + Service: Service{ + Name: "webdav", + Namespace: "com.owncloud.web", + }, + OcisPublicURL: "https://127.0.0.1:9200", + WebdavNamespace: "/home", + } +} diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go new file mode 100644 index 00000000000..7fa86211ef7 --- /dev/null +++ b/webdav/pkg/config/mappings.go @@ -0,0 +1,107 @@ +package config + +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list +// with all the environment variables an extension supports. +func GetEnv(cfg *Config) []string { + var r = make([]string, len(structMappings(cfg))) + for i := range structMappings(cfg) { + r = append(r, structMappings(cfg)[i].EnvVars...) + } + + return r +} + +// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the +// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets +// us propagate changes easier. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ + { + EnvVars: []string{"OCIS_LOG_FILE", "WEBDAV_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCIS_LOG_LEVEL", "WEBDAV_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCIS_LOG_PRETTY", "WEBDAV_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCIS_LOG_COLOR", "WEBDAV_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"WEBDAV_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCIS_TRACING_ENABLED", "WEBDAV_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCIS_TRACING_TYPE", "WEBDAV_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "WEBDAV_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "WEBDAV_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, + }, + { + EnvVars: []string{"WEBDAV_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, + }, + { + EnvVars: []string{"WEBDAV_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, + }, + { + EnvVars: []string{"WEBDAV_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, + }, + { + EnvVars: []string{"WEBDAV_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, + }, + { + EnvVars: []string{"WEBDAV_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, + }, + { + EnvVars: []string{"WEBDAV_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, + }, + { + EnvVars: []string{"WEBDAV_HTTP_NAMESPACE"}, + Destination: &cfg.Service.Namespace, + }, + { + EnvVars: []string{"WEBDAV_SERVICE_NAME"}, + Destination: &cfg.Service.Name, + }, + { + EnvVars: []string{"WEBDAV_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, + }, + { + EnvVars: []string{"OCIS_URL", "OCIS_PUBLIC_URL"}, + Destination: &cfg.OcisPublicURL, + }, + { + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.WebdavNamespace, + }, + } +} diff --git a/webdav/pkg/flagset/flagset.go b/webdav/pkg/flagset/flagset.go deleted file mode 100644 index 7df00873cd1..00000000000 --- a/webdav/pkg/flagset/flagset.go +++ /dev/null @@ -1,207 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/webdav/pkg/config" - "github.com/urfave/cli/v2" -) - -// HealthWithConfig applies cfg to the root flagset -func HealthWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9119"), - Usage: "Address to debug endpoint", - EnvVars: []string{"WEBDAV_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// ServerWithConfig applies cfg to the root flagset -func ServerWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "log-file", - Usage: "Enable log to file", - EnvVars: []string{"WEBDAV_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - &cli.StringFlag{ - Name: "log-level", - Usage: "Set logging level", - EnvVars: []string{"WEBDAV_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"WEBDAV_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"WEBDAV_LOG_COLOR", "OCIS_LOG_COLOR"}, - Destination: &cfg.Log.Color, - }, - &cli.StringFlag{ - Name: "config-file", - Value: "", - Usage: "Path to config file", - EnvVars: []string{"WEBDAV_CONFIG_FILE"}, - Destination: &cfg.File, - }, - &cli.BoolFlag{ - Name: "tracing-enabled", - Usage: "Enable sending traces", - EnvVars: []string{"WEBDAV_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - &cli.StringFlag{ - Name: "tracing-type", - Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), - Usage: "Tracing backend type", - EnvVars: []string{"WEBDAV_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - &cli.StringFlag{ - Name: "tracing-endpoint", - Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), - Usage: "Endpoint for the agent", - EnvVars: []string{"WEBDAV_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - &cli.StringFlag{ - Name: "tracing-collector", - Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), - Usage: "Endpoint for the collector", - EnvVars: []string{"WEBDAV_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - Destination: &cfg.Tracing.Collector, - }, - &cli.StringFlag{ - Name: "tracing-service", - Value: flags.OverrideDefaultString(cfg.Tracing.Service, "webdav"), - Usage: "Service name for tracing", - EnvVars: []string{"WEBDAV_TRACING_SERVICE"}, - Destination: &cfg.Tracing.Service, - }, - &cli.StringFlag{ - Name: "debug-addr", - Value: flags.OverrideDefaultString(cfg.Debug.Addr, "127.0.0.1:9119"), - Usage: "Address to bind debug server", - EnvVars: []string{"WEBDAV_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - &cli.StringFlag{ - Name: "debug-token", - Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), - Usage: "Token to grant metrics access", - EnvVars: []string{"WEBDAV_DEBUG_TOKEN"}, - Destination: &cfg.Debug.Token, - }, - &cli.BoolFlag{ - Name: "debug-pprof", - Usage: "Enable pprof debugging", - EnvVars: []string{"WEBDAV_DEBUG_PPROF"}, - Destination: &cfg.Debug.Pprof, - }, - &cli.BoolFlag{ - Name: "debug-zpages", - Usage: "Enable zpages debugging", - EnvVars: []string{"WEBDAV_DEBUG_ZPAGES"}, - Destination: &cfg.Debug.Zpages, - }, - &cli.StringFlag{ - Name: "http-addr", - Value: flags.OverrideDefaultString(cfg.HTTP.Addr, "127.0.0.1:9115"), - Usage: "Address to bind http server", - EnvVars: []string{"WEBDAV_HTTP_ADDR"}, - Destination: &cfg.HTTP.Addr, - }, - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for service discovery", - EnvVars: []string{"WEBDAV_HTTP_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-origins", - Value: cli.NewStringSlice("*"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"WEBDAV_CORS_ALLOW_ORIGINS", "OCIS_CORS_ALLOW_ORIGINS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-methods", - Value: cli.NewStringSlice("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"WEBDAV_CORS_ALLOW_METHODS", "OCIS_CORS_ALLOW_METHODS"}, - }, - &cli.StringSliceFlag{ - Name: "cors-allowed-headers", - Value: cli.NewStringSlice("Authorization", "Origin", "Content-Type", "Accept", "X-Requested-With"), - Usage: "Set the allowed CORS origins", - EnvVars: []string{"WEBDAV_CORS_ALLOW_HEADERS", "OCIS_CORS_ALLOW_HEADERS"}, - }, - &cli.BoolFlag{ - Name: "cors-allow-credentials", - Value: flags.OverrideDefaultBool(cfg.HTTP.CORS.AllowCredentials, true), - Usage: "Allow credentials for CORS", - EnvVars: []string{"WEBDAV_CORS_ALLOW_CREDENTIALS", "OCIS_CORS_ALLOW_CREDENTIALS"}, - }, - &cli.StringFlag{ - Name: "service-name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "webdav"), - Usage: "Service name", - EnvVars: []string{"WEBDAV_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, - &cli.StringFlag{ - Name: "http-root", - Value: flags.OverrideDefaultString(cfg.HTTP.Root, "/"), - Usage: "Root path of http server", - EnvVars: []string{"WEBDAV_HTTP_ROOT"}, - Destination: &cfg.HTTP.Root, - }, - &cli.StringFlag{ - Name: "ocis-public-url", - Value: flags.OverrideDefaultString(cfg.OcisPublicURL, "https://127.0.0.1:9200"), - Usage: "The domain under which oCIS is reachable", - EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"}, - Destination: &cfg.OcisPublicURL, - }, - &cli.StringFlag{ - Name: "webdav-namespace", - Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"), - Usage: "Namespace prefix for the /webdav endpoint", - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, - Destination: &cfg.WebdavNamespace, - }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", - }, - } -} - -// ListWebdavWithConfig applies the config to the list commands flagset. -func ListWebdavWithConfig(cfg *config.Config) []cli.Flag { - return []cli.Flag{ - &cli.StringFlag{ - Name: "http-namespace", - Value: flags.OverrideDefaultString(cfg.Service.Namespace, "com.owncloud.web"), - Usage: "Set the base namespace for service discovery", - EnvVars: []string{"WEBDAV_HTTP_NAMESPACE"}, - Destination: &cfg.Service.Namespace, - }, - &cli.StringFlag{ - Name: "service-name", - Value: flags.OverrideDefaultString(cfg.Service.Name, "webdav"), - Usage: "Service name", - EnvVars: []string{"WEBDAV_SERVICE_NAME"}, - Destination: &cfg.Service.Name, - }, - } -}