From 34253fcae29c5806a270c36cb1dfee0d9bca43bc Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 29 Oct 2021 11:51:08 +0200 Subject: [PATCH 001/147] remove flagset on proxy, use default config values --- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/proxy.go | 3 +- ocis/pkg/config/config.go | 2 +- proxy/cmd/proxy/main.go | 2 +- proxy/pkg/command/health.go | 3 +- proxy/pkg/command/root.go | 3 +- proxy/pkg/command/server.go | 3 +- proxy/pkg/config/config.go | 60 +++++++ proxy/pkg/flagset/flagset.go | 295 ----------------------------------- 9 files changed, 67 insertions(+), 306 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 01ca3187f1..b2a88c791a 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -116,7 +116,7 @@ func New() *Config { IDP: idp.New(), OCS: ocs.New(), Web: web.New(), - Proxy: proxy.New(), + Proxy: proxy.DefaultConfig(), Settings: settings.New(), Storage: storage.New(), Store: store.New(), diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 8ac4816c53..aaec5a56ed 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -9,7 +9,6 @@ import ( "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,7 +18,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: "proxy", Usage: "Start proxy server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Proxy), + //Flags: flagset.ServerWithConfig(cfg.Proxy), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Proxy), }, diff --git a/ocis/pkg/config/config.go b/ocis/pkg/config/config.go index f02f06b4ab..51fc2db77c 100644 --- a/ocis/pkg/config/config.go +++ b/ocis/pkg/config/config.go @@ -93,7 +93,7 @@ func New() *Config { IDP: idp.New(), OCS: ocs.New(), Web: web.New(), - Proxy: proxy.New(), + Proxy: proxy.DefaultConfig(), Settings: settings.New(), Storage: storage.New(), Store: store.New(), diff --git a/proxy/cmd/proxy/main.go b/proxy/cmd/proxy/main.go index fbc6a6d744..f67b685f34 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 4dbe95aa7d..adb3f0a77b 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 81a135d7fc..721f809ed0 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -11,7 +11,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" "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" @@ -32,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 8b43411034..e01d4219fd 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,7 +39,7 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), + //Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), Before: func(ctx *cli.Context) error { logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 9dd370118e..3a555b276a 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -2,6 +2,9 @@ package config import ( "context" + "path" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) // Log defines the available logging configuration. @@ -192,3 +195,60 @@ func New() *Config { HTTP: HTTP{}, } } + +// DefaultConfig are values stored in the flag set, but moved to a struct. +func DefaultConfig() *Config { + return &Config{ + File: "", + Log: Log{}, // logging config is inherited. + 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, + } +} diff --git a/proxy/pkg/flagset/flagset.go b/proxy/pkg/flagset/flagset.go index 2f1d6b8858..5b7118623b 100644 --- a/proxy/pkg/flagset/flagset.go +++ b/proxy/pkg/flagset/flagset.go @@ -1,306 +1,11 @@ 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, true), - Usage: "OIDC allow insecure communication", - EnvVars: []string{"PROXY_OIDC_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{ From 94aeefb7fd1ad3d5de5efe9f697d49b7bf806003 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 29 Oct 2021 16:15:35 +0200 Subject: [PATCH 002/147] first examples of config parsing --- go.mod | 2 + go.sum | 32 +++++++++++ proxy/pkg/command/proxy_example_config.yaml | 6 +++ proxy/pkg/command/root.go | 52 +++++------------- proxy/pkg/command/server.go | 7 ++- proxy/pkg/config/config.go | 60 ++++++++++----------- 6 files changed, 89 insertions(+), 70 deletions(-) create mode 100644 proxy/pkg/command/proxy_example_config.yaml diff --git a/go.mod b/go.mod index a5878bd105..34f45d067a 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 @@ -142,6 +143,7 @@ require ( 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 diff --git a/go.sum b/go.sum index c915a1684f..ef5600eccf 100644 --- a/go.sum +++ b/go.sum @@ -105,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/akamai/AkamaiOPEN-edgegrid-golang v1.1.0/go.mod h1:kX6YddBkXqqywAe8c9LyvgTCyFuZCTMF4cRPQhc3Fy8= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -119,6 +120,9 @@ 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= @@ -502,6 +506,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= @@ -568,6 +573,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= @@ -643,6 +649,15 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ 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= @@ -701,6 +716,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ 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= @@ -800,6 +816,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= @@ -852,6 +869,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= @@ -898,6 +916,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= @@ -1177,6 +1196,7 @@ github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmq 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= @@ -1231,6 +1251,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= @@ -1247,11 +1270,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= @@ -1259,6 +1285,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 h1:1E+zymteWxvDLpo4EDixRmXC+ELOAyFGfOdO60ScVbU= @@ -1337,6 +1366,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= @@ -1404,6 +1434,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= @@ -1520,6 +1551,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= diff --git a/proxy/pkg/command/proxy_example_config.yaml b/proxy/pkg/command/proxy_example_config.yaml new file mode 100644 index 0000000000..0c2bff022d --- /dev/null +++ b/proxy/pkg/command/proxy_example_config.yaml @@ -0,0 +1,6 @@ +log: + level: info + color: true + pretty: true +http: + addr: "${PROXY_HTTP_ADDR|localhost:2222}" diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 721f809ed0..fcba39fd32 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -3,15 +3,13 @@ package command import ( "context" "os" - "strings" - - "github.com/owncloud/ocis/ocis-pkg/sync" + gofig "github.com/gookit/config/v2" + gooyaml "github.com/gookit/config/v2/yaml" 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/proxy/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -71,45 +69,23 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads proxy configuration from Viper known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - sync.ParsingViperConfig.Lock() - defer sync.ParsingViperConfig.Unlock() - logger := NewLogger(cfg) + // create a new config and load files and env values onto it since this needs to be thread-safe. + cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv) - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("PROXY") - viper.AutomaticEnv() + // TODO(refs) add ENV + toml + json + cnf.AddDriver(gooyaml.Driver) - 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") + // TODO(refs) load from expected locations with the expected name + err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/proxy/pkg/command/proxy_example_config.yaml") + if err != nil { + panic(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") - } - } + // bind all keys to cfg, as we expect an entire proxy.[yaml, toml...] to define all keys and not only sub values. + err = cnf.BindStruct("", cfg) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") - } + // step 2: overwrite the config values with those from ENV variables. Sadly the library only parses config files and does + // not support tags for env variables. return nil } diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index e01d4219fd..6a14657674 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -55,9 +55,12 @@ func Server(cfg *config.Config) *cli.Command { return err } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + panic(err) } + //if !cfg.Supervised { + // return ParseConfig(ctx, cfg) + //} logger.Debug().Str("service", "ocs").Msg("ignoring config file parsing when running supervised") return nil }, diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 3a555b276a..9d8a3a3949 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -25,11 +25,11 @@ type Debug struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - TLSCert string - TLSKey string - TLS bool + Addr string `mapstructure:"addr"` + Root string `mapstructure:"http_root"` + TLSCert string `mapstructure:"http_tls_cert"` + TLSKey string `mapstructure:"http_tls_key"` + TLS bool `mapstructure:"http_tls"` } // Service defines the available service configuration. @@ -105,25 +105,25 @@ type Cache struct { // 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 + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Service Service `mapstructure:"service"` + Tracing Tracing `mapstructure:"tracing"` + Policies []Policy `mapstructure:"policies"` + OIDC OIDC `mapstructure:"oidc"` + TokenManager TokenManager `mapstructure:"token_manager"` PolicySelector *PolicySelector `mapstructure:"policy_selector"` - Reva Reva - PreSignedURL PreSignedURL - AccountBackend string - UserOIDCClaim string - UserCS3Claim string - MachineAuthAPIKey string - AutoprovisionAccounts bool - EnableBasicAuth bool - InsecureBackends bool + Reva Reva `mapstructure:"reva"` + PreSignedURL PreSignedURL `mapstructure:"pre_signed_url"` + AccountBackend string `mapstructure:"account_backend"` + UserOIDCClaim string `mapstructure:"user_oidc_claim"` + UserCS3Claim string `mapstructure:"user_cs3_claim"` + MachineAuthAPIKey string `mapstructure:"machine_auth_api_key"` + AutoprovisionAccounts bool `mapstructure:"auto_provision_accounts"` + EnableBasicAuth bool `mapstructure:"enable_basic_auth"` + InsecureBackends bool `mapstructure:"insecure_backends"` Context context.Context Supervised bool @@ -132,9 +132,9 @@ 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 `mapstructure:"issuer"` + Insecure bool `mapstructure:"insecure"` + UserinfoCache Cache `mapstructure:"user_info_cache"` } // PolicySelector is the toplevel-configuration for different selectors @@ -147,18 +147,18 @@ type PolicySelector struct { // StaticSelectorConf is the config for the static-policy-selector type StaticSelectorConf struct { - Policy string + Policy string `mapstructure:"policy"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `mapstructure:"jwt_secret"` } // PreSignedURL is the config for the presigned url middleware type PreSignedURL struct { - AllowedHTTPMethods []string - Enabled bool + AllowedHTTPMethods []string `mapstructure:"allowed_http_methods"` + Enabled bool `mapstructure:"enabled"` } // MigrationSelectorConf is the config for the migration-selector From 998df71ae370a7cb14b0977b55f806b718b08bca Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 29 Oct 2021 23:41:41 +0200 Subject: [PATCH 003/147] poors man struct inheritance and perpetuity --- ocis/pkg/runtime/service/service.go | 2 +- proxy/pkg/command/proxy_example_config.yaml | 8 ++++---- proxy/pkg/command/root.go | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 78e8350edd..52d0ad166c 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -159,7 +159,7 @@ 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. + // reva storages have their own logging. For consistency's 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 diff --git a/proxy/pkg/command/proxy_example_config.yaml b/proxy/pkg/command/proxy_example_config.yaml index 0c2bff022d..4cfb08b5d5 100644 --- a/proxy/pkg/command/proxy_example_config.yaml +++ b/proxy/pkg/command/proxy_example_config.yaml @@ -1,6 +1,6 @@ -log: - level: info - color: true - pretty: true +#log: +# level: debug +# color: false +# pretty: false http: addr: "${PROXY_HTTP_ADDR|localhost:2222}" diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index fcba39fd32..eab14795d3 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -78,15 +78,12 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // TODO(refs) load from expected locations with the expected name err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/proxy/pkg/command/proxy_example_config.yaml") if err != nil { - panic(err) + return err } // bind all keys to cfg, as we expect an entire proxy.[yaml, toml...] to define all keys and not only sub values. err = cnf.BindStruct("", cfg) - // step 2: overwrite the config values with those from ENV variables. Sadly the library only parses config files and does - // not support tags for env variables. - return nil } @@ -97,10 +94,10 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Proxy.Supervised = true } - cfg.Proxy.Log.File = cfg.Log.File return SutureService{ cfg: cfg.Proxy, } @@ -114,3 +111,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Proxy.Log.File = cfg.Log.File + cfg.Proxy.Log.Color = cfg.Log.Color + cfg.Proxy.Log.Pretty = cfg.Log.Pretty + cfg.Proxy.Log.Level = cfg.Log.Level +} From 711acbb3549fa8a1cdc0b471384f03feccddce19 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Sun, 31 Oct 2021 00:08:46 +0200 Subject: [PATCH 004/147] inherit logging config from ocis.yaml, let extensions overwrite their logging. Considering using a package level global logging... --- accounts/pkg/command/root.go | 14 +++- glauth/pkg/command/root.go | 14 +++- graph-explorer/pkg/command/root.go | 18 +++-- graph/pkg/command/root.go | 7 +- idp/pkg/command/root.go | 14 +++- ocis-pkg/config/config.go | 84 +++++++++++------------ ocis-pkg/service/debug/service.go | 6 -- ocis-pkg/service/grpc/service.go | 5 -- ocis-pkg/service/http/service.go | 5 -- ocis/pkg/command/ocis_example_config.yaml | 4 ++ ocis/pkg/command/root.go | 54 +++------------ ocs/pkg/command/root.go | 11 +++ proxy/pkg/command/root.go | 2 +- settings/pkg/command/root.go | 14 +++- storage/pkg/command/root.go | 3 +- storage/pkg/command/storagemetadata.go | 2 +- store/pkg/command/root.go | 14 +++- thumbnails/pkg/command/root.go | 11 +++ web/pkg/command/root.go | 11 +++ web/pkg/command/server.go | 2 +- webdav/pkg/command/root.go | 11 +++ 21 files changed, 180 insertions(+), 126 deletions(-) create mode 100644 ocis/pkg/command/ocis_example_config.yaml diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index c4757d23e0..6a840af40e 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "strings" "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" @@ -36,7 +35,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Server.Version = version.String @@ -131,6 +130,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Accounts.Supervised = true } @@ -148,3 +148,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Accounts.Log.File = cfg.Log.File + cfg.Accounts.Log.Color = cfg.Log.Color + cfg.Accounts.Log.Pretty = cfg.Log.Pretty + cfg.Accounts.Log.Level = cfg.Log.Level +} diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index d8b39a9804..f5af7df620 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "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" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Version = version.String @@ -120,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.GLAuth.Supervised = true } @@ -137,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.GLAuth.Log.File = cfg.Log.File + cfg.GLAuth.Log.Color = cfg.Log.Color + cfg.GLAuth.Log.Pretty = cfg.Log.Pretty + cfg.GLAuth.Log.Level = cfg.Log.Level +} diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 83cdcb1861..6b3dd841b8 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "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" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Server.Version = version.String @@ -91,8 +90,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err := viper.ReadInConfig(); err != nil { switch err.(type) { case viper.ConfigFileNotFoundError: - logger.Info(). - Msg("Continue without config") + //logger.Info(). + // Msg("Continue without config") case viper.UnsupportedConfigError: logger.Fatal(). Err(err). @@ -120,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new graph-explorer.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.GraphExplorer.Supervised = true } @@ -137,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.GraphExplorer.Log.File = cfg.Log.File + cfg.GraphExplorer.Log.Color = cfg.Log.Color + cfg.GraphExplorer.Log.Pretty = cfg.Log.Pretty + cfg.GraphExplorer.Log.Level = cfg.Log.Level +} diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index c342d81b55..cfe7783c9d 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -9,7 +9,6 @@ import ( "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" @@ -32,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Server.Version = version.String @@ -92,8 +91,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err := viper.ReadInConfig(); err != nil { switch err.(type) { case viper.ConfigFileNotFoundError: - logger.Info(). - Msg("Continue without config") + //logger.Info(). + // Msg("Continue without config") case viper.UnsupportedConfigError: logger.Fatal(). Err(err). diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 640e750356..cccbc36b22 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -6,7 +6,6 @@ import ( "strings" "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" @@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String @@ -121,6 +120,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.IDP.Supervised = true } @@ -138,3 +138,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.IDP.Log.File = cfg.Log.File + cfg.IDP.Log.Color = cfg.Log.Color + cfg.IDP.Log.Pretty = cfg.Log.Pretty + cfg.IDP.Log.Level = cfg.Log.Level +} diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index b2a88c791a..a61bb89a52 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -18,43 +18,43 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string + Addr string `mapstructure:"addr"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `mapstructure:"jwt_secret"` } const ( @@ -69,41 +69,41 @@ type Mode int // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { - Port string - Host string - Extensions string + Port string `mapstructure:"port"` + Host string `mapstructure:"host"` + Extensions string `mapstructure:"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 + // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regard 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 + Registry string `mapstructure:"registry"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + GRPC GRPC `mapstructure:"grpc"` + Tracing Tracing `mapstructure:"tracing"` + TokenManager TokenManager `mapstructure:"token_manager"` + Runtime Runtime `mapstructure:"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 + Accounts *accounts.Config `mapstructure:"accounts"` + GLAuth *glauth.Config `mapstructure:"glauth"` + Graph *graph.Config `mapstructure:"graph"` + GraphExplorer *graphExplorer.Config `mapstructure:"graph_explorer"` + IDP *idp.Config `mapstructure:"idp"` + OCS *ocs.Config `mapstructure:"ocs"` + Web *web.Config `mapstructure:"web"` + Proxy *proxy.Config `mapstructure:"proxy"` + Settings *settings.Config `mapstructure:"settings"` + Storage *storage.Config `mapstructure:"storage"` + Store *store.Config `mapstructure:"store"` + Thumbnails *thumbnails.Config `mapstructure:"thumbnails"` + WebDAV *webdav.Config `mapstructure:"webdav"` } // New initializes a new configuration with or without defaults. diff --git a/ocis-pkg/service/debug/service.go b/ocis-pkg/service/debug/service.go index a89ea0c53c..e0fc938537 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( diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 34c20c8264..c21609b53b 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 f23bf7a885..98317e7a9a 100644 --- a/ocis-pkg/service/http/service.go +++ b/ocis-pkg/service/http/service.go @@ -20,11 +20,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), diff --git a/ocis/pkg/command/ocis_example_config.yaml b/ocis/pkg/command/ocis_example_config.yaml new file mode 100644 index 0000000000..280f0627aa --- /dev/null +++ b/ocis/pkg/command/ocis_example_config.yaml @@ -0,0 +1,4 @@ +log: + pretty: true + color: true + level: info diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index e132e26506..43fbafa8ba 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -2,18 +2,16 @@ package command import ( "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" + gofig "github.com/gookit/config/v2" + gooyaml "github.com/gookit/config/v2/yaml" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/urfave/cli/v2" "github.com/owncloud/ocis/ocis-pkg/config" "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" ) // Execute is the entry point for the ocis command. @@ -25,18 +23,15 @@ func Execute() error { 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 +65,16 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig load configuration for every extension +// ParseConfig loads ocis 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("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") + cnf := gofig.NewWithOptions("ocis", gofig.ParseEnv) + cnf.AddDriver(gooyaml.Driver) + err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/ocis/pkg/command/ocis_example_config.yaml") + 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") - } + err = cnf.BindStruct("", cfg) return nil } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index d7921b159c..281a793ff8 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -119,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.OCS.Supervised = true } @@ -136,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.OCS.Log.File = cfg.Log.File + cfg.OCS.Log.Color = cfg.Log.Color + cfg.OCS.Log.Pretty = cfg.Log.Pretty + cfg.OCS.Log.Level = cfg.Log.Level +} diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index eab14795d3..54506cac8e 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -67,7 +67,7 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from Viper known paths. +// ParseConfig loads proxy configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { // create a new config and load files and env values onto it since this needs to be thread-safe. cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index de90398455..170b10cd54 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -11,7 +11,6 @@ import ( "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,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String @@ -122,6 +121,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Settings.Supervised = true } @@ -139,3 +139,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Settings.Log.File = cfg.Log.File + cfg.Settings.Log.Color = cfg.Log.Color + cfg.Settings.Log.Pretty = cfg.Log.Pretty + cfg.Settings.Log.Level = cfg.Log.Level +} diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 9d0ee792ae..a2cce06b1c 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -7,7 +7,6 @@ import ( "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" ) @@ -27,7 +26,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index c27b27a424..74d8b82b4f 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -31,7 +31,7 @@ func StorageMetadata(cfg *config.Config) *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)...), + Flags: flagset.StorageMetadata(cfg), Category: "Extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index a875d5a1bf..b16eae65fc 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -11,7 +11,6 @@ import ( "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,7 +31,7 @@ func Execute(cfg *config.Config) error { }, }, - Flags: flagset.RootWithConfig(cfg), + //Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { cfg.Service.Version = version.String @@ -122,6 +121,7 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Store.Supervised = true } @@ -139,3 +139,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Store.Log.File = cfg.Log.File + cfg.Store.Log.Color = cfg.Log.Color + cfg.Store.Log.Pretty = cfg.Log.Pretty + cfg.Store.Log.Level = cfg.Log.Level +} diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 0e297c5ea5..c6b0d43a12 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -119,6 +119,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Thumbnails.Supervised = true } @@ -136,3 +137,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Thumbnails.Log.File = cfg.Log.File + cfg.Thumbnails.Log.Color = cfg.Log.Color + cfg.Thumbnails.Log.Pretty = cfg.Log.Pretty + cfg.Thumbnails.Log.Level = cfg.Log.Level +} diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index a7b5bbba8a..0114791d3b 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -111,6 +111,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.Web.Supervised = true } @@ -128,3 +129,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.Web.Log.File = cfg.Log.File + cfg.Web.Log.Color = cfg.Log.Color + cfg.Web.Log.Pretty = cfg.Log.Pretty + cfg.Web.Log.Level = cfg.Log.Level +} diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 287507628e..77ee5dce3b 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -22,7 +22,7 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), + Flags: flagset.ServerWithConfig(cfg), Before: func(ctx *cli.Context) error { logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 99c902e89e..bc5bb5fe74 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -117,6 +117,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + inheritLogging(cfg) if cfg.Mode == 0 { cfg.WebDAV.Supervised = true } @@ -134,3 +135,13 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } + +// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging +// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, +// being overwritten when the extension parses its config file / env variables. +func inheritLogging(cfg *ociscfg.Config) { + cfg.WebDAV.Log.File = cfg.Log.File + cfg.WebDAV.Log.Color = cfg.Log.Color + cfg.WebDAV.Log.Pretty = cfg.Log.Pretty + cfg.WebDAV.Log.Level = cfg.Log.Level +} From 7df000d06fc16a75669374cce15fabd1fff496c4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Sun, 31 Oct 2021 00:30:48 +0200 Subject: [PATCH 005/147] parse config regardless of supervised / unsupervised --- proxy/pkg/command/proxy_example_config.yaml | 8 ++++---- proxy/pkg/command/server.go | 16 +++++----------- proxy/pkg/proxy/proxy.go | 11 +++-------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/proxy/pkg/command/proxy_example_config.yaml b/proxy/pkg/command/proxy_example_config.yaml index 4cfb08b5d5..0c2bff022d 100644 --- a/proxy/pkg/command/proxy_example_config.yaml +++ b/proxy/pkg/command/proxy_example_config.yaml @@ -1,6 +1,6 @@ -#log: -# level: debug -# color: false -# pretty: false +log: + level: info + color: true + pretty: true http: addr: "${PROXY_HTTP_ADDR|localhost:2222}" diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 6a14657674..521d2f07db 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -39,14 +39,15 @@ 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.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") } @@ -55,13 +56,6 @@ func Server(cfg *config.Config) *cli.Command { return err } - if err := ParseConfig(ctx, cfg); err != nil { - panic(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/proxy/proxy.go b/proxy/pkg/proxy/proxy.go index a863fd5e9f..465c1563c8 100644 --- a/proxy/pkg/proxy/proxy.go +++ b/proxy/pkg/proxy/proxy.go @@ -93,20 +93,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) } } From 20b6d0a635bd1e2aef9b6a692efedfbf9a45f442 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 10:57:25 +0100 Subject: [PATCH 006/147] add DefaultConfig on accounts --- accounts/pkg/config/config.go | 205 +++++++++++++++++++++++----------- 1 file changed, 138 insertions(+), 67 deletions(-) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index a98554f0e2..cca797c1df 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -1,140 +1,147 @@ // Package config should be moved to internal package config -import "context" +import ( + "context" + "path" + + "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 `mapstructure:"hostname"` + Port int `mapstructure:"port"` + BaseDN string `mapstructure:"base_dn"` + UserFilter string `mapstructure:"user_filter"` + GroupFilter string `mapstructure:"group_filter"` + BindDN string `mapstructure:"bind_dn"` + BindPassword string `mapstructure:"bind_password"` + IDP string `mapstructure:"idp"` + Schema LDAPSchema `mapstructure:"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 `mapstructure:"account_id"` + Identities string `mapstructure:"identities"` + Username string `mapstructure:"username"` + DisplayName string `mapstructure:"display_name"` + Mail string `mapstructure:"mail"` + Groups string `mapstructure:"groups"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `mapstructure:"allowed_origins"` + AllowedMethods []string `mapstructure:"allowed_methods"` + AllowedHeaders []string `mapstructure:"allowed_headers"` + AllowCredentials bool `mapstructure:"allowed_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string - CacheTTL int - CORS CORS + Addr string `mapstructure:"addr"` + Namespace string `mapstructure:"namespace"` + Root string `mapstructure:"root"` + CacheTTL int `mapstructure:"cache_ttl"` + CORS CORS `mapstructure:"cors"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string - Namespace string + Addr string `mapstructure:"addr"` + Namespace string `mapstructure:"namespace"` } // Server configures a server. type Server struct { - Version string - Name string - HashDifficulty int - DemoUsersAndGroups bool + Version string `mapstructure:"version"` + Name string `mapstructure:"name"` + HashDifficulty int `mapstructure:"hash_difficulty"` + DemoUsersAndGroups bool `mapstructure:"demo_users_and_groups"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `mapstructure:"path"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `mapstructure:"jwt_secret"` } // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Repo defines which storage implementation is to be used. type Repo struct { - Backend string - Disk Disk - CS3 CS3 + Backend string `mapstructure:"backend"` + Disk Disk `mapstructure:"disk"` + CS3 CS3 `mapstructure:"cs3"` } // Disk is the local disk implementation of the storage. type Disk struct { - Path string + Path string `mapstructure:"path"` } // CS3 is the cs3 implementation of the storage. type CS3 struct { - ProviderAddr string - DataURL string - DataPrefix string - JWTSecret string + ProviderAddr string `mapstructure:"provider_addr"` + DataURL string `mapstructure:"data_url"` + DataPrefix string `mapstructure:"data_prefix"` + JWTSecret string `mapstructure:"jwt_secret"` } // ServiceUser defines the user required for EOS. type ServiceUser struct { - UUID string - Username string - UID int64 - GID int64 + UUID string `mapstructure:"uuid"` + Username string `mapstructure:"username"` + UID int64 `mapstructure:"uid"` + GID int64 `mapstructure:"gid"` } // Index defines config for indexes. type Index struct { - UID, GID Bound + UID Bound `mapstructure:"uid"` + GID Bound `mapstructure:"gid"` } // Bound defines a lower and upper bound. type Bound struct { - Lower, Upper int64 + Lower int64 `mapstructure:"lower"` + Upper int64 `mapstructure:"upper"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"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 + LDAP LDAP `mapstructure:"ldap"` + HTTP HTTP `mapstructure:"http"` + GRPC GRPC `mapstructure:"grpc"` + Server Server `mapstructure:"server"` + Asset Asset `mapstructure:"asset"` + Log Log `mapstructure:"log"` + TokenManager TokenManager `mapstructure:"token_manager"` + Repo Repo `mapstructure:"repo"` + Index Index `mapstructure:"index"` + ServiceUser ServiceUser `mapstructure:"service_user"` + Tracing Tracing `mapstructure:"tracing"` Context context.Context Supervised bool @@ -144,3 +151,67 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + LDAP: LDAP{}, + HTTP: HTTP{ + Addr: "127.0.0.1:9181", + Namespace: "com.owncloud.web", + Root: "/", + CacheTTL: 604800, + 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{}, + Log: Log{}, + 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", + }, + } +} From 7ca93450a2360e6d697c8cda0362496586905497 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 11:29:52 +0100 Subject: [PATCH 007/147] adjust accounts flagset, replace new with defaultconfig --- accounts/cmd/accounts/main.go | 2 +- accounts/pkg/flagset/flagset.go | 489 ++++++++++++++++---------------- ocis-pkg/config/config.go | 2 +- ocis/pkg/config/config.go | 2 +- 4 files changed, 246 insertions(+), 249 deletions(-) diff --git a/accounts/cmd/accounts/main.go b/accounts/cmd/accounts/main.go index 553fc79ef7..35262ccad8 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/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index abc32ec571..bbd2c27c96 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -1,11 +1,8 @@ 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" ) @@ -41,249 +38,249 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { // 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", - }, + //&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", + //}, } } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index a61bb89a52..c69ba71473 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -109,7 +109,7 @@ type Config struct { // New initializes a new configuration with or without defaults. func New() *Config { return &Config{ - Accounts: accounts.New(), + Accounts: accounts.DefaultConfig(), GLAuth: glauth.New(), Graph: graph.New(), GraphExplorer: graphExplorer.New(), diff --git a/ocis/pkg/config/config.go b/ocis/pkg/config/config.go index 51fc2db77c..76f3a052a3 100644 --- a/ocis/pkg/config/config.go +++ b/ocis/pkg/config/config.go @@ -86,7 +86,7 @@ type Config struct { // New initializes a new configuration with or without defaults. func New() *Config { return &Config{ - Accounts: accounts.New(), + Accounts: accounts.DefaultConfig(), GLAuth: glauth.New(), Graph: graph.New(), GraphExplorer: graphExplorer.New(), From a767356bba7b5ece0f9bb039b132199d3b059561 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 12:09:21 +0100 Subject: [PATCH 008/147] provide example config + implement parse config on accounts --- .../pkg/command/accounts_example_config.yaml | 4 ++ accounts/pkg/command/root.go | 54 ++++++------------- 2 files changed, 19 insertions(+), 39 deletions(-) create mode 100644 accounts/pkg/command/accounts_example_config.yaml diff --git a/accounts/pkg/command/accounts_example_config.yaml b/accounts/pkg/command/accounts_example_config.yaml new file mode 100644 index 0000000000..38d8419e05 --- /dev/null +++ b/accounts/pkg/command/accounts_example_config.yaml @@ -0,0 +1,4 @@ +log: + level: info + color: true + pretty: true diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 6a840af40e..989a5841e2 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -3,14 +3,14 @@ package command import ( "context" "os" - "strings" + + gofig "github.com/gookit/config/v2" + gooyaml "github.com/gookit/config/v2/yaml" "github.com/owncloud/ocis/accounts/pkg/config" 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" ) @@ -78,47 +78,23 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// 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) + // create a new config and load files and env values onto it since this needs to be thread-safe. + cnf := gofig.NewWithOptions("accounts", gofig.ParseEnv) - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("ACCOUNTS") - viper.AutomaticEnv() + // TODO(refs) add ENV + toml + json + cnf.AddDriver(gooyaml.Driver) - if c.IsSet("config-file") { - viper.SetConfigFile(c.String("config-file")) - } else { - viper.SetConfigName(defaultFilename) - - for _, v := range defaultConfigPaths { - viper.AddConfigPath(v) - } + // TODO(refs) load from expected locations with the expected name + err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/accounts/pkg/command/accounts_example_config.yaml") + if err != nil { + // we have to swallow the error, since it is not mission critical a + // config file is missing and default values are loaded instead. + //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") - } + err = cnf.BindStruct("", cfg) return nil } From 10731c3878977237ad9f34834bce8b78b4f38d30 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 12:12:09 +0100 Subject: [PATCH 009/147] general restructuring --- accounts/pkg/command/accounts_example_config.yaml | 3 +++ accounts/pkg/command/root.go | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/accounts/pkg/command/accounts_example_config.yaml b/accounts/pkg/command/accounts_example_config.yaml index 38d8419e05..bb3c6019da 100644 --- a/accounts/pkg/command/accounts_example_config.yaml +++ b/accounts/pkg/command/accounts_example_config.yaml @@ -2,3 +2,6 @@ log: level: info color: true pretty: true +repo: + cs3: + provider_addr: "localhost:9214" diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 989a5841e2..325b589bd4 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -27,16 +27,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) From ab1703c2e898bd14a2665af7739b95b77dff0c9f Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 14:19:14 +0100 Subject: [PATCH 010/147] refactor around config parsing --- .../pkg/command/accounts_example_config.yaml | 7 -- accounts/pkg/command/root.go | 21 +---- ocis-pkg/config/helpers.go | 80 +++++++++++++++++++ proxy/pkg/command/proxy_example_config.yaml | 6 -- proxy/pkg/command/root.go | 19 +---- 5 files changed, 82 insertions(+), 51 deletions(-) delete mode 100644 accounts/pkg/command/accounts_example_config.yaml create mode 100644 ocis-pkg/config/helpers.go delete mode 100644 proxy/pkg/command/proxy_example_config.yaml diff --git a/accounts/pkg/command/accounts_example_config.yaml b/accounts/pkg/command/accounts_example_config.yaml deleted file mode 100644 index bb3c6019da..0000000000 --- a/accounts/pkg/command/accounts_example_config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -log: - level: info - color: true - pretty: true -repo: - cs3: - provider_addr: "localhost:9214" diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 325b589bd4..3109ae54b1 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -4,9 +4,6 @@ import ( "context" "os" - gofig "github.com/gookit/config/v2" - gooyaml "github.com/gookit/config/v2/yaml" - "github.com/owncloud/ocis/accounts/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -76,23 +73,7 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - // create a new config and load files and env values onto it since this needs to be thread-safe. - cnf := gofig.NewWithOptions("accounts", gofig.ParseEnv) - - // TODO(refs) add ENV + toml + json - cnf.AddDriver(gooyaml.Driver) - - // TODO(refs) load from expected locations with the expected name - err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/accounts/pkg/command/accounts_example_config.yaml") - if err != nil { - // we have to swallow the error, since it is not mission critical a - // config file is missing and default values are loaded instead. - //return err - } - - err = cnf.BindStruct("", cfg) - - return nil + return ociscfg.BindSourcesToStructs("accounts", cfg) } // SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree. diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go new file mode 100644 index 0000000000..175c0b6a1e --- /dev/null +++ b/ocis-pkg/config/helpers.go @@ -0,0 +1,80 @@ +package config + +import ( + "io/fs" + "os" + "path/filepath" + "strings" + + gofig "github.com/gookit/config/v2" + 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. For the purposes of the PR MVP we will focus on yaml, looking + // into extending it to all supported drivers. + supportedExtensions = []string{ + "yaml", + "yml", + } +) + +// 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 { + _fs := os.DirFS(defaultLocations[i]) + pattern := filename + ".*" + matched, _ := fs.Glob(_fs, 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{}) error { + sources := DefaultConfigSources(extension, supportedExtensions) + cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv) + cnf.AddDriver(gooyaml.Driver) + _ = cnf.LoadFiles(sources...) + + err := cnf.BindStruct("", &dst) + if err != nil { + return err + } + + return nil +} diff --git a/proxy/pkg/command/proxy_example_config.yaml b/proxy/pkg/command/proxy_example_config.yaml deleted file mode 100644 index 0c2bff022d..0000000000 --- a/proxy/pkg/command/proxy_example_config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -log: - level: info - color: true - pretty: true -http: - addr: "${PROXY_HTTP_ADDR|localhost:2222}" diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 54506cac8e..3603180d0d 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -4,8 +4,6 @@ import ( "context" "os" - gofig "github.com/gookit/config/v2" - gooyaml "github.com/gookit/config/v2/yaml" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" @@ -69,22 +67,7 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads proxy configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - // create a new config and load files and env values onto it since this needs to be thread-safe. - cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv) - - // TODO(refs) add ENV + toml + json - cnf.AddDriver(gooyaml.Driver) - - // TODO(refs) load from expected locations with the expected name - err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/proxy/pkg/command/proxy_example_config.yaml") - if err != nil { - return err - } - - // bind all keys to cfg, as we expect an entire proxy.[yaml, toml...] to define all keys and not only sub values. - err = cnf.BindStruct("", cfg) - - return nil + return ociscfg.BindSourcesToStructs("proxy", cfg) } // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. From 2a14bb362a7e7a5bdb36993c2da0d325510d6f17 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 14:48:40 +0100 Subject: [PATCH 011/147] fix smells --- accounts/pkg/command/root.go | 5 ----- ocis-pkg/service/http/service.go | 9 --------- ocis/pkg/command/root.go | 3 +++ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 3109ae54b1..0c0e3d8508 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -12,11 +12,6 @@ import ( "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{ diff --git a/ocis-pkg/service/http/service.go b/ocis-pkg/service/http/service.go index 98317e7a9a..2af5e9d7e5 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" @@ -34,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/command/root.go b/ocis/pkg/command/root.go index 43fbafa8ba..75408d5d79 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -75,6 +75,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { } err = cnf.BindStruct("", cfg) + if err != nil { + return err + } return nil } From 24b336331094c345f7fbe9fa85618f2d472fb5d8 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 2 Nov 2021 14:50:31 +0100 Subject: [PATCH 012/147] rename _fs -> dirFS --- ocis-pkg/config/helpers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 175c0b6a1e..40e3e7471b 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -33,9 +33,9 @@ func DefaultConfigSources(filename string, drivers []string) []string { var sources []string for i := range defaultLocations { - _fs := os.DirFS(defaultLocations[i]) + dirFS := os.DirFS(defaultLocations[i]) pattern := filename + ".*" - matched, _ := fs.Glob(_fs, pattern) + matched, _ := fs.Glob(dirFS, pattern) if len(matched) > 0 { // prepend path to results for j := 0; j < len(matched); j++ { From d54fc2f5b978df4df49c8ca43c785c3568cf5f89 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 11:34:43 +0100 Subject: [PATCH 013/147] ignoring config/ ignores changes done to extensions config packages --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0f6d809d95..9a2e33a360 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ node_modules/ ocis/ocis ocis/cmd/ocis/__debug_bin ocis/cmd/ocis/config/ -config/ .idea From 09195ffc8c02f188f4f12234c80f762ac9a4f77d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 11:34:56 +0100 Subject: [PATCH 014/147] use reflection to set config values from environment --- accounts/pkg/command/root.go | 7 ++- ocis-pkg/config/helpers.go | 6 +-- proxy/pkg/command/root.go | 14 +++++- proxy/pkg/config/env_mapping.go | 82 +++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 proxy/pkg/config/env_mapping.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 0c0e3d8508..5849a808b6 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -68,7 +68,12 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - return ociscfg.BindSourcesToStructs("accounts", cfg) + _, err := ociscfg.BindSourcesToStructs("accounts", cfg) + if err != nil { + return err + } + + return nil } // SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree. diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 40e3e7471b..660befed65 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -65,7 +65,7 @@ func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) [] // 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{}) error { +func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) { sources := DefaultConfigSources(extension, supportedExtensions) cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv) cnf.AddDriver(gooyaml.Driver) @@ -73,8 +73,8 @@ func BindSourcesToStructs(extension string, dst interface{}) error { err := cnf.BindStruct("", &dst) if err != nil { - return err + return nil, err } - return nil + return cnf, nil } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 3603180d0d..0eaa5260a4 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -67,7 +67,19 @@ func NewLogger(cfg *config.Config) log.Logger { // ParseConfig loads proxy configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - return ociscfg.BindSourcesToStructs("proxy", cfg) + conf, err := ociscfg.BindSourcesToStructs("proxy", cfg) + if err != nil { + return err + } + + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) + + if err = config.UnmapEnv(conf, cfg); err != nil { + return err + } + + return nil } // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. diff --git a/proxy/pkg/config/env_mapping.go b/proxy/pkg/config/env_mapping.go new file mode 100644 index 0000000000..77c999921d --- /dev/null +++ b/proxy/pkg/config/env_mapping.go @@ -0,0 +1,82 @@ +package config + +import ( + "fmt" + "reflect" + "strings" + + gofig "github.com/gookit/config/v2" +) + +var mappings = []struct { + gType string // expected type, used for decoding. It is the type expected from gookit. + envName string // name of the env var + tagName string // name of the tag to select the value from. Tag names are to be unique. +}{ + { + gType: "bool", + envName: "PROXY_ENABLE_BASIC_AUTH", + tagName: "enable_basic_auth", + }, +} + +// GetEnv fetches a list of known env variables for this extension. +func GetEnv() []string { + var r []string + for i := range mappings { + r = append(r, mappings[i].envName) + } + + return r +} + +func UnmapEnv(gooconf *gofig.Config, cfg *Config) error { + for i := range mappings { + switch mappings[i].gType { + case "bool": + v := gooconf.Bool(mappings[i].envName) + if err := setField(cfg, mappings[i].tagName, v); err != nil { + return err + } + case "string": + v := gooconf.String(mappings[i].envName) + if err := setField(cfg, mappings[i].tagName, v); err != nil { + return err + } + default: + return fmt.Errorf("invalid type for env var: `%v`", mappings[i].envName) + } + } + + return nil +} + +// setField allows us to set a value on a struct selecting by its `mapstructure` tag. +func setField(item interface{}, fieldName string, value interface{}) error { + v := reflect.ValueOf(item).Elem() + if !v.CanAddr() { + return fmt.Errorf("cannot assign to the item passed, item must be a pointer in order to assign") + } + fName := func(t reflect.StructTag) (string, error) { + if jt, ok := t.Lookup("mapstructure"); ok { + return strings.Split(jt, ",")[0], nil + } + return "", fmt.Errorf("tag %s provided does not define a json tag", fieldName) + } + + fieldNames := map[string]int{} + for i := 0; i < v.NumField(); i++ { + typeField := v.Type().Field(i) + tag := typeField.Tag + jName, _ := fName(tag) + fieldNames[jName] = i + } + + fieldNum, ok := fieldNames[fieldName] + if !ok { + return fmt.Errorf("field does not exist within the provided item") + } + fieldVal := v.Field(fieldNum) + fieldVal.Set(reflect.ValueOf(value)) + return nil +} From 850fe65f4b52fa817feb1cb180746964f5c58b26 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 11:39:23 +0100 Subject: [PATCH 015/147] comments for mappings --- proxy/pkg/config/env_mapping.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/proxy/pkg/config/env_mapping.go b/proxy/pkg/config/env_mapping.go index 77c999921d..6e34a3a2d4 100644 --- a/proxy/pkg/config/env_mapping.go +++ b/proxy/pkg/config/env_mapping.go @@ -8,6 +8,23 @@ import ( gofig "github.com/gookit/config/v2" ) +// mappings holds a record of how to get an env variable's value onto a config.Config value. Field selectors are made via +// the `tagName` field. For instance having the following value: +// type example struct { +// enable `mapstructure:"enable"` +// } +// +// e := example{enable: false} +// +// we can link the field `e.enable` with the environment variable EXTENSION_ENABLE by adding an entry in this mappings: +// { +// gType: "bool", +// envName: "EXTENSION_ENABLE", +// tagName: "enable", +// } +// +// so when a config is parsed the value is read from the environment, parsed and loaded onto whatever destination +// has the tagName. var mappings = []struct { gType string // expected type, used for decoding. It is the type expected from gookit. envName string // name of the env var From ac373dd004017b7cec10b1c76fdaad72cbaf2b56 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 11:49:21 +0100 Subject: [PATCH 016/147] add mode mappings to proxy config struct --- proxy/pkg/config/config.go | 67 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 9d8a3a3949..13cbb0eefd 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -9,23 +9,23 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"log_level"` + Pretty bool `mapstructure:"log_pretty"` + Color bool `mapstructure:"log_color"` + File string `mapstructure:"log_file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"debug_addr"` + Token string `mapstructure:"debug_token"` + Pprof bool `mapstructure:"debug_pprof"` + Zpages bool `mapstructure:"debug_zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `mapstructure:"addr"` + Addr string `mapstructure:"http_addr"` Root string `mapstructure:"http_root"` TLSCert string `mapstructure:"http_tls_cert"` TLSKey string `mapstructure:"http_tls_key"` @@ -34,32 +34,32 @@ type HTTP struct { // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `mapstructure:"service_name"` + Namespace string `mapstructure:"service_namespace"` + Version string `mapstructure:"service_version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"tracing_enabled"` + Type string `mapstructure:"tracing_type"` + Endpoint string `mapstructure:"tracing_endpoint"` + Collector string `mapstructure:"tracing_collector"` + Service string `mapstructure:"tracing_service"` } // Policy enables us to use multiple directors. type Policy struct { - Name string - Routes []Route + Name string `mapstructure:"policy_name"` + Routes []Route `mapstructure:"policy_routes"` } // Route define forwarding routes type Route struct { - Type RouteType - Endpoint string - Backend string - ApacheVHost bool `mapstructure:"apache-vhost"` + Type RouteType `mapstructure:"route_type"` + Endpoint string `mapstructure:"route_endpoint"` + Backend string `mapstructure:"route_backend"` + ApacheVHost bool `mapstructure:"apache-vhost"` } // RouteType defines the type of a route @@ -83,24 +83,24 @@ var ( // Reva defines all available REVA configuration. type Reva struct { - Address string - Middleware Middleware + Address string `mapstructure:"reva_address"` + Middleware Middleware `mapstructure:"reva_middleware"` } // Middleware configures proxy middlewares. type Middleware struct { - Auth Auth + Auth Auth `mapstructure:""` } // Auth configures proxy http auth middleware. type Auth struct { - CredentialsByUserAgent map[string]string + CredentialsByUserAgent map[string]string `mapstructure:""` } // Cache is a TTL cache configuration. type Cache struct { - Size int - TTL int + Size int `mapstructure:"cache_size"` + TTL int `mapstructure:"cache_ttl"` } // Config combines all available configuration parts. @@ -132,9 +132,9 @@ 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 `mapstructure:"issuer"` - Insecure bool `mapstructure:"insecure"` - UserinfoCache Cache `mapstructure:"user_info_cache"` + Issuer string `mapstructure:"oidc_issuer"` + Insecure bool `mapstructure:"oidc_insecure"` + UserinfoCache Cache `mapstructure:"oidc_user_info_cache"` } // PolicySelector is the toplevel-configuration for different selectors @@ -147,7 +147,7 @@ type PolicySelector struct { // StaticSelectorConf is the config for the static-policy-selector type StaticSelectorConf struct { - Policy string `mapstructure:"policy"` + Policy string `mapstructure:"static_selector_policy"` } // TokenManager is the config for using the reva token manager @@ -182,6 +182,7 @@ type RegexSelectorConf struct { UnauthenticatedPolicy string `mapstructure:"unauthenticated_policy"` SelectorCookieName string `mapstructure:"selector_cookie_name"` } + type RegexRuleConf struct { Priority int `mapstructure:"priority"` Property string `mapstructure:"property"` From 90844c5c84a76ddb727db7e24f887f3818d17d1d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 14:46:38 +0100 Subject: [PATCH 017/147] first draft of config loading exclusively using env vars --- proxy/pkg/command/root.go | 2 +- proxy/pkg/config/config.go | 72 ++++++++++++------------ proxy/pkg/config/env.go | 55 ++++++++++++++++++ proxy/pkg/config/env_mapping.go | 99 --------------------------------- proxy/pkg/config/mappings.go | 27 +++++++++ 5 files changed, 119 insertions(+), 136 deletions(-) create mode 100644 proxy/pkg/config/env.go delete mode 100644 proxy/pkg/config/env_mapping.go create mode 100644 proxy/pkg/config/mappings.go diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 0eaa5260a4..ae5ce38b39 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -75,7 +75,7 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = config.UnmapEnv(conf, cfg); err != nil { + if err = cfg.UnmapEnv(conf); err != nil { return err } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 13cbb0eefd..5e9c1fb94a 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -9,56 +9,56 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string `mapstructure:"log_level"` - Pretty bool `mapstructure:"log_pretty"` - Color bool `mapstructure:"log_color"` - File string `mapstructure:"log_file"` + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"debug_addr"` - Token string `mapstructure:"debug_token"` - Pprof bool `mapstructure:"debug_pprof"` - Zpages bool `mapstructure:"debug_zpages"` + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string `mapstructure:"http_addr"` - Root string `mapstructure:"http_root"` - TLSCert string `mapstructure:"http_tls_cert"` - TLSKey string `mapstructure:"http_tls_key"` - TLS bool `mapstructure:"http_tls"` + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + TLSCert string `mapstructure:"tls_cert"` + TLSKey string `mapstructure:"tls_key"` + TLS bool `mapstructure:"tls"` } // Service defines the available service configuration. type Service struct { - Name string `mapstructure:"service_name"` - Namespace string `mapstructure:"service_namespace"` - Version string `mapstructure:"service_version"` + Name string `mapstructure:"name"` + Namespace string `mapstructure:"namespace"` + Version string `mapstructure:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"tracing_enabled"` - Type string `mapstructure:"tracing_type"` - Endpoint string `mapstructure:"tracing_endpoint"` - Collector string `mapstructure:"tracing_collector"` - Service string `mapstructure:"tracing_service"` + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Policy enables us to use multiple directors. type Policy struct { - Name string `mapstructure:"policy_name"` - Routes []Route `mapstructure:"policy_routes"` + Name string `mapstructure:"name"` + Routes []Route `mapstructure:"routes"` } // Route define forwarding routes type Route struct { - Type RouteType `mapstructure:"route_type"` - Endpoint string `mapstructure:"route_endpoint"` - Backend string `mapstructure:"route_backend"` + Type RouteType `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Backend string `mapstructure:"backend"` ApacheVHost bool `mapstructure:"apache-vhost"` } @@ -78,18 +78,18 @@ 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 `mapstructure:"reva_address"` - Middleware Middleware `mapstructure:"reva_middleware"` + Address string `mapstructure:"address"` + Middleware Middleware `mapstructure:"middleware"` } // Middleware configures proxy middlewares. type Middleware struct { - Auth Auth `mapstructure:""` + Auth Auth `mapstructure:"middleware"` } // Auth configures proxy http auth middleware. @@ -99,8 +99,8 @@ type Auth struct { // Cache is a TTL cache configuration. type Cache struct { - Size int `mapstructure:"cache_size"` - TTL int `mapstructure:"cache_ttl"` + Size int `mapstructure:"size"` + TTL int `mapstructure:"ttl"` } // Config combines all available configuration parts. @@ -132,9 +132,9 @@ 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 `mapstructure:"oidc_issuer"` - Insecure bool `mapstructure:"oidc_insecure"` - UserinfoCache Cache `mapstructure:"oidc_user_info_cache"` + Issuer string `mapstructure:"issuer"` + Insecure bool `mapstructure:"insecure"` + UserinfoCache Cache `mapstructure:"user_info_cache"` } // PolicySelector is the toplevel-configuration for different selectors @@ -147,7 +147,7 @@ type PolicySelector struct { // StaticSelectorConf is the config for the static-policy-selector type StaticSelectorConf struct { - Policy string `mapstructure:"static_selector_policy"` + Policy string `mapstructure:"policy"` } // TokenManager is the config for using the reva token manager diff --git a/proxy/pkg/config/env.go b/proxy/pkg/config/env.go new file mode 100644 index 0000000000..d75650ff92 --- /dev/null +++ b/proxy/pkg/config/env.go @@ -0,0 +1,55 @@ +package config + +import ( + "fmt" + + gofig "github.com/gookit/config/v2" +) + +type mapping struct { + goType string // expected type, used for decoding. It is the field dynamic type. + env string // name of the env var. + destination interface{} // memory address of the original config value to modify. +} + +// 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].env) + } + + return r +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + // 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 := gooconf.GetValue(vals[i].env); ok && v != "" { + switch vals[i].goType { + case "bool": + r := gooconf.Bool(vals[i].env) + *vals[i].destination.(*bool) = r + case "string": + r := gooconf.String(vals[i].env) + *vals[i].destination.(*string) = r + case "int": + r := gooconf.Int(vals[i].env) + *vals[i].destination.(*int) = r + case "float": + // defaults to float64 + r := gooconf.Float(vals[i].env) + *vals[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`", vals[i].env) + } + } + } + + return nil +} diff --git a/proxy/pkg/config/env_mapping.go b/proxy/pkg/config/env_mapping.go deleted file mode 100644 index 6e34a3a2d4..0000000000 --- a/proxy/pkg/config/env_mapping.go +++ /dev/null @@ -1,99 +0,0 @@ -package config - -import ( - "fmt" - "reflect" - "strings" - - gofig "github.com/gookit/config/v2" -) - -// mappings holds a record of how to get an env variable's value onto a config.Config value. Field selectors are made via -// the `tagName` field. For instance having the following value: -// type example struct { -// enable `mapstructure:"enable"` -// } -// -// e := example{enable: false} -// -// we can link the field `e.enable` with the environment variable EXTENSION_ENABLE by adding an entry in this mappings: -// { -// gType: "bool", -// envName: "EXTENSION_ENABLE", -// tagName: "enable", -// } -// -// so when a config is parsed the value is read from the environment, parsed and loaded onto whatever destination -// has the tagName. -var mappings = []struct { - gType string // expected type, used for decoding. It is the type expected from gookit. - envName string // name of the env var - tagName string // name of the tag to select the value from. Tag names are to be unique. -}{ - { - gType: "bool", - envName: "PROXY_ENABLE_BASIC_AUTH", - tagName: "enable_basic_auth", - }, -} - -// GetEnv fetches a list of known env variables for this extension. -func GetEnv() []string { - var r []string - for i := range mappings { - r = append(r, mappings[i].envName) - } - - return r -} - -func UnmapEnv(gooconf *gofig.Config, cfg *Config) error { - for i := range mappings { - switch mappings[i].gType { - case "bool": - v := gooconf.Bool(mappings[i].envName) - if err := setField(cfg, mappings[i].tagName, v); err != nil { - return err - } - case "string": - v := gooconf.String(mappings[i].envName) - if err := setField(cfg, mappings[i].tagName, v); err != nil { - return err - } - default: - return fmt.Errorf("invalid type for env var: `%v`", mappings[i].envName) - } - } - - return nil -} - -// setField allows us to set a value on a struct selecting by its `mapstructure` tag. -func setField(item interface{}, fieldName string, value interface{}) error { - v := reflect.ValueOf(item).Elem() - if !v.CanAddr() { - return fmt.Errorf("cannot assign to the item passed, item must be a pointer in order to assign") - } - fName := func(t reflect.StructTag) (string, error) { - if jt, ok := t.Lookup("mapstructure"); ok { - return strings.Split(jt, ",")[0], nil - } - return "", fmt.Errorf("tag %s provided does not define a json tag", fieldName) - } - - fieldNames := map[string]int{} - for i := 0; i < v.NumField(); i++ { - typeField := v.Type().Field(i) - tag := typeField.Tag - jName, _ := fName(tag) - fieldNames[jName] = i - } - - fieldNum, ok := fieldNames[fieldName] - if !ok { - return fmt.Errorf("field does not exist within the provided item") - } - fieldVal := v.Field(fieldNum) - fieldVal.Set(reflect.ValueOf(value)) - return nil -} diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go new file mode 100644 index 0000000000..8bab88fe26 --- /dev/null +++ b/proxy/pkg/config/mappings.go @@ -0,0 +1,27 @@ +package config + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + goType: "bool", + env: "PROXY_ENABLE_BASIC_AUTH", + destination: &cfg.EnableBasicAuth, + }, + { + goType: "string", + env: "PROXY_LOG_LEVEL", + destination: &cfg.Log.Level, + }, + { + goType: "bool", + env: "PROXY_LOG_COLOR", + destination: &cfg.Log.Color, + }, + { + goType: "bool", + env: "PROXY_LOG_PRETTY", + destination: &cfg.Log.Pretty, + }, + } +} From 7ac71b65f65c5066051bfe10ca5041a77be66586 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 14:56:31 +0100 Subject: [PATCH 018/147] backwards compatibility with urfave/cli --- proxy/pkg/config/env.go | 46 +++++++++++++++++++----------------- proxy/pkg/config/mappings.go | 8 +++---- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/proxy/pkg/config/env.go b/proxy/pkg/config/env.go index d75650ff92..23848cd052 100644 --- a/proxy/pkg/config/env.go +++ b/proxy/pkg/config/env.go @@ -8,7 +8,7 @@ import ( type mapping struct { goType string // expected type, used for decoding. It is the field dynamic type. - env string // name of the env var. + env []string // name of the env var. destination interface{} // memory address of the original config value to modify. } @@ -17,7 +17,7 @@ type mapping struct { func GetEnv() []string { var r = make([]string, len(structMappings(&Config{}))) for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].env) + r = append(r, structMappings(&Config{})[i].env...) } return r @@ -27,26 +27,28 @@ func GetEnv() []string { func (c *Config) UnmapEnv(gooconf *gofig.Config) error { vals := structMappings(c) for i := range vals { - // 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 := gooconf.GetValue(vals[i].env); ok && v != "" { - switch vals[i].goType { - case "bool": - r := gooconf.Bool(vals[i].env) - *vals[i].destination.(*bool) = r - case "string": - r := gooconf.String(vals[i].env) - *vals[i].destination.(*string) = r - case "int": - r := gooconf.Int(vals[i].env) - *vals[i].destination.(*int) = r - case "float": - // defaults to float64 - r := gooconf.Float(vals[i].env) - *vals[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`", vals[i].env) + for j := range vals[i].env { + // 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 := gooconf.GetValue(vals[i].env[j]); ok && v != "" { + switch vals[i].goType { + case "bool": + r := gooconf.Bool(vals[i].env[j]) + *vals[i].destination.(*bool) = r + case "string": + r := gooconf.String(vals[i].env[j]) + *vals[i].destination.(*string) = r + case "int": + r := gooconf.Int(vals[i].env[j]) + *vals[i].destination.(*int) = r + case "float": + // defaults to float64 + r := gooconf.Float(vals[i].env[j]) + *vals[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`", vals[i].env[j]) + } } } } diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 8bab88fe26..948e09e149 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -5,22 +5,22 @@ func structMappings(cfg *Config) []mapping { return []mapping{ { goType: "bool", - env: "PROXY_ENABLE_BASIC_AUTH", + env: []string{"PROXY_ENABLE_BASIC_AUTH"}, destination: &cfg.EnableBasicAuth, }, { goType: "string", - env: "PROXY_LOG_LEVEL", + env: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, destination: &cfg.Log.Level, }, { goType: "bool", - env: "PROXY_LOG_COLOR", + env: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, destination: &cfg.Log.Color, }, { goType: "bool", - env: "PROXY_LOG_PRETTY", + env: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, destination: &cfg.Log.Pretty, }, } From 572e238dcd4620f80fc09119bd5fa70922d06b76 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 16:01:45 +0100 Subject: [PATCH 019/147] infere go type from destination --- proxy/pkg/config/env.go | 14 +-- proxy/pkg/config/mappings.go | 190 +++++++++++++++++++++++++++++++++-- 2 files changed, 190 insertions(+), 14 deletions(-) diff --git a/proxy/pkg/config/env.go b/proxy/pkg/config/env.go index 23848cd052..3af7345803 100644 --- a/proxy/pkg/config/env.go +++ b/proxy/pkg/config/env.go @@ -2,12 +2,12 @@ package config import ( "fmt" + "reflect" gofig "github.com/gookit/config/v2" ) type mapping struct { - goType string // expected type, used for decoding. It is the field dynamic type. env []string // name of the env var. destination interface{} // memory address of the original config value to modify. } @@ -31,17 +31,19 @@ func (c *Config) UnmapEnv(gooconf *gofig.Config) error { // 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 := gooconf.GetValue(vals[i].env[j]); ok && v != "" { - switch vals[i].goType { - case "bool": + + // get the destination type from destination + switch reflect.ValueOf(vals[i].destination).Type().String() { + case "*bool": r := gooconf.Bool(vals[i].env[j]) *vals[i].destination.(*bool) = r - case "string": + case "*string": r := gooconf.String(vals[i].env[j]) *vals[i].destination.(*string) = r - case "int": + case "*int": r := gooconf.Int(vals[i].env[j]) *vals[i].destination.(*int) = r - case "float": + case "*float64": // defaults to float64 r := gooconf.Float(vals[i].env[j]) *vals[i].destination.(*float64) = r diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 948e09e149..762426330e 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -3,25 +3,199 @@ package config // structMappings binds a set of environment variables to a destination on cfg. func structMappings(cfg *Config) []mapping { return []mapping{ + // Logging { - goType: "bool", - env: []string{"PROXY_ENABLE_BASIC_AUTH"}, - destination: &cfg.EnableBasicAuth, - }, - { - goType: "string", env: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, destination: &cfg.Log.Level, }, { - goType: "bool", env: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, destination: &cfg.Log.Color, }, { - goType: "bool", env: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, destination: &cfg.Log.Pretty, }, + { + env: []string{"PROXY_LOG_FILE", "OCIS_LOG_FILE"}, + destination: &cfg.Log.File, + }, + + // Basic auth + { + env: []string{"PROXY_ENABLE_BASIC_AUTH"}, + destination: &cfg.EnableBasicAuth, + }, + + // Debug (health) + { + env: []string{"PROXY_DEBUG_ADDR"}, + destination: &cfg.Debug.Addr, + }, + + { + env: []string{"PROXY_CONFIG_FILE"}, + destination: &cfg.File, + }, + + // Tracing + { + env: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + destination: &cfg.Tracing.Enabled, + }, + { + env: []string{"PROXY_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + destination: &cfg.Tracing.Type, + }, + { + env: []string{"PROXY_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + destination: &cfg.Tracing.Endpoint, + }, + { + env: []string{"PROXY_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + destination: &cfg.Tracing.Collector, + }, + { + env: []string{"PROXY_TRACING_SERVICE"}, + destination: &cfg.Tracing.Service, + }, + + // Debug + { + env: []string{"PROXY_DEBUG_ADDR"}, + destination: &cfg.Debug.Addr, + }, + { + env: []string{"PROXY_DEBUG_TOKEN"}, + destination: &cfg.Debug.Token, + }, + { + env: []string{"PROXY_DEBUG_PPROF"}, + destination: &cfg.Debug.Pprof, + }, + { + env: []string{"PROXY_DEBUG_ZPAGES"}, + destination: &cfg.Debug.Zpages, + }, + + // HTTP + { + env: []string{"PROXY_HTTP_ADDR"}, + destination: &cfg.HTTP.Addr, + }, + { + env: []string{"PROXY_HTTP_ROOT"}, + destination: &cfg.HTTP.Root, + }, + + // Service + { + env: []string{"PROXY_SERVICE_NAMESPACE"}, + destination: &cfg.Service.Name, + }, + { + env: []string{"PROXY_SERVICE_NAME"}, + destination: &cfg.Service.Namespace, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, + { + env: nil, + destination: nil, + }, } } From 418cc97fb9f27b81a460038594e608a8489c34e6 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 3 Nov 2021 16:32:11 +0100 Subject: [PATCH 020/147] update proxy bindings --- proxy/pkg/config/env.go | 30 +++--- proxy/pkg/config/mappings.go | 191 +++++++++++++++-------------------- 2 files changed, 96 insertions(+), 125 deletions(-) diff --git a/proxy/pkg/config/env.go b/proxy/pkg/config/env.go index 3af7345803..e8afc953d8 100644 --- a/proxy/pkg/config/env.go +++ b/proxy/pkg/config/env.go @@ -8,8 +8,8 @@ import ( ) type mapping struct { - env []string // name of the env var. - destination interface{} // memory address of the original config value to modify. + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. } // GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list @@ -17,7 +17,7 @@ type mapping struct { func GetEnv() []string { var r = make([]string, len(structMappings(&Config{}))) for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].env...) + r = append(r, structMappings(&Config{})[i].EnvVars...) } return r @@ -27,29 +27,29 @@ func GetEnv() []string { func (c *Config) UnmapEnv(gooconf *gofig.Config) error { vals := structMappings(c) for i := range vals { - for j := range vals[i].env { + for j := range vals[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 := gooconf.GetValue(vals[i].env[j]); ok && v != "" { + if v, ok := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { // get the destination type from destination - switch reflect.ValueOf(vals[i].destination).Type().String() { + switch reflect.ValueOf(vals[i].Destination).Type().String() { case "*bool": - r := gooconf.Bool(vals[i].env[j]) - *vals[i].destination.(*bool) = r + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r case "*string": - r := gooconf.String(vals[i].env[j]) - *vals[i].destination.(*string) = r + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r case "*int": - r := gooconf.Int(vals[i].env[j]) - *vals[i].destination.(*int) = r + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r case "*float64": // defaults to float64 - r := gooconf.Float(vals[i].env[j]) - *vals[i].destination.(*float64) = r + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].env[j]) + return fmt.Errorf("invalid type for env var: `%v`", vals[i].EnvVars[j]) } } } diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 762426330e..a0c6467db7 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -5,197 +5,168 @@ func structMappings(cfg *Config) []mapping { return []mapping{ // Logging { - env: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, - destination: &cfg.Log.Level, + EnvVars: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, }, { - env: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, - destination: &cfg.Log.Color, + EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, }, { - env: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, - destination: &cfg.Log.Pretty, + EnvVars: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, }, { - env: []string{"PROXY_LOG_FILE", "OCIS_LOG_FILE"}, - destination: &cfg.Log.File, + EnvVars: []string{"PROXY_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, }, // Basic auth { - env: []string{"PROXY_ENABLE_BASIC_AUTH"}, - destination: &cfg.EnableBasicAuth, + EnvVars: []string{"PROXY_ENABLE_BASIC_AUTH"}, + Destination: &cfg.EnableBasicAuth, }, // Debug (health) { - env: []string{"PROXY_DEBUG_ADDR"}, - destination: &cfg.Debug.Addr, + EnvVars: []string{"PROXY_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, }, { - env: []string{"PROXY_CONFIG_FILE"}, - destination: &cfg.File, + EnvVars: []string{"PROXY_CONFIG_FILE"}, + Destination: &cfg.File, }, // Tracing { - env: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - destination: &cfg.Tracing.Enabled, + EnvVars: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, }, { - env: []string{"PROXY_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - destination: &cfg.Tracing.Type, + EnvVars: []string{"PROXY_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, }, { - env: []string{"PROXY_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - destination: &cfg.Tracing.Endpoint, + EnvVars: []string{"PROXY_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, }, { - env: []string{"PROXY_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, - destination: &cfg.Tracing.Collector, + EnvVars: []string{"PROXY_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + Destination: &cfg.Tracing.Collector, }, { - env: []string{"PROXY_TRACING_SERVICE"}, - destination: &cfg.Tracing.Service, + EnvVars: []string{"PROXY_TRACING_SERVICE"}, + Destination: &cfg.Tracing.Service, }, // Debug { - env: []string{"PROXY_DEBUG_ADDR"}, - destination: &cfg.Debug.Addr, + EnvVars: []string{"PROXY_DEBUG_ADDR"}, + Destination: &cfg.Debug.Addr, }, { - env: []string{"PROXY_DEBUG_TOKEN"}, - destination: &cfg.Debug.Token, + EnvVars: []string{"PROXY_DEBUG_TOKEN"}, + Destination: &cfg.Debug.Token, }, { - env: []string{"PROXY_DEBUG_PPROF"}, - destination: &cfg.Debug.Pprof, + EnvVars: []string{"PROXY_DEBUG_PPROF"}, + Destination: &cfg.Debug.Pprof, }, { - env: []string{"PROXY_DEBUG_ZPAGES"}, - destination: &cfg.Debug.Zpages, + EnvVars: []string{"PROXY_DEBUG_ZPAGES"}, + Destination: &cfg.Debug.Zpages, }, // HTTP { - env: []string{"PROXY_HTTP_ADDR"}, - destination: &cfg.HTTP.Addr, + EnvVars: []string{"PROXY_HTTP_ADDR"}, + Destination: &cfg.HTTP.Addr, }, { - env: []string{"PROXY_HTTP_ROOT"}, - destination: &cfg.HTTP.Root, + EnvVars: []string{"PROXY_HTTP_ROOT"}, + Destination: &cfg.HTTP.Root, }, // Service { - env: []string{"PROXY_SERVICE_NAMESPACE"}, - destination: &cfg.Service.Name, + EnvVars: []string{"PROXY_SERVICE_NAMESPACE"}, + Destination: &cfg.Service.Namespace, }, { - env: []string{"PROXY_SERVICE_NAME"}, - destination: &cfg.Service.Namespace, + EnvVars: []string{"PROXY_SERVICE_NAME"}, + Destination: &cfg.Service.Name, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_TRANSPORT_TLS_CERT"}, + Destination: &cfg.HTTP.TLSCert, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_TRANSPORT_TLS_KEY"}, + Destination: &cfg.HTTP.TLSKey, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_TLS"}, + Destination: &cfg.HTTP.TLS, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_JWT_SECRET", "OCIS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.Address, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_INSECURE_BACKENDS"}, + Destination: &cfg.InsecureBackends, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_OIDC_ISSUER", "OCIS_URL"}, // PROXY_OIDC_ISSUER takes precedence over OCIS_URL + Destination: &cfg.OIDC.Issuer, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_OIDC_INSECURE"}, + Destination: &cfg.OIDC.Insecure, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_TTL"}, + Destination: &cfg.OIDC.UserinfoCache.TTL, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_OIDC_USERINFO_CACHE_SIZE"}, + Destination: &cfg.OIDC.UserinfoCache.Size, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_AUTOPROVISION_ACCOUNTS"}, + Destination: &cfg.AutoprovisionAccounts, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_USER_OIDC_CLAIM"}, + Destination: &cfg.UserOIDCClaim, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_USER_CS3_CLAIM"}, + Destination: &cfg.UserCS3Claim, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_ENABLE_PRESIGNEDURLS"}, + Destination: &cfg.PreSignedURL.Enabled, }, { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_ACCOUNT_BACKEND_TYPE"}, + Destination: &cfg.AccountBackend, }, { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, - }, - { - env: nil, - destination: nil, + EnvVars: []string{"PROXY_MACHINE_AUTH_API_KEY", "OCIS_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 } } From 4194da4e884a149ee0e19e8a367916d40dc329c2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 10:53:40 +0100 Subject: [PATCH 021/147] add ocis.yaml --- ocis-pkg/config/config.go | 79 +++++++++++++++++ ocis-pkg/config/helpers.go | 2 +- ocis/pkg/command/ocis_example_config.yaml | 4 - ocis/pkg/command/root.go | 22 ++--- ocis/pkg/config/config.go | 103 ---------------------- proxy/pkg/command/root.go | 2 - 6 files changed, 89 insertions(+), 123 deletions(-) delete mode 100644 ocis/pkg/command/ocis_example_config.yaml diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index c69ba71473..d5c0dc6341 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -1,6 +1,10 @@ package config import ( + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" 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" @@ -124,3 +128,78 @@ func New() *Config { WebDAV: webdav.New(), } } + +// TODO(refs) refactoir refactor this outside +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +// TODO(refs) can we avoid repetition here? +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"OCIS_LOG_FILE"}, + Destination: &cfg.Log.Level, + }, + { + 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, + }, + } +} diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 660befed65..08dd5ed75c 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -67,7 +67,7 @@ func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) [] // 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("proxy", gofig.ParseEnv) + cnf := gofig.NewWithOptions(extension, gofig.ParseEnv) cnf.AddDriver(gooyaml.Driver) _ = cnf.LoadFiles(sources...) diff --git a/ocis/pkg/command/ocis_example_config.yaml b/ocis/pkg/command/ocis_example_config.yaml deleted file mode 100644 index 280f0627aa..0000000000 --- a/ocis/pkg/command/ocis_example_config.yaml +++ /dev/null @@ -1,4 +0,0 @@ -log: - pretty: true - color: true - level: info diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 75408d5d79..c37595ff93 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -3,15 +3,12 @@ package command import ( "os" - gofig "github.com/gookit/config/v2" - gooyaml "github.com/gookit/config/v2/yaml" - - "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/register" + "github.com/urfave/cli/v2" ) // Execute is the entry point for the ocis command. @@ -24,7 +21,7 @@ func Execute() error { Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) + return ParseConfig(cfg) }, Authors: []*cli.Author{ { @@ -66,16 +63,15 @@ func NewLogger(cfg *config.Config) log.Logger { } // ParseConfig loads ocis configuration from known paths. -func ParseConfig(c *cli.Context, cfg *config.Config) error { - cnf := gofig.NewWithOptions("ocis", gofig.ParseEnv) - cnf.AddDriver(gooyaml.Driver) - err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/ocis/pkg/command/ocis_example_config.yaml") +func ParseConfig(cfg *config.Config) error { + conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) if err != nil { return err } - err = cnf.BindStruct("", cfg) - if err != nil { + conf.LoadOSEnv(config.GetEnv(), false) + + if err = cfg.UnmapEnv(conf); err != nil { return err } diff --git a/ocis/pkg/config/config.go b/ocis/pkg/config/config.go index 76f3a052a3..d912156bec 100644 --- a/ocis/pkg/config/config.go +++ b/ocis/pkg/config/config.go @@ -1,104 +1 @@ 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.DefaultConfig(), - GLAuth: glauth.New(), - Graph: graph.New(), - GraphExplorer: graphExplorer.New(), - IDP: idp.New(), - OCS: ocs.New(), - Web: web.New(), - Proxy: proxy.DefaultConfig(), - Settings: settings.New(), - Storage: storage.New(), - Store: store.New(), - Thumbnails: thumbnails.New(), - WebDAV: webdav.New(), - Runtime: pman.NewConfig(), - } -} diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index ae5ce38b39..1753992842 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -27,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 nil From e858fa01889c07b3870b767f7d9ad7ebadf27aa6 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 12:58:18 +0100 Subject: [PATCH 022/147] define ocis_url as a shared option in ocis-pkg/config --- ocis-pkg/config/config.go | 5 +++-- ocis/pkg/command/proxy.go | 2 +- ocis/pkg/command/root.go | 4 ++-- proxy/pkg/command/server.go | 8 ++++++++ proxy/pkg/config/config.go | 2 ++ proxy/pkg/config/mappings.go | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index d5c0dc6341..a2f8b5fafc 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -83,8 +83,9 @@ type Config struct { // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regard 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 + Mode Mode + File string + OcisURL string `mapstructure:"ocis_url"` Registry string `mapstructure:"registry"` Log Log `mapstructure:"log"` diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index aaec5a56ed..29ea6b73b6 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -18,7 +18,6 @@ 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), }, @@ -33,6 +32,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { } func configureProxy(cfg *config.Config) *svcconfig.Config { + cfg.Proxy.OcisURL = cfg.OcisURL cfg.Proxy.Log.Level = cfg.Log.Level cfg.Proxy.Log.Pretty = cfg.Log.Pretty cfg.Proxy.Log.Color = cfg.Log.Color diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index c37595ff93..a004ec77a7 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -21,7 +21,7 @@ func Execute() error { Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), Before: func(c *cli.Context) error { - return ParseConfig(cfg) + return ParseConfig(c, cfg) }, Authors: []*cli.Author{ { @@ -63,7 +63,7 @@ func NewLogger(cfg *config.Config) log.Logger { } // ParseConfig loads ocis configuration from known paths. -func ParseConfig(cfg *config.Config) error { +func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) if err != nil { return err diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 521d2f07db..88c6667870 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -52,6 +52,14 @@ func Server(cfg *config.Config) *cli.Command { cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method") } + // we need a starting point to compare the default config values to determine if the outcome of ParseConfig + // modified a value that should be shared just because it is present in the ocis.yaml file. + defaultConfig := config.DefaultConfig() + + if cfg.OcisURL != "" && cfg.OIDC.Issuer == defaultConfig.OIDC.Issuer { + cfg.OIDC.Issuer = cfg.OcisURL + } + if err := loadUserAgent(ctx, cfg); err != nil { return err } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 5e9c1fb94a..9097390fc1 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -105,6 +105,8 @@ type Cache struct { // Config combines all available configuration parts. type Config struct { + OcisURL string + File string `mapstructure:"file"` Log Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index a0c6467db7..c09936d542 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -123,7 +123,7 @@ func structMappings(cfg *Config) []mapping { Destination: &cfg.InsecureBackends, }, { - EnvVars: []string{"PROXY_OIDC_ISSUER", "OCIS_URL"}, // PROXY_OIDC_ISSUER takes precedence over OCIS_URL + EnvVars: []string{"PROXY_OIDC_ISSUER"}, Destination: &cfg.OIDC.Issuer, }, { From b61887aca17be28bfbf754dbc0b8f1c39c7543f7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 13:16:16 +0100 Subject: [PATCH 023/147] hook accounts to env variables --- accounts/pkg/command/root.go | 11 +- accounts/pkg/command/server.go | 2 - accounts/pkg/config/config.go | 211 +++++++++++++++++++++++++++ accounts/pkg/flagset/flagset.go | 249 -------------------------------- ocis/pkg/command/accounts.go | 3 +- 5 files changed, 221 insertions(+), 255 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 5849a808b6..d2eda25363 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -66,13 +66,20 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads accounts configuration from known paths. +// ParseConfig loads proxy configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs("accounts", cfg) + conf, err := ociscfg.BindSourcesToStructs("accounts", cfg) if err != nil { return err } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) + + if err = cfg.UnmapEnv(conf); err != nil { + return err + } + return nil } diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 6dbabfaffa..acbb7fcd8d 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -8,7 +8,6 @@ import ( "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,7 +22,6 @@ 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 != "/" { diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index cca797c1df..57673bd9ca 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -3,7 +3,11 @@ package config import ( "context" + "fmt" "path" + "reflect" + + gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) @@ -215,3 +219,210 @@ func DefaultConfig() *Config { }, } } + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR", "OCIS_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{"ACCOUNTS_JWT_SECRET", "OCIS_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{"ACCOUNTS_STORAGE_CS3_JWT_SECRET", "OCIS_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, + }, + } +} + +// TODO(refs) What is with the variables with no destination defined? +//&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"}, +//}, diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index bbd2c27c96..7633674a70 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -35,255 +35,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { } } -// 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/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index a89afa655a..910116ceff 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -6,7 +6,6 @@ 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" @@ -19,7 +18,7 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Name: "accounts", Usage: "Start accounts server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Accounts), + //Flags: flagset.ServerWithConfig(cfg.Accounts), Subcommands: []*cli.Command{ command.ListAccounts(cfg.Accounts), command.AddAccount(cfg.Accounts), From cfe1ac30af98036b724ae5a5f722421560b83a8e Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 13:50:42 +0100 Subject: [PATCH 024/147] add graph --- accounts/pkg/command/server.go | 4 +- accounts/pkg/config/config.go | 161 -------------------------------- accounts/pkg/config/env.go | 162 +++++++++++++++++++++++++++++++++ graph/pkg/command/root.go | 49 ++-------- graph/pkg/command/server.go | 4 +- graph/pkg/config/config.go | 150 +++++++++++++++++++++++------- graph/pkg/config/env.go | 100 ++++++++++++++++++++ 7 files changed, 389 insertions(+), 241 deletions(-) create mode 100644 accounts/pkg/config/env.go create mode 100644 graph/pkg/config/env.go diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index acbb7fcd8d..8fc613601a 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -32,9 +32,7 @@ func Server(cfg *config.Config) *cli.Command { // 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) - } + return ParseConfig(ctx, cfg) if origins := ctx.StringSlice("cors-allowed-origins"); len(origins) != 0 { cfg.HTTP.CORS.AllowedOrigins = origins } diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 57673bd9ca..2ca48d58f1 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -265,164 +265,3 @@ func (c *Config) UnmapEnv(gooconf *gofig.Config) error { return nil } - -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. -} - -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []mapping { - return []mapping{ - { - EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, - Destination: &cfg.Log.File, - }, - { - EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, - Destination: &cfg.Tracing.Enabled, - }, - { - EnvVars: []string{"ACCOUNTS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, - Destination: &cfg.Tracing.Type, - }, - { - EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, - Destination: &cfg.Tracing.Endpoint, - }, - { - EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR", "OCIS_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{"ACCOUNTS_JWT_SECRET", "OCIS_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{"ACCOUNTS_STORAGE_CS3_JWT_SECRET", "OCIS_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, - }, - } -} - -// TODO(refs) What is with the variables with no destination defined? -//&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"}, -//}, diff --git a/accounts/pkg/config/env.go b/accounts/pkg/config/env.go new file mode 100644 index 0000000000..6b5e39c132 --- /dev/null +++ b/accounts/pkg/config/env.go @@ -0,0 +1,162 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR", "OCIS_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{"ACCOUNTS_JWT_SECRET", "OCIS_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{"ACCOUNTS_STORAGE_CS3_JWT_SECRET", "OCIS_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, + }, + } +} + +// TODO(refs) What is with the variables with no destination defined? +//&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"}, +//}, diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index cfe7783c9d..67e6103da3 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -3,16 +3,13 @@ package command import ( "context" "os" - "strings" - "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/thejerf/suture/v4" "github.com/owncloud/ocis/graph/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/spf13/viper" "github.com/urfave/cli/v2" ) @@ -31,8 +28,6 @@ func Execute(cfg *config.Config) error { }, }, - //Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Server.Version = version.String return ParseConfig(c, cfg) @@ -68,46 +63,18 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig reads graph configuration from fs. +// ParseConfig loads proxy 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index fb649db7b9..91ca8960a4 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -29,9 +29,7 @@ func Server(cfg *config.Config) *cli.Command { // 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) - } + return ParseConfig(ctx, cfg) logger.Debug().Str("service", "graph").Msg("ignoring config file parsing when running supervised") return nil }, diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index d766029dbf..c59d69dcb0 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -1,72 +1,78 @@ package config -import "context" +import ( + "context" + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" +) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string + Addr string `mapstructure:"addr"` + Namespace string `mapstructure:"namespace"` + Root string `mapstructure:"root"` } // Server configures a server. type Server struct { - Version string - Name string + Version string `mapstructure:"version"` + Name string `mapstructure:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Reva defines all available REVA configuration. type Reva struct { - Address string + Address string `mapstructure:"address"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `mapstructure:"jwt_secret"` } type Spaces struct { - WebDavBase string - WebDavPath string - DefaultQuota string + WebDavBase string `mapstructure:"webdav_base"` + WebDavPath string `mapstructure:"webdav_path"` + DefaultQuota string `mapstructure:"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 + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + Reva Reva `mapstructure:"reva"` + TokenManager TokenManager `mapstructure:"token_manager"` + Spaces Spaces `mapstructure:"spaces"` Context context.Context Supervised bool @@ -76,3 +82,81 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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", + }, + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/graph/pkg/config/env.go b/graph/pkg/config/env.go new file mode 100644 index 0000000000..2f22b33d2b --- /dev/null +++ b/graph/pkg/config/env.go @@ -0,0 +1,100 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"GRAPH_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"GRAPH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"GRAPH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"GRAPH_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"GRAPH_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"GRAPH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"GRAPH_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"GRAPH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"GRAPH_TRACING_COLLECTOR", "OCIS_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{"GRAPH_SPACES_WEBDAV_BASE", "OCIS_URL"}, + 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{"GRAPH_JWT_SECRET", "OCIS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.Reva.Address, + }, + } +} From a76ad08d12d208adad9c76ff998c6d3fb439a911 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 14:19:41 +0100 Subject: [PATCH 025/147] fix dead code logic --- accounts/pkg/command/server.go | 24 +++++++++++++----------- graph/pkg/command/server.go | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 8fc613601a..9ca1112b4b 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -23,7 +23,6 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", Before: func(ctx *cli.Context) error { - logger := NewLogger(cfg) if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -32,17 +31,20 @@ func Server(cfg *config.Config) *cli.Command { // 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. - return ParseConfig(ctx, cfg) - if origins := ctx.StringSlice("cors-allowed-origins"); len(origins) != 0 { - cfg.HTTP.CORS.AllowedOrigins = origins + if err := ParseConfig(ctx, cfg); err != nil { + return err } - 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 - } - logger.Debug().Str("service", "accounts").Msg("ignoring config file parsing when running supervised") + + // TODO(this is not in the cli context anymore) + //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 + //} return nil }, Action: func(c *cli.Context) error { diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 91ca8960a4..5e788db151 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -22,15 +22,15 @@ func Server(cfg *config.Config) *cli.Command { 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. - return ParseConfig(ctx, cfg) - logger.Debug().Str("service", "graph").Msg("ignoring config file parsing when running supervised") + if err := ParseConfig(ctx, cfg); err != nil { + return err + } return nil }, Action: func(c *cli.Context) error { From da36ca8cdef51b65ddb8b0b418f4cb4a47abee65 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Nov 2021 15:56:01 +0100 Subject: [PATCH 026/147] adjust flagsets --- accounts/pkg/flagset/flagset.go | 28 ---- glauth/pkg/command/root.go | 47 +----- glauth/pkg/command/server.go | 26 ++- glauth/pkg/config/config.go | 183 ++++++++++++++++----- glauth/pkg/config/env.go | 152 +++++++++++++++++ glauth/pkg/flagset/flagset.go | 279 -------------------------------- graph/pkg/command/server.go | 2 - graph/pkg/flagset/flagset.go | 135 ---------------- ocis-pkg/config/config.go | 4 +- ocis/pkg/command/glauth.go | 2 - 10 files changed, 315 insertions(+), 543 deletions(-) create mode 100644 glauth/pkg/config/env.go diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 7633674a70..3815f0784a 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -7,34 +7,6 @@ import ( "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", - }, - } -} - // UpdateAccountWithConfig applies update command flags to cfg func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { if a.PasswordProfile == nil { diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index f5af7df620..711f780844 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -3,14 +3,11 @@ package command import ( "context" "os" - "strings" "github.com/owncloud/ocis/glauth/pkg/config" 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" ) @@ -67,46 +64,18 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads glauth configuration from Viper known paths. +// ParseConfig loads proxy 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index b3ae41e53d..7716e8f9c8 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,23 @@ 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 err := ParseConfig(ctx, cfg); err != nil { + return err } - if len(ctx.StringSlice("fallback-server")) > 0 { - cfg.Fallback.Servers = ctx.StringSlice("fallback-server") - } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) - } - logger.Debug().Strs("backend-server", ctx.StringSlice("backend-server")).Str("service", "glauth").Msg("ignoring config file parsing when running supervised") + + // TODO(refs) there is no cli flags anymore... + //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") + //} + return nil }, Action: func(c *cli.Context) error { diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 0d88c318a0..6380aa8c64 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -1,78 +1,86 @@ package config -import "context" +import ( + "context" + "fmt" + "path" + "reflect" + + gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Namespace string - Root string + Addr string `mapstructure:"addr"` + Namespace string `mapstructure:"namespace"` + Root string `mapstructure:"root"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Ldap defined the available LDAP configuration. type Ldap struct { - Addr string - Enabled bool + Enabled bool `mapstructure:"enabled"` + Addr string `mapstructure:"addr"` } // Ldaps defined the available LDAPS configuration. type Ldaps struct { - Addr string - Enabled bool - Cert string - Key string + Addr string `mapstructure:"addr"` + Enabled bool `mapstructure:"enabled"` + Cert string `mapstructure:"cert"` + Key string `mapstructure:"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 `mapstructure:"datastore"` + BaseDN string `mapstructure:"base_dn"` + Insecure bool `mapstructure:"insecure"` + NameFormat string `mapstructure:"name_format"` + GroupFormat string `mapstructure:"group_format"` + Servers []string `mapstructure:"servers"` + SSHKeyAttr string `mapstructure:"ssh_key_attr"` + UseGraphAPI bool `mapstructure:"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 + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Ldap Ldap `mapstructure:"ldap"` + Ldaps Ldaps `mapstructure:"ldaps"` + Backend Backend `mapstructure:"backend"` + Fallback Backend `mapstructure:"fallback"` + Version string `mapstructure:"version"` + RoleBundleUUID string `mapstructure:"role_bundle_uuid"` Context context.Context Supervised bool @@ -82,3 +90,94 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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 + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/glauth/pkg/config/env.go b/glauth/pkg/config/env.go new file mode 100644 index 0000000000..ef48fdc5f4 --- /dev/null +++ b/glauth/pkg/config/env.go @@ -0,0 +1,152 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"GLAUTH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"GLAUTH_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"GLAUTH_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"GLAUTH_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"GLAUTH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"GLAUTH_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"GLAUTH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"GLAUTH_TRACING_COLLECTOR", "OCIS_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 index 9b939e0d4e..4473813848 100644 --- a/glauth/pkg/flagset/flagset.go +++ b/glauth/pkg/flagset/flagset.go @@ -1,38 +1,11 @@ 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{ @@ -45,255 +18,3 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { }, } } - -// 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/graph/pkg/command/server.go b/graph/pkg/command/server.go index 5e788db151..480adca305 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,7 +19,6 @@ 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 { if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index 39326e8789..5216fcd1ab 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -49,138 +49,3 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { }, } } - -// 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/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index a2f8b5fafc..5ed94a55f6 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -115,8 +115,8 @@ type Config struct { func New() *Config { return &Config{ Accounts: accounts.DefaultConfig(), - GLAuth: glauth.New(), - Graph: graph.New(), + GLAuth: glauth.DefaultConfig(), + Graph: graph.DefaultConfig(), GraphExplorer: graphExplorer.New(), IDP: idp.New(), OCS: ocs.New(), diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 6a69699e54..4b9dbade53 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -3,7 +3,6 @@ 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" @@ -16,7 +15,6 @@ 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) }, From ba1635165b9b66424421d52c211ba04685aebaf7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 11:15:55 +0100 Subject: [PATCH 027/147] migrate idp to the new config scheme --- accounts/pkg/command/root.go | 2 +- glauth/pkg/command/root.go | 2 +- graph/pkg/command/root.go | 2 +- graph/pkg/flagset/flagset.go | 31 --- idp/cmd/idp/main.go | 2 +- idp/pkg/command/root.go | 51 +---- idp/pkg/command/server.go | 8 +- idp/pkg/config/config.go | 244 ++++++++++++++++---- idp/pkg/config/env.go | 228 +++++++++++++++++++ idp/pkg/flagset/flagset.go | 406 ---------------------------------- idp/pkg/service/v0/service.go | 5 +- ocis-pkg/config/config.go | 4 +- ocis/pkg/command/accounts.go | 1 - ocis/pkg/command/idp.go | 2 - 14 files changed, 449 insertions(+), 539 deletions(-) create mode 100644 idp/pkg/config/env.go diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index d2eda25363..305e6ae703 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -66,7 +66,7 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from known paths. +// ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("accounts", cfg) if err != nil { diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 711f780844..55b5070d67 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -64,7 +64,7 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from known paths. +// ParseConfig loads glauth configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("glauth", cfg) if err != nil { diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 67e6103da3..606d768788 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -63,7 +63,7 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from known paths. +// ParseConfig loads graph configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("graph", cfg) if err != nil { diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index 5216fcd1ab..d660716e7b 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -6,37 +6,6 @@ import ( "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{ diff --git a/idp/cmd/idp/main.go b/idp/cmd/idp/main.go index 10bf21ffe8..c60ac2f401 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/root.go b/idp/pkg/command/root.go index cccbc36b22..60db566552 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -3,14 +3,11 @@ package command import ( "context" "os" - "strings" "github.com/owncloud/ocis/idp/pkg/config" 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" ) @@ -22,16 +19,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 @@ -68,46 +61,18 @@ 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index 425fc8ad13..97120aa07f 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,9 +19,7 @@ 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, "/") } @@ -41,10 +38,9 @@ func Server(cfg *config.Config) *cli.Command { cfg.IDP.SigningPrivateKeyFiles = ctx.StringSlice("signing-private-key") } - if !cfg.Supervised { - return ParseConfig(ctx, cfg) + if err := ParseConfig(ctx, cfg); err != nil { + return err } - 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/config/config.go b/idp/pkg/config/config.go index 3fac9d0d1e..7d0c2771f4 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -2,82 +2,121 @@ package config import ( "context" + "fmt" + "path" + "reflect" - "github.com/libregraph/lico/bootstrap" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" + + gofig "github.com/gookit/config/v2" ) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - TLSCert string - TLSKey string - TLS bool + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + TLSCert string `mapstructure:"tls_cert"` + TLSKey string `mapstructure:"tls_key"` + TLS bool `mapstructure:"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 `mapstructure:"uri"` + BindDN string `mapstructure:"bind_dn"` + BindPassword string `mapstructure:"bind_password"` + BaseDN string `mapstructure:"base_dn"` + Scope string `mapstructure:"scope"` + LoginAttribute string `mapstructure:"login_attribute"` + EmailAttribute string `mapstructure:"email_attribute"` + NameAttribute string `mapstructure:"name_attribute"` + UUIDAttribute string `mapstructure:"uuid_attribute"` + UUIDAttributeType string `mapstructure:"uuid_attribute_type"` + Filter string `mapstructure:"filter"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `mapstructure:"name"` + Namespace string `mapstructure:"namespace"` + Version string `mapstructure:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `mapstructure:"asset"` +} + +type Settings struct { + Iss string `mapstructure:"iss"` + IdentityManager string `mapstructure:"identity_manager"` + URIBasePath string `mapstructure:"uri_base_path"` + SignInURI string `mapstructure:"sign_in_uri"` + SignedOutURI string `mapstructure:"signed_out_uri"` + AuthorizationEndpointURI string `mapstructure:"authorization_endpoint_uri"` + EndsessionEndpointURI string `mapstructure:"end_session_endpoint_uri"` + Insecure bool `mapstructure:"insecure"` + TrustedProxy []string `mapstructure:"trusted_proxy"` + AllowScope []string `mapstructure:"allow_scope"` + AllowClientGuests bool `mapstructure:"allow_client_guests"` + AllowDynamicClientRegistration bool `mapstructure:"allow_dynamic_client_registration"` + EncryptionSecretFile string `mapstructure:"encrypt_secret_file"` + Listen string `mapstructure:"listen"` + IdentifierClientDisabled bool `mapstructure:"identifier_client_disabled"` + IdentifierClientPath string `mapstructure:"identifier_client_path"` + IdentifierRegistrationConf string `mapstructure:"identifier_registration_conf"` + IdentifierScopesConf string `mapstructure:"identifier_scopes_conf"` + IdentifierDefaultBannerLogo string `mapstructure:"identifier_default_banner_logo"` + IdentifierDefaultSignInPageText string `mapstructure:"identifier_default_sign_in_page_text"` + IdentifierDefaultUsernameHintText string `mapstructure:"identifier_default_username_hint_text"` + SigningKid string `mapstructure:"sign_in_kid"` + SigningMethod string `mapstructure:"sign_in_method"` + SigningPrivateKeyFiles []string `mapstructure:"sign_in_private_key_files"` + ValidationKeysPath string `mapstructure:"validation_keys_path"` + CookieBackendURI string `mapstructure:"cookie_backend_uri"` + CookieNames []string `mapstructure:"cookie_names"` + AccessTokenDurationSeconds uint64 `mapstructure:"access_token_duration_seconds"` + IDTokenDurationSeconds uint64 `mapstructure:"id_token_duration_seconds"` + RefreshTokenDurationSeconds uint64 `mapstructure:"refresh_token_duration_seconds"` + DyamicClientSecretDurationSeconds uint64 `mapstructure:"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 + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"asset"` + IDP Settings `mapstructure:"idp"` + Ldap Ldap `mapstructure:"ldap"` + Service Service `mapstructure:"service"` Context context.Context Supervised bool @@ -87,3 +126,122 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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", + }, + } +} + +// 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(DefaultConfig()))) + for i := range structMappings(DefaultConfig()) { + r = append(r, structMappings(DefaultConfig())[i].EnvVars...) + } + + return r +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/idp/pkg/config/env.go b/idp/pkg/config/env.go new file mode 100644 index 0000000000..71f4639796 --- /dev/null +++ b/idp/pkg/config/env.go @@ -0,0 +1,228 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"IDP_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"IDP_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"IDP_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"IDP_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"IDP_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"IDP_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"IDP_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"IDP_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"IDP_TRACING_COLLECTOR", "OCIS_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{"IDP_ISS", "OCIS_URL"}, // 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 index fbb36d2194..5cbcde7019 100644 --- a/idp/pkg/flagset/flagset.go +++ b/idp/pkg/flagset/flagset.go @@ -1,38 +1,11 @@ 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{ @@ -46,385 +19,6 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { } } -// 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", - 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{ diff --git a/idp/pkg/service/v0/service.go b/idp/pkg/service/v0/service.go index c149b11af4..0f949a91a1 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 5ed94a55f6..81c593d024 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -117,11 +117,11 @@ func New() *Config { Accounts: accounts.DefaultConfig(), GLAuth: glauth.DefaultConfig(), Graph: graph.DefaultConfig(), + IDP: idp.DefaultConfig(), + Proxy: proxy.DefaultConfig(), GraphExplorer: graphExplorer.New(), - IDP: idp.New(), OCS: ocs.New(), Web: web.New(), - Proxy: proxy.DefaultConfig(), Settings: settings.New(), Storage: storage.New(), Store: store.New(), diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 910116ceff..13594bf267 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -18,7 +18,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), diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 46f24ec7b7..7663c94496 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,7 +3,6 @@ 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" @@ -16,7 +15,6 @@ 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), }, From 91c766210c98844ff0e411e57e4884469d0de128 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 11:31:35 +0100 Subject: [PATCH 028/147] migrate graph-explorer to the new config scheme --- graph-explorer/cmd/graph-explorer/main.go | 2 +- graph-explorer/pkg/command/root.go | 50 ++------- graph-explorer/pkg/command/server.go | 11 +- graph-explorer/pkg/config/config.go | 85 ++++++++++++++- graph-explorer/pkg/config/env.go | 80 ++++++++++++++ graph-explorer/pkg/flagset/flagset.go | 125 ---------------------- graph/pkg/command/server.go | 2 - ocis-pkg/config/config.go | 2 +- 8 files changed, 177 insertions(+), 180 deletions(-) create mode 100644 graph-explorer/pkg/config/env.go diff --git a/graph-explorer/cmd/graph-explorer/main.go b/graph-explorer/cmd/graph-explorer/main.go index f0d3cdcac7..a8357cb1f2 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/root.go b/graph-explorer/pkg/command/root.go index 6b3dd841b8..3ebaa4422f 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -3,14 +3,11 @@ package command import ( "context" "os" - "strings" "github.com/owncloud/ocis/graph-explorer/pkg/config" 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" ) @@ -29,9 +26,6 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, - - //Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { cfg.Server.Version = version.String return ParseConfig(c, cfg) @@ -67,46 +61,18 @@ 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") + conf, err := ociscfg.BindSourcesToStructs("graph-explorer", 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index fa15eaf360..773a8b61f0 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,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-explorer").Msg("ignoring config file parsing when running supervised") + return nil }, Action: func(c *cli.Context) error { diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 12653c78c2..8b50a3115b 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -1,6 +1,12 @@ package config -import "context" +import ( + "context" + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" +) // Log defines the available logging configuration. type Log struct { @@ -66,3 +72,80 @@ type Config struct { func New() *Config { return &Config{} } + +// DefaultConfig provides with a working version of a config. +func DefaultConfig() *Config { + return &Config{ + Log: 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/graph-explorer/pkg/config/env.go b/graph-explorer/pkg/config/env.go new file mode 100644 index 0000000000..f36e9d83ae --- /dev/null +++ b/graph-explorer/pkg/config/env.go @@ -0,0 +1,80 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_TRACING_COLLECTOR", "OCIS_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{"GRAPH_EXPLORER_ISSUER", "OCIS_URL"}, + Destination: &cfg.GraphExplorer.Issuer, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_CLIENT_ID"}, + Destination: &cfg.GraphExplorer.ClientID, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_BASE", "OCIS_URL"}, + 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 index 06acd9502a..5215ded0d5 100644 --- a/graph-explorer/pkg/flagset/flagset.go +++ b/graph-explorer/pkg/flagset/flagset.go @@ -42,128 +42,3 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { }, } } - -// 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/server.go b/graph/pkg/command/server.go index 480adca305..cf4b638127 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -24,8 +24,6 @@ func Server(cfg *config.Config) *cli.Command { 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 err := ParseConfig(ctx, cfg); err != nil { return err } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 81c593d024..74771ce4dd 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -119,7 +119,7 @@ func New() *Config { Graph: graph.DefaultConfig(), IDP: idp.DefaultConfig(), Proxy: proxy.DefaultConfig(), - GraphExplorer: graphExplorer.New(), + GraphExplorer: graphExplorer.DefaultConfig(), OCS: ocs.New(), Web: web.New(), Settings: settings.New(), From be9eff8ba8c5ebe1e43a89761a963c755795936c Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 11:37:16 +0100 Subject: [PATCH 029/147] add tags to structs --- graph-explorer/pkg/config/config.go | 58 ++++++++++++++--------------- graph-explorer/pkg/config/env.go | 12 ++++++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 8b50a3115b..3a52e857d4 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -10,59 +10,59 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - Namespace string + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + Namespace string `mapstructure:"namespace"` } // Server configures a server. type Server struct { - Version string - Name string + Version string `mapstructure:"version"` + Name string `mapstructure:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // GraphExplorer defines the available graph-explorer configuration. type GraphExplorer struct { - ClientID string - Issuer string - GraphURLBase string - GraphURLPath string + ClientID string `mapstructure:"client_id"` + Issuer string `mapstructure:"issuer"` + GraphURLBase string `mapstructure:"graph_url_base"` + GraphURLPath string `mapstructure:"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 `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + GraphExplorer GraphExplorer `mapstructure:"graph_explorer"` Context context.Context Supervised bool diff --git a/graph-explorer/pkg/config/env.go b/graph-explorer/pkg/config/env.go index f36e9d83ae..e5dd435e82 100644 --- a/graph-explorer/pkg/config/env.go +++ b/graph-explorer/pkg/config/env.go @@ -8,6 +8,18 @@ type mapping struct { // structMappings binds a set of environment variables to a destination on cfg. func structMappings(cfg *Config) []mapping { return []mapping{ + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"GRAPH_EXPLORER_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, { EnvVars: []string{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"}, Destination: &cfg.Log.File, From ff7022a256d74ff694908752bb01e1eed06a9a46 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 12:06:35 +0100 Subject: [PATCH 030/147] migrate ocs to the new config scheme --- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/ocs.go | 2 - ocs/cmd/ocs/main.go | 2 +- ocs/pkg/command/server.go | 18 +--- ocs/pkg/config/config.go | 98 +++++++++++++++++- ocs/pkg/config/env.go | 108 ++++++++++++++++++++ ocs/pkg/flagset/flagset.go | 198 ------------------------------------- 7 files changed, 210 insertions(+), 218 deletions(-) create mode 100644 ocs/pkg/config/env.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 74771ce4dd..2b18352a69 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -120,7 +120,7 @@ func New() *Config { IDP: idp.DefaultConfig(), Proxy: proxy.DefaultConfig(), GraphExplorer: graphExplorer.DefaultConfig(), - OCS: ocs.New(), + OCS: ocs.DefaultConfig(), Web: web.New(), Settings: settings.New(), Storage: storage.New(), diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 12d39be922..9a08c49d98 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -9,7 +9,6 @@ import ( "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,7 +18,6 @@ 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), }, diff --git a/ocs/cmd/ocs/main.go b/ocs/cmd/ocs/main.go index aac75b441f..ca3ea14b36 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/server.go b/ocs/pkg/command/server.go index 0e66aa9aa4..722673cd13 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 err := ParseConfig(ctx, cfg); err != nil { + return err } - 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 - } - 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/config/config.go b/ocs/pkg/config/config.go index 6ee0377a44..5098589b59 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -1,6 +1,12 @@ package config -import "context" +import ( + "context" + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" +) // Log defines the available logging configuration. type Log struct { @@ -84,3 +90,93 @@ type Config struct { func New() *Config { return &Config{} } + +// DefaultConfig provides default values for a config struct. +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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", + RevaAddress: "127.0.0.1:9142", + StorageUsersDriver: "ocis", + MachineAuthAPIKey: "change-me-please", + IdentityManagement: IdentityManagement{ + Address: "https://localhost:9200", + }, + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/ocs/pkg/config/env.go b/ocs/pkg/config/env.go new file mode 100644 index 0000000000..5ef5ac450d --- /dev/null +++ b/ocs/pkg/config/env.go @@ -0,0 +1,108 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"OCS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"OCS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"OCS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"OCS_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"OCS_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"OCS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"OCS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"OCS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"OCS_TRACING_COLLECTOR", "OCIS_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{"OCS_JWT_SECRET", "OCIS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + { + EnvVars: []string{"OCS_ACCOUNT_BACKEND_TYPE"}, + Destination: &cfg.AccountBackend, + }, + { + EnvVars: []string{"REVA_GATEWAY"}, + Destination: &cfg.RevaAddress, + }, + { + EnvVars: []string{"OCS_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, + Destination: &cfg.MachineAuthAPIKey, + }, + { + EnvVars: []string{"OCS_IDM_ADDRESS", "OCIS_URL"}, + Destination: &cfg.IdentityManagement.Address, + }, + { + EnvVars: []string{"OCS_STORAGE_USERS_DRIVER", "STORAGE_USERS_DRIVER"}, + Destination: &cfg.StorageUsersDriver, + }, + } +} diff --git a/ocs/pkg/flagset/flagset.go b/ocs/pkg/flagset/flagset.go index 378d07eafc..f210b31bc4 100644 --- a/ocs/pkg/flagset/flagset.go +++ b/ocs/pkg/flagset/flagset.go @@ -19,204 +19,6 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { } } -// 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.RevaAddress, "127.0.0.1:9142"), - Usage: "Address of REVA gateway endpoint", - EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.RevaAddress, - }, - &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{ From 28b0b8fccd1946571f39d298af058a07125501a4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 12:10:37 +0100 Subject: [PATCH 031/147] fix ocis root flagset --- ocis/pkg/command/root.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index a004ec77a7..cd2b49eb0f 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -3,6 +3,8 @@ package command import ( "os" + "github.com/owncloud/ocis/ocis/pkg/flagset" + "github.com/owncloud/ocis/ocis-pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -20,6 +22,7 @@ func Execute() error { Version: version.String, Usage: "ownCloud Infinite Scale Stack", Compiled: version.Compiled(), + Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { return ParseConfig(c, cfg) }, From 17dbc3d5ee0432ac32ca3420d2edb8b83a8b9fcb Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 12:25:32 +0100 Subject: [PATCH 032/147] migrate settings to the new config scheme --- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/settings.go | 2 - ocs/pkg/command/root.go | 48 ++------ settings/cmd/settings/main.go | 2 +- settings/pkg/command/root.go | 50 ++------ settings/pkg/command/server.go | 20 +--- settings/pkg/config/config.go | 103 ++++++++++++++++- settings/pkg/config/env.go | 104 +++++++++++++++++ settings/pkg/flagset/flagset.go | 198 -------------------------------- 9 files changed, 227 insertions(+), 302 deletions(-) create mode 100644 settings/pkg/config/env.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 2b18352a69..224c90327e 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -121,8 +121,8 @@ func New() *Config { Proxy: proxy.DefaultConfig(), GraphExplorer: graphExplorer.DefaultConfig(), OCS: ocs.DefaultConfig(), + Settings: settings.DefaultConfig(), Web: web.New(), - Settings: settings.New(), Storage: storage.New(), Store: store.New(), Thumbnails: thumbnails.New(), diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 7970d406a1..43fad1e790 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -9,7 +9,6 @@ import ( "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,7 +18,6 @@ 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), }, diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 281a793ff8..eaf26f2e92 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -3,15 +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/ocs/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -67,46 +63,18 @@ 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/settings/cmd/settings/main.go b/settings/cmd/settings/main.go index 56ced7764f..cfee45c698 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/root.go b/settings/pkg/command/root.go index 170b10cd54..e952d28188 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -3,15 +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/settings/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -31,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 nil @@ -69,46 +63,18 @@ 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 630930a857..894b159ff7 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 err := ParseConfig(ctx, cfg); err != nil { + return err } - 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 - } - 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/config/config.go b/settings/pkg/config/config.go index 71053c421f..d8f7302c4f 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -1,6 +1,15 @@ package config -import "context" +import ( + "context" + "fmt" + "path" + "reflect" + + gofig "github.com/gookit/config/v2" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Log defines the available logging configuration. type Log struct { @@ -87,3 +96,95 @@ type Config struct { func New() *Config { return &Config{} } + +// DefaultConfig provides sane bootstrapping defaults. +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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, // 10 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", + }, + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/settings/pkg/config/env.go b/settings/pkg/config/env.go new file mode 100644 index 0000000000..0160dd8737 --- /dev/null +++ b/settings/pkg/config/env.go @@ -0,0 +1,104 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"SETTINGS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"SETTINGS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"SETTINGS_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"SETTINGS_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"SETTINGS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"SETTINGS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"SETTINGS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"SETTINGS_TRACING_COLLECTOR", "OCIS_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{"SETTINGS_JWT_SECRET", "OCIS_JWT_SECRET"}, + Destination: &cfg.TokenManager.JWTSecret, + }, + } +} diff --git a/settings/pkg/flagset/flagset.go b/settings/pkg/flagset/flagset.go index 585cfcecfa..73eb906a1b 100644 --- a/settings/pkg/flagset/flagset.go +++ b/settings/pkg/flagset/flagset.go @@ -1,38 +1,11 @@ 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{ @@ -46,177 +19,6 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { } } -// 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{ From b44ebce526589d69f1ecfb4d9039ddb523cfefb4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 12:49:52 +0100 Subject: [PATCH 033/147] continue thumbnails migration --- glauth/pkg/command/server.go | 8 -- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/thumbnails.go | 2 - thumbnails/cmd/thumbnails/main.go | 2 +- thumbnails/pkg/command/root.go | 47 ++------- thumbnails/pkg/command/server.go | 16 +-- thumbnails/pkg/config/config.go | 150 ++++++++++++++++++++++------ thumbnails/pkg/config/env.go | 96 ++++++++++++++++++ thumbnails/pkg/flagset/flagset.go | 159 ------------------------------ 9 files changed, 229 insertions(+), 253 deletions(-) create mode 100644 thumbnails/pkg/config/env.go diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index 7716e8f9c8..d3e903503f 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -32,14 +32,6 @@ func Server(cfg *config.Config) *cli.Command { return err } - // TODO(refs) there is no cli flags anymore... - //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") - //} - return nil }, Action: func(c *cli.Context) error { diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 224c90327e..f445a99911 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -125,7 +125,7 @@ func New() *Config { Web: web.New(), Storage: storage.New(), Store: store.New(), - Thumbnails: thumbnails.New(), + Thumbnails: thumbnails.DefaultConfig(), WebDAV: webdav.New(), } } diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 083442f8af..b81a0eedb5 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -8,7 +8,6 @@ import ( "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" @@ -20,7 +19,6 @@ 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), }, diff --git a/thumbnails/cmd/thumbnails/main.go b/thumbnails/cmd/thumbnails/main.go index 7d89ce29f1..2098a63413 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/root.go b/thumbnails/pkg/command/root.go index c6b0d43a12..4ebc5e413f 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -3,15 +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/thumbnails/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -68,45 +64,18 @@ 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 856b7a5a8d..4a96c12e52 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,19 +19,12 @@ 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 { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + 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) - } logger.Debug().Str("service", "thumbnails").Msg("ignoring config file parsing when running supervised") return nil }, diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 7f8a97a81c..5706956984 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -1,48 +1,57 @@ package config -import "context" +import ( + "context" + "fmt" + "path" + "reflect" + + gofig "github.com/gookit/config/v2" + + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // Server defines the available server configuration. type Server struct { - Name string - Namespace string - Address string - Version string + Name string `mapstructure:"name"` + Namespace string `mapstructure:"namespace"` + Address string `mapstructure:"address"` + Version string `mapstructure:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - Server Server - Tracing Tracing - Thumbnail Thumbnail + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + Thumbnail Thumbnail `mapstructure:"thumbnail"` Context context.Context Supervised bool @@ -50,24 +59,103 @@ type Config struct { // FileSystemStorage defines the available filesystem storage configuration. type FileSystemStorage struct { - RootDirectory string + RootDirectory string `mapstructure:"root_directory"` } // FileSystemSource defines the available filesystem source configuration. type FileSystemSource struct { - BasePath string + BasePath string `mapstructure:"base_path"` } // Thumbnail defines the available thumbnail related configuration. type Thumbnail struct { - Resolutions []string - FileSystemStorage FileSystemStorage - WebdavAllowInsecure bool - RevaGateway string - WebdavNamespace string + Resolutions []string `mapstructure:"resolutions"` + FileSystemStorage FileSystemStorage `mapstructure:"filesystem_storage"` + WebdavAllowInsecure bool `mapstructure:"webdav_allow_insecure"` + RevaGateway string `mapstructure:"reva_gateway"` + WebdavNamespace string `mapstructure:"webdav_namespace"` } // New initializes a new configuration with or without defaults. func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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", + }, + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/thumbnails/pkg/config/env.go b/thumbnails/pkg/config/env.go new file mode 100644 index 0000000000..7c012b6917 --- /dev/null +++ b/thumbnails/pkg/config/env.go @@ -0,0 +1,96 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"THUMBNAILS_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"THUMBNAILS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"THUMBNAILS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"THUMBNAILS_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"THUMBNAILS_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"THUMBNAILS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"THUMBNAILS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"THUMBNAILS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"THUMBNAILS_TRACING_COLLECTOR", "OCIS_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{"THUMBNAILS_WEBDAVSOURCE_INSECURE"}, + Destination: &cfg.Thumbnail.WebdavAllowInsecure, + }, + { + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.Thumbnail.WebdavNamespace, + }, + } +} diff --git a/thumbnails/pkg/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go index 6a877400e9..0640c730b3 100644 --- a/thumbnails/pkg/flagset/flagset.go +++ b/thumbnails/pkg/flagset/flagset.go @@ -1,9 +1,6 @@ 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" @@ -23,162 +20,6 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { } } -// 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, true), - Usage: "Whether to skip certificate checks", - EnvVars: []string{"THUMBNAILS_WEBDAVSOURCE_INSECURE"}, - Destination: &cfg.Thumbnail.WebdavAllowInsecure, - }, - &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{ From ca997e5bfcbc4755d0ef79e29d1105849b54df6f Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 13:33:03 +0100 Subject: [PATCH 034/147] migrate web to the new config scheme --- accounts/pkg/config/config.go | 2 +- ocis-pkg/config/config.go | 2 +- ocis/pkg/command/web.go | 2 - settings/pkg/config/config.go | 2 +- web/cmd/web/main.go | 2 +- web/pkg/command/root.go | 48 +++---------- web/pkg/command/server.go | 15 +--- web/pkg/config/config.go | 101 ++++++++++++++++++++++++++- web/pkg/config/env.go | 128 ++++++++++++++++++++++++++++++++++ 9 files changed, 242 insertions(+), 60 deletions(-) create mode 100644 web/pkg/config/env.go diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 2ca48d58f1..340f07f045 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -163,7 +163,7 @@ func DefaultConfig() *Config { Addr: "127.0.0.1:9181", Namespace: "com.owncloud.web", Root: "/", - CacheTTL: 604800, + CacheTTL: 604800, // 7 days CORS: CORS{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index f445a99911..74d92dc2f7 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -122,7 +122,7 @@ func New() *Config { GraphExplorer: graphExplorer.DefaultConfig(), OCS: ocs.DefaultConfig(), Settings: settings.DefaultConfig(), - Web: web.New(), + Web: web.DefaultConfig(), Storage: storage.New(), Store: store.New(), Thumbnails: thumbnails.DefaultConfig(), diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 431443cada..736d320600 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -5,7 +5,6 @@ import ( "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,7 +14,6 @@ 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) }, diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index d8f7302c4f..b6d3f29e7d 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -115,7 +115,7 @@ func DefaultConfig() *Config { Addr: "127.0.0.1:9190", Namespace: "com.owncloud.web", Root: "/", - CacheTTL: 604800, // 10 days + CacheTTL: 604800, // 7 days CORS: CORS{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, diff --git a/web/cmd/web/main.go b/web/cmd/web/main.go index 50ca749a73..7334862fee 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/root.go b/web/pkg/command/root.go index 0114791d3b..bef81771b4 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -3,15 +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/web/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -59,46 +55,18 @@ 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 77ee5dce3b..ff4865651d 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,24 +21,16 @@ 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.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 err := ParseConfig(ctx, cfg); err != nil { + return err } - if !cfg.Supervised { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - } + logger := NewLogger(cfg) logger.Debug().Str("service", "web").Msg("ignoring config file parsing when running supervised") // build well known openid-configuration endpoint if it is not set diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 64a03838bd..7e0f795a74 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -1,6 +1,12 @@ package config -import "context" +import ( + "context" + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" +) // Log defines the available logging configuration. type Log struct { @@ -96,7 +102,6 @@ type Config struct { HTTP HTTP Tracing Tracing Asset Asset - OIDC OIDC Web Web Context context.Context @@ -107,3 +112,95 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + 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"}, + }, + }, + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/web/pkg/config/env.go b/web/pkg/config/env.go new file mode 100644 index 0000000000..771fd4c806 --- /dev/null +++ b/web/pkg/config/env.go @@ -0,0 +1,128 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"WEB_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"WEB_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"WEB_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"WEB_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"WEB_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"WEB_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"WEB_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"WEB_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"WEB_TRACING_COLLECTOR", "OCIS_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{"WEB_UI_CONFIG_SERVER", "OCIS_URL"}, // WEB_UI_CONFIG_SERVER takes precedence over OCIS_URL + Destination: &cfg.Web.Config.Server, + }, + { + EnvVars: []string{"WEB_UI_THEME_SERVER", "OCIS_URL"}, // 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{"WEB_OIDC_AUTHORITY", "OCIS_URL"}, // 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, + }, + } +} From ad72f7574c23285a8fdef0ae83b44d1663e0da0a Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 13:45:15 +0100 Subject: [PATCH 035/147] migrate webdav to the new config scheme --- ocis-pkg/config/config.go | 2 +- web/pkg/config/config.go | 90 ++++++++++----------- webdav/cmd/webdav/main.go | 2 +- webdav/pkg/command/root.go | 48 ++--------- webdav/pkg/command/server.go | 16 +--- webdav/pkg/config/config.go | 151 +++++++++++++++++++++++++++-------- webdav/pkg/config/env.go | 92 +++++++++++++++++++++ 7 files changed, 270 insertions(+), 131 deletions(-) create mode 100644 webdav/pkg/config/env.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 74d92dc2f7..b379d6a2e9 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -126,7 +126,7 @@ func New() *Config { Storage: storage.New(), Store: store.New(), Thumbnails: thumbnails.DefaultConfig(), - WebDAV: webdav.New(), + WebDAV: webdav.DefaultConfig(), } } diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 7e0f795a74..974a204f10 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -10,60 +10,60 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - Namespace string - CacheTTL int + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + Namespace string `mapstructure:"namespace"` + CacheTTL int `mapstructure:"cache_ttl"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `mapstructure:"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",mapstructure:"server"` + Theme string `json:"theme,omitempty",mapstructure:"theme"` + Version string `json:"version,omitempty",mapstructure:"version"` // TODO what is version used for? + OpenIDConnect OIDC `json:"openIdConnect,omitempty",mapstructure:"oids"` + Apps []string `json:"apps",mapstructure:"apps"` // TODO add nil as empty when https://go-review.googlesource.com/c/go/+/205897/ is released + ExternalApps []ExternalApp `json:"external_apps,omitempty",mapstructure:"external_apps"` + Options map[string]interface{} `json:"options,omitempty",mapstructure:"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",mapstructure:"metadata_url"` + Authority string `json:"authority,omitempty",mapstructure:"authority"` + ClientID string `json:"client_id,omitempty",mapstructure:"client_id"` + ResponseType string `json:"response_type,omitempty",mapstructure:"response_type"` + Scope string `json:"scope,omitempty",mapstructure:"scope"` } // ExternalApp defines an external web app. @@ -75,34 +75,34 @@ type OIDC struct { // } // } type ExternalApp struct { - ID string `json:"id,omitempty"` - Path string `json:"path,omitempty"` + ID string `json:"id,omitempty",mapstructure:"id"` + Path string `json:"path,omitempty",mapstructure:"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",mapstructure:"config"` } // ExternalAppConfig defines an external web app configuration. type ExternalAppConfig struct { - URL string `json:"url,omitempty"` + URL string `json:"url,omitempty",mapstructure:"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 `mapstructure:"path"` + ThemeServer string `mapstructure:"theme_server"` // used to build Theme in WebConfig + ThemePath string `mapstructure:"theme_path"` // used to build Theme in WebConfig + Config WebConfig `mapstructure:"config"` } // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Tracing Tracing - Asset Asset - Web Web + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"asset"` + Web Web `mapstructure:"web"` Context context.Context Supervised bool diff --git a/webdav/cmd/webdav/main.go b/webdav/cmd/webdav/main.go index fe242ff533..f03fd520c8 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/root.go b/webdav/pkg/command/root.go index bc5bb5fe74..1eff029c57 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -3,15 +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/webdav/pkg/config" - "github.com/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -65,46 +61,18 @@ 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 47a5090993..c3dc2ea74d 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -22,23 +22,15 @@ func Server(cfg *config.Config) *cli.Command { 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 := NewLogger(cfg) logger.Debug().Str("service", "webdav").Msg("ignoring config file parsing when running supervised") return nil }, diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index dfd4f46c6f..e24b86617e 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -1,64 +1,70 @@ package config -import "context" +import ( + "context" + "fmt" + "reflect" + + gofig "github.com/gookit/config/v2" +) // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `mapstructure:"allowed_origins"` + AllowedMethods []string `mapstructure:"allowed_methods"` + AllowedHeaders []string `mapstructure:"allowed_headers"` + AllowCredentials bool `mapstructure:"allow_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - CORS CORS + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + CORS CORS `mapstructure:"cors"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `mapstructure:"name"` + Namespace string `mapstructure:"namespace"` + Version string `mapstructure:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"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 + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Service Service `mapstructure:"service"` + OcisPublicURL string `mapstructure:"ocis_public_url"` + WebdavNamespace string `mapstructure:"webdav_namespace"` Context context.Context Supervised bool @@ -68,3 +74,84 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: Log{}, + Debug: Debug{ + Addr: "", + 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", + } +} + +// 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/webdav/pkg/config/env.go b/webdav/pkg/config/env.go new file mode 100644 index 0000000000..e0392c64f6 --- /dev/null +++ b/webdav/pkg/config/env.go @@ -0,0 +1,92 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"WEBDAV_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"WEBDAV_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"WEBDAV_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"WEBDAV_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"WEBDAV_CONFIG_FILE"}, + Destination: &cfg.File, + }, + { + EnvVars: []string{"WEBDAV_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"WEBDAV_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"WEBDAV_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"WEBDAV_TRACING_COLLECTOR", "OCIS_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_PUBLIC_URL", "OCIS_URL"}, + Destination: &cfg.OcisPublicURL, + }, + { + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.WebdavNamespace, + }, + } +} From 99f28e601c98c5e6877e0cdd0a661b8868c4ca46 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 14:10:25 +0100 Subject: [PATCH 036/147] migrate store to the new config scheme --- ocis-pkg/config/config.go | 4 +- ocis/pkg/command/store.go | 2 - store/cmd/store/main.go | 2 +- store/pkg/command/root.go | 50 ++++------------------ store/pkg/command/server.go | 10 ++--- store/pkg/config/config.go | 83 +++++++++++++++++++++++++++++++++++- store/pkg/config/env.go | 80 ++++++++++++++++++++++++++++++++++ store/pkg/flagset/flagset.go | 31 -------------- 8 files changed, 178 insertions(+), 84 deletions(-) create mode 100644 store/pkg/config/env.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index b379d6a2e9..da41c2b775 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -123,10 +123,10 @@ func New() *Config { OCS: ocs.DefaultConfig(), Settings: settings.DefaultConfig(), Web: web.DefaultConfig(), - Storage: storage.New(), - Store: store.New(), + Store: store.DefaultConfig(), Thumbnails: thumbnails.DefaultConfig(), WebDAV: webdav.DefaultConfig(), + Storage: storage.New(), } } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 74d2a84fed..b37d10a769 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -9,7 +9,6 @@ import ( "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" ) @@ -19,7 +18,6 @@ func StoreCommand(cfg *config.Config) *cli.Command { Name: "store", Usage: "Start a go-micro store", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.Store), Subcommands: []*cli.Command{ command.PrintVersion(cfg.Store), }, diff --git a/store/cmd/store/main.go b/store/cmd/store/main.go index ad2549012a..f20f59258e 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/root.go b/store/pkg/command/root.go index b16eae65fc..882607891f 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -3,15 +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/spf13/viper" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" ) @@ -31,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) @@ -69,46 +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") + conf, err := ociscfg.BindSourcesToStructs("store", 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") - } - } + // load all env variables relevant to the config in the current context. + conf.LoadOSEnv(config.GetEnv(), false) - if err := viper.Unmarshal(&cfg); err != nil { - logger.Fatal(). - Err(err). - Msg("Failed to parse config") + if err = cfg.UnmapEnv(conf); err != nil { + return err } return nil diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 1fec4e195e..311ceb4535 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -23,12 +23,12 @@ func Server(cfg *config.Config) *cli.Command { 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) + + if err := ParseConfig(ctx, cfg); err != nil { + return err } + + logger := NewLogger(cfg) logger.Debug().Str("service", "store").Msg("ignoring config file parsing when running supervised") return nil }, diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index ce9c852521..eabf1d0589 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -1,6 +1,14 @@ package config -import "context" +import ( + "context" + "fmt" + "path" + "reflect" + + gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) // Log defines the available logging configuration. type Log struct { @@ -58,3 +66,76 @@ type Config struct { func New() *Config { return &Config{} } + +func DefaultConfig() *Config { + return &Config{ + Log: 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 +} + +// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. +func (c *Config) UnmapEnv(gooconf *gofig.Config) error { + vals := structMappings(c) + for i := range vals { + for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { + + // get the destination type from destination + switch reflect.ValueOf(vals[i].Destination).Type().String() { + case "*bool": + r := gooconf.Bool(vals[i].EnvVars[j]) + *vals[i].Destination.(*bool) = r + case "*string": + r := gooconf.String(vals[i].EnvVars[j]) + *vals[i].Destination.(*string) = r + case "*int": + r := gooconf.Int(vals[i].EnvVars[j]) + *vals[i].Destination.(*int) = r + case "*float64": + // defaults to float64 + r := gooconf.Float(vals[i].EnvVars[j]) + *vals[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`", vals[i].EnvVars[j]) + } + } + } + } + + return nil +} diff --git a/store/pkg/config/env.go b/store/pkg/config/env.go new file mode 100644 index 0000000000..42e09aedc5 --- /dev/null +++ b/store/pkg/config/env.go @@ -0,0 +1,80 @@ +package config + +type mapping struct { + EnvVars []string // name of the EnvVars var. + Destination interface{} // memory address of the original config value to modify. +} + +// structMappings binds a set of environment variables to a destination on cfg. +func structMappings(cfg *Config) []mapping { + return []mapping{ + { + EnvVars: []string{"STORE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + Destination: &cfg.Log.Level, + }, + { + EnvVars: []string{"STORE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, + { + EnvVars: []string{"STORE_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"STORE_LOG_FILE", "OCIS_LOG_FILE"}, + Destination: &cfg.Log.File, + }, + { + EnvVars: []string{"STORE_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + Destination: &cfg.Tracing.Enabled, + }, + { + EnvVars: []string{"STORE_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + Destination: &cfg.Tracing.Type, + }, + { + EnvVars: []string{"STORE_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + Destination: &cfg.Tracing.Endpoint, + }, + { + EnvVars: []string{"STORE_TRACING_COLLECTOR", "OCIS_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 index 2651bbf983..1f9e5e7cd8 100644 --- a/store/pkg/flagset/flagset.go +++ b/store/pkg/flagset/flagset.go @@ -9,37 +9,6 @@ import ( "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{ From 8202f7b2ad06e3f8ed2976d251c1d14daeb3d012 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 14:23:12 +0100 Subject: [PATCH 037/147] fix offenses --- web/pkg/config/config.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 974a204f10..f6ad152e7c 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -48,22 +48,22 @@ type Asset struct { // WebConfig defines the available web configuration for a dynamically rendered config.json. type WebConfig struct { - Server string `json:"server,omitempty",mapstructure:"server"` - Theme string `json:"theme,omitempty",mapstructure:"theme"` - Version string `json:"version,omitempty",mapstructure:"version"` // TODO what is version used for? - OpenIDConnect OIDC `json:"openIdConnect,omitempty",mapstructure:"oids"` - Apps []string `json:"apps",mapstructure:"apps"` // TODO add nil as empty when https://go-review.googlesource.com/c/go/+/205897/ is released - ExternalApps []ExternalApp `json:"external_apps,omitempty",mapstructure:"external_apps"` - Options map[string]interface{} `json:"options,omitempty",mapstructure:"options"` + Server string `json:"server,omitempty" mapstructure:"server"` + Theme string `json:"theme,omitempty" mapstructure:"theme"` + Version string `json:"version,omitempty" mapstructure:"version"` // TODO what is version used for? + OpenIDConnect OIDC `json:"openIdConnect,omitempty" mapstructure:"oids"` + Apps []string `json:"apps" mapstructure:"apps"` // TODO add nil as empty when https://go-review.googlesource.com/c/go/+/205897/ is released + ExternalApps []ExternalApp `json:"external_apps,omitempty" mapstructure:"external_apps"` + Options map[string]interface{} `json:"options,omitempty" mapstructure:"options"` } // OIDC defines the available oidc configuration type OIDC struct { - MetadataURL string `json:"metadata_url,omitempty",mapstructure:"metadata_url"` - Authority string `json:"authority,omitempty",mapstructure:"authority"` - ClientID string `json:"client_id,omitempty",mapstructure:"client_id"` - ResponseType string `json:"response_type,omitempty",mapstructure:"response_type"` - Scope string `json:"scope,omitempty",mapstructure:"scope"` + MetadataURL string `json:"metadata_url,omitempty" mapstructure:"metadata_url"` + Authority string `json:"authority,omitempty" mapstructure:"authority"` + ClientID string `json:"client_id,omitempty" mapstructure:"client_id"` + ResponseType string `json:"response_type,omitempty" mapstructure:"response_type"` + Scope string `json:"scope,omitempty" mapstructure:"scope"` } // ExternalApp defines an external web app. @@ -75,15 +75,15 @@ type OIDC struct { // } // } type ExternalApp struct { - ID string `json:"id,omitempty",mapstructure:"id"` - Path string `json:"path,omitempty",mapstructure:"path"` + ID string `json:"id,omitempty" mapstructure:"id"` + Path string `json:"path,omitempty" mapstructure:"path"` // Config is completely dynamic, because it depends on the extension - Config map[string]interface{} `json:"config,omitempty",mapstructure:"config"` + Config map[string]interface{} `json:"config,omitempty" mapstructure:"config"` } // ExternalAppConfig defines an external web app configuration. type ExternalAppConfig struct { - URL string `json:"url,omitempty",mapstructure:"url"` + URL string `json:"url,omitempty" mapstructure:"url"` } // Web defines the available web configuration. From b94c0e683fdf69603c08e257cbd2d80aac2aa37d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 14:26:02 +0100 Subject: [PATCH 038/147] fix yet more offenses --- accounts/pkg/command/server.go | 10 ---------- accounts/pkg/config/env.go | 26 -------------------------- ocis-pkg/config/config.go | 2 -- web/pkg/config/config.go | 12 +++++++----- 4 files changed, 7 insertions(+), 43 deletions(-) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 9ca1112b4b..8de6f9d8f6 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -35,16 +35,6 @@ func Server(cfg *config.Config) *cli.Command { return err } - // TODO(this is not in the cli context anymore) - //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 - //} return nil }, Action: func(c *cli.Context) error { diff --git a/accounts/pkg/config/env.go b/accounts/pkg/config/env.go index 6b5e39c132..d2193575b4 100644 --- a/accounts/pkg/config/env.go +++ b/accounts/pkg/config/env.go @@ -134,29 +134,3 @@ func structMappings(cfg *Config) []mapping { }, } } - -// TODO(refs) What is with the variables with no destination defined? -//&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"}, -//}, diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index da41c2b775..7cec4f664d 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -130,7 +130,6 @@ func New() *Config { } } -// TODO(refs) refactoir refactor this outside type mapping struct { EnvVars []string // name of the EnvVars var. Destination interface{} // memory address of the original config value to modify. @@ -148,7 +147,6 @@ func GetEnv() []string { } // UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -// TODO(refs) can we avoid repetition here? func (c *Config) UnmapEnv(gooconf *gofig.Config) error { vals := structMappings(c) for i := range vals { diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index f6ad152e7c..5a85684e70 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -8,6 +8,8 @@ import ( gofig "github.com/gookit/config/v2" ) +const defaultIngressURL = "https://localhost:9200" + // Log defines the available logging configuration. type Log struct { Level string `mapstructure:"level"` @@ -50,9 +52,9 @@ type Asset struct { type WebConfig struct { Server string `json:"server,omitempty" mapstructure:"server"` Theme string `json:"theme,omitempty" mapstructure:"theme"` - Version string `json:"version,omitempty" mapstructure:"version"` // TODO what is version used for? + Version string `json:"version,omitempty" mapstructure:"version"` OpenIDConnect OIDC `json:"openIdConnect,omitempty" mapstructure:"oids"` - Apps []string `json:"apps" mapstructure:"apps"` // TODO add nil as empty when https://go-review.googlesource.com/c/go/+/205897/ is released + Apps []string `json:"apps" mapstructure:"apps"` ExternalApps []ExternalApp `json:"external_apps,omitempty" mapstructure:"external_apps"` Options map[string]interface{} `json:"options,omitempty" mapstructure:"options"` } @@ -140,15 +142,15 @@ func DefaultConfig() *Config { }, Web: Web{ Path: "", - ThemeServer: "https://localhost:9200", + ThemeServer: defaultIngressURL, ThemePath: "/themes/owncloud/theme.json", Config: WebConfig{ - Server: "https://localhost:9200", + Server: defaultIngressURL, Theme: "", Version: "0.1.0", OpenIDConnect: OIDC{ MetadataURL: "", - Authority: "https://localhost:9200", + Authority: defaultIngressURL, ClientID: "web", ResponseType: "code", Scope: "openid profile email", From a55a0395eb0b3f7ddd5a1a27734f1596f0eb1ec7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 15:16:03 +0100 Subject: [PATCH 039/147] add mapstructure to ocs --- accounts/pkg/command/server.go | 2 - ocs/pkg/config/config.go | 74 +++++++++++++++++----------------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 8de6f9d8f6..04f6410d2f 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -29,8 +29,6 @@ func Server(cfg *config.Config) *cli.Command { 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 err := ParseConfig(ctx, cfg); err != nil { return err } diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 5098589b59..f04c3a3111 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -10,77 +10,77 @@ import ( // Log defines the available logging configuration. type Log struct { - Level string - Pretty bool - Color bool - File string + Level string `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"zpages"` } // CORS defines the available cors configuration. type CORS struct { - AllowedOrigins []string - AllowedMethods []string - AllowedHeaders []string - AllowCredentials bool + AllowedOrigins []string `mapstructure:"allowed_origins"` + AllowedMethods []string `mapstructure:"allowed_methods"` + AllowedHeaders []string `mapstructure:"allowed_headers"` + AllowCredentials bool `mapstructure:"allow_credentials"` } // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string - CORS CORS + Addr string `mapstructure:"addr"` + Root string `mapstructure:"root"` + CORS CORS `mapstructure:"cors"` } // Service defines the available service configuration. type Service struct { - Name string - Namespace string - Version string + Name string `mapstructure:"name"` + Namespace string `mapstructure:"namespace"` + Version string `mapstructure:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string + JWTSecret string `mapstructure:"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 `mapstructure:"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 - RevaAddress string - StorageUsersDriver string - MachineAuthAPIKey string - IdentityManagement IdentityManagement + File string `mapstructure:"file"` + Log Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + TokenManager TokenManager `mapstructure:"token_manager"` + Service Service `mapstructure:"service"` + AccountBackend string `mapstructure:"account_backend"` + RevaAddress string `mapstructure:"reva_address"` + StorageUsersDriver string `mapstructure:"storage_users_driver"` + MachineAuthAPIKey string `mapstructure:"machine_auth_api_key"` + IdentityManagement IdentityManagement `mapstructure:"identity_management"` Context context.Context Supervised bool From 9466e01a3c195d3655848fa814c0c2ce543882e5 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 15:18:34 +0100 Subject: [PATCH 040/147] change log level to debug --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 11833cabdc..14fe1dc9df 100644 --- a/.drone.star +++ b/.drone.star @@ -1472,7 +1472,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []): "PROXY_ENABLE_BASIC_AUTH": True, "WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json", "IDP_IDENTIFIER_REGISTRATION_CONF": "/drone/src/tests/config/drone/identifier-registration.yml", - "OCIS_LOG_LEVEL": "error", + "OCIS_LOG_LEVEL": "debug", "SETTINGS_DATA_PATH": "/srv/app/tmp/ocis/settings", } From 3206b9835965b9025a1ad360445a993cd73f72f5 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 5 Nov 2021 16:20:00 +0100 Subject: [PATCH 041/147] attempt to fix flags --- ocis/pkg/command/webdav.go | 2 - proxy/pkg/config/mappings.go | 2 +- store/pkg/command/server.go | 2 - store/pkg/flagset/flagset.go | 107 ------------------- web/pkg/flagset/flagset.go | 194 ---------------------------------- webdav/pkg/command/server.go | 2 - webdav/pkg/flagset/flagset.go | 167 ----------------------------- 7 files changed, 1 insertion(+), 475 deletions(-) diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index b84453a516..22e58e944a 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -9,7 +9,6 @@ import ( "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" ) @@ -19,7 +18,6 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Name: "webdav", Usage: "Start webdav server", Category: "Extensions", - Flags: flagset.ServerWithConfig(cfg.WebDAV), Subcommands: []*cli.Command{ command.PrintVersion(cfg.WebDAV), }, diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index c09936d542..d5ed4bb3d8 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -123,7 +123,7 @@ func structMappings(cfg *Config) []mapping { Destination: &cfg.InsecureBackends, }, { - EnvVars: []string{"PROXY_OIDC_ISSUER"}, + EnvVars: []string{"PROXY_OIDC_ISSUER", "OCIS_URL"}, Destination: &cfg.OIDC.Issuer, }, { diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 311ceb4535..1a25eafd36 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -9,7 +9,6 @@ import ( "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,7 +20,6 @@ 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 { if err := ParseConfig(ctx, cfg); err != nil { diff --git a/store/pkg/flagset/flagset.go b/store/pkg/flagset/flagset.go index 1f9e5e7cd8..a2085be67d 100644 --- a/store/pkg/flagset/flagset.go +++ b/store/pkg/flagset/flagset.go @@ -1,9 +1,6 @@ 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" @@ -22,110 +19,6 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { } } -// 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{ diff --git a/web/pkg/flagset/flagset.go b/web/pkg/flagset/flagset.go index 2b3d77d1a8..f389805ae2 100644 --- a/web/pkg/flagset/flagset.go +++ b/web/pkg/flagset/flagset.go @@ -42,197 +42,3 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { }, } } - -// 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/pkg/command/server.go b/webdav/pkg/command/server.go index c3dc2ea74d..fdcbbb9931 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,7 +19,6 @@ 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 { if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") diff --git a/webdav/pkg/flagset/flagset.go b/webdav/pkg/flagset/flagset.go index 7df00873cd..87fc458249 100644 --- a/webdav/pkg/flagset/flagset.go +++ b/webdav/pkg/flagset/flagset.go @@ -19,173 +19,6 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { } } -// 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{ From 6f27c1a100ed06724e3b97741a78b6a28e9cbf04 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Sun, 7 Nov 2021 20:52:36 +0100 Subject: [PATCH 042/147] refactor env unbinding to ocis-pkg --- ocis-pkg/config/config.go | 11 +++----- ocis-pkg/config/environment.go | 48 +++++++++++++++++++++++++++++++++ ocis-pkg/shared/shared_types.go | 9 +++++++ proxy/pkg/command/root.go | 8 ++---- proxy/pkg/config/env.go | 42 ----------------------------- proxy/pkg/config/mappings.go | 12 ++++++--- 6 files changed, 72 insertions(+), 58 deletions(-) create mode 100644 ocis-pkg/config/environment.go create mode 100644 ocis-pkg/shared/shared_types.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 7cec4f664d..5e97e79c96 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -4,6 +4,8 @@ import ( "fmt" "reflect" + "github.com/owncloud/ocis/ocis-pkg/shared" + gofig "github.com/gookit/config/v2" accounts "github.com/owncloud/ocis/accounts/pkg/config" glauth "github.com/owncloud/ocis/glauth/pkg/config" @@ -130,11 +132,6 @@ func New() *Config { } } -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. -} - // 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 { @@ -182,8 +179,8 @@ func (c *Config) UnmapEnv(gooconf *gofig.Config) error { } // structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"OCIS_LOG_FILE"}, Destination: &cfg.Log.Level, diff --git a/ocis-pkg/config/environment.go b/ocis-pkg/config/environment.go new file mode 100644 index 0000000000..14d62609c1 --- /dev/null +++ b/ocis-pkg/config/environment.go @@ -0,0 +1,48 @@ +package config + +import ( + "fmt" + "reflect" + + "github.com/owncloud/ocis/ocis-pkg/shared" + + gofig "github.com/gookit/config/v2" +) + +// UnbindEnv takes a config `c` and a EnvBinding +func UnbindEnv(c *gofig.Config, bindings []shared.EnvBinding) error { + return unbindEnv(c, bindings) +} + +func unbindEnv(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/shared/shared_types.go b/ocis-pkg/shared/shared_types.go new file mode 100644 index 0000000000..4897dc3cb0 --- /dev/null +++ b/ocis-pkg/shared/shared_types.go @@ -0,0 +1,9 @@ +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. +} diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 1753992842..9b1430df13 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -72,12 +72,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + bindings := config.StructMappings(cfg) + return ociscfg.UnbindEnv(conf, bindings) } // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. diff --git a/proxy/pkg/config/env.go b/proxy/pkg/config/env.go index e8afc953d8..0662983e3a 100644 --- a/proxy/pkg/config/env.go +++ b/proxy/pkg/config/env.go @@ -1,12 +1,5 @@ package config -import ( - "fmt" - "reflect" - - gofig "github.com/gookit/config/v2" -) - type mapping struct { EnvVars []string // name of the EnvVars var. Destination interface{} // memory address of the original config value to modify. @@ -22,38 +15,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index d5ed4bb3d8..5119ff5712 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -1,8 +1,14 @@ package config -// structMappings binds a set of environment variables to a destination on cfg. -func structMappings(cfg *Config) []mapping { - return []mapping{ +import "github.com/owncloud/ocis/ocis-pkg/shared" + +// StructMappings binds a set of environment variables to a destination on cfg. +func StructMappings(cfg *Config) []shared.EnvBinding { + return structMappings(cfg) +} + +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ // Logging { EnvVars: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, From 74dae6dad93b990e473a5b83dfffbbcd42b4e548 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 11:14:26 +0100 Subject: [PATCH 043/147] add ocis-pkg/config default config + fix logging inheritance --- ocis-pkg/config/config.go | 126 +++++++++++++++++++++++-- ocis-pkg/config/environment.go | 11 +-- ocis/pkg/command/proxy.go | 25 +---- ocis/pkg/command/root.go | 5 +- ocis/pkg/command/server.go | 4 +- ocis/pkg/config/config.go | 1 - ocis/pkg/flagset/flagset.go | 164 +-------------------------------- proxy/pkg/command/root.go | 25 ++--- proxy/pkg/config/config.go | 8 +- proxy/pkg/config/env.go | 17 ---- proxy/pkg/config/mappings.go | 15 ++- 11 files changed, 152 insertions(+), 249 deletions(-) delete mode 100644 ocis/pkg/config/config.go delete mode 100644 proxy/pkg/config/env.go diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 5e97e79c96..1b8f7e9634 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -82,10 +82,7 @@ type Runtime struct { // 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 regard 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 + Mode Mode // DEPRECATED File string OcisURL string `mapstructure:"ocis_url"` @@ -132,6 +129,54 @@ func New() *Config { } } +func DefaultConfig() *Config { + return &Config{ + Log: Log{ + Level: "info", + }, + 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.New(), + } +} + // 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 { @@ -178,13 +223,8 @@ func (c *Config) UnmapEnv(gooconf *gofig.Config) error { return nil } -// 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"}, - Destination: &cfg.Log.Level, - }, { EnvVars: []string{"OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, @@ -197,5 +237,73 @@ func structMappings(cfg *Config) []shared.EnvBinding { 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/environment.go b/ocis-pkg/config/environment.go index 14d62609c1..c713d92e40 100644 --- a/ocis-pkg/config/environment.go +++ b/ocis-pkg/config/environment.go @@ -4,17 +4,16 @@ import ( "fmt" "reflect" - "github.com/owncloud/ocis/ocis-pkg/shared" - gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) -// UnbindEnv takes a config `c` and a EnvBinding -func UnbindEnv(c *gofig.Config, bindings []shared.EnvBinding) error { - return unbindEnv(c, bindings) +// 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 unbindEnv(c *gofig.Config, bindings []shared.EnvBinding) error { +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. diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 29ea6b73b6..df4e865629 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -5,10 +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/urfave/cli/v2" ) @@ -25,33 +23,12 @@ func ProxyCommand(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, 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.OcisURL = cfg.OcisURL - 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 cd2b49eb0f..4750c986b0 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -3,8 +3,6 @@ package command import ( "os" - "github.com/owncloud/ocis/ocis/pkg/flagset" - "github.com/owncloud/ocis/ocis-pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -15,14 +13,13 @@ import ( // 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(), - Flags: flagset.RootWithConfig(cfg), Before: func(c *cli.Context) error { return ParseConfig(c, cfg) }, diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index acd66bc268..0863c5746a 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -7,7 +7,6 @@ import ( "strings" "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,13 +18,12 @@ 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 { r := runtime.New(cfg) diff --git a/ocis/pkg/config/config.go b/ocis/pkg/config/config.go deleted file mode 100644 index d912156bec..0000000000 --- a/ocis/pkg/config/config.go +++ /dev/null @@ -1 +0,0 @@ -package config diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go index 68bcdb14a6..1450838fca 100644 --- a/ocis/pkg/flagset/flagset.go +++ b/ocis/pkg/flagset/flagset.go @@ -5,109 +5,7 @@ import ( "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 +// HealthWithConfig applies cfg to the root flag-set. func HealthWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ @@ -119,63 +17,3 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { }, } } - -// 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/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 9b1430df13..64ecbe874d 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -63,17 +63,22 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads proxy configuration from 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 { conf, err := ociscfg.BindSourcesToStructs("proxy", cfg) if err != nil { return err } - // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) bindings := config.StructMappings(cfg) - return ociscfg.UnbindEnv(conf, bindings) + return ociscfg.BindEnv(conf, bindings) } // SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree. @@ -83,10 +88,6 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Proxy.Supervised = true - } return SutureService{ cfg: cfg.Proxy, } @@ -100,13 +101,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Proxy.Log.File = cfg.Log.File - cfg.Proxy.Log.Color = cfg.Log.Color - cfg.Proxy.Log.Pretty = cfg.Log.Pretty - cfg.Proxy.Log.Level = cfg.Log.Level -} diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 9097390fc1..f2c16df67b 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -141,10 +141,10 @@ type OIDC struct { // PolicySelector is the toplevel-configuration for different selectors type PolicySelector struct { - Static *StaticSelectorConf - Migration *MigrationSelectorConf - Claims *ClaimsSelectorConf - Regex *RegexSelectorConf + Static *StaticSelectorConf `mapstructure:"static"` + Migration *MigrationSelectorConf `mapstructure:"migration"` + Claims *ClaimsSelectorConf `mapstructure:"claims"` + Regex *RegexSelectorConf `mapstructure:"regex"` } // StaticSelectorConf is the config for the static-policy-selector diff --git a/proxy/pkg/config/env.go b/proxy/pkg/config/env.go deleted file mode 100644 index 0662983e3a..0000000000 --- a/proxy/pkg/config/env.go +++ /dev/null @@ -1,17 +0,0 @@ -package config - -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. -} - -// 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/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 5119ff5712..fc9433818f 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -2,7 +2,20 @@ package config import "github.com/owncloud/ocis/ocis-pkg/shared" -// StructMappings binds a set of environment variables to a destination on 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() []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) } From 0e9b6d8c52f6c0801bee3d359ad95ac816cfa866 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 11:35:41 +0100 Subject: [PATCH 044/147] fix log inheritance --- ocis-pkg/config/config.go | 12 ++---------- ocis-pkg/shared/shared_types.go | 8 ++++++++ ocis/pkg/command/proxy.go | 1 + proxy/pkg/command/root.go | 1 + proxy/pkg/config/config.go | 5 +++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 1b8f7e9634..0f1edfb95d 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -22,14 +22,6 @@ import ( webdav "github.com/owncloud/ocis/webdav/pkg/config" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -87,7 +79,7 @@ type Config struct { OcisURL string `mapstructure:"ocis_url"` Registry string `mapstructure:"registry"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` GRPC GRPC `mapstructure:"grpc"` @@ -131,7 +123,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{ + Log: shared.Log{ Level: "info", }, Debug: Debug{ diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go index 4897dc3cb0..9a938d5533 100644 --- a/ocis-pkg/shared/shared_types.go +++ b/ocis-pkg/shared/shared_types.go @@ -7,3 +7,11 @@ 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"` +} diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index df4e865629..3b768a201d 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -23,6 +23,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { + cfg.Proxy.Log = cfg.Log origCmd := command.Server(cfg.Proxy) return handleOriginalAction(c, origCmd) }, diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 64ecbe874d..cc1f91fe1e 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -88,6 +88,7 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { + cfg.Proxy.Log = cfg.Log return SutureService{ cfg: cfg.Proxy, } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index f2c16df67b..fec1e7449f 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -5,6 +5,7 @@ import ( "path" "github.com/owncloud/ocis/ocis-pkg/config/defaults" + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Log defines the available logging configuration. @@ -108,7 +109,7 @@ type Config struct { OcisURL string File string `mapstructure:"file"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Service Service `mapstructure:"service"` @@ -203,7 +204,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ File: "", - Log: Log{}, // logging config is inherited. + Log: shared.Log{}, // logging config is inherited. Debug: Debug{ Addr: "0.0.0.0:9205", Token: "", From 4999d4a04cfc9970c1baa8ac824d6f81c7f17a69 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 11:47:20 +0100 Subject: [PATCH 045/147] fix test --- proxy/pkg/proxy/proxy_integration_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/pkg/proxy/proxy_integration_test.go b/proxy/pkg/proxy/proxy_integration_test.go index 3b439e7c09..b9777ac666 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" ) @@ -214,7 +216,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{}, From d7828141f620d4452f0833dd30ba0954d91eaa92 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 11:51:35 +0100 Subject: [PATCH 046/147] fix log inheritance for accounts --- accounts/pkg/command/root.go | 16 +--------------- accounts/pkg/config/config.go | 14 ++++---------- ocis/pkg/command/accounts.go | 26 ++------------------------ 3 files changed, 7 insertions(+), 49 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 305e6ae703..af45789771 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -90,11 +90,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Accounts.Supervised = true - } - cfg.Accounts.Log.File = cfg.Log.File + cfg.Accounts.Log = cfg.Log return SutureService{ cfg: cfg.Accounts, } @@ -108,13 +104,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Accounts.Log.File = cfg.Log.File - cfg.Accounts.Log.Color = cfg.Log.Color - cfg.Accounts.Log.Pretty = cfg.Log.Pretty - cfg.Accounts.Log.Level = cfg.Log.Level -} diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 340f07f045..329a29048e 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -7,6 +7,8 @@ import ( "path" "reflect" + "github.com/owncloud/ocis/ocis-pkg/shared" + gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/config/defaults" @@ -76,14 +78,6 @@ type TokenManager struct { JWTSecret string `mapstructure:"jwt_secret"` } -// 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"` -} - // Repo defines which storage implementation is to be used. type Repo struct { Backend string `mapstructure:"backend"` @@ -140,7 +134,7 @@ type Config struct { GRPC GRPC `mapstructure:"grpc"` Server Server `mapstructure:"server"` Asset Asset `mapstructure:"asset"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` TokenManager TokenManager `mapstructure:"token_manager"` Repo Repo `mapstructure:"repo"` Index Index `mapstructure:"index"` @@ -181,7 +175,7 @@ func DefaultConfig() *Config { DemoUsersAndGroups: true, }, Asset: Asset{}, - Log: Log{}, + Log: shared.Log{}, TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 13594bf267..12d16109dd 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -5,9 +5,7 @@ package command import ( "github.com/owncloud/ocis/accounts/pkg/command" - svcconfig "github.com/owncloud/ocis/accounts/pkg/config" "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" ) @@ -30,33 +28,13 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureAccounts(cfg)) + cfg.Accounts.Log = cfg.Log + 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) } From e8b9186ba34b26fa0e222b6df6c33062d629be96 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:01:08 +0100 Subject: [PATCH 047/147] normalize glauth --- glauth/pkg/command/root.go | 29 ++----------------- glauth/pkg/config/config.go | 34 ++++++++++------------- glauth/pkg/config/{env.go => mappings.go} | 13 +++++++-- proxy/pkg/command/root.go | 3 -- 4 files changed, 28 insertions(+), 51 deletions(-) rename glauth/pkg/config/{env.go => mappings.go} (88%) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 55b5070d67..6c8baa610c 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -19,21 +19,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), @@ -73,12 +68,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + 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. @@ -88,11 +79,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.GLAuth.Supervised = true - } - cfg.GLAuth.Log.File = cfg.Log.File + cfg.GLAuth.Log = cfg.Log return SutureService{ cfg: cfg.GLAuth, } @@ -106,13 +93,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.GLAuth.Log.File = cfg.Log.File - cfg.GLAuth.Log.Color = cfg.Log.Color - cfg.GLAuth.Log.Pretty = cfg.Log.Pretty - cfg.GLAuth.Log.Level = cfg.Log.Level -} diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 6380aa8c64..89339a5fe4 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -6,18 +6,12 @@ import ( "path" "reflect" + "github.com/owncloud/ocis/ocis-pkg/shared" + gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -70,17 +64,17 @@ type Backend struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Ldap Ldap `mapstructure:"ldap"` - Ldaps Ldaps `mapstructure:"ldaps"` - Backend Backend `mapstructure:"backend"` - Fallback Backend `mapstructure:"fallback"` - Version string `mapstructure:"version"` - RoleBundleUUID string `mapstructure:"role_bundle_uuid"` + File string `mapstructure:"file"` + Log shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Ldap Ldap `mapstructure:"ldap"` + Ldaps Ldaps `mapstructure:"ldaps"` + Backend Backend `mapstructure:"backend"` + Fallback Backend `mapstructure:"fallback"` + Version string `mapstructure:"version"` + RoleBundleUUID string `mapstructure:"role_bundle_uuid"` Context context.Context Supervised bool @@ -93,7 +87,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9129", }, diff --git a/glauth/pkg/config/env.go b/glauth/pkg/config/mappings.go similarity index 88% rename from glauth/pkg/config/env.go rename to glauth/pkg/config/mappings.go index ef48fdc5f4..7d2a1393d2 100644 --- a/glauth/pkg/config/env.go +++ b/glauth/pkg/config/mappings.go @@ -1,13 +1,22 @@ package config +import "github.com/owncloud/ocis/ocis-pkg/shared" + type mapping struct { EnvVars []string // name of the EnvVars var. Destination interface{} // memory address of the original config value to modify. } +// 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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index cc1f91fe1e..7544f9a91c 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -19,19 +19,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", }, }, - Before: func(c *cli.Context) error { cfg.Service.Version = version.String return nil }, - Commands: []*cli.Command{ Server(cfg), Health(cfg), From 4c9e4713cfd43d7d92706bdfd0a1866159f9c4f0 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:04:30 +0100 Subject: [PATCH 048/147] normalize graph --- glauth/pkg/config/mappings.go | 5 ----- graph/pkg/command/root.go | 15 +++------------ graph/pkg/command/server.go | 5 +---- graph/pkg/config/config.go | 5 +++-- graph/pkg/config/{env.go => mappings.go} | 14 +++++++++----- 5 files changed, 16 insertions(+), 28 deletions(-) rename graph/pkg/config/{env.go => mappings.go} (82%) diff --git a/glauth/pkg/config/mappings.go b/glauth/pkg/config/mappings.go index 7d2a1393d2..c1af621315 100644 --- a/glauth/pkg/config/mappings.go +++ b/glauth/pkg/config/mappings.go @@ -2,11 +2,6 @@ package config import "github.com/owncloud/ocis/ocis-pkg/shared" -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. -} - // 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. diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 606d768788..11cfdabb72 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -20,30 +20,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", }, }, - 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", @@ -73,9 +68,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) return nil } @@ -87,10 +81,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.Log = cfg.Log return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index cf4b638127..36daa2daa7 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -24,10 +24,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index c59d69dcb0..3d35692c7e 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -6,6 +6,7 @@ import ( "reflect" gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) // Log defines the available logging configuration. @@ -65,7 +66,7 @@ type Spaces struct { // Config combines all available configuration parts. type Config struct { File string `mapstructure:"file"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Server Server `mapstructure:"server"` @@ -85,7 +86,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9124", Token: "", diff --git a/graph/pkg/config/env.go b/graph/pkg/config/mappings.go similarity index 82% rename from graph/pkg/config/env.go rename to graph/pkg/config/mappings.go index 2f22b33d2b..d32b519aa7 100644 --- a/graph/pkg/config/env.go +++ b/graph/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"GRAPH_CONFIG_FILE"}, Destination: &cfg.File, From 22601de35185bfd46ea307631dbe4782607dc1f3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:08:35 +0100 Subject: [PATCH 049/147] normalize graph-explorer --- graph-explorer/pkg/command/root.go | 29 ++----------------- graph-explorer/pkg/command/server.go | 7 +---- graph-explorer/pkg/config/config.go | 13 ++------- .../pkg/config/{env.go => mappings.go} | 14 +++++---- graph/pkg/command/root.go | 5 ---- graph/pkg/config/config.go | 8 ----- 6 files changed, 16 insertions(+), 60 deletions(-) rename graph-explorer/pkg/config/{env.go => mappings.go} (82%) diff --git a/graph-explorer/pkg/command/root.go b/graph-explorer/pkg/command/root.go index 3ebaa4422f..2f5f679a4c 100644 --- a/graph-explorer/pkg/command/root.go +++ b/graph-explorer/pkg/command/root.go @@ -19,7 +19,6 @@ func Execute(cfg *config.Config) error { Version: version.String, Usage: "Serve Graph-Explorer for oCIS", Compiled: version.Compiled(), - Authors: []*cli.Author{ { Name: "ownCloud GmbH", @@ -30,18 +29,15 @@ func Execute(cfg *config.Config) 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,14 +64,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + 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. @@ -85,11 +76,7 @@ type SutureService struct { // NewSutureService creates a new graph-explorer.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - 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, } @@ -103,13 +90,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.GraphExplorer.Log.File = cfg.Log.File - cfg.GraphExplorer.Log.Color = cfg.Log.Color - cfg.GraphExplorer.Log.Pretty = cfg.Log.Pretty - cfg.GraphExplorer.Log.Level = cfg.Log.Level -} diff --git a/graph-explorer/pkg/command/server.go b/graph-explorer/pkg/command/server.go index 773a8b61f0..f97daa3b8e 100644 --- a/graph-explorer/pkg/command/server.go +++ b/graph-explorer/pkg/command/server.go @@ -24,15 +24,10 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - 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 3a52e857d4..558273a683 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -6,16 +6,9 @@ import ( "reflect" gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -57,7 +50,7 @@ type GraphExplorer struct { // Config combines all available configuration parts. type Config struct { File string `mapstructure:"file"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Server Server `mapstructure:"server"` @@ -76,7 +69,7 @@ func New() *Config { // DefaultConfig provides with a working version of a config. func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9136", Token: "", diff --git a/graph-explorer/pkg/config/env.go b/graph-explorer/pkg/config/mappings.go similarity index 82% rename from graph-explorer/pkg/config/env.go rename to graph-explorer/pkg/config/mappings.go index e5dd435e82..09173763ee 100644 --- a/graph-explorer/pkg/config/env.go +++ b/graph-explorer/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"GRAPH_EXPLORER_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 11cfdabb72..094736e3bd 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -64,14 +64,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - - // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) - - return nil } // SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree. diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 3d35692c7e..9bfb29167a 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -9,14 +9,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` From a515a97c8fa3c4cf4961031d7899f7331689c44a Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:17:23 +0100 Subject: [PATCH 050/147] normalize idp --- accounts/pkg/command/root.go | 7 +-- accounts/pkg/config/{env.go => mappings.go} | 22 +++++-- glauth/pkg/config/config.go | 38 ------------ graph-explorer/pkg/config/config.go | 38 ------------ graph/pkg/config/config.go | 38 ------------ idp/pkg/command/root.go | 23 +------ idp/pkg/command/server.go | 29 ++++----- idp/pkg/config/config.go | 69 ++++----------------- idp/pkg/config/{env.go => mappings.go} | 14 +++-- ocs/pkg/server/http/svc_test.go | 4 +- 10 files changed, 58 insertions(+), 224 deletions(-) rename accounts/pkg/config/{env.go => mappings.go} (82%) rename idp/pkg/config/{env.go => mappings.go} (91%) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index af45789771..153a01545f 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -76,11 +76,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - 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. diff --git a/accounts/pkg/config/env.go b/accounts/pkg/config/mappings.go similarity index 82% rename from accounts/pkg/config/env.go rename to accounts/pkg/config/mappings.go index d2193575b4..cb710237f6 100644 --- a/accounts/pkg/config/env.go +++ b/accounts/pkg/config/mappings.go @@ -1,17 +1,29 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, Destination: &cfg.Log.File, }, + { + EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"}, + Destination: &cfg.Log.Color, + }, + { + EnvVars: []string{"ACCOUNTS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + Destination: &cfg.Log.Pretty, + }, { EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 89339a5fe4..00843b8845 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -2,13 +2,10 @@ package config import ( "context" - "fmt" "path" - "reflect" "github.com/owncloud/ocis/ocis-pkg/shared" - gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) @@ -140,38 +137,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 558273a683..07d55dd484 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -2,10 +2,7 @@ package config import ( "context" - "fmt" - "reflect" - gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/shared" ) @@ -107,38 +104,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 9bfb29167a..c29fcfb2eb 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -2,10 +2,7 @@ package config import ( "context" - "fmt" - "reflect" - gofig "github.com/gookit/config/v2" "github.com/owncloud/ocis/ocis-pkg/shared" ) @@ -118,38 +115,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 60db566552..1f78830a5d 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -71,11 +71,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - 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. @@ -85,11 +82,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.IDP.Supervised = true - } - cfg.IDP.Log.File = cfg.Log.File + cfg.IDP.Log = cfg.Log return SutureService{ cfg: cfg.IDP, } @@ -103,13 +96,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.IDP.Log.File = cfg.Log.File - cfg.IDP.Log.Color = cfg.Log.Color - cfg.IDP.Log.Pretty = cfg.Log.Pretty - cfg.IDP.Log.Level = cfg.Log.Level -} diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index 97120aa07f..1036f6d6ad 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -24,24 +24,19 @@ func Server(cfg *config.Config) *cli.Command { 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("trusted-proxy")) > 0 { - cfg.IDP.TrustedProxy = ctx.StringSlice("trusted-proxy") - } + //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 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 err := ParseConfig(ctx, cfg); err != nil { - return err - } - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 7d0c2771f4..9ee63acfc2 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -2,23 +2,13 @@ package config import ( "context" - "fmt" "path" - "reflect" + + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/config/defaults" - - gofig "github.com/gookit/config/v2" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -108,15 +98,15 @@ type Settings struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` - IDP Settings `mapstructure:"idp"` - Ldap Ldap `mapstructure:"ldap"` - Service Service `mapstructure:"service"` + File string `mapstructure:"file"` + Log shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"asset"` + IDP Settings `mapstructure:"idp"` + Ldap Ldap `mapstructure:"ldap"` + Service Service `mapstructure:"service"` Context context.Context Supervised bool @@ -129,7 +119,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9134", }, @@ -210,38 +200,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/idp/pkg/config/env.go b/idp/pkg/config/mappings.go similarity index 91% rename from idp/pkg/config/env.go rename to idp/pkg/config/mappings.go index 71f4639796..60467e6de2 100644 --- a/idp/pkg/config/env.go +++ b/idp/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"IDP_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index cdcb2eee9a..3016ee705c 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -14,6 +14,8 @@ 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" @@ -549,7 +551,7 @@ func init() { Path: dataPath, }, }, - Log: accountsCfg.Log{ + Log: shared.Log{ Level: "info", Pretty: true, Color: true, From e297142529a12e81aeba37de93c7a7a6aa560346 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:19:26 +0100 Subject: [PATCH 051/147] normalize ocs --- ocs/pkg/command/root.go | 23 ++---------- ocs/pkg/command/server.go | 6 +-- ocs/pkg/config/config.go | 51 ++------------------------ ocs/pkg/config/{env.go => mappings.go} | 14 ++++--- 4 files changed, 16 insertions(+), 78 deletions(-) rename ocs/pkg/config/{env.go => mappings.go} (83%) diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index eaf26f2e92..5393527b42 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -73,11 +73,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - 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. @@ -87,11 +84,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.OCS.Supervised = true - } - cfg.OCS.Log.File = cfg.Log.File + cfg.OCS.Log = cfg.Log return SutureService{ cfg: cfg.OCS, } @@ -105,13 +98,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.OCS.Log.File = cfg.Log.File - cfg.OCS.Log.Color = cfg.Log.Color - cfg.OCS.Log.Pretty = cfg.Log.Pretty - cfg.OCS.Log.Level = cfg.Log.Level -} diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 722673cd13..7b3ff62523 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -26,11 +26,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index f04c3a3111..f2ee415b91 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -2,20 +2,10 @@ package config import ( "context" - "fmt" - "reflect" - gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -70,7 +60,7 @@ type IdentityManagement struct { // Config combines all available configuration parts. type Config struct { File string `mapstructure:"file"` - Log Log `mapstructure:"log"` + Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Tracing Tracing `mapstructure:"tracing"` @@ -94,7 +84,7 @@ func New() *Config { // DefaultConfig provides default values for a config struct. func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9114", Token: "", @@ -145,38 +135,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/ocs/pkg/config/env.go b/ocs/pkg/config/mappings.go similarity index 83% rename from ocs/pkg/config/env.go rename to ocs/pkg/config/mappings.go index 5ef5ac450d..7346ffd98e 100644 --- a/ocs/pkg/config/env.go +++ b/ocs/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"OCS_LOG_FILE", "OCIS_LOG_FILE"}, Destination: &cfg.Log.File, From db9dc745554bcc72e1528bfc3e406ab97b8559b1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:21:07 +0100 Subject: [PATCH 052/147] normalize settings --- settings/pkg/command/root.go | 26 ++--------- settings/pkg/command/server.go | 6 +-- settings/pkg/config/config.go | 51 ++------------------- settings/pkg/config/{env.go => mappings.go} | 14 ++++-- 4 files changed, 16 insertions(+), 81 deletions(-) rename settings/pkg/config/{env.go => mappings.go} (83%) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index e952d28188..be06943a9a 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -69,15 +69,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - - // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + 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. @@ -87,11 +81,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Settings.Supervised = true - } - cfg.Settings.Log.File = cfg.Log.File + cfg.Settings.Log = cfg.Log return SutureService{ cfg: cfg.Settings, } @@ -105,13 +95,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Settings.Log.File = cfg.Log.File - cfg.Settings.Log.Color = cfg.Log.Color - cfg.Settings.Log.Pretty = cfg.Log.Pretty - cfg.Settings.Log.Level = cfg.Log.Level -} diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index 894b159ff7..e8215fe7d2 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -25,11 +25,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index b6d3f29e7d..62da7e7781 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -2,23 +2,13 @@ package config import ( "context" - "fmt" "path" - "reflect" - gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) -// 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 @@ -80,7 +70,7 @@ type TokenManager struct { type Config struct { File string Service Service - Log Log + Log shared.Log Debug Debug HTTP HTTP GRPC GRPC @@ -100,7 +90,7 @@ func New() *Config { // DefaultConfig provides sane bootstrapping defaults. func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Service: Service{ Name: "settings", DataPath: path.Join(defaults.BaseDataPath(), "settings"), @@ -153,38 +143,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/settings/pkg/config/env.go b/settings/pkg/config/mappings.go similarity index 83% rename from settings/pkg/config/env.go rename to settings/pkg/config/mappings.go index 0160dd8737..f37e05b848 100644 --- a/settings/pkg/config/env.go +++ b/settings/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"SETTINGS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, From 23cfb909eb61f5451dd6efdba7fcbceebdde7048 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:22:56 +0100 Subject: [PATCH 053/147] normalize store --- store/pkg/command/root.go | 7 +--- store/pkg/command/server.go | 9 +---- store/pkg/config/config.go | 51 ++---------------------- store/pkg/config/{env.go => mappings.go} | 14 ++++--- 4 files changed, 15 insertions(+), 66 deletions(-) rename store/pkg/config/{env.go => mappings.go} (78%) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 882607891f..115660b73f 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -73,11 +73,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - 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. diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 1a25eafd36..a8677eb169 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -21,14 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - logger := NewLogger(cfg) - logger.Debug().Str("service", "store").Msg("ignoring config file parsing when running supervised") - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index eabf1d0589..ad597bb480 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -2,22 +2,12 @@ package config import ( "context" - "fmt" "path" - "reflect" - gofig "github.com/gookit/config/v2" "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 -} - // Debug defines the available debug configuration. type Debug struct { Addr string @@ -51,7 +41,7 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { File string - Log Log + Log shared.Log Debug Debug GRPC GRPC Tracing Tracing @@ -69,7 +59,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9464", Token: "", @@ -104,38 +94,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/store/pkg/config/env.go b/store/pkg/config/mappings.go similarity index 78% rename from store/pkg/config/env.go rename to store/pkg/config/mappings.go index 42e09aedc5..5c31346d17 100644 --- a/store/pkg/config/env.go +++ b/store/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"STORE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, From f76dfc9af11d7b010950b302425d757cf89b81a3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:25:15 +0100 Subject: [PATCH 054/147] normalize thumbnails --- store/pkg/command/root.go | 16 +---- thumbnails/pkg/command/root.go | 26 +------- thumbnails/pkg/command/server.go | 8 +-- thumbnails/pkg/config/config.go | 62 +++---------------- thumbnails/pkg/config/{env.go => mappings.go} | 14 +++-- 5 files changed, 22 insertions(+), 104 deletions(-) rename thumbnails/pkg/config/{env.go => mappings.go} (82%) diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 115660b73f..07425fa54f 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -84,11 +84,7 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Store.Supervised = true - } - cfg.Store.Log.File = cfg.Log.File + cfg.Store.Log = cfg.Log return SutureService{ cfg: cfg.Store, } @@ -102,13 +98,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Store.Log.File = cfg.Log.File - cfg.Store.Log.Color = cfg.Log.Color - cfg.Store.Log.Pretty = cfg.Log.Pretty - cfg.Store.Log.Level = cfg.Log.Level -} diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index 4ebc5e413f..b32d6b9b4f 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -70,15 +70,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - - // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + 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. @@ -88,11 +82,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Thumbnails.Supervised = true - } - cfg.Thumbnails.Log.File = cfg.Log.File + cfg.Thumbnails.Log = cfg.Log return SutureService{ cfg: cfg.Thumbnails, } @@ -106,13 +96,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Thumbnails.Log.File = cfg.Log.File - cfg.Thumbnails.Log.Color = cfg.Log.Color - cfg.Thumbnails.Log.Pretty = cfg.Log.Pretty - cfg.Thumbnails.Log.Level = cfg.Log.Level -} diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 4a96c12e52..8225495413 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -20,13 +20,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - logger := NewLogger(cfg) - logger.Debug().Str("service", "thumbnails").Msg("ignoring config file parsing when running supervised") - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 5706956984..d8cb7bd48e 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -2,23 +2,12 @@ package config import ( "context" - "fmt" "path" - "reflect" - - gofig "github.com/gookit/config/v2" "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 `mapstructure:"level"` - Pretty bool `mapstructure:"pretty"` - Color bool `mapstructure:"color"` - File string `mapstructure:"file"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -46,12 +35,12 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - Server Server `mapstructure:"server"` - Tracing Tracing `mapstructure:"tracing"` - Thumbnail Thumbnail `mapstructure:"thumbnail"` + File string `mapstructure:"file"` + Log shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + Thumbnail Thumbnail `mapstructure:"thumbnail"` Context context.Context Supervised bool @@ -83,7 +72,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9189", Token: "", @@ -124,38 +113,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/thumbnails/pkg/config/env.go b/thumbnails/pkg/config/mappings.go similarity index 82% rename from thumbnails/pkg/config/env.go rename to thumbnails/pkg/config/mappings.go index 7c012b6917..9c44c5c812 100644 --- a/thumbnails/pkg/config/env.go +++ b/thumbnails/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"THUMBNAILS_LOG_FILE", "OCIS_LOG_FILE"}, Destination: &cfg.Log.File, From b1de937c05037d748b5efbf47a509dbba9b93660 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:26:17 +0100 Subject: [PATCH 055/147] fix tests --- ocs/pkg/server/http/svc_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 3016ee705c..24ffb6e1d5 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -698,7 +698,7 @@ func getService() svc.Service { TokenManager: config.TokenManager{ JWTSecret: jwtSecret, }, - Log: config.Log{ + Log: shared.Log{ Level: "debug", }, } From 185cee04e9d74ec2f486dae70fadba15c983e453 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:28:56 +0100 Subject: [PATCH 056/147] normalize web --- web/pkg/command/root.go | 25 ++-------- web/pkg/command/server.go | 3 -- web/pkg/config/config.go | 63 ++++---------------------- web/pkg/config/{env.go => mappings.go} | 14 ++++-- 4 files changed, 21 insertions(+), 84 deletions(-) rename web/pkg/config/{env.go => mappings.go} (86%) diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index bef81771b4..4c654ed4f5 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -62,14 +62,9 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + 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. @@ -79,11 +74,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.Web.Supervised = true - } - cfg.Web.Log.File = cfg.Log.File + cfg.Web.Log = cfg.Log return SutureService{ cfg: cfg.Web, } @@ -97,13 +88,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.Web.Log.File = cfg.Log.File - cfg.Web.Log.Color = cfg.Log.Color - cfg.Web.Log.Pretty = cfg.Log.Pretty - cfg.Web.Log.Level = cfg.Log.Level -} diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index ff4865651d..1a63e88991 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -30,9 +30,6 @@ func Server(cfg *config.Config) *cli.Command { return err } - logger := NewLogger(cfg) - 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" diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 5a85684e70..a702903f42 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -2,22 +2,12 @@ package config import ( "context" - "fmt" - "reflect" - gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) const defaultIngressURL = "https://localhost:9200" -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -98,13 +88,13 @@ type Web struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` - Web Web `mapstructure:"web"` + File string `mapstructure:"file"` + Log shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"asset"` + Web Web `mapstructure:"web"` Context context.Context Supervised bool @@ -117,7 +107,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9104", Token: "", @@ -171,38 +161,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/web/pkg/config/env.go b/web/pkg/config/mappings.go similarity index 86% rename from web/pkg/config/env.go rename to web/pkg/config/mappings.go index 771fd4c806..d54190f5ae 100644 --- a/web/pkg/config/env.go +++ b/web/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"WEB_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, From 8c2a6819373a16b9cdd6f5b99eaad059c4c5ee50 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 12:32:52 +0100 Subject: [PATCH 057/147] normalize webdav --- accounts/pkg/config/config.go | 39 -------------- webdav/pkg/command/root.go | 23 ++------ webdav/pkg/command/server.go | 8 +-- webdav/pkg/config/config.go | 65 ++++------------------- webdav/pkg/config/{env.go => mappings.go} | 14 +++-- 5 files changed, 23 insertions(+), 126 deletions(-) rename webdav/pkg/config/{env.go => mappings.go} (81%) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 329a29048e..e382cc9651 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -3,14 +3,10 @@ package config import ( "context" - "fmt" "path" - "reflect" "github.com/owncloud/ocis/ocis-pkg/shared" - gofig "github.com/gookit/config/v2" - "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) @@ -224,38 +220,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index 1eff029c57..f6ee762a10 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -71,11 +71,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { // load all env variables relevant to the config in the current context. conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - 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. @@ -85,11 +82,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - inheritLogging(cfg) - if cfg.Mode == 0 { - cfg.WebDAV.Supervised = true - } - cfg.WebDAV.Log.File = cfg.Log.File + cfg.WebDAV.Log = cfg.Log return SutureService{ cfg: cfg.WebDAV, } @@ -103,13 +96,3 @@ func (s SutureService) Serve(ctx context.Context) error { return nil } - -// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging -// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults, -// being overwritten when the extension parses its config file / env variables. -func inheritLogging(cfg *ociscfg.Config) { - cfg.WebDAV.Log.File = cfg.Log.File - cfg.WebDAV.Log.Color = cfg.Log.Color - cfg.WebDAV.Log.Pretty = cfg.Log.Pretty - cfg.WebDAV.Log.Level = cfg.Log.Level -} diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index fdcbbb9931..009497d29f 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -24,13 +24,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - logger := NewLogger(cfg) - logger.Debug().Str("service", "webdav").Msg("ignoring config file parsing when running supervised") - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index e24b86617e..801de7213d 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -2,20 +2,10 @@ package config import ( "context" - "fmt" - "reflect" - gofig "github.com/gookit/config/v2" + "github.com/owncloud/ocis/ocis-pkg/shared" ) -// 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"` -} - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -57,14 +47,14 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Service Service `mapstructure:"service"` - OcisPublicURL string `mapstructure:"ocis_public_url"` - WebdavNamespace string `mapstructure:"webdav_namespace"` + File string `mapstructure:"file"` + Log shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Service Service `mapstructure:"service"` + OcisPublicURL string `mapstructure:"ocis_public_url"` + WebdavNamespace string `mapstructure:"webdav_namespace"` Context context.Context Supervised bool @@ -77,7 +67,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: Log{}, + Log: shared.Log{}, Debug: Debug{ Addr: "", Token: "", @@ -120,38 +110,3 @@ func GetEnv() []string { return r } - -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil -} diff --git a/webdav/pkg/config/env.go b/webdav/pkg/config/mappings.go similarity index 81% rename from webdav/pkg/config/env.go rename to webdav/pkg/config/mappings.go index e0392c64f6..0a118c24af 100644 --- a/webdav/pkg/config/env.go +++ b/webdav/pkg/config/mappings.go @@ -1,13 +1,17 @@ package config -type mapping struct { - EnvVars []string // name of the EnvVars var. - Destination interface{} // memory address of the original config value to modify. +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) []mapping { - return []mapping{ +func structMappings(cfg *Config) []shared.EnvBinding { + return []shared.EnvBinding{ { EnvVars: []string{"WEBDAV_LOG_FILE", "OCIS_LOG_FILE"}, Destination: &cfg.Log.File, From 2dd9a7b14cb051bd9a54ee4ebea90e0dd31acd9e Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:32:58 +0100 Subject: [PATCH 058/147] new config framework in proxy --- ocis-pkg/config/config.go | 42 +++++-------------------------------- ocis/pkg/command/proxy.go | 17 +++++++++++++-- ocis/pkg/command/root.go | 9 +++----- proxy/pkg/command/root.go | 6 +++++- proxy/pkg/command/server.go | 21 +++++++++++++++++++ 5 files changed, 49 insertions(+), 46 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 0f1edfb95d..dc08ec50ff 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -1,12 +1,8 @@ package config import ( - "fmt" - "reflect" - "github.com/owncloud/ocis/ocis-pkg/shared" - gofig "github.com/gookit/config/v2" 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" @@ -180,39 +176,11 @@ func GetEnv() []string { return r } -// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination. -func (c *Config) UnmapEnv(gooconf *gofig.Config) error { - vals := structMappings(c) - for i := range vals { - for j := range vals[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 := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" { - - // get the destination type from destination - switch reflect.ValueOf(vals[i].Destination).Type().String() { - case "*bool": - r := gooconf.Bool(vals[i].EnvVars[j]) - *vals[i].Destination.(*bool) = r - case "*string": - r := gooconf.String(vals[i].EnvVars[j]) - *vals[i].Destination.(*string) = r - case "*int": - r := gooconf.Int(vals[i].EnvVars[j]) - *vals[i].Destination.(*int) = r - case "*float64": - // defaults to float64 - r := gooconf.Float(vals[i].EnvVars[j]) - *vals[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`", vals[i].EnvVars[j]) - } - } - } - } - - return nil +// 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 { diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 3b768a201d..7ed1f6c192 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -5,11 +5,14 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/proxy/pkg/command" "github.com/urfave/cli/v2" ) +var globalLog shared.Log + // ProxyCommand is the entry point for the proxy command. func ProxyCommand(cfg *config.Config) *cli.Command { return &cli.Command{ @@ -20,10 +23,20 @@ func ProxyCommand(cfg *config.Config) *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 + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - cfg.Proxy.Log = cfg.Log + // if proxy logging is empty in ocis.yaml + if (cfg.Proxy.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Proxy.Log = globalLog + } origCmd := command.Server(cfg.Proxy) return handleOriginalAction(c, origCmd) }, diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 4750c986b0..7272c357f5 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -62,7 +62,7 @@ func NewLogger(cfg *config.Config) log.Logger { ) } -// ParseConfig loads ocis configuration from known paths. +// ParseConfig loads ocis configuration. func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("ocis", cfg) if err != nil { @@ -71,9 +71,6 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { conf.LoadOSEnv(config.GetEnv(), false) - if err = cfg.UnmapEnv(conf); err != nil { - return err - } - - return nil + bindings := config.StructMappings(cfg) + return ociscfg.BindEnv(conf, bindings) } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 7544f9a91c..924461ea6c 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -85,7 +87,9 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Proxy.Log = cfg.Log + if (cfg.Proxy.Log == shared.Log{}) { + cfg.Proxy.Log = cfg.Log + } return SutureService{ cfg: cfg.Proxy, } diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 88c6667870..4853149589 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -8,6 +8,11 @@ import ( "strings" "time" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/coreos/go-oidc/v3/oidc" "github.com/cs3org/reva/pkg/token/manager/jwt" chimiddleware "github.com/go-chi/chi/v5/middleware" @@ -40,10 +45,26 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // 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 + } + } + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } From bff4ec48b0eedd87297170a5f6efcab1b514bae7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:41:59 +0100 Subject: [PATCH 059/147] new config framework in accounts --- accounts/pkg/command/root.go | 6 +++++- accounts/pkg/command/server.go | 19 +++++++++++++++++++ ocis/pkg/command/accounts.go | 17 +++++++++++++++-- ocis/pkg/command/proxy.go | 4 ++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 153a01545f..5b380faea5 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/accounts/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -87,7 +89,9 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Accounts.Log = cfg.Log + if (cfg.Accounts.Log == shared.Log{}) { + cfg.Accounts.Log = cfg.Log + } return SutureService{ cfg: cfg.Accounts, } diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 04f6410d2f..360e9c7ac9 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + 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/ocis-pkg/sync" "github.com/oklog/run" @@ -23,6 +27,8 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -33,6 +39,19 @@ func Server(cfg *config.Config) *cli.Command { 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 + } + } + return nil }, Action: func(c *cli.Context) error { diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 12d16109dd..b335b54963 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -6,12 +6,15 @@ package command import ( "github.com/owncloud/ocis/accounts/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) // AccountsCommand is the entrypoint for the accounts command. func AccountsCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "accounts", Usage: "Start accounts server", @@ -25,10 +28,20 @@ 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 + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - cfg.Accounts.Log = cfg.Log + // if accounts logging is empty in ocis.yaml + if (cfg.Accounts.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Accounts.Log = globalLog + } origCmd := command.Server(cfg.Accounts) return handleOriginalAction(c, origCmd) }, diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 7ed1f6c192..f2cfe5e2b3 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -11,10 +11,10 @@ import ( "github.com/urfave/cli/v2" ) -var globalLog shared.Log - // ProxyCommand is the entry point for the proxy command. func ProxyCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "proxy", Usage: "Start proxy server", From 3d90b21e3b3e6d64f4ef7faea499924ed36f00c1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:48:07 +0100 Subject: [PATCH 060/147] new config framework in glauth --- glauth/pkg/command/root.go | 6 +++++- glauth/pkg/command/server.go | 20 ++++++++++++++++++++ ocis/pkg/command/glauth.go | 34 ++++++++++++++-------------------- ocis/pkg/command/idp.go | 21 +-------------------- ocis/pkg/command/proxy.go | 2 -- 5 files changed, 40 insertions(+), 43 deletions(-) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 6c8baa610c..18ada7b921 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/glauth/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -79,7 +81,9 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.GLAuth.Log = cfg.Log + if (cfg.GLAuth.Log == shared.Log{}) { + cfg.GLAuth.Log = cfg.Log + } return SutureService{ cfg: cfg.GLAuth, } diff --git a/glauth/pkg/command/server.go b/glauth/pkg/command/server.go index d3e903503f..380eba4199 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + glauthcfg "github.com/glauth/glauth/v2/pkg/config" "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" @@ -24,6 +28,9 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -32,6 +39,19 @@ func Server(cfg *config.Config) *cli.Command { 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 + } + } + return nil }, Action: func(c *cli.Context) error { diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 4b9dbade53..dcbfda8bdb 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -2,45 +2,39 @@ package command import ( "github.com/owncloud/ocis/glauth/pkg/command" - svcconfig "github.com/owncloud/ocis/glauth/pkg/config" "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/urfave/cli/v2" ) // GLAuthCommand is the entrypoint for the glauth command. func GLAuthCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "glauth", Usage: "Start glauth server", Category: "Extensions", 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(configureGLAuth(cfg)) + // if Glauth logging is empty in ocis.yaml + if (cfg.GLAuth.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.GLAuth.Log = globalLog + } + 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/idp.go b/ocis/pkg/command/idp.go index 7663c94496..9ee679aad2 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -2,9 +2,7 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" - svcconfig "github.com/owncloud/ocis/idp/pkg/config" "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" ) @@ -22,7 +20,7 @@ func IDPCommand(cfg *config.Config) *cli.Command { return ParseConfig(ctx, cfg) }, 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 @@ -33,23 +31,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/proxy.go b/ocis/pkg/command/proxy.go index f2cfe5e2b3..3f327d8169 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -26,9 +26,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command { if err := ParseConfig(ctx, cfg); err != nil { return err } - globalLog = cfg.Log - return nil }, Action: func(c *cli.Context) error { From 6da95d3ddd5a27826e5fc7ed1d510d6e41f52a74 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:50:52 +0100 Subject: [PATCH 061/147] new config framework in graph --- graph/pkg/command/root.go | 6 +++++- graph/pkg/command/server.go | 26 +++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 094736e3bd..a41e800304 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/thejerf/suture/v4" "github.com/owncloud/ocis/graph/pkg/config" @@ -76,7 +78,9 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Graph.Log = cfg.Log + if (cfg.Accounts.Log == shared.Log{}) { + cfg.Accounts.Log = cfg.Log + } return SutureService{ cfg: cfg.Graph, } diff --git a/graph/pkg/command/server.go b/graph/pkg/command/server.go index 36daa2daa7..b8a90ecbdf 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/oklog/run" "github.com/owncloud/ocis/graph/pkg/config" "github.com/owncloud/ocis/graph/pkg/metrics" @@ -20,11 +24,31 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return ParseConfig(ctx, cfg) + 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From 261a800b6b710d2ce7d06b78e4370e3c6e47c800 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:53:24 +0100 Subject: [PATCH 062/147] new config framework in idp --- idp/pkg/command/root.go | 6 +++++- idp/pkg/command/server.go | 25 ++++++++++++++++++++++++- ocis/pkg/command/idp.go | 17 +++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index 1f78830a5d..e4cff0b260 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/idp/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" @@ -82,7 +84,9 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.IDP.Log = cfg.Log + if (cfg.Accounts.Log == shared.Log{}) { + cfg.Accounts.Log = cfg.Log + } return SutureService{ cfg: cfg.IDP, } diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index 1036f6d6ad..cb56afc2f5 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -4,12 +4,15 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" "github.com/owncloud/ocis/idp/pkg/tracing" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -20,6 +23,9 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -36,7 +42,24 @@ func Server(cfg *config.Config) *cli.Command { // cfg.IDP.SigningPrivateKeyFiles = ctx.StringSlice("signing-private-key") //} - return ParseConfig(ctx, cfg) + 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 9ee679aad2..01f12c210f 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,12 +3,15 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) // IDPCommand is the entrypoint for the idp command. func IDPCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "idp", Usage: "Start idp server", @@ -17,11 +20,21 @@ func IDPCommand(cfg *config.Config) *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 + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { + // if idp logging is empty in ocis.yaml + if (cfg.IDP.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.IDP.Log = globalLog + } idpCommand := command.Server(cfg.IDP) - if err := idpCommand.Before(c); err != nil { return err } From 51dc1715cee0bda98ada405a4934a6c38f14eb28 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 13:58:13 +0100 Subject: [PATCH 063/147] new config framework in ocs --- graph/pkg/command/root.go | 4 ++-- idp/pkg/command/root.go | 4 ++-- ocis/pkg/command/ocs.go | 50 ++++++++++++++++----------------------- ocs/pkg/command/root.go | 6 ++++- ocs/pkg/command/server.go | 25 +++++++++++++++++++- 5 files changed, 54 insertions(+), 35 deletions(-) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index a41e800304..4e07ad4b88 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -78,8 +78,8 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Accounts.Log == shared.Log{}) { - cfg.Accounts.Log = cfg.Log + if (cfg.Graph.Log == shared.Log{}) { + cfg.Graph.Log = cfg.Log } return SutureService{ cfg: cfg.Graph, diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index e4cff0b260..c62f9e7912 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -84,8 +84,8 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Accounts.Log == shared.Log{}) { - cfg.Accounts.Log = cfg.Log + if (cfg.IDP.Log == shared.Log{}) { + cfg.IDP.Log = cfg.Log } return SutureService{ cfg: cfg.IDP, diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 9a08c49d98..8c3b11baca 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -5,52 +5,44 @@ 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/ocs/pkg/command" - svcconfig "github.com/owncloud/ocis/ocs/pkg/config" "github.com/urfave/cli/v2" ) // OCSCommand is the entrypoint for the ocs command. func OCSCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "ocs", Usage: "Start ocs server", Category: "Extensions", + Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + globalLog = cfg.Log + + return nil + }, + Action: func(c *cli.Context) error { + // if accounts logging is empty in ocis.yaml + if (cfg.OCS.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.OCS.Log = globalLog + } + origCmd := command.Server(cfg.OCS) + return handleOriginalAction(c, origCmd) + }, Subcommands: []*cli.Command{ command.PrintVersion(cfg.OCS), }, - Before: func(ctx *cli.Context) error { - return ParseConfig(ctx, cfg) - }, - Action: func(c *cli.Context) error { - origCmd := command.Server(configureOCS(cfg)) - return handleOriginalAction(c, origCmd) - }, } } -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/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 5393527b42..4f939fc1b5 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -84,7 +86,9 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.OCS.Log = cfg.Log + if (cfg.OCS.Log == shared.Log{}) { + cfg.OCS.Log = cfg.Log + } return SutureService{ cfg: cfg.OCS, } diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index 7b3ff62523..dc4e6a4cb2 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + 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/ocs/pkg/tracing" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -22,11 +26,30 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return ParseConfig(ctx, cfg) + 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From 8f99fdc90291640ea77682aa4e7c09cdb286b6f2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:00:25 +0100 Subject: [PATCH 064/147] new config framework in settings --- ocis/pkg/command/settings.go | 40 ++++++++++++++-------------------- settings/pkg/command/root.go | 6 ++++- settings/pkg/command/server.go | 26 +++++++++++++++++++++- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 43fad1e790..9a25845662 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -5,15 +5,16 @@ 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/settings/pkg/command" - svcconfig "github.com/owncloud/ocis/settings/pkg/config" "github.com/urfave/cli/v2" ) // SettingsCommand is the entry point for the settings command. func SettingsCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "settings", Usage: "Start settings server", @@ -22,35 +23,26 @@ func SettingsCommand(cfg *config.Config) *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 + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureSettings(cfg)) + // if accounts logging is empty in ocis.yaml + if (cfg.Settings.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Settings.Log = globalLog + } + 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/settings/pkg/command/root.go b/settings/pkg/command/root.go index be06943a9a..2aba1f46ad 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -81,7 +83,9 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Settings.Log = cfg.Log + if (cfg.Settings.Log == shared.Log{}) { + cfg.Settings.Log = cfg.Log + } return SutureService{ cfg: cfg.Settings, } diff --git a/settings/pkg/command/server.go b/settings/pkg/command/server.go index e8215fe7d2..22e483af34 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/settings/pkg/config" @@ -21,11 +25,31 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return ParseConfig(ctx, cfg) + 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From ef1361846228e774c8132c57ac5e87dd965887dd Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:02:36 +0100 Subject: [PATCH 065/147] new config framework in store --- ocis/pkg/command/store.go | 37 +++++++++++++++++-------------------- store/pkg/command/root.go | 6 +++++- store/pkg/command/server.go | 25 ++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index b37d10a769..6394621179 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -5,15 +5,16 @@ 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/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", @@ -22,31 +23,27 @@ func StoreCommand(cfg *config.Config) *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/store/pkg/command/root.go b/store/pkg/command/root.go index 07425fa54f..6b6ef33c1e 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -84,7 +86,9 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Store.Log = cfg.Log + if (cfg.Accounts.Log == shared.Log{}) { + cfg.Accounts.Log = cfg.Log + } return SutureService{ cfg: cfg.Store, } diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index a8677eb169..6227198742 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,6 +3,10 @@ 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" @@ -21,7 +25,26 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From 96033dc9b3c7f7aeae8f06ba45e5aa946a7c76ad Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:06:29 +0100 Subject: [PATCH 066/147] new config framework in thumbnails --- ocis/pkg/command/thumbnails.go | 37 ++++++++++++++------------------ thumbnails/pkg/command/root.go | 6 +++++- thumbnails/pkg/command/server.go | 26 +++++++++++++++++++++- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index b81a0eedb5..a6054da87d 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -5,16 +5,16 @@ 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/thumbnails/pkg/command" "github.com/urfave/cli/v2" - - svcconfig "github.com/owncloud/ocis/thumbnails/pkg/config" ) // ThumbnailsCommand is the entrypoint for the thumbnails command. func ThumbnailsCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "thumbnails", Usage: "Start thumbnails server", @@ -23,31 +23,26 @@ func ThumbnailsCommand(cfg *config.Config) *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 + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureThumbnails(cfg)) + // if thumbnails logging is empty in ocis.yaml + if (cfg.Thumbnails.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Thumbnails.Log = globalLog + } + 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/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index b32d6b9b4f..c6c6be4240 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -82,7 +84,9 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Thumbnails.Log = cfg.Log + if (cfg.Thumbnails.Log == shared.Log{}) { + cfg.Thumbnails.Log = cfg.Log + } return SutureService{ cfg: cfg.Thumbnails, } diff --git a/thumbnails/pkg/command/server.go b/thumbnails/pkg/command/server.go index 8225495413..8e9db2538d 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "fmt" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/thumbnails/pkg/config" @@ -20,7 +24,27 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From c05c3db392465e3ece644ac2a8c15bec7bd44920 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:08:05 +0100 Subject: [PATCH 067/147] new config framework in web --- ocis/pkg/command/web.go | 34 ++++++++++++++++------------------ web/pkg/command/root.go | 6 +++++- web/pkg/command/server.go | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 736d320600..fcfbbb6f2a 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -2,43 +2,41 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/web/pkg/command" - svcconfig "github.com/owncloud/ocis/web/pkg/config" "github.com/urfave/cli/v2" ) // WebCommand is the entrypoint for the web command. func WebCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "web", Usage: "Start web server", Category: "Extensions", 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(configureWeb(cfg)) + // if accounts logging is empty in ocis.yaml + if (cfg.Web.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.Web.Log = globalLog + } + 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/web/pkg/command/root.go b/web/pkg/command/root.go index 4c654ed4f5..2fee6f7990 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -74,7 +76,9 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.Web.Log = cfg.Log + if (cfg.Web.Log == shared.Log{}) { + cfg.Web.Log = cfg.Log + } return SutureService{ cfg: cfg.Web, } diff --git a/web/pkg/command/server.go b/web/pkg/command/server.go index 1a63e88991..f02b79b323 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -6,6 +6,10 @@ import ( "io/ioutil" "strings" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/web/pkg/config" @@ -22,6 +26,9 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") } @@ -34,6 +41,20 @@ func Server(cfg *config.Config) *cli.Command { if cfg.Web.Config.OpenIDConnect.MetadataURL == "" { cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" } + + 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 + } + } + return nil }, Action: func(c *cli.Context) error { From e308992e854ab9506ac9f32ecd0b9964a58dae2b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:09:52 +0100 Subject: [PATCH 068/147] new config framework in webdav --- ocis/pkg/command/webdav.go | 36 ++++++++++++++++-------------------- webdav/pkg/command/root.go | 6 +++++- webdav/pkg/command/server.go | 26 +++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 22e58e944a..ae9e50fda3 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -5,15 +5,16 @@ 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/webdav/pkg/command" - svcconfig "github.com/owncloud/ocis/webdav/pkg/config" "github.com/urfave/cli/v2" ) // WebDAVCommand is the entrypoint for the webdav command. func WebDAVCommand(cfg *config.Config) *cli.Command { + var globalLog shared.Log + return &cli.Command{ Name: "webdav", Usage: "Start webdav server", @@ -22,31 +23,26 @@ func WebDAVCommand(cfg *config.Config) *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 + } + + globalLog = cfg.Log + + return nil }, Action: func(c *cli.Context) error { - origCmd := command.Server(configureWebDAV(cfg)) + // if webdav logging is empty in ocis.yaml + if (cfg.WebDAV.Log == shared.Log{}) && (globalLog != shared.Log{}) { + // we can safely inherit the global logging values. + cfg.WebDAV.Log = globalLog + } + 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/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index f6ee762a10..ea54640001 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "context" "os" + "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" @@ -82,7 +84,9 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - cfg.WebDAV.Log = cfg.Log + if (cfg.WebDAV.Log == shared.Log{}) { + cfg.WebDAV.Log = cfg.Log + } return SutureService{ cfg: cfg.WebDAV, } diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 009497d29f..8e28925e72 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -4,6 +4,10 @@ import ( "context" "strings" + gofig "github.com/gookit/config/v2" + ociscfg "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/webdav/pkg/config" @@ -20,11 +24,31 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { + // remember shared logging info to prevent empty overwrites + inLog := cfg.Log + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return ParseConfig(ctx, cfg) + 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From 9d0809bd8179da8b5bdc0d9bf8ae847ba38ead18 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 14:20:36 +0100 Subject: [PATCH 069/147] update drone star ocis debug level --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 14fe1dc9df..11833cabdc 100644 --- a/.drone.star +++ b/.drone.star @@ -1472,7 +1472,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []): "PROXY_ENABLE_BASIC_AUTH": True, "WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json", "IDP_IDENTIFIER_REGISTRATION_CONF": "/drone/src/tests/config/drone/identifier-registration.yml", - "OCIS_LOG_LEVEL": "debug", + "OCIS_LOG_LEVEL": "error", "SETTINGS_DATA_PATH": "/srv/app/tmp/ocis/settings", } From e7f9fb3bcb58eb8ac8bfab4ef99874f746e0c4e1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 8 Nov 2021 19:38:40 +0100 Subject: [PATCH 070/147] refactor NewLogger away to ocis-pkg --- accounts/pkg/command/root.go | 12 ------------ accounts/pkg/command/server.go | 4 +++- accounts/pkg/proto/v0/accounts.pb.micro_test.go | 5 ++--- ocis-pkg/log/log.go | 13 +++++++++++++ ocs/pkg/server/http/svc_test.go | 4 ++-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 5b380faea5..910a9240c1 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -8,7 +8,6 @@ import ( "github.com/owncloud/ocis/accounts/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/thejerf/suture/v4" "github.com/urfave/cli/v2" @@ -57,17 +56,6 @@ 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 known paths. func ParseConfig(c *cli.Context, cfg *config.Config) error { conf, err := ociscfg.BindSourcesToStructs("accounts", cfg) diff --git a/accounts/pkg/command/server.go b/accounts/pkg/command/server.go index 360e9c7ac9..bb820b921f 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -4,6 +4,8 @@ import ( "context" "strings" + "github.com/owncloud/ocis/ocis-pkg/log" + gofig "github.com/gookit/config/v2" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/shared" @@ -55,7 +57,7 @@ func Server(cfg *config.Config) *cli.Command { 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/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index deb52596e8..3a4054d041 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/ocis-pkg/log/log.go b/ocis-pkg/log/log.go index 0436391955..42ae508f82 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/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 24ffb6e1d5..32e38a9c11 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -22,11 +22,11 @@ import ( "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" @@ -562,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 { From 2c49ee6ab901ff619f0bda0ff9aa74c146b14bb1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 00:50:27 +0100 Subject: [PATCH 071/147] first doc draft + glauth logging small refactor --- docs/ocis/config.md | 126 ++++++++++++++++++ .../static/ocis-config-redesign.drawio.svg | 4 + glauth/pkg/command/root.go | 12 +- ocis-pkg/config/config_test.go | 17 +++ 4 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 docs/ocis/config.md create mode 100644 docs/ocis/static/ocis-config-redesign.drawio.svg create mode 100644 ocis-pkg/config/config_test.go diff --git a/docs/ocis/config.md b/docs/ocis/config.md new file mode 100644 index 0000000000..56690d3119 --- /dev/null +++ b/docs/ocis/config.md @@ -0,0 +1,126 @@ +--- +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 shared values, such as config file sources (`--config-file`) or logging (`--log-level`, `--log-pretty`, `--log-file` or `--log-color`). + +The hierarchy is clear enough, leaving us with a clear: + +_(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 with the sources mentioned previously. An administrator must be aware of this 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. + +#### 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. This is a living design document, and if the need arise where we want to stick to the loading defaults, we could. + +#### 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` are parsed, the `proxy.yaml` and finally any environment variables. + +## Default config values (in yaml) + +TBD. Needs to be generated and merged with the env mappings. 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 0000000000..ff2ee40fac --- /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/root.go b/glauth/pkg/command/root.go index 18ada7b921..4d68ded216 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -4,11 +4,11 @@ import ( "context" "os" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/owncloud/ocis/glauth/pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" + oclog "github.com/owncloud/ocis/ocis-pkg/log" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/thejerf/suture/v4" "github.com/urfave/cli/v2" @@ -52,13 +52,7 @@ 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 known paths. diff --git a/ocis-pkg/config/config_test.go b/ocis-pkg/config/config_test.go new file mode 100644 index 0000000000..6a77d3cda9 --- /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)) +} From 82a66b51d9583ff7dea019fa6c05acfc0346d396 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 10:20:34 +0100 Subject: [PATCH 072/147] added shared log values to config template --- docs/ocis/config.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/ocis/config.md b/docs/ocis/config.md index 56690d3119..f644373f24 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -121,6 +121,45 @@ You are using the supervised mode whenever you issue the `ocis server` command. 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` are parsed, the `proxy.yaml` and finally any 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. From 26aa37c2d764a1ae12c48f2dcfcc08a412a4998d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 12:12:34 +0100 Subject: [PATCH 073/147] reword docs --- docs/ocis/config.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/ocis/config.md b/docs/ocis/config.md index f644373f24..11bc35bfd9 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -21,7 +21,7 @@ In order to simplify deployments and development the configuration model from oC 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 shared values, such as config file sources (`--config-file`) or logging (`--log-level`, `--log-pretty`, `--log-file` or `--log-color`). -The hierarchy is clear enough, leaving us with a clear: +The hierarchy is clear enough, leaving us with: _(each element above overwrites its precedent)_ @@ -29,7 +29,7 @@ _(each element above overwrites its precedent)_ 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 with the sources mentioned previously. An administrator must be aware of this sources, since mis-managing them can be a source of confusion, having undesired transformations on config files believed not to be applied. +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 @@ -115,11 +115,11 @@ Since one can run an extension using the runtime (supervised) or not (unsupervis #### 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. This is a living design document, and if the need arise where we want to stick to the loading defaults, we could. +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` are parsed, the `proxy.yaml` and finally any environment variables. +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 From c335c4dc292e6cb355236cd033b6dee195f44827 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 14:14:31 +0100 Subject: [PATCH 074/147] config dump endpoint for proxy --- ocis-pkg/service/debug/option.go | 8 ++++++++ ocis-pkg/service/debug/service.go | 4 ++++ proxy/pkg/server/debug/server.go | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/ocis-pkg/service/debug/option.go b/ocis-pkg/service/debug/option.go index ef39d9ce42..d33420ca49 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 e0fc938537..8112618a53 100644 --- a/ocis-pkg/service/debug/service.go +++ b/ocis-pkg/service/debug/service.go @@ -28,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/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 2d8bfb7382..b4106f2a8c 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) + } +} From ee03185b22499a696d07aab718fa613e7656205b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 14:19:28 +0100 Subject: [PATCH 075/147] add support for json driver --- ocis-pkg/config/helpers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 08dd5ed75c..8cb6e00790 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -17,11 +17,11 @@ var ( ".config/", } - // supportedExtensions is determined by gookit/config. For the purposes of the PR MVP we will focus on yaml, looking - // into extending it to all supported drivers. + // supportedExtensions is determined by gookit/config. supportedExtensions = []string{ "yaml", "yml", + "json", } ) From 16bb92f89c2c00c28bd5918b60ee7a871c23b95b Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 9 Nov 2021 15:22:26 +0100 Subject: [PATCH 076/147] fix hello deployment --- .../config/ocis/entrypoint-override.sh | 5 - .../ocis/{proxy-config.json => proxy.json} | 0 .../examples/ocis_hello/docker-compose.yml | 7 +- ocis-pkg/config/helpers.go | 4 +- proxy/pkg/config/config.go | 165 +++++++++++++++++- proxy/pkg/config/mappings.go | 5 - proxy/pkg/proxy/proxy.go | 165 ------------------ proxy/pkg/proxy/proxy_integration_test.go | 1 - proxy/pkg/proxy/proxy_test.go | 2 +- 9 files changed, 167 insertions(+), 187 deletions(-) rename deployments/examples/ocis_hello/config/ocis/{proxy-config.json => proxy.json} (100%) diff --git a/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh b/deployments/examples/ocis_hello/config/ocis/entrypoint-override.sh index d90e287a94..6cd8f27182 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 bde3af9d84..635517e87d 100644 --- a/deployments/examples/ocis_hello/docker-compose.yml +++ b/deployments/examples/ocis_hello/docker-compose.yml @@ -52,7 +52,8 @@ services: environment: OCIS_URL: https://${OCIS_DOMAIN:-ocis.owncloud.test} OCIS_DOMAIN: ${OCIS_DOMAIN:-ocis.owncloud.test} - OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose + #OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose + PROXY_LOG_LEVEL: debug PROXY_OIDC_INSECURE: "${INSECURE:-false}" # needed if Traefik is using self generated certificates PROXY_TLS: "false" # do not use SSL between Traefik and oCIS # change default secrets @@ -63,14 +64,12 @@ 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 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/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 8cb6e00790..6acb6654f7 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -12,8 +12,8 @@ import ( var ( defaultLocations = []string{ - filepath.Join(os.Getenv("HOME"), "/.ocis/config"), - "/etc/ocis", + filepath.Join(os.Getenv("HOME"), "/.ocis/config/"), + "/etc/ocis/", ".config/", } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index fec1e7449f..9e858a0eed 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -108,7 +108,6 @@ type Cache struct { type Config struct { OcisURL string - File string `mapstructure:"file"` Log shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` @@ -203,8 +202,7 @@ func New() *Config { // DefaultConfig are values stored in the flag set, but moved to a struct. func DefaultConfig() *Config { return &Config{ - File: "", - Log: shared.Log{}, // logging config is inherited. + Log: shared.Log{}, // logging config is inherited. Debug: Debug{ Addr: "0.0.0.0:9205", Token: "", @@ -253,6 +251,165 @@ func DefaultConfig() *Config { //AutoprovisionAccounts: false, //EnableBasicAuth: false, //InsecureBackends: false, - Context: nil, + 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 index fc9433818f..f417ec2576 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -52,11 +52,6 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Debug.Addr, }, - { - EnvVars: []string{"PROXY_CONFIG_FILE"}, - Destination: &cfg.File, - }, - // Tracing { EnvVars: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, diff --git a/proxy/pkg/proxy/proxy.go b/proxy/pkg/proxy/proxy.go index 465c1563c8..7681defb80 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") @@ -263,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 b9777ac666..3e7736e83b 100644 --- a/proxy/pkg/proxy/proxy_integration_test.go +++ b/proxy/pkg/proxy/proxy_integration_test.go @@ -215,7 +215,6 @@ func (tc *testCase) expectProxyTo(strURL string) testCase { func testConfig(policy []config.Policy) *config.Config { return &config.Config{ - File: "", Log: shared.Log{}, Debug: config.Debug{}, HTTP: config.HTTP{}, diff --git a/proxy/pkg/proxy/proxy_test.go b/proxy/pkg/proxy/proxy_test.go index 8eefe3143b..256a559dc4 100644 --- a/proxy/pkg/proxy/proxy_test.go +++ b/proxy/pkg/proxy/proxy_test.go @@ -13,7 +13,7 @@ type matchertest struct { } func TestPrefixRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ From e4742fbb53367af7b558d0386e34730cb780c1a6 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 9 Nov 2021 15:40:22 +0100 Subject: [PATCH 077/147] fix cs3 users example --- .../cs3_users_ocis/config/ocis/entrypoint-override.sh | 5 ----- .../config/ocis/{proxy-config.json => proxy.json} | 0 deployments/examples/cs3_users_ocis/docker-compose.yml | 4 +--- deployments/examples/ocis_hello/docker-compose.yml | 3 +-- 4 files changed, 2 insertions(+), 10 deletions(-) rename deployments/examples/cs3_users_ocis/config/ocis/{proxy-config.json => proxy.json} (100%) 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 ac598cb60f..2fd09563b2 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 501e4af7f4..9b9f10f772 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} @@ -90,7 +88,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/ocis_hello/docker-compose.yml b/deployments/examples/ocis_hello/docker-compose.yml index 635517e87d..997a491416 100644 --- a/deployments/examples/ocis_hello/docker-compose.yml +++ b/deployments/examples/ocis_hello/docker-compose.yml @@ -52,8 +52,7 @@ services: environment: OCIS_URL: https://${OCIS_DOMAIN:-ocis.owncloud.test} OCIS_DOMAIN: ${OCIS_DOMAIN:-ocis.owncloud.test} - #OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose - PROXY_LOG_LEVEL: debug + OCIS_LOG_LEVEL: ${OCIS_LOG_LEVEL:-error} # make oCIS less verbose PROXY_OIDC_INSECURE: "${INSECURE:-false}" # needed if Traefik is using self generated certificates PROXY_TLS: "false" # do not use SSL between Traefik and oCIS # change default secrets From 713c0bb3d2350f5fb0072364ba6e9351f11ef0f9 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 9 Nov 2021 16:10:11 +0100 Subject: [PATCH 078/147] fix oc10 ocis parallel deployment --- .../config/ocis/entrypoint-override.sh | 11 ----------- .../ocis/{proxy-config.dist.json => proxy.json} | 7 ++++--- .../examples/oc10_ocis_parallel/docker-compose.yml | 3 +-- 3 files changed, 5 insertions(+), 16 deletions(-) rename deployments/examples/oc10_ocis_parallel/config/ocis/{proxy-config.dist.json => proxy.json} (95%) 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 547ece0141..cd72bb548d 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 95% 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 23269f4323..993327d628 100644 --- a/deployments/examples/oc10_ocis_parallel/config/ocis/proxy-config.dist.json +++ b/deployments/examples/oc10_ocis_parallel/config/ocis/proxy.json @@ -1,7 +1,4 @@ { - "log": { - "level": "PROXY_LOG_LEVEL" - }, "policy_selector": { "claims": { "default_policy": "oc10", @@ -54,6 +51,10 @@ "endpoint": "/index.php/", "backend": "http://localhost:9140" }, + { + "endpoint": "/app/", + "backend": "http://localhost:9140" + }, { "endpoint": "/data", "backend": "http://localhost:9140" diff --git a/deployments/examples/oc10_ocis_parallel/docker-compose.yml b/deployments/examples/oc10_ocis_parallel/docker-compose.yml index cd02bd92b8..c498927918 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_OIDC_INSECURE: "${INSECURE:-false}" # needed if Traefik is using self generated certificates PROXY_TLS: "false" # do not use SSL between Traefik and oCIS @@ -119,7 +118,7 @@ services: OCIS_MACHINE_AUTH_API_KEY: ${OCIS_MACHINE_AUTH_API_KEY:-change-me-please} 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 From 51bee0e5313d5c5f397660ff43d32315ed1276f0 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 17:29:46 +0100 Subject: [PATCH 079/147] sort out flags precedence --- .vscode/launch.json | 4 ++-- accounts/pkg/config/mappings.go | 18 +++++++++--------- glauth/pkg/config/mappings.go | 16 ++++++++-------- graph-explorer/pkg/config/mappings.go | 20 ++++++++++---------- graph-explorer/pkg/flagset/flagset.go | 24 ------------------------ graph/pkg/config/mappings.go | 20 ++++++++++---------- idp/pkg/config/mappings.go | 18 +++++++++--------- ocs/pkg/config/mappings.go | 24 ++++++++++++------------ proxy/pkg/config/mappings.go | 22 +++++++++++----------- settings/pkg/config/mappings.go | 16 ++++++++-------- storage/pkg/flagset/frontend.go | 2 +- storage/pkg/flagset/gateway.go | 2 +- storage/pkg/flagset/root.go | 6 +++--- store/pkg/config/mappings.go | 16 ++++++++-------- thumbnails/pkg/config/mappings.go | 16 ++++++++-------- web/pkg/config/mappings.go | 22 +++++++++++----------- web/pkg/flagset/flagset.go | 6 +++--- webdav/pkg/config/mappings.go | 18 +++++++++--------- 18 files changed, 123 insertions(+), 147 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 37d283a4bf..1062890650 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,6 +14,6 @@ "OCIS_LOG_COLOR": "true", "PROXY_ENABLE_BASIC_AUTH": "true" } - }, + } ] -} \ No newline at end of file +} diff --git a/accounts/pkg/config/mappings.go b/accounts/pkg/config/mappings.go index cb710237f6..4789fc8d69 100644 --- a/accounts/pkg/config/mappings.go +++ b/accounts/pkg/config/mappings.go @@ -13,31 +13,31 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"ACCOUNTS_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "ACCOUNTS_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "ACCOUNTS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"ACCOUNTS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "ACCOUNTS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"ACCOUNTS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "ACCOUNTS_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"ACCOUNTS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "ACCOUNTS_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"ACCOUNTS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "ACCOUNTS_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"ACCOUNTS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "ACCOUNTS_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -85,7 +85,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Asset.Path, }, { - EnvVars: []string{"ACCOUNTS_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "ACCOUNTS_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, { @@ -109,7 +109,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Repo.CS3.DataPrefix, }, { - EnvVars: []string{"ACCOUNTS_STORAGE_CS3_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "ACCOUNTS_STORAGE_CS3_JWT_SECRET"}, Destination: &cfg.Repo.CS3.JWTSecret, }, { diff --git a/glauth/pkg/config/mappings.go b/glauth/pkg/config/mappings.go index c1af621315..b7fc75748d 100644 --- a/glauth/pkg/config/mappings.go +++ b/glauth/pkg/config/mappings.go @@ -13,19 +13,19 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "GLAUTH_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"GLAUTH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "GLAUTH_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"GLAUTH_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "GLAUTH_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"GLAUTH_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "GLAUTH_LOG_FILE"}, Destination: &cfg.Log.File, }, { @@ -33,19 +33,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"GLAUTH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "GLAUTH_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"GLAUTH_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "GLAUTH_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"GLAUTH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GLAUTH_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"GLAUTH_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GLAUTH_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { diff --git a/graph-explorer/pkg/config/mappings.go b/graph-explorer/pkg/config/mappings.go index 09173763ee..85014e61b6 100644 --- a/graph-explorer/pkg/config/mappings.go +++ b/graph-explorer/pkg/config/mappings.go @@ -13,35 +13,35 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"GRAPH_EXPLORER_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_EXPLORER_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"GRAPH_EXPLORER_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_EXPLORER_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"GRAPH_EXPLORER_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_EXPLORER_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"GRAPH_EXPLORER_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_EXPLORER_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"GRAPH_EXPLORER_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_EXPLORER_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"GRAPH_EXPLORER_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_EXPLORER_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"GRAPH_EXPLORER_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_EXPLORER_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"GRAPH_EXPLORER_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_EXPLORER_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -77,7 +77,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.Namespace, }, { - EnvVars: []string{"GRAPH_EXPLORER_ISSUER", "OCIS_URL"}, + EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_ISSUER"}, Destination: &cfg.GraphExplorer.Issuer, }, { @@ -85,7 +85,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.GraphExplorer.ClientID, }, { - EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL_BASE", "OCIS_URL"}, + EnvVars: []string{"OCIS_URL", "GRAPH_EXPLORER_GRAPH_URL_BASE"}, Destination: &cfg.GraphExplorer.GraphURLBase, }, { diff --git a/graph-explorer/pkg/flagset/flagset.go b/graph-explorer/pkg/flagset/flagset.go index 5215ded0d5..ef4c46e863 100644 --- a/graph-explorer/pkg/flagset/flagset.go +++ b/graph-explorer/pkg/flagset/flagset.go @@ -6,30 +6,6 @@ import ( "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{ diff --git a/graph/pkg/config/mappings.go b/graph/pkg/config/mappings.go index d32b519aa7..a8239f37ee 100644 --- a/graph/pkg/config/mappings.go +++ b/graph/pkg/config/mappings.go @@ -17,35 +17,35 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"GRAPH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "GRAPH_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"GRAPH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "GRAPH_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"GRAPH_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "GRAPH_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"GRAPH_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "GRAPH_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"GRAPH_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "GRAPH_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"GRAPH_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "GRAPH_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"GRAPH_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "GRAPH_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"GRAPH_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "GRAPH_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -81,7 +81,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.Namespace, }, { - EnvVars: []string{"GRAPH_SPACES_WEBDAV_BASE", "OCIS_URL"}, + EnvVars: []string{"OCIS_URL", "GRAPH_SPACES_WEBDAV_BASE"}, Destination: &cfg.Spaces.WebDavBase, }, { @@ -93,7 +93,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Spaces.DefaultQuota, }, { - EnvVars: []string{"GRAPH_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "GRAPH_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, { diff --git a/idp/pkg/config/mappings.go b/idp/pkg/config/mappings.go index 60467e6de2..f450cc049f 100644 --- a/idp/pkg/config/mappings.go +++ b/idp/pkg/config/mappings.go @@ -13,19 +13,19 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"IDP_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "IDP_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"IDP_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "IDP_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"IDP_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "IDP_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"IDP_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "IDP_LOG_FILE"}, Destination: &cfg.Log.File, }, { @@ -33,19 +33,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"IDP_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "IDP_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"IDP_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "IDP_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"IDP_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "IDP_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"IDP_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "IDP_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -141,7 +141,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.TLSKey, }, { - EnvVars: []string{"IDP_ISS", "OCIS_URL"}, // IDP_ISS takes precedence over OCIS_URL + EnvVars: []string{"OCIS_URL", "IDP_ISS"}, // IDP_ISS takes precedence over OCIS_URL Destination: &cfg.IDP.Iss, }, { diff --git a/ocs/pkg/config/mappings.go b/ocs/pkg/config/mappings.go index 7346ffd98e..cdb721ff64 100644 --- a/ocs/pkg/config/mappings.go +++ b/ocs/pkg/config/mappings.go @@ -13,19 +13,19 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"OCS_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "OCS_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"OCS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "OCS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"OCS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "OCS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"OCS_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "OCS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { @@ -33,19 +33,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"OCS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "OCS_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"OCS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "OCS_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"OCS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "OCS_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"OCS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "OCS_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -85,7 +85,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.Root, }, { - EnvVars: []string{"OCS_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "OCS_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, { @@ -97,15 +97,15 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.RevaAddress, }, { - EnvVars: []string{"OCS_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, + EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "OCS_MACHINE_AUTH_API_KEY"}, Destination: &cfg.MachineAuthAPIKey, }, { - EnvVars: []string{"OCS_IDM_ADDRESS", "OCIS_URL"}, + EnvVars: []string{"OCIS_URL", "OCS_IDM_ADDRESS"}, Destination: &cfg.IdentityManagement.Address, }, { - EnvVars: []string{"OCS_STORAGE_USERS_DRIVER", "STORAGE_USERS_DRIVER"}, + EnvVars: []string{"STORAGE_USERS_DRIVER", "OCS_STORAGE_USERS_DRIVER"}, Destination: &cfg.StorageUsersDriver, }, } diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index f417ec2576..a13fedf37d 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -24,19 +24,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ // Logging { - EnvVars: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "PROXY_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "PROXY_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "PROXY_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"PROXY_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "PROXY_LOG_FILE"}, Destination: &cfg.Log.File, }, @@ -54,19 +54,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { // Tracing { - EnvVars: []string{"PROXY_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "PROXY_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"PROXY_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "PROXY_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"PROXY_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "PROXY_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"PROXY_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "PROXY_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -124,7 +124,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.TLS, }, { - EnvVars: []string{"PROXY_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "PROXY_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, @@ -137,7 +137,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.InsecureBackends, }, { - EnvVars: []string{"PROXY_OIDC_ISSUER", "OCIS_URL"}, + EnvVars: []string{"OCIS_URL", "PROXY_OIDC_ISSUER"}, Destination: &cfg.OIDC.Issuer, }, { @@ -173,7 +173,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.AccountBackend, }, { - EnvVars: []string{"PROXY_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, + EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "PROXY_MACHINE_AUTH_API_KEY"}, Destination: &cfg.MachineAuthAPIKey, }, // there are 2 missing bindings: diff --git a/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go index f37e05b848..c19dfcaadd 100644 --- a/settings/pkg/config/mappings.go +++ b/settings/pkg/config/mappings.go @@ -13,15 +13,15 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"SETTINGS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "SETTINGS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"SETTINGS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "SETTINGS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"SETTINGS_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "SETTINGS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { @@ -29,19 +29,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"SETTINGS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "SETTINGS_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"SETTINGS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "SETTINGS_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"SETTINGS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "SETTINGS_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"SETTINGS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "SETTINGS_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -101,7 +101,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Service.DataPath, }, { - EnvVars: []string{"SETTINGS_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "SETTINGS_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, } diff --git a/storage/pkg/flagset/frontend.go b/storage/pkg/flagset/frontend.go index 4f5956aec8..eb963a7e65 100644 --- a/storage/pkg/flagset/frontend.go +++ b/storage/pkg/flagset/frontend.go @@ -103,7 +103,7 @@ func FrontendWithConfig(cfg *config.Config) []cli.Flag { 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 + EnvVars: []string{"OCIS_URL", "STORAGE_FRONTEND_PUBLIC_URL"}, // STORAGE_FRONTEND_PUBLIC_URL takes precedence over OCIS_URL Destination: &cfg.Reva.Frontend.PublicURL, }, &cli.StringSliceFlag{ diff --git a/storage/pkg/flagset/gateway.go b/storage/pkg/flagset/gateway.go index 34c008e0ce..01de385663 100644 --- a/storage/pkg/flagset/gateway.go +++ b/storage/pkg/flagset/gateway.go @@ -186,7 +186,7 @@ func GatewayWithConfig(cfg *config.Config) []cli.Flag { 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 + EnvVars: []string{"OCIS_URL", "STORAGE_FRONTEND_PUBLIC_URL"}, // STORAGE_FRONTEND_PUBLIC_URL takes precedence over OCIS_URL Destination: &cfg.Reva.Frontend.PublicURL, }, &cli.StringFlag{ diff --git a/storage/pkg/flagset/root.go b/storage/pkg/flagset/root.go index dce2fc5818..6f6130d228 100644 --- a/storage/pkg/flagset/root.go +++ b/storage/pkg/flagset/root.go @@ -18,19 +18,19 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { &cli.StringFlag{ Name: "log-level", Usage: "Set logging level", - EnvVars: []string{"STORAGE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "STORAGE_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", Usage: "Enable pretty logging", - EnvVars: []string{"STORAGE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "STORAGE_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", Usage: "Enable colored logging", - EnvVars: []string{"STORAGE_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "STORAGE_LOG_COLOR"}, Destination: &cfg.Log.Color, }, } diff --git a/store/pkg/config/mappings.go b/store/pkg/config/mappings.go index 5c31346d17..62eea4e71e 100644 --- a/store/pkg/config/mappings.go +++ b/store/pkg/config/mappings.go @@ -13,35 +13,35 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"STORE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "STORE_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"STORE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "STORE_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"STORE_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "STORE_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"STORE_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "STORE_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"STORE_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "STORE_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"STORE_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "STORE_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"STORE_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "STORE_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"STORE_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "STORE_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index 9c44c5c812..2a7e181a36 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -13,19 +13,19 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"THUMBNAILS_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "THUMBNAILS_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"THUMBNAILS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "THUMBNAILS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"THUMBNAILS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "THUMBNAILS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"THUMBNAILS_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "THUMBNAILS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { @@ -33,19 +33,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"THUMBNAILS_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "THUMBNAILS_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"THUMBNAILS_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "THUMBNAILS_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"THUMBNAILS_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "THUMBNAILS_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"THUMBNAILS_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "THUMBNAILS_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { diff --git a/web/pkg/config/mappings.go b/web/pkg/config/mappings.go index d54190f5ae..31d82b7726 100644 --- a/web/pkg/config/mappings.go +++ b/web/pkg/config/mappings.go @@ -13,19 +13,19 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"WEB_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "WEB_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"WEB_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "WEB_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"WEB_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "WEB_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { - EnvVars: []string{"WEB_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "WEB_LOG_FILE"}, Destination: &cfg.Log.File, }, { @@ -33,19 +33,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"WEB_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "WEB_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"WEB_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "WEB_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"WEB_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "WEB_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"WEB_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "WEB_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -93,11 +93,11 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Web.Path, }, { - EnvVars: []string{"WEB_UI_CONFIG_SERVER", "OCIS_URL"}, // WEB_UI_CONFIG_SERVER takes precedence over OCIS_URL + EnvVars: []string{"OCIS_URL", "WEB_UI_CONFIG_SERVER"}, // WEB_UI_CONFIG_SERVER takes precedence over OCIS_URL Destination: &cfg.Web.Config.Server, }, { - EnvVars: []string{"WEB_UI_THEME_SERVER", "OCIS_URL"}, // WEB_UI_THEME_SERVER takes precedence over OCIS_URL + EnvVars: []string{"OCIS_URL", "WEB_UI_THEME_SERVER"}, // WEB_UI_THEME_SERVER takes precedence over OCIS_URL Destination: &cfg.Web.ThemeServer, }, { @@ -113,7 +113,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Web.Config.OpenIDConnect.MetadataURL, }, { - EnvVars: []string{"WEB_OIDC_AUTHORITY", "OCIS_URL"}, // WEB_OIDC_AUTHORITY takes precedence over OCIS_URL + EnvVars: []string{"OCIS_URL", "WEB_OIDC_AUTHORITY"}, // WEB_OIDC_AUTHORITY takes precedence over OCIS_URL Destination: &cfg.Web.Config.OpenIDConnect.Authority, }, { diff --git a/web/pkg/flagset/flagset.go b/web/pkg/flagset/flagset.go index f389805ae2..c1aa3eae63 100644 --- a/web/pkg/flagset/flagset.go +++ b/web/pkg/flagset/flagset.go @@ -12,19 +12,19 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { &cli.StringFlag{ Name: "log-level", Usage: "Set logging level", - EnvVars: []string{"WEB_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "WEB_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", Usage: "Enable pretty logging", - EnvVars: []string{"WEB_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "WEB_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", Usage: "Enable colored logging", - EnvVars: []string{"WEB_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "WEB_LOG_COLOR"}, Destination: &cfg.Log.Color, }, } diff --git a/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index 0a118c24af..e2637e4782 100644 --- a/webdav/pkg/config/mappings.go +++ b/webdav/pkg/config/mappings.go @@ -13,19 +13,19 @@ func StructMappings(cfg *Config) []shared.EnvBinding { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ { - EnvVars: []string{"WEBDAV_LOG_FILE", "OCIS_LOG_FILE"}, + EnvVars: []string{"OCIS_LOG_FILE", "WEBDAV_LOG_FILE"}, Destination: &cfg.Log.File, }, { - EnvVars: []string{"WEBDAV_LOG_LEVEL", "OCIS_LOG_LEVEL"}, + EnvVars: []string{"OCIS_LOG_LEVEL", "WEBDAV_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, { - EnvVars: []string{"WEBDAV_LOG_PRETTY", "OCIS_LOG_PRETTY"}, + EnvVars: []string{"OCIS_LOG_PRETTY", "WEBDAV_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, { - EnvVars: []string{"WEBDAV_LOG_COLOR", "OCIS_LOG_COLOR"}, + EnvVars: []string{"OCIS_LOG_COLOR", "WEBDAV_LOG_COLOR"}, Destination: &cfg.Log.Color, }, { @@ -33,19 +33,19 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.File, }, { - EnvVars: []string{"WEBDAV_TRACING_ENABLED", "OCIS_TRACING_ENABLED"}, + EnvVars: []string{"OCIS_TRACING_ENABLED", "WEBDAV_TRACING_ENABLED"}, Destination: &cfg.Tracing.Enabled, }, { - EnvVars: []string{"WEBDAV_TRACING_TYPE", "OCIS_TRACING_TYPE"}, + EnvVars: []string{"OCIS_TRACING_TYPE", "WEBDAV_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, { - EnvVars: []string{"WEBDAV_TRACING_ENDPOINT", "OCIS_TRACING_ENDPOINT"}, + EnvVars: []string{"OCIS_TRACING_ENDPOINT", "WEBDAV_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, { - EnvVars: []string{"WEBDAV_TRACING_COLLECTOR", "OCIS_TRACING_COLLECTOR"}, + EnvVars: []string{"OCIS_TRACING_COLLECTOR", "WEBDAV_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, { @@ -85,7 +85,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.HTTP.Root, }, { - EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"}, + EnvVars: []string{"OCIS_URL", "OCIS_PUBLIC_URL"}, Destination: &cfg.OcisPublicURL, }, { From b9618175193b5dddb38ed3814874c2f20ef752bd Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 9 Nov 2021 20:40:35 +0100 Subject: [PATCH 080/147] fix proxy default config --- proxy/pkg/proxy/proxy_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/pkg/proxy/proxy_test.go b/proxy/pkg/proxy/proxy_test.go index 256a559dc4..c0b584d6dc 100644 --- a/proxy/pkg/proxy/proxy_test.go +++ b/proxy/pkg/proxy/proxy_test.go @@ -32,7 +32,7 @@ func TestPrefixRouteMatcher(t *testing.T) { } func TestQueryRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -59,7 +59,7 @@ func TestQueryRouteMatcher(t *testing.T) { } func TestRegexRouteMatcher(t *testing.T) { - cfg := config.New() + cfg := config.DefaultConfig() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ From aa67106e04b142a4ef9935085eb0621171e3bdbe Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 12:51:57 +0100 Subject: [PATCH 081/147] sane common configurations --- accounts/pkg/command/root.go | 18 ++++++++++--- accounts/pkg/command/server.go | 21 +-------------- accounts/pkg/config/config.go | 13 +++++----- go.mod | 2 +- ocis-pkg/config/config.go | 5 ++-- ocis-pkg/shared/shared_types.go | 7 +++++ ocis/pkg/command/proxy.go | 14 ++++------ proxy/pkg/command/root.go | 45 ++++++++++++++++++++------------- proxy/pkg/command/server.go | 29 --------------------- proxy/pkg/config/config.go | 7 +++-- proxy/pkg/config/mappings.go | 8 +++--- 11 files changed, 72 insertions(+), 97 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index 910a9240c1..19eae93b2f 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -63,8 +63,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &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(), false) + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) @@ -77,9 +89,7 @@ type SutureService struct { // NewSutureService creates a new accounts.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Accounts.Log == shared.Log{}) { - cfg.Accounts.Log = cfg.Log - } + 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 bb820b921f..45298d2980 100644 --- a/accounts/pkg/command/server.go +++ b/accounts/pkg/command/server.go @@ -6,10 +6,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/log" - 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/ocis-pkg/sync" "github.com/oklog/run" @@ -29,8 +25,6 @@ func Server(cfg *config.Config) *cli.Command { Usage: "Start ocis accounts service", Description: "uses an LDAP server as the storage backend", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -41,23 +35,10 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { - logger := log.LoggerFromConfig("accounts", cfg.Log) + logger := log.LoggerFromConfig("accounts", *cfg.Log) err := tracing.Configure(cfg) if err != nil { return err diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index e382cc9651..fbb299a632 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -125,12 +125,14 @@ type Tracing struct { // Config merges all Account config parameters. type Config struct { + *shared.Commons + LDAP LDAP `mapstructure:"ldap"` HTTP HTTP `mapstructure:"http"` GRPC GRPC `mapstructure:"grpc"` Server Server `mapstructure:"server"` Asset Asset `mapstructure:"asset"` - Log shared.Log `mapstructure:"log"` + Log *shared.Log `mapstructure:"log"` TokenManager TokenManager `mapstructure:"token_manager"` Repo Repo `mapstructure:"repo"` Index Index `mapstructure:"index"` @@ -171,7 +173,6 @@ func DefaultConfig() *Config { DemoUsersAndGroups: true, }, Asset: Asset{}, - Log: shared.Log{}, TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, @@ -212,10 +213,10 @@ func DefaultConfig() *Config { // 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...) +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/go.mod b/go.mod index 8edb1d288a..d821d7072b 100644 --- a/go.mod +++ b/go.mod @@ -70,6 +70,7 @@ 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 ) @@ -243,7 +244,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/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index dc08ec50ff..cbb79bcb33 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -70,6 +70,8 @@ type Runtime struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons `mapstructure:"shared"` + Mode Mode // DEPRECATED File string OcisURL string `mapstructure:"ocis_url"` @@ -119,9 +121,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{ - Level: "info", - }, Debug: Debug{ Addr: "127.0.0.1:9010", Token: "", diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go index 9a938d5533..fc655e73df 100644 --- a/ocis-pkg/shared/shared_types.go +++ b/ocis-pkg/shared/shared_types.go @@ -15,3 +15,10 @@ type Log struct { 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/proxy.go b/ocis/pkg/command/proxy.go index 3f327d8169..321298689b 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/proxy/pkg/command" "github.com/urfave/cli/v2" @@ -13,8 +12,6 @@ import ( // ProxyCommand is the entry point for the proxy command. func ProxyCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "proxy", Usage: "Start proxy server", @@ -26,15 +23,14 @@ func ProxyCommand(cfg *config.Config) *cli.Command { if err := ParseConfig(ctx, cfg); err != nil { return err } - globalLog = cfg.Log + + if cfg.Commons != nil { + cfg.Proxy.Commons = cfg.Commons + } + return nil }, Action: func(c *cli.Context) error { - // if proxy logging is empty in ocis.yaml - if (cfg.Proxy.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Proxy.Log = globalLog - } origCmd := command.Server(cfg.Proxy) return handleOriginalAction(c, origCmd) }, diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 924461ea6c..caad7d3477 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -4,10 +4,9 @@ import ( "context" "os" - "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/shared" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/proxy/pkg/config" "github.com/thejerf/suture/v4" @@ -51,17 +50,6 @@ 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. 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. @@ -75,7 +63,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - conf.LoadOSEnv(config.GetEnv(), false) + // 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{} + } + + conf.LoadOSEnv(config.GetEnv(cfg), false) + bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -87,9 +88,8 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Proxy.Log == shared.Log{}) { - cfg.Proxy.Log = cfg.Log - } + // inherit common configuration from ocis config parsing. + cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.Proxy, } @@ -103,3 +103,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 4853149589..521d2f07db 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -8,11 +8,6 @@ import ( "strings" "time" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/coreos/go-oidc/v3/oidc" "github.com/cs3org/reva/pkg/token/manager/jwt" chimiddleware "github.com/go-chi/chi/v5/middleware" @@ -45,26 +40,10 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // 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 - } - } - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -73,14 +52,6 @@ func Server(cfg *config.Config) *cli.Command { cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method") } - // we need a starting point to compare the default config values to determine if the outcome of ParseConfig - // modified a value that should be shared just because it is present in the ocis.yaml file. - defaultConfig := config.DefaultConfig() - - if cfg.OcisURL != "" && cfg.OIDC.Issuer == defaultConfig.OIDC.Issuer { - cfg.OIDC.Issuer = cfg.OcisURL - } - if err := loadUserAgent(ctx, cfg); err != nil { return err } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 9e858a0eed..18a20ba1da 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -106,9 +106,9 @@ type Cache struct { // Config combines all available configuration parts. type Config struct { - OcisURL string + *shared.Commons - Log shared.Log `mapstructure:"log"` + Log *shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Service Service `mapstructure:"service"` @@ -199,10 +199,9 @@ func New() *Config { } } -// DefaultConfig are values stored in the flag set, but moved to a struct. +// DefaultConfig provides with a working local configuration for a proxy service. func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, // logging config is inherited. Debug: Debug{ Addr: "0.0.0.0:9205", Token: "", diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index a13fedf37d..106f16d6bd 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -4,10 +4,10 @@ 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() []string { - var r = make([]string, len(structMappings(&Config{}))) - for i := range structMappings(&Config{}) { - r = append(r, structMappings(&Config{})[i].EnvVars...) +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 From 52d55390abd28d11c223cd54bbd79714be9a6e9c Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 12:57:18 +0100 Subject: [PATCH 082/147] fix inheritance config on accounts command --- ocis/pkg/command/accounts.go | 12 +++--------- store/pkg/command/root.go | 5 ----- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index b335b54963..1cacd70d0a 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -6,15 +6,12 @@ package command import ( "github.com/owncloud/ocis/accounts/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) // AccountsCommand is the entrypoint for the accounts command. func AccountsCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "accounts", Usage: "Start accounts server", @@ -32,16 +29,13 @@ func AccountsCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Accounts.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if accounts logging is empty in ocis.yaml - if (cfg.Accounts.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Accounts.Log = globalLog - } origCmd := command.Server(cfg.Accounts) return handleOriginalAction(c, origCmd) }, diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 6b6ef33c1e..49584e63cc 100644 --- a/store/pkg/command/root.go +++ b/store/pkg/command/root.go @@ -4,8 +4,6 @@ import ( "context" "os" - "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" @@ -86,9 +84,6 @@ type SutureService struct { // NewSutureService creates a new store.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Accounts.Log == shared.Log{}) { - cfg.Accounts.Log = cfg.Log - } return SutureService{ cfg: cfg.Store, } From cfc9738e5143c887c7121179827fb29a2ea10ebd Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:06:03 +0100 Subject: [PATCH 083/147] format --- ocs/pkg/config/config.go | 6 +++--- thumbnails/pkg/config/config.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 7be7e86228..7d6da5df9b 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -47,7 +47,7 @@ type Tracing struct { // Reva defines all available REVA configuration. type Reva struct { - Address string `address` + Address string `mapstructure:"address"` } // TokenManager is the config for using the reva token manager @@ -72,7 +72,7 @@ type Config struct { TokenManager TokenManager `mapstructure:"token_manager"` Service Service `mapstructure:"service"` AccountBackend string `mapstructure:"account_backend"` - Reva Reva `mapstructure:"reva"` + Reva Reva `mapstructure:"reva"` StorageUsersDriver string `mapstructure:"storage_users_driver"` MachineAuthAPIKey string `mapstructure:"machine_auth_api_key"` IdentityManagement IdentityManagement `mapstructure:"identity_management"` @@ -121,7 +121,7 @@ func DefaultConfig() *Config { Namespace: "com.owncloud.web", }, AccountBackend: "accounts", - Reva: Reva{Address: "127.0.0.1:9142"}, + Reva: Reva{Address: "127.0.0.1:9142"}, StorageUsersDriver: "ocis", MachineAuthAPIKey: "change-me-please", IdentityManagement: IdentityManagement{ diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 07af523676..e91137d13e 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -61,7 +61,7 @@ type Thumbnail struct { Resolutions []string `mapstructure:"resolutions"` FileSystemStorage FileSystemStorage `mapstructure:"filesystem_storage"` WebdavAllowInsecure bool `mapstructure:"webdav_allow_insecure"` - CS3AllowInsecure bool `mapstructure:"cs3_allow_insecure"` + CS3AllowInsecure bool `mapstructure:"cs3_allow_insecure"` RevaGateway string `mapstructure:"reva_gateway"` WebdavNamespace string `mapstructure:"webdav_namespace"` } @@ -100,7 +100,7 @@ func DefaultConfig() *Config { WebdavAllowInsecure: true, RevaGateway: "127.0.0.1:9142", WebdavNamespace: "/home", - CS3AllowInsecure: false, + CS3AllowInsecure: false, }, } } From 0d1c8accf2336353e860a2a4797dadc7b63bd82b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:06:59 +0100 Subject: [PATCH 084/147] fix deref memory location --- ocs/pkg/config/mappings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocs/pkg/config/mappings.go b/ocs/pkg/config/mappings.go index cdb721ff64..dc253e7e13 100644 --- a/ocs/pkg/config/mappings.go +++ b/ocs/pkg/config/mappings.go @@ -94,7 +94,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { }, { EnvVars: []string{"REVA_GATEWAY"}, - Destination: &cfg.RevaAddress, + Destination: &cfg.Reva.Address, }, { EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "OCS_MACHINE_AUTH_API_KEY"}, From 6391d94516c02eb66c21ec8e3075d59cd442c251 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:14:19 +0100 Subject: [PATCH 085/147] glauth --- glauth/pkg/command/root.go | 20 ++++++++++++++----- glauth/pkg/command/server.go | 20 ------------------- glauth/pkg/config/config.go | 36 +++++++++++++---------------------- glauth/pkg/config/mappings.go | 11 +++++++++++ ocis/pkg/command/glauth.go | 14 +++++--------- proxy/pkg/command/root.go | 1 - 6 files changed, 44 insertions(+), 58 deletions(-) diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 4d68ded216..e6017cfef5 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -52,7 +52,7 @@ func Execute(cfg *config.Config) error { // NewLogger initializes a service-specific logger instance. func NewLogger(cfg *config.Config) log.Logger { - return oclog.LoggerFromConfig("glauth", cfg.Log) + return oclog.LoggerFromConfig("glauth", *cfg.Log) } // ParseConfig loads glauth configuration from known paths. @@ -62,8 +62,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &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(), false) + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -75,9 +87,7 @@ type SutureService struct { // NewSutureService creates a new glauth.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.GLAuth.Log == shared.Log{}) { - cfg.GLAuth.Log = cfg.Log - } + 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 380eba4199..d3e903503f 100644 --- a/glauth/pkg/command/server.go +++ b/glauth/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "strings" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - glauthcfg "github.com/glauth/glauth/v2/pkg/config" "github.com/oklog/run" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" @@ -28,9 +24,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -39,19 +32,6 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 00843b8845..3268e13274 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -61,17 +61,19 @@ type Backend struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Ldap Ldap `mapstructure:"ldap"` - Ldaps Ldaps `mapstructure:"ldaps"` - Backend Backend `mapstructure:"backend"` - Fallback Backend `mapstructure:"fallback"` - Version string `mapstructure:"version"` - RoleBundleUUID string `mapstructure:"role_bundle_uuid"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Ldap Ldap `mapstructure:"ldap"` + Ldaps Ldaps `mapstructure:"ldaps"` + Backend Backend `mapstructure:"backend"` + Fallback Backend `mapstructure:"fallback"` + Version string `mapstructure:"version"` + RoleBundleUUID string `mapstructure:"role_bundle_uuid"` Context context.Context Supervised bool @@ -84,7 +86,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9129", }, @@ -126,14 +127,3 @@ func DefaultConfig() *Config { RoleBundleUUID: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin } } - -// 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/glauth/pkg/config/mappings.go b/glauth/pkg/config/mappings.go index b7fc75748d..4867fc9ea2 100644 --- a/glauth/pkg/config/mappings.go +++ b/glauth/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index dcbfda8bdb..c6baacfdeb 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -3,15 +3,12 @@ package command import ( "github.com/owncloud/ocis/glauth/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) // GLAuthCommand is the entrypoint for the glauth command. func GLAuthCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "glauth", Usage: "Start glauth server", @@ -20,15 +17,14 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { if err := ParseConfig(ctx, cfg); err != nil { return err } - globalLog = cfg.Log + + if cfg.Commons != nil { + cfg.GLAuth.Commons = cfg.Commons + } + return nil }, Action: func(c *cli.Context) error { - // if Glauth logging is empty in ocis.yaml - if (cfg.GLAuth.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.GLAuth.Log = globalLog - } origCmd := command.Server(cfg.GLAuth) return handleOriginalAction(c, origCmd) }, diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index caad7d3477..13ea25e99d 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -88,7 +88,6 @@ type SutureService struct { // NewSutureService creates a new proxy.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - // inherit common configuration from ocis config parsing. cfg.Proxy.Commons = cfg.Commons return SutureService{ cfg: cfg.Proxy, From f118357a18472960fb12673b59e8ec1f21f31e85 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:18:53 +0100 Subject: [PATCH 086/147] graph --- graph/pkg/command/root.go | 19 +++++++++++++++---- graph/pkg/command/server.go | 20 -------------------- graph/pkg/config/config.go | 16 +++------------- graph/pkg/config/mappings.go | 11 +++++++++++ 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/graph/pkg/command/root.go b/graph/pkg/command/root.go index 4e07ad4b88..20d07c88ea 100644 --- a/graph/pkg/command/root.go +++ b/graph/pkg/command/root.go @@ -66,7 +66,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - conf.LoadOSEnv(config.GetEnv(), false) + + // 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{} + } + + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -78,9 +91,7 @@ type SutureService struct { // NewSutureService creates a new graph.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Graph.Log == shared.Log{}) { - cfg.Graph.Log = cfg.Log - } + 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 b8a90ecbdf..1c4341bcc7 100644 --- a/graph/pkg/command/server.go +++ b/graph/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "strings" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/oklog/run" "github.com/owncloud/ocis/graph/pkg/config" "github.com/owncloud/ocis/graph/pkg/metrics" @@ -24,9 +20,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -35,19 +28,6 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index c29fcfb2eb..57e2b0b803 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -54,8 +54,10 @@ type Spaces struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` + Log *shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Server Server `mapstructure:"server"` @@ -75,7 +77,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9124", Token: "", @@ -104,14 +105,3 @@ func DefaultConfig() *Config { }, } } - -// 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/pkg/config/mappings.go b/graph/pkg/config/mappings.go index a8239f37ee..2c74cc9f17 100644 --- a/graph/pkg/config/mappings.go +++ b/graph/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. From c6191b74049d7edf3dc23f6e9256fab64e0a9c17 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:46:07 +0100 Subject: [PATCH 087/147] fix account unit tests --- accounts/pkg/config/config.go | 4 +++- accounts/pkg/proto/v0/accounts.pb.micro_test.go | 2 +- accounts/pkg/service/v0/service.go | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index fbb299a632..12e72d670c 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -145,7 +145,9 @@ type Config struct { // New returns a new config. func New() *Config { - return &Config{} + return &Config{ + Log: &shared.Log{}, + } } func DefaultConfig() *Config { diff --git a/accounts/pkg/proto/v0/accounts.pb.micro_test.go b/accounts/pkg/proto/v0/accounts.pb.micro_test.go index 3a4054d041..89cf6c346b 100644 --- a/accounts/pkg/proto/v0/accounts.pb.micro_test.go +++ b/accounts/pkg/proto/v0/accounts.pb.micro_test.go @@ -85,7 +85,7 @@ func init() { var hdlr *svc.Service var err error - if hdlr, err = svc.New(svc.Logger(oclog.LoggerFromConfig("accounts", cfg.Log)), 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 b95455204b..e4a5feefbd 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 { From 7eb2c25d653647836c8b25e994db600d9375c255 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 13:58:19 +0100 Subject: [PATCH 088/147] propagate storage common logging config --- ocis/pkg/runtime/service/service.go | 8 +------- storage/pkg/command/appprovider.go | 4 +--- storage/pkg/command/authbasic.go | 4 +--- storage/pkg/command/authbearer.go | 4 +--- storage/pkg/command/authmachine.go | 4 +--- storage/pkg/command/frontend.go | 6 ++---- storage/pkg/command/gateway.go | 4 +--- storage/pkg/command/groups.go | 4 +--- storage/pkg/command/sharing.go | 4 +--- storage/pkg/command/storagehome.go | 4 +--- storage/pkg/command/storagemetadata.go | 4 +--- storage/pkg/command/storagepubliclink.go | 4 +--- storage/pkg/command/storageusers.go | 4 +--- storage/pkg/command/users.go | 4 +--- storage/pkg/config/config.go | 12 +++++++++--- 15 files changed, 24 insertions(+), 50 deletions(-) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 52d0ad166c..4313a14730 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -159,13 +159,7 @@ func Start(o ...Option) error { FailureBackoff: 3 * time.Second, }) - // reva storages have their own logging. For consistency's 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 err := rpc.Register(s); err != nil { + if err = rpc.Register(s); err != nil { if s != nil { s.Log.Fatal().Err(err) } diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 1a8b9e5d95..59c0684ec0 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -132,9 +132,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.Log = cfg.Commons.Log return AppProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 840963058d..cd9ac7977d 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -151,9 +151,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.Log = cfg.Commons.Log return AuthBasicSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 4a2b43c05e..4c8d87463a 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -127,9 +127,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.Log = cfg.Commons.Log return AuthBearerSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 8bdb111014..9a0244895a 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -123,9 +123,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.Log = cfg.Commons.Log return AuthMachineSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 19822f7f28..314d1e149b 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -335,11 +335,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.Log = cfg.Commons.Log return FrontendSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index b1047367fb..f684083429 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -351,9 +351,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.Log = cfg.Commons.Log return GatewaySutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index e3758080f7..4142c8e9a1 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -165,9 +165,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.Log = cfg.Commons.Log return GroupSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index 50f50c64b6..c23455eb43 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -191,9 +191,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.Log = cfg.Commons.Log return SharingSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index fff984b13c..1ab83572a6 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -150,9 +150,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.Log = cfg.Commons.Log return StorageHomeSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 29cd5deb1c..665d4606ab 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -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.Log = cfg.Commons.Log return MetadataSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index d90b971fc0..d5bb031c79 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -124,9 +124,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.Log = cfg.Commons.Log return StoragePublicLinkSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 99ae03348c..51b48508d3 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -150,9 +150,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.Log = cfg.Commons.Log return StorageUsersSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 2f4c3e87cc..60115b8757 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -186,9 +186,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.Log = cfg.Commons.Log return UserProviderSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 4797b77362..7b34ec6470 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -1,6 +1,10 @@ package config -import "context" +import ( + "context" + + "github.com/owncloud/ocis/ocis-pkg/shared" +) // Log defines the available logging configuration. type Log struct { @@ -497,7 +501,7 @@ type Asset struct { // Config combines all available configuration parts. type Config struct { File string - Log Log + Log *shared.Log Debug Debug Reva Reva Tracing Tracing @@ -506,5 +510,7 @@ type Config struct { // New initializes a new configuration with or without defaults. func New() *Config { - return &Config{} + return &Config{ + Log: &shared.Log{}, + } } From e8559d17aa87b7d618f664cc4347b833e78235c9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 14:00:42 +0100 Subject: [PATCH 089/147] fix proxy integration tests --- ocs/pkg/server/http/svc_test.go | 4 ++-- proxy/pkg/proxy/proxy_integration_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 32e38a9c11..0d4695a232 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -551,7 +551,7 @@ func init() { Path: dataPath, }, }, - Log: shared.Log{ + Log: &shared.Log{ Level: "info", Pretty: true, Color: true, @@ -562,7 +562,7 @@ func init() { var err error if hdlr, err = accountsSvc.New( - accountsSvc.Logger(oclog.LoggerFromConfig("accounts", c.Log)), + accountsSvc.Logger(oclog.LoggerFromConfig("accounts", *c.Log)), accountsSvc.Config(c), accountsSvc.RoleService(buildRoleServiceMock()), ); err != nil { diff --git a/proxy/pkg/proxy/proxy_integration_test.go b/proxy/pkg/proxy/proxy_integration_test.go index 3e7736e83b..9809383a67 100644 --- a/proxy/pkg/proxy/proxy_integration_test.go +++ b/proxy/pkg/proxy/proxy_integration_test.go @@ -215,7 +215,7 @@ func (tc *testCase) expectProxyTo(strURL string) testCase { func testConfig(policy []config.Policy) *config.Config { return &config.Config{ - Log: shared.Log{}, + Log: &shared.Log{}, Debug: config.Debug{}, HTTP: config.HTTP{}, Tracing: config.Tracing{}, From 48eab0ccc791e0d0a428dc02c358e4b928fcd2e7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 14:03:56 +0100 Subject: [PATCH 090/147] add idp common options --- idp/pkg/command/root.go | 18 ++++++++++++++---- idp/pkg/command/server.go | 19 ------------------- idp/pkg/config/config.go | 32 +++++++++++--------------------- idp/pkg/config/mappings.go | 11 +++++++++++ 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index c62f9e7912..e0d5ba775f 100644 --- a/idp/pkg/command/root.go +++ b/idp/pkg/command/root.go @@ -70,8 +70,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &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(), false) + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) @@ -84,9 +96,7 @@ type SutureService struct { // NewSutureService creates a new idp.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.IDP.Log == shared.Log{}) { - cfg.IDP.Log = cfg.Log - } + 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 cb56afc2f5..cc33fe911e 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -4,15 +4,12 @@ import ( "context" "strings" - gofig "github.com/gookit/config/v2" "github.com/oklog/run" "github.com/owncloud/ocis/idp/pkg/config" "github.com/owncloud/ocis/idp/pkg/metrics" "github.com/owncloud/ocis/idp/pkg/server/debug" "github.com/owncloud/ocis/idp/pkg/server/http" "github.com/owncloud/ocis/idp/pkg/tracing" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/urfave/cli/v2" ) @@ -23,9 +20,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -46,19 +40,6 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 9ee63acfc2..6297a9af1e 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -98,15 +98,17 @@ type Settings struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` - IDP Settings `mapstructure:"idp"` - Ldap Ldap `mapstructure:"ldap"` - Service Service `mapstructure:"service"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"asset"` + IDP Settings `mapstructure:"idp"` + Ldap Ldap `mapstructure:"ldap"` + Service Service `mapstructure:"service"` Context context.Context Supervised bool @@ -119,7 +121,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9134", }, @@ -189,14 +190,3 @@ func DefaultConfig() *Config { }, } } - -// 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(DefaultConfig()))) - for i := range structMappings(DefaultConfig()) { - r = append(r, structMappings(DefaultConfig())[i].EnvVars...) - } - - return r -} diff --git a/idp/pkg/config/mappings.go b/idp/pkg/config/mappings.go index f450cc049f..68383fe5c7 100644 --- a/idp/pkg/config/mappings.go +++ b/idp/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. From 34840d62e3b2b31f5cf7ce7d68ebc8c33d6ccb01 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 14:06:40 +0100 Subject: [PATCH 091/147] fix individual idp command --- ocis/pkg/command/idp.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 01f12c210f..7b35c15ba8 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -3,15 +3,12 @@ package command import ( "github.com/owncloud/ocis/idp/pkg/command" "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/urfave/cli/v2" ) // IDPCommand is the entrypoint for the idp command. func IDPCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "idp", Usage: "Start idp server", @@ -24,16 +21,13 @@ func IDPCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.IDP.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if idp logging is empty in ocis.yaml - if (cfg.IDP.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.IDP.Log = globalLog - } idpCommand := command.Server(cfg.IDP) if err := idpCommand.Before(c); err != nil { return err From 202e63bcb60fd705f4c82419cbdb0c7cd90afb90 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 14:15:28 +0100 Subject: [PATCH 092/147] made ocs compliant with shared.Commons --- ocis/pkg/command/ocs.go | 12 +++--------- ocs/pkg/command/root.go | 18 ++++++++++++++---- ocs/pkg/command/server.go | 19 ------------------- ocs/pkg/config/config.go | 16 +++------------- ocs/pkg/config/mappings.go | 11 +++++++++++ 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 8c3b11baca..17f2d927e6 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocs/pkg/command" "github.com/urfave/cli/v2" @@ -13,8 +12,6 @@ import ( // OCSCommand is the entrypoint for the ocs command. func OCSCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "ocs", Usage: "Start ocs server", @@ -24,16 +21,13 @@ func OCSCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.OCS.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if accounts logging is empty in ocis.yaml - if (cfg.OCS.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.OCS.Log = globalLog - } origCmd := command.Server(cfg.OCS) return handleOriginalAction(c, origCmd) }, diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 4f939fc1b5..19c53801c6 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -72,8 +72,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &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(), false) + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) @@ -86,9 +98,7 @@ type SutureService struct { // NewSutureService creates a new ocs.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.OCS.Log == shared.Log{}) { - cfg.OCS.Log = cfg.Log - } + 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 dc4e6a4cb2..722673cd13 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "strings" - 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/ocs/pkg/tracing" "github.com/owncloud/ocis/ocis-pkg/sync" @@ -26,8 +22,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -36,19 +30,6 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 7d6da5df9b..48c9eb2281 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -64,8 +64,10 @@ type IdentityManagement struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` + Log *shared.Log `mapstructure:"log"` Debug Debug `mapstructure:"debug"` HTTP HTTP `mapstructure:"http"` Tracing Tracing `mapstructure:"tracing"` @@ -89,7 +91,6 @@ func New() *Config { // DefaultConfig provides default values for a config struct. func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9114", Token: "", @@ -129,14 +130,3 @@ func DefaultConfig() *Config { }, } } - -// 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/ocs/pkg/config/mappings.go b/ocs/pkg/config/mappings.go index dc253e7e13..2aab7b910c 100644 --- a/ocs/pkg/config/mappings.go +++ b/ocs/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. From a29f10e764ee77a0a4722135ba351f0e9e2881d3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 14:17:24 +0100 Subject: [PATCH 093/147] adapted proxy tests to support shared.Commons --- ocs/pkg/server/http/svc_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocs/pkg/server/http/svc_test.go b/ocs/pkg/server/http/svc_test.go index 0d4695a232..0e432054bb 100644 --- a/ocs/pkg/server/http/svc_test.go +++ b/ocs/pkg/server/http/svc_test.go @@ -698,7 +698,7 @@ func getService() svc.Service { TokenManager: config.TokenManager{ JWTSecret: jwtSecret, }, - Log: shared.Log{ + Log: &shared.Log{ Level: "debug", }, } From 3580e167714e5d4c5a86ea6be26a79bac6bdc4f2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:12:37 +0100 Subject: [PATCH 094/147] losing my mind --- ocis/pkg/command/settings.go | 12 +++--------- ocis/pkg/runtime/service/service.go | 5 +++++ settings/pkg/command/root.go | 19 +++++++++++++++---- settings/pkg/command/server.go | 20 -------------------- settings/pkg/config/config.go | 16 +++------------- settings/pkg/config/mappings.go | 11 +++++++++++ settings/pkg/store/filesystem/store.go | 14 +++++++------- storage/pkg/command/appprovider.go | 2 +- storage/pkg/command/authbasic.go | 2 +- storage/pkg/command/authbearer.go | 2 +- storage/pkg/command/authmachine.go | 2 +- storage/pkg/command/frontend.go | 2 +- storage/pkg/command/gateway.go | 2 +- storage/pkg/command/groups.go | 2 +- storage/pkg/command/sharing.go | 2 +- storage/pkg/command/storagehome.go | 2 +- storage/pkg/command/storagemetadata.go | 2 +- storage/pkg/command/storagepubliclink.go | 2 +- storage/pkg/command/storageusers.go | 2 +- storage/pkg/command/users.go | 2 +- storage/pkg/config/config.go | 2 ++ 21 files changed, 59 insertions(+), 66 deletions(-) diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 9a25845662..adb37be5b0 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/settings/pkg/command" "github.com/urfave/cli/v2" @@ -13,8 +12,6 @@ import ( // SettingsCommand is the entry point for the settings command. func SettingsCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "settings", Usage: "Start settings server", @@ -27,16 +24,13 @@ func SettingsCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Settings.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if accounts logging is empty in ocis.yaml - if (cfg.Settings.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Settings.Log = globalLog - } origCmd := command.Server(cfg.Settings) return handleOriginalAction(c, origCmd) }, diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 4313a14730..4f041b2a00 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -159,6 +159,11 @@ func Start(o ...Option) error { FailureBackoff: 3 * time.Second, }) + 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 err = rpc.Register(s); err != nil { if s != nil { s.Log.Fatal().Err(err) diff --git a/settings/pkg/command/root.go b/settings/pkg/command/root.go index 2aba1f46ad..74c09626e3 100644 --- a/settings/pkg/command/root.go +++ b/settings/pkg/command/root.go @@ -71,7 +71,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - conf.LoadOSEnv(config.GetEnv(), false) + + // 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{} + } + + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -83,9 +96,7 @@ type SutureService struct { // NewSutureService creates a new settings.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Settings.Log == shared.Log{}) { - cfg.Settings.Log = cfg.Log - } + 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 22e483af34..894b159ff7 100644 --- a/settings/pkg/command/server.go +++ b/settings/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "strings" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/settings/pkg/config" @@ -25,9 +21,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -36,19 +29,6 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index 62da7e7781..c41e2d8c90 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -68,9 +68,11 @@ type TokenManager struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string Service Service - Log shared.Log + Log *shared.Log Debug Debug HTTP HTTP GRPC GRPC @@ -90,7 +92,6 @@ func New() *Config { // DefaultConfig provides sane bootstrapping defaults. func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Service: Service{ Name: "settings", DataPath: path.Join(defaults.BaseDataPath(), "settings"), @@ -132,14 +133,3 @@ func DefaultConfig() *Config { }, } } - -// 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/settings/pkg/config/mappings.go b/settings/pkg/config/mappings.go index c19dfcaadd..0fd5a9f2d6 100644 --- a/settings/pkg/config/mappings.go +++ b/settings/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. diff --git a/settings/pkg/store/filesystem/store.go b/settings/pkg/store/filesystem/store.go index 8eb3f03416..cf81638b9e 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/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 59c0684ec0..07abdc79be 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -132,7 +132,7 @@ type AppProviderSutureService struct { // NewAppProvider creates a new store.AppProviderSutureService func NewAppProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 cd9ac7977d..35ec897373 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -151,7 +151,7 @@ type AuthBasicSutureService struct { // NewAuthBasicSutureService creates a new store.AuthBasicSutureService func NewAuthBasic(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 4c8d87463a..beaf9b37b6 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -127,7 +127,7 @@ type AuthBearerSutureService struct { // NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService func NewAuthBearer(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 9a0244895a..8b6ea05bb4 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -123,7 +123,7 @@ type AuthMachineSutureService struct { // NewAuthMachineSutureService creates a new gateway.AuthMachineSutureService func NewAuthMachine(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 314d1e149b..aefd4f5722 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -337,7 +337,7 @@ type FrontendSutureService struct { // NewFrontend creates a new frontend.FrontendSutureService func NewFrontend(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 f684083429..9b1ec57176 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -351,7 +351,7 @@ type GatewaySutureService struct { // NewGatewaySutureService creates a new gateway.GatewaySutureService func NewGateway(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return GatewaySutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 4142c8e9a1..318386082d 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -165,7 +165,7 @@ type GroupSutureService struct { // NewGroupProviderSutureService creates a new storage.GroupProvider func NewGroupProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + cfg.Storage.Commons = cfg.Commons return GroupSutureService{ cfg: cfg.Storage, } diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index c23455eb43..6a71e5b22a 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -191,7 +191,7 @@ type SharingSutureService struct { // NewSharingSutureService creates a new store.SharingSutureService func NewSharing(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 1ab83572a6..5d4e6d5a4b 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -150,7 +150,7 @@ type StorageHomeSutureService struct { // NewStorageHomeSutureService creates a new storage.StorageHomeSutureService func NewStorageHome(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 665d4606ab..a853c68fb6 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -166,7 +166,7 @@ type MetadataSutureService struct { // NewSutureService creates a new storagemetadata.SutureService func NewStorageMetadata(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 d5bb031c79..eb3803e504 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -124,7 +124,7 @@ type StoragePublicLinkSutureService struct { // NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 51b48508d3..d86d49b53c 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -150,7 +150,7 @@ type StorageUsersSutureService struct { // NewStorageUsersSutureService creates a new storage.StorageUsersSutureService func NewStorageUsers(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 60115b8757..6bc2bdc608 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -186,7 +186,7 @@ type UserProviderSutureService struct { // NewUserProviderSutureService creates a new storage.UserProvider func NewUserProvider(cfg *ociscfg.Config) suture.Service { - cfg.Storage.Log = cfg.Commons.Log + 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 7b34ec6470..cda41e5d57 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -500,6 +500,8 @@ type Asset struct { // Config combines all available configuration parts. type Config struct { + *shared.Commons + File string Log *shared.Log Debug Debug From 582649b7d4f47c450c65b18a965228a955647ab0 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:18:44 +0100 Subject: [PATCH 095/147] fix more inheritance on storages --- ocis/pkg/runtime/service/service.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 4f041b2a00..e272560736 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,10 +161,16 @@ func Start(o ...Option) error { FailureBackoff: 3 * time.Second, }) - 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{}, + } + } + + 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 s != nil { From 59f53390a84bd16d54d9d8abe736094b49476572 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:48:00 +0100 Subject: [PATCH 096/147] fix all storages --- ocis/pkg/command/storageappprovider.go | 21 ++++--------------- ocis/pkg/command/storageauthbasic.go | 21 ++++--------------- ocis/pkg/command/storageauthbearer.go | 21 ++++--------------- ocis/pkg/command/storagefrontend.go | 21 ++++--------------- ocis/pkg/command/storagegateway.go | 21 ++++--------------- ocis/pkg/command/storagegroupprovider.go | 21 ++++--------------- ocis/pkg/command/storagehome.go | 21 ++++--------------- ocis/pkg/command/storagemetadata.go | 21 ++++--------------- ocis/pkg/command/storagepubliclink.go | 21 ++++--------------- ocis/pkg/command/storagesharing.go | 21 ++++--------------- ocis/pkg/command/storageuserprovider.go | 21 ++++--------------- ocis/pkg/command/storageusers.go | 21 ++++--------------- ocis/pkg/command/util.go | 26 ++++++++++++++++++++++++ ocis/pkg/runtime/service/service.go | 4 ++++ storage/pkg/command/root.go | 9 +++++--- storage/pkg/config/config.go | 4 +--- 16 files changed, 85 insertions(+), 210 deletions(-) create mode 100644 ocis/pkg/command/util.go diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index cb60828d06..6672282b6e 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageAppProviderCommand(cfg *config.Config) *cli.Command { Usage: "Start storage app-provider service", Category: "Extensions", 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 fe7a87eb1f..02446b4481 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageAuthBasicCommand(cfg *config.Config) *cli.Command { Usage: "Start storage auth-basic service", Category: "Extensions", 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 004d0b7936..ab14a42368 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command { Usage: "Start storage auth-bearer service", Category: "Extensions", 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 220eabc744..853a9bc44a 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command { Usage: "Start storage frontend", Category: "Extensions", 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 d0e4e61fa0..a9fe1a6f3b 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageGatewayCommand(cfg *config.Config) *cli.Command { Usage: "Start storage gateway", Category: "Extensions", 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 3f77796e38..3500780beb 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageGroupProviderCommand(cfg *config.Config) *cli.Command { Usage: "Start storage groupprovider service", Category: "Extensions", 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 9e025b2856..5ed11b581e 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storagehome.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageHomeCommand(cfg *config.Config) *cli.Command { Usage: "Start storage and data provider for /home mount", Category: "Extensions", 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 90c56da007..0729d6e311 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -4,7 +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" ) @@ -16,28 +15,16 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command { Usage: "Start storage and data service for metadata", Category: "Extensions", 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 0d94d5afb6..07e7d94763 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { Usage: "Start storage public link storage", Category: "Extensions", 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 d712f9e9a3..672e209e7a 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageSharingCommand(cfg *config.Config) *cli.Command { Usage: "Start storage sharing service", Category: "Extensions", 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 ea701a1c3b..671d87ff9b 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageUserProviderCommand(cfg *config.Config) *cli.Command { Usage: "Start storage userprovider service", Category: "Extensions", 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 80f32e796b..c6c2b7700b 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -7,7 +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" ) @@ -19,28 +18,16 @@ func StorageUsersCommand(cfg *config.Config) *cli.Command { Usage: "Start storage and data provider for /users mount", Category: "Extensions", 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/util.go b/ocis/pkg/command/util.go new file mode 100644 index 0000000000..a2e9b1abc0 --- /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/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index e272560736..a725b04bf8 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -167,6 +167,10 @@ func Start(o ...Option) error { } } + 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 diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index a2cce06b1c..4c526e06a4 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -4,6 +4,8 @@ import ( "os" "strings" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" @@ -25,10 +27,11 @@ func Execute(cfg *config.Config) error { Email: "support@owncloud.com", }, }, - - //Flags: flagset.RootWithConfig(cfg), - Before: func(c *cli.Context) error { + if cfg.Log == nil { + cfg.Log = &shared.Log{} + } + logger := NewLogger(cfg) viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index cda41e5d57..19c45739b5 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -512,7 +512,5 @@ type Config struct { // New initializes a new configuration with or without defaults. func New() *Config { - return &Config{ - Log: &shared.Log{}, - } + return &Config{} } From 5f19300aaab061bec593bb7f68322636fc0ccc22 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:52:56 +0100 Subject: [PATCH 097/147] addded thumbnails to the new inheritance strategy --- ocis/pkg/command/thumbnails.go | 12 +++--------- thumbnails/pkg/command/root.go | 19 +++++++++++++++---- thumbnails/pkg/command/server.go | 21 --------------------- thumbnails/pkg/config/config.go | 26 ++++++++------------------ thumbnails/pkg/config/mappings.go | 11 +++++++++++ 5 files changed, 37 insertions(+), 52 deletions(-) diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index a6054da87d..0562b5d617 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/thumbnails/pkg/command" "github.com/urfave/cli/v2" @@ -13,8 +12,6 @@ import ( // ThumbnailsCommand is the entrypoint for the thumbnails command. func ThumbnailsCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "thumbnails", Usage: "Start thumbnails server", @@ -27,16 +24,13 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Thumbnails.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if thumbnails logging is empty in ocis.yaml - if (cfg.Thumbnails.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Thumbnails.Log = globalLog - } origCmd := command.Server(cfg.Thumbnails) return handleOriginalAction(c, origCmd) }, diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index c6c6be4240..5136f0df0c 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -72,7 +72,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { if err != nil { return err } - conf.LoadOSEnv(config.GetEnv(), false) + + // 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{} + } + + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -84,9 +97,7 @@ type SutureService struct { // NewSutureService creates a new thumbnails.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Thumbnails.Log == shared.Log{}) { - cfg.Thumbnails.Log = cfg.Log - } + 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 8e9db2538d..e929245a47 100644 --- a/thumbnails/pkg/command/server.go +++ b/thumbnails/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "fmt" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/thumbnails/pkg/config" @@ -24,26 +20,9 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index e91137d13e..8e5e52517b 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -35,12 +35,14 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - Server Server `mapstructure:"server"` - Tracing Tracing `mapstructure:"tracing"` - Thumbnail Thumbnail `mapstructure:"thumbnail"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + Server Server `mapstructure:"server"` + Tracing Tracing `mapstructure:"tracing"` + Thumbnail Thumbnail `mapstructure:"thumbnail"` Context context.Context Supervised bool @@ -73,7 +75,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9189", Token: "", @@ -104,14 +105,3 @@ func DefaultConfig() *Config { }, } } - -// 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/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index 2a7e181a36..c4e5e07b53 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. From 4cecd9b5d2e7892436088a10540bb1c021ec31a9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:56:38 +0100 Subject: [PATCH 098/147] addded web to the new inheritance strategy --- ocis/pkg/command/web.go | 12 +++--------- web/pkg/command/root.go | 18 ++++++++++++++---- web/pkg/command/server.go | 22 +--------------------- web/pkg/config/config.go | 28 +++++++++------------------- web/pkg/config/mappings.go | 11 +++++++++++ 5 files changed, 38 insertions(+), 53 deletions(-) diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index fcfbbb6f2a..c3f2df2eaf 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -2,7 +2,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/web/pkg/command" "github.com/urfave/cli/v2" @@ -10,8 +9,6 @@ import ( // WebCommand is the entrypoint for the web command. func WebCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log - return &cli.Command{ Name: "web", Usage: "Start web server", @@ -21,16 +18,13 @@ func WebCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.Web.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if accounts logging is empty in ocis.yaml - if (cfg.Web.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.Web.Log = globalLog - } origCmd := command.Server(cfg.Web) return handleOriginalAction(c, origCmd) }, diff --git a/web/pkg/command/root.go b/web/pkg/command/root.go index 2fee6f7990..8c99ecad62 100644 --- a/web/pkg/command/root.go +++ b/web/pkg/command/root.go @@ -64,7 +64,19 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } - conf.LoadOSEnv(config.GetEnv(), false) + // 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{} + } + + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) } @@ -76,9 +88,7 @@ type SutureService struct { // NewSutureService creates a new web.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.Web.Log == shared.Log{}) { - cfg.Web.Log = cfg.Log - } + 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 f02b79b323..a0a11f37d6 100644 --- a/web/pkg/command/server.go +++ b/web/pkg/command/server.go @@ -6,10 +6,6 @@ import ( "io/ioutil" "strings" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/web/pkg/config" @@ -26,9 +22,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/") } @@ -42,19 +35,6 @@ func Server(cfg *config.Config) *cli.Command { cfg.Web.Config.OpenIDConnect.MetadataURL = strings.TrimRight(cfg.Web.Config.OpenIDConnect.Authority, "/") + "/.well-known/openid-configuration" } - 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 - } - } - return nil }, Action: func(c *cli.Context) error { @@ -71,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 a702903f42..b48e020e0d 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -88,13 +88,15 @@ type Web struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` - Web Web `mapstructure:"web"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"asset"` + Web Web `mapstructure:"web"` Context context.Context Supervised bool @@ -107,7 +109,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "127.0.0.1:9104", Token: "", @@ -150,14 +151,3 @@ func DefaultConfig() *Config { }, } } - -// 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/web/pkg/config/mappings.go b/web/pkg/config/mappings.go index 31d82b7726..3957c225ed 100644 --- a/web/pkg/config/mappings.go +++ b/web/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. From 9c2150422debb259821598fe07844afa55167b07 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 15:59:13 +0100 Subject: [PATCH 099/147] addded webdav to the new inheritance strategy --- ocis/pkg/command/webdav.go | 11 +++-------- webdav/pkg/command/root.go | 18 ++++++++++++++---- webdav/pkg/command/server.go | 20 -------------------- webdav/pkg/config/config.go | 30 ++++++++++-------------------- webdav/pkg/config/mappings.go | 11 +++++++++++ 5 files changed, 38 insertions(+), 52 deletions(-) diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index ae9e50fda3..0502642bb2 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/webdav/pkg/command" "github.com/urfave/cli/v2" @@ -13,7 +12,6 @@ import ( // WebDAVCommand is the entrypoint for the webdav command. func WebDAVCommand(cfg *config.Config) *cli.Command { - var globalLog shared.Log return &cli.Command{ Name: "webdav", @@ -27,16 +25,13 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { return err } - globalLog = cfg.Log + if cfg.Commons != nil { + cfg.WebDAV.Commons = cfg.Commons + } return nil }, Action: func(c *cli.Context) error { - // if webdav logging is empty in ocis.yaml - if (cfg.WebDAV.Log == shared.Log{}) && (globalLog != shared.Log{}) { - // we can safely inherit the global logging values. - cfg.WebDAV.Log = globalLog - } origCmd := command.Server(cfg.WebDAV) return handleOriginalAction(c, origCmd) }, diff --git a/webdav/pkg/command/root.go b/webdav/pkg/command/root.go index ea54640001..f221de8328 100644 --- a/webdav/pkg/command/root.go +++ b/webdav/pkg/command/root.go @@ -70,8 +70,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return err } + // provide with defaults for shared logging, since we need a valid destination address for BindEnv. + if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil { + cfg.Log = &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(), false) + conf.LoadOSEnv(config.GetEnv(cfg), false) bindings := config.StructMappings(cfg) return ociscfg.BindEnv(conf, bindings) @@ -84,9 +96,7 @@ type SutureService struct { // NewSutureService creates a new webdav.SutureService func NewSutureService(cfg *ociscfg.Config) suture.Service { - if (cfg.WebDAV.Log == shared.Log{}) { - cfg.WebDAV.Log = cfg.Log - } + 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 8e28925e72..16be22e978 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -4,10 +4,6 @@ import ( "context" "strings" - gofig "github.com/gookit/config/v2" - ociscfg "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" - "github.com/oklog/run" "github.com/owncloud/ocis/ocis-pkg/sync" "github.com/owncloud/ocis/webdav/pkg/config" @@ -24,9 +20,6 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // remember shared logging info to prevent empty overwrites - inLog := cfg.Log - if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } @@ -35,19 +28,6 @@ func Server(cfg *config.Config) *cli.Command { 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 - } - } - return nil }, Action: func(c *cli.Context) error { diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 801de7213d..e8319c8b68 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -47,14 +47,16 @@ type Tracing struct { // Config combines all available configuration parts. type Config struct { - File string `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Service Service `mapstructure:"service"` - OcisPublicURL string `mapstructure:"ocis_public_url"` - WebdavNamespace string `mapstructure:"webdav_namespace"` + *shared.Commons + + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + HTTP HTTP `mapstructure:"http"` + Tracing Tracing `mapstructure:"tracing"` + Service Service `mapstructure:"service"` + OcisPublicURL string `mapstructure:"ocis_public_url"` + WebdavNamespace string `mapstructure:"webdav_namespace"` Context context.Context Supervised bool @@ -67,7 +69,6 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ - Log: shared.Log{}, Debug: Debug{ Addr: "", Token: "", @@ -99,14 +100,3 @@ func DefaultConfig() *Config { WebdavNamespace: "/home", } } - -// 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/webdav/pkg/config/mappings.go b/webdav/pkg/config/mappings.go index e2637e4782..7fa86211ef 100644 --- a/webdav/pkg/config/mappings.go +++ b/webdav/pkg/config/mappings.go @@ -2,6 +2,17 @@ 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. From 732e04ca7347dda783e9e493e43f0bf88c855a61 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 11 Nov 2021 17:06:46 +0100 Subject: [PATCH 100/147] debug config ... trigger CI --- go.sum | 2 -- webdav/pkg/command/server.go | 6 ++++-- webdav/pkg/config/config.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.sum b/go.sum index 3f479f9c6d..ca065e44f3 100644 --- a/go.sum +++ b/go.sum @@ -300,8 +300,6 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.15.1-0.20211110104228-63cd96849ff2 h1:Cka+iK9qhpdqIulCXZ9yhZQCLR1vHG2NfQRJOPPYgxY= -github.com/cs3org/reva v1.15.1-0.20211110104228-63cd96849ff2/go.mod h1:DzqOq0OpB4P5j66RVsTw2e9JK2XECH4AATIdTTqifb8= github.com/cs3org/reva v1.15.1-0.20211110160042-a6eb9d5a7cd2 h1:+aPM9Pa8J+Ab4veJ7103tUN6RtHuruwxUfqN1htFkZU= github.com/cs3org/reva v1.15.1-0.20211110160042-a6eb9d5a7cd2/go.mod h1:DzqOq0OpB4P5j66RVsTw2e9JK2XECH4AATIdTTqifb8= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= diff --git a/webdav/pkg/command/server.go b/webdav/pkg/command/server.go index 16be22e978..c0248c5a07 100644 --- a/webdav/pkg/command/server.go +++ b/webdav/pkg/command/server.go @@ -71,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") @@ -92,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/config/config.go b/webdav/pkg/config/config.go index e8319c8b68..b5b1d8eb4d 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -70,7 +70,7 @@ func New() *Config { func DefaultConfig() *Config { return &Config{ Debug: Debug{ - Addr: "", + Addr: "127.0.0.1:9119", Token: "", Pprof: false, Zpages: false, From 4db1697f8929f025f419ee965f234b495a4be427 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 12 Nov 2021 13:53:19 +0100 Subject: [PATCH 101/147] leftover env variables on thumbnails --- thumbnails/pkg/config/mappings.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/thumbnails/pkg/config/mappings.go b/thumbnails/pkg/config/mappings.go index c4e5e07b53..3a75427c06 100644 --- a/thumbnails/pkg/config/mappings.go +++ b/thumbnails/pkg/config/mappings.go @@ -100,9 +100,13 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Thumbnail.RevaGateway, }, { - EnvVars: []string{"THUMBNAILS_WEBDAVSOURCE_INSECURE"}, + 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, From a22342ea2889c20c80def19d1ed751e8d4bce8f9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 15 Nov 2021 10:03:42 +0100 Subject: [PATCH 102/147] fix code smells --- proxy/pkg/config/config.go | 51 +++++++++++++++++--------------- proxy/pkg/server/debug/server.go | 8 +++-- storage/pkg/config/config.go | 1 - 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 18a20ba1da..dafa8a7997 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -256,6 +256,10 @@ func DefaultConfig() *Config { } func defaultPolicies() []Policy { + const idpBackend = "http://localhost:9130" + const revaBackend = "http://localhost:9140" + const namedDemoBackend = "https://demo.owncloud.com" + return []Policy{ { Name: "ocis", @@ -266,19 +270,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: RegexRoute, @@ -287,7 +291,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: QueryRoute, @@ -296,31 +300,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/dav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/webdav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/status.php", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/index.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/data", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/app/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/graph/", @@ -335,7 +339,6 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, - // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -359,53 +362,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, { Endpoint: "/data", - Backend: "https://demo.owncloud.com", + Backend: namedDemoBackend, ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index b4106f2a8c..e2a7f1e32b 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,10 +27,12 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } +const contentTypeHeader = "Content-Type" + // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -44,7 +46,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -58,7 +60,7 @@ 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") + w.Header().Set(contentTypeHeader, "application/json") b, err := json.Marshal(cfg) if err != nil { diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 19c45739b5..1e34e47b61 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -220,7 +220,6 @@ type StorageConfig struct { S3 DriverS3 S3NG DriverS3NG OCIS DriverOCIS - // TODO checksums ... figure out what that is supposed to do } // DriverCommon defines common driver configuration options. From 2b0f414b46ea4c807a03358a34ed72d9c610cca8 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 15 Nov 2021 10:16:20 +0100 Subject: [PATCH 103/147] Revert "fix code smells" This reverts commit a22342ea2889c20c80def19d1ed751e8d4bce8f9. --- proxy/pkg/config/config.go | 51 +++++++++++++++----------------- proxy/pkg/server/debug/server.go | 8 ++--- storage/pkg/config/config.go | 1 + 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index dafa8a7997..18a20ba1da 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -256,10 +256,6 @@ func DefaultConfig() *Config { } func defaultPolicies() []Policy { - const idpBackend = "http://localhost:9130" - const revaBackend = "http://localhost:9140" - const namedDemoBackend = "https://demo.owncloud.com" - return []Policy{ { Name: "ocis", @@ -270,19 +266,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/konnect/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/signin/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/archiver", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Type: RegexRoute, @@ -291,7 +287,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Type: QueryRoute, @@ -300,31 +296,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/dav/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/webdav/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/status.php", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/index.php/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/data", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/app/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/graph/", @@ -339,6 +335,7 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, + // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -362,53 +359,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/konnect/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/signin/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/archiver", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/ocs/", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/data", - Backend: namedDemoBackend, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index e2a7f1e32b..b4106f2a8c 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,12 +27,10 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } -const contentTypeHeader = "Content-Type" - // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentTypeHeader, "text/plain") + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -46,7 +44,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentTypeHeader, "text/plain") + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -60,7 +58,7 @@ 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(contentTypeHeader, "application/json") + w.Header().Set("Content-Type", "application/json") b, err := json.Marshal(cfg) if err != nil { diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 1e34e47b61..19c45739b5 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -220,6 +220,7 @@ type StorageConfig struct { S3 DriverS3 S3NG DriverS3NG OCIS DriverOCIS + // TODO checksums ... figure out what that is supposed to do } // DriverCommon defines common driver configuration options. From fde5e3549644946a672321c430b16e49257d86d3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 15 Nov 2021 10:38:02 +0100 Subject: [PATCH 104/147] fix commons propagation --- ocis/pkg/command/server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 0863c5746a..336a39e87a 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -6,6 +6,8 @@ package command import ( "strings" + "github.com/owncloud/ocis/ocis-pkg/shared" + "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/ocis/pkg/runtime" @@ -26,6 +28,11 @@ func Server(cfg *config.Config) *cli.Command { return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { + + cfg.Commons = &shared.Commons{ + Log: &cfg.Log, + } + r := runtime.New(cfg) return r.Start() }, From cfbe37de61ac1171cbb29422635a70f0d76de3f4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 15 Nov 2021 16:58:22 +0100 Subject: [PATCH 105/147] WIP - replace flags in storage commands --- ocis-pkg/config/config.go | 4 +- storage/cmd/storage/main.go | 2 +- storage/pkg/command/appprovider.go | 5 +- storage/pkg/command/authbasic.go | 5 +- storage/pkg/command/authbearer.go | 5 +- storage/pkg/command/authmachine.go | 5 +- storage/pkg/command/frontend.go | 8 +- storage/pkg/command/gateway.go | 53 +- storage/pkg/command/groups.go | 5 +- storage/pkg/command/root.go | 48 +- storage/pkg/command/sharing.go | 5 +- storage/pkg/command/storagehome.go | 5 +- storage/pkg/command/storagemetadata.go | 6 +- storage/pkg/command/storagepubliclink.go | 10 +- storage/pkg/command/storageusers.go | 5 +- storage/pkg/command/users.go | 5 +- storage/pkg/config/config.go | 989 +++++++++++++++++------ 17 files changed, 811 insertions(+), 354 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index cbb79bcb33..a334797fc3 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -115,7 +115,7 @@ func New() *Config { Store: store.DefaultConfig(), Thumbnails: thumbnails.DefaultConfig(), WebDAV: webdav.DefaultConfig(), - Storage: storage.New(), + Storage: storage.DefaultConfig(), } } @@ -160,7 +160,7 @@ func DefaultConfig() *Config { Store: store.DefaultConfig(), Thumbnails: thumbnails.DefaultConfig(), WebDAV: webdav.DefaultConfig(), - Storage: storage.New(), + Storage: storage.DefaultConfig(), } } diff --git a/storage/cmd/storage/main.go b/storage/cmd/storage/main.go index 2eaed0e963..78ccf99eca 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 07abdc79be..a4d4b24a22 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,11 @@ func AppProvider(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "app-provider", Usage: "Start appprovider for providing apps", - Flags: flagset.AppProviderWithConfig(cfg), + //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) diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 35ec897373..2bb7ff3af5 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,11 @@ func AuthBasic(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-basic", Usage: "Start authprovider for basic auth", - Flags: flagset.AuthBasicWithConfig(cfg), + //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) diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index beaf9b37b6..95270e0139 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,11 @@ func AuthBearer(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-bearer", Usage: "Start authprovider for bearer auth", - Flags: flagset.AuthBearerWithConfig(cfg), + //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) diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 8b6ea05bb4..50df131765 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,11 @@ func AuthMachine(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "auth-machine", Usage: "Start authprovider for machine auth", - Flags: flagset.AuthMachineWithConfig(cfg), + //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) diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index aefd4f5722..208d7dd442 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,14 @@ func Frontend(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "frontend", Usage: "Start frontend service", - Flags: flagset.FrontendWithConfig(cfg), + //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) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 9b1ec57176..ede3f43a63 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,7 +31,7 @@ func Gateway(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "gateway", Usage: "Start gateway", - Flags: flagset.GatewayWithConfig(cfg), + //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") @@ -42,7 +40,7 @@ func Gateway(cfg *config.Config) *cli.Command { cfg.Reva.DataGateway.PublicURL = strings.TrimRight(cfg.Reva.Frontend.PublicURL, "/") + "/data" } - return nil + return ParseConfig(c, cfg, "storage-gatway") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) @@ -222,11 +220,12 @@ 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{}{ - cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint}, - cfg.Reva.StorageHome.MountID: {"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}, + cfg.Reva.StorageHome.MountPath: {"address": cfg.Reva.StorageHome.Endpoint}, + // this is an ugly hack. Why is it here in the first place? + "1284d238-aa92-42ce-bdc4-0b0000009154": {"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}, // public link storage returns the mount id of the actual storage // medatada storage not part of the global namespace } @@ -378,3 +377,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 318386082d..0acb622cf3 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,11 @@ func Groups(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "groups", Usage: "Start groups service", - Flags: flagset.GroupsWithConfig(cfg), + //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) diff --git a/storage/pkg/command/root.go b/storage/pkg/command/root.go index 4c526e06a4..4ac235e8cc 100644 --- a/storage/pkg/command/root.go +++ b/storage/pkg/command/root.go @@ -2,14 +2,10 @@ package command import ( "os" - "strings" - - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/version" "github.com/owncloud/ocis/storage/pkg/config" - "github.com/spf13/viper" "github.com/urfave/cli/v2" ) @@ -28,49 +24,7 @@ func Execute(cfg *config.Config) error { }, }, Before: func(c *cli.Context) error { - if cfg.Log == nil { - cfg.Log = &shared.Log{} - } - - 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 6a71e5b22a..692631b58b 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,11 @@ func Sharing(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "sharing", Usage: "Start sharing service", - Flags: flagset.SharingWithConfig(cfg), + //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) diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index 5d4e6d5a4b..72772be555 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,11 @@ func StorageHome(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-home", Usage: "Start storage-home service", - Flags: flagset.StorageHomeWithConfig(cfg), + //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) diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index a853c68fb6..74864e2c68 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" @@ -31,7 +30,10 @@ func StorageMetadata(cfg *config.Config) *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: flagset.StorageMetadata(cfg), + //Flags: flagset.StorageMetadata(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg, "storage-metadata") + }, Category: "Extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index eb3803e504..467749aa03 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,12 @@ 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", + //Flags: flagset.StoragePublicLink(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg, "storage-public-link") + }, Category: "Extensions", Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index d86d49b53c..996655502b 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,11 @@ func StorageUsers(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-users", Usage: "Start storage-users service", - Flags: flagset.StorageUsersWithConfig(cfg), + //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) diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 6bc2bdc608..7f2cf88d9a 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,11 @@ func Users(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "users", Usage: "Start users service", - Flags: flagset.UsersWithConfig(cfg), + //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) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 19c45739b5..fef2ec62fc 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -2,238 +2,241 @@ package config 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 `mapstructure:"level"` + Pretty bool `mapstructure:"pretty"` + Color bool `mapstructure:"color"` + File string `mapstructure:"file"` } // Debug defines the available debug configuration. type Debug struct { - Addr string - Token string - Pprof bool - Zpages bool + Addr string `mapstructure:"addr"` + Token string `mapstructure:"token"` + Pprof bool `mapstructure:"pprof"` + Zpages bool `mapstructure:"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 `mapstructure:"commit_share_to_storage_grant"` + CommitShareToStorageRef bool `mapstructure:"commit_share_to_storage_ref"` + DisableHomeCreationOnLogin bool `mapstructure:"disable_home_creation_on_login"` + ShareFolder string `mapstructure:"share_folder"` + LinkGrants string `mapstructure:"link_grants"` + HomeMapping string `mapstructure:"home_mapping"` + EtagCacheTTL int `mapstructure:"etag_cache_ttl"` } // StorageRegistry defines the available storage registry configuration type StorageRegistry struct { - Driver string + Driver string `mapstructure:"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 `mapstructure:"home_provider"` + Rules []string `mapstructure:"rules"` + JSON string `mapstructure:"json"` } // AppRegistry defines the available app registry configuration type AppRegistry struct { - Driver string - MimetypesJSON string + Driver string `mapstructure:"driver"` + MimetypesJSON string `mapstructure:"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 `mapstructure:"external_addr"` + Driver string `mapstructure:"driver"` + WopiDriver WopiDriver `mapstructure:"wopi_driver"` + AppsURL string `mapstructure:"apps_url"` + OpenURL string `mapstructure:"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 `mapstructure:"app_api_key"` + AppDesktopOnly bool `mapstructure:"app_desktop_only"` + AppIconURI string `mapstructure:"app_icon_uri"` + AppInternalURL string `mapstructure:"app_internal_url"` + AppName string `mapstructure:"app_name"` + AppURL string `mapstructure:"app_url"` + Insecure bool `mapstructure:"insecure"` + IopSecret string `mapstructure:"ipo_secret"` + JWTSecret string `mapstructure:"jwt_secret"` + WopiURL string `mapstructure:"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 `mapstructure:"user_driver"` + UserJSONFile string `mapstructure:"user_json_file"` + UserSQLUsername string `mapstructure:"user_sql_username"` + UserSQLPassword string `mapstructure:"user_sql_password"` + UserSQLHost string `mapstructure:"user_sql_host"` + UserSQLPort int `mapstructure:"user_sql_port"` + UserSQLName string `mapstructure:"user_sql_name"` + PublicDriver string `mapstructure:"public_driver"` + PublicJSONFile string `mapstructure:"public_json_file"` + PublicPasswordHashCost int `mapstructure:"public_password_hash_cost"` + PublicEnableExpiredSharesCleanup bool `mapstructure:"public_enable_expired_shares_cleanup"` + PublicJanitorRunInterval int `mapstructure:"public_janitor_run_interval"` + UserStorageMountID string `mapstructure:"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 `mapstructure:"max_cpus"` + LogLevel string `mapstructure:"log_level"` // GRPCNetwork can be tcp, udp or unix - GRPCNetwork string + GRPCNetwork string `mapstructure:"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 `mapstructure:"grpc_addr"` // Protocol can be grpc or http // HTTPNetwork can be tcp, udp or unix - HTTPNetwork string + HTTPNetwork string `mapstructure:"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 `mapstructure:"http_addr"` // Protocol can be grpc or http - Protocol string + Protocol string `mapstructure:"protocol"` // Endpoint is used by the gateway and registries (eg localhost:9100 or cloud.example.com) - Endpoint string + Endpoint string `mapstructure:"endpoint"` // DebugAddr for the debug endpoint to bind to - DebugAddr string + DebugAddr string `mapstructure:"debug_addr"` // Services can be used to give a list of services that should be started on this port - Services []string + Services []string `mapstructure:"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{} `mapstructure:"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 `mapstucture:"driver"` + JSON string `mapstucture:"json"` + UserGroupsCacheExpiration int `mapstucture:"user_groups_cache_expiration"` } // AuthMachineConfig defines the available configuration for the machine auth driver. type AuthMachineConfig struct { - MachineAuthAPIKey string + MachineAuthAPIKey string `mapstucture:"machine_auth_api_key"` } // Groups defines the available groups configuration. type Groups struct { Port - Driver string - JSON string - GroupMembersCacheExpiration int + Driver string `mapstucture:"driver"` + JSON string `mapstucture:"json"` + GroupMembersCacheExpiration int `mapstucture:"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 `mapstucture:"app_provider_insecure"` + AppProviderPrefix string `mapstucture:"app_provider_prefix"` + ArchiverInsecure bool `mapstucture:"archiver_insecure"` + ArchiverPrefix string `mapstucture:"archiver_prefix"` + DatagatewayPrefix string `mapstucture:"data_gateway_prefix"` + Favorites bool `mapstucture:"favorites"` + OCDavInsecure bool `mapstucture:"ocdav_insecure"` + OCDavPrefix string `mapstucture:"ocdav_prefix"` + OCSPrefix string `mapstucture:"ocs_prefix"` + OCSSharePrefix string `mapstucture:"ocs_share_prefix"` + OCSHomeNamespace string `mapstucture:"ocs_home_namespace"` + PublicURL string `mapstucture:"public_url"` + OCSCacheWarmupDriver string `mapstucture:"ocs_cache_warmup_driver"` + OCSAdditionalInfoAttribute string `mapstucture:"ocs_additional_info_attribute"` + OCSResourceInfoCacheTTL int `mapstucture:"ocs_resource_info_cache_ttl"` + Middleware Middleware `mapstucture:"middleware"` } // Middleware configures reva middlewares. type Middleware struct { - Auth Auth + Auth Auth `mapstructure:"auth"` } // Auth configures reva http auth middleware. type Auth struct { - CredentialsByUserAgent map[string]string + CredentialsByUserAgent map[string]string `mapstructure:"credentials_by_user_agenr"` } // DataGatewayPort has a public url type DataGatewayPort struct { Port - PublicURL string + PublicURL string `mapstructure:""` } type DataProvider struct { - Insecure bool + Insecure bool `mapstructure:"insecure"` } // StoragePort defines the available storage configuration. type StoragePort struct { Port - Driver string - MountPath string - MountID string - ExposeDataServer bool + Driver string `mapstructure:"driver"` + MountPath string `mapstructure:"mount_path"` + MountID string `mapstructure:"mount_id"` + ExposeDataServer bool `mapstructure:"expose_data_server"` // url the data gateway will use to route requests - DataServerURL string + DataServerURL string `mapstructure:"data_server_url"` // for HTTP ports with only one http service - HTTPPrefix string - TempFolder string - ReadOnly bool - DataProvider DataProvider + HTTPPrefix string `mapstructure:"http_prefix"` + TempFolder string `mapstructure:"temp_folder"` + ReadOnly bool `mapstructure:"read_only"` + DataProvider DataProvider `mapstructure:"data_provider"` } // PublicStorage configures a public storage provider type PublicStorage struct { StoragePort - PublicShareProviderAddr string - UserProviderAddr string + PublicShareProviderAddr string `mapstructure:"public_share_provider_addr"` + UserProviderAddr string `mapstructure:"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 `mapstructure:"eos"` + Local DriverCommon `mapstructure:"local"` + OwnCloud DriverOwnCloud `mapstructure:"owncloud"` + OwnCloudSQL DriverOwnCloudSQL `mapstructure:"owncloud_sql"` + S3 DriverS3 `mapstructure:"s3"` + S3NG DriverS3NG `mapstructure:"s3ng"` + OCIS DriverOCIS `mapstructure:"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 `mapstructure:"root"` //ShareFolder defines the name of the folder jailing all shares - ShareFolder string + ShareFolder string `mapstructure:"share_folder"` // UserLayout contains the template used to construct // the internal path, eg: `{{substr 0 1 .Username}}/{{.Username}}` - UserLayout string + UserLayout string `mapstructure:"user_layout"` // EnableHome enables the creation of home directories. - EnableHome bool + EnableHome bool `mapstructure:"enable_home"` } // DriverEOS defines the available EOS driver configuration. @@ -241,276 +244,754 @@ type DriverEOS struct { DriverCommon // ShadowNamespace for storing shadow data - ShadowNamespace string + ShadowNamespace string `mapstructure:"shadow_namespace"` // UploadsNamespace for storing upload data - UploadsNamespace string + UploadsNamespace string `mapstructure:"uploads_namespace"` // Location of the eos binary. // Default is /usr/bin/eos. - EosBinary string + EosBinary string `mapstructure:"eos_binary"` // Location of the xrdcopy binary. // Default is /usr/bin/xrdcopy. - XrdcopyBinary string + XrdcopyBinary string `mapstructure:"xrd_copy_binary"` // URL of the Master EOS MGM. // Default is root://eos-example.org - MasterURL string + MasterURL string `mapstructure:"master_url"` // URI of the EOS MGM grpc server // Default is empty - GrpcURI string + GrpcURI string `mapstructure:"grpc_uri"` // URL of the Slave EOS MGM. // Default is root://eos-example.org - SlaveURL string + SlaveURL string `mapstructure:"slave_url"` // Location on the local fs where to store reads. // Defaults to os.TempDir() - CacheDirectory string + CacheDirectory string `mapstructure:"cache_directory"` // Enables logging of the commands executed // Defaults to false - EnableLogging bool + EnableLogging bool `mapstructure:"enable_logging"` // ShowHiddenSysFiles shows internal EOS files like // .sys.v# and .sys.a# files. - ShowHiddenSysFiles bool + ShowHiddenSysFiles bool `mapstructure:"shadow_hidden_files"` // ForceSingleUserMode will force connections to EOS to use SingleUsername - ForceSingleUserMode bool + ForceSingleUserMode bool `mapstructure:"force_single_user_mode"` // UseKeyTabAuth changes will authenticate requests by using an EOS keytab. - UseKeytab bool + UseKeytab bool `mapstructure:"user_keytab"` // SecProtocol specifies the xrootd security protocol to use between the server and EOS. - SecProtocol string + SecProtocol string `mapstructure:"sec_protocol"` // Keytab specifies the location of the keytab to use to authenticate to EOS. - Keytab string + Keytab string `mapstructure:"keytab"` // SingleUsername is the username to use when SingleUserMode is enabled - SingleUsername string + SingleUsername string `mapstructure:"single_username"` // gateway service to use for uid lookups - GatewaySVC string + GatewaySVC string `mapstructure:"gateway_svc"` } // DriverOCIS defines the available oCIS storage driver configuration. type DriverOCIS struct { DriverCommon - ServiceUserUUID string + ServiceUserUUID string `mapstructure:"service_user_uuid"` } // DriverOwnCloud defines the available ownCloud storage driver configuration. type DriverOwnCloud struct { DriverCommon - UploadInfoDir string - Redis string - Scan bool + UploadInfoDir string `mapstructure:"upload_info_dir"` + Redis string `mapstructure:"redis"` + Scan bool `mapstructure:"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 `mapstructure:"upload_info_dir"` + DBUsername string `mapstructure:"db_username"` + DBPassword string `mapstructure:"db_password"` + DBHost string `mapstructure:"db_host"` + DBPort int `mapstructure:"db_port"` + DBName string `mapstructure:"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 `mapstructure:"region"` + AccessKey string `mapstructure:"access_key"` + SecretKey string `mapstructure:"secret_key"` + Endpoint string `mapstructure:"endpoint"` + Bucket string `mapstructure:"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 `mapstructure:"region"` + AccessKey string `mapstructure:"access_key"` + SecretKey string `mapstructure:"secret_key"` + Endpoint string `mapstructure:"endpoint"` + Bucket string `mapstructure:"bucket"` } // OIDC defines the available OpenID Connect configuration. type OIDC struct { - Issuer string - Insecure bool - IDClaim string - UIDClaim string - GIDClaim string + Issuer string `mapstructure:"issuer"` + Insecure bool `mapstructure:"insecure"` + IDClaim string `mapstructure:"id_claim"` + UIDClaim string `mapstructure:"uid_claim"` + GIDClaim string `mapstructure:"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 `mapstructure:"hostname"` + Port int `mapstructure:"port"` + CACert string `mapstructure:"ca_cert"` + Insecure bool `mapstructure:"insecure"` + BaseDN string `mapstructure:"base_dn"` + LoginFilter string `mapstructure:"login_filter"` + UserFilter string `mapstructure:"user_filter"` + UserAttributeFilter string `mapstructure:"user_attribute_filter"` + UserFindFilter string `mapstructure:"user_find_filter"` + UserGroupFilter string `mapstructure:"user_group_filter"` + GroupFilter string `mapstructure:"group_filter"` + GroupAttributeFilter string `mapstructure:"group_attribute_filter"` + GroupFindFilter string `mapstructure:"group_finder_filter"` + GroupMemberFilter string `mapstructure:"group_member_filter"` + BindDN string `mapstructure:"bind_dn"` + BindPassword string `mapstructure:"bind_password"` + IDP string `mapstructure:"idp"` + UserSchema LDAPUserSchema `mapstructure:"user_schema"` + GroupSchema LDAPGroupSchema `mapstructure:"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 `mapstructure:"client_id"` + ClientSecret string `mapstructure:"client_secret"` + RedisAddress string `mapstructure:"redis_address"` + RedisUsername string `mapstructure:"redis_username"` + RedisPassword string `mapstructure:"redis_password"` + IDProvider string `mapstructure:"idp_provider"` + APIBaseURL string `mapstructure:"api_base_url"` + OIDCTokenEndpoint string `mapstructure:"oidc_token_endpoint"` + TargetAPI string `mapstructure:"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 `mapstructure:"db_username"` + DBPassword string `mapstructure:"db_password"` + DBHost string `mapstructure:"db_host"` + DBPort int `mapstructure:"db_port"` + DBName string `mapstructure:"db_name"` + Idp string `mapstructure:"idp"` + Nobody int64 `mapstructure:"nobody"` + JoinUsername bool `mapstructure:"join_username"` + JoinOwnCloudUUID bool `mapstructure:"join_owncloud_uuid"` + EnableMedialSearch bool `mapstructure:"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 `mapstructure:"uid"` + Mail string `mapstructure:"mail"` + DisplayName string `mapstructure:"display_name"` + CN string `mapstructure:"cn"` + UIDNumber string `mapstructure:"uid_number"` + GIDNumber string `mapstructure:"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 `mapstructure:"gid"` + Mail string `mapstructure:"mail"` + DisplayName string `mapstructure:"display_name"` + CN string `mapstructure:"cn"` + GIDNumber string `mapstructure:"gid_number"` } // OCDav defines the available ocdav configuration. type OCDav struct { - WebdavNamespace string - DavFilesNamespace string + WebdavNamespace string `mapstructure:"webdav_namespace"` + DavFilesNamespace string `mapstructure:"dav_files_namespace"` } // Archiver defines the available archiver configuration. type Archiver struct { - MaxNumFiles int64 - MaxSize int64 - ArchiverURL string + MaxNumFiles int64 `mapstructure:"max_num_files"` + MaxSize int64 `mapstructure:"max_size"` + ArchiverURL string `mapstructure:"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 `mapstructure:"jwt_secret"` + SkipUserGroupsInToken bool `mapstructure:"skip_user_grooups_in_token"` + TransferSecret string `mapstructure:"transfer_secret"` + TransferExpires int `mapstructure:"transfer_expires"` + OIDC OIDC `mapstructure:"oidc"` + LDAP LDAP `mapstructure:"ldap"` + UserGroupRest UserGroupRest `mapstructure:"user_group_rest"` + UserOwnCloudSQL UserOwnCloudSQL `mapstructure:"user_owncloud_sql"` + OCDav OCDav `mapstructure:"ocdav"` + Archiver Archiver `mapstructure:"archiver"` + UserStorage StorageConfig `mapstructure:"user_storage"` + MetadataStorage StorageConfig `mapstructure:"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 `mapstructure:"frontend"` + DataGateway DataGatewayPort `mapstructure:"data_gateway"` + Gateway Gateway `mapstructure:"gateway"` + StorageRegistry StorageRegistry `mapstructure:"storage_registry"` + AppRegistry AppRegistry `mapstructure:"app_registry"` + Users Users `mapstructure:"users"` + Groups Groups `mapstructure:"groups"` + AuthProvider Users `mapstructure:"auth_provider"` + AuthBasic Port `mapstructure:"auth_basic"` + AuthBearer Port `mapstructure:"auth_bearer"` + AuthMachine Port `mapstructure:"auth_machine"` + AuthMachineConfig AuthMachineConfig `mapstructure:"auth_machine_config"` + Sharing Sharing `mapstructure:"sharing"` + StorageHome StoragePort `mapstructure:"storage_home"` + StorageUsers StoragePort `mapstructure:"storage_users"` + StoragePublicLink PublicStorage `mapstructure:"storage_public_link"` + StorageMetadata StoragePort `mapstructure:"storage_metadata"` + AppProvider AppProvider `mapstructure:"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{} `mapstructure:"configs"` // chunking and resumable upload config (TUS) - UploadMaxChunkSize int - UploadHTTPMethodOverride string + UploadMaxChunkSize int `mapstructure:"uppload_max_chunk_size"` + UploadHTTPMethodOverride string `mapstructure:"upload_http_method_override"` // checksumming capabilities - ChecksumSupportedTypes []string - ChecksumPreferredUploadType string - DefaultUploadProtocol string + ChecksumSupportedTypes []string `mapstructure:"checksum_supported_types"` + ChecksumPreferredUploadType string `mapstructure:"checksum_preferred_upload_type"` + DefaultUploadProtocol string `mapstructure:"default_upload_protocol"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool - Type string - Endpoint string - Collector string - Service string + Enabled bool `mapstructure:"enabled"` + Type string `mapstructure:"type"` + Endpoint string `mapstructure:"endpoint"` + Collector string `mapstructure:"collector"` + Service string `mapstructure:"service"` } // Asset defines the available asset configuration. type Asset struct { - Path string + Path string `mapstructure:"path"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - File string - Log *shared.Log - Debug Debug - Reva Reva - Tracing Tracing - Asset Asset + File string `mapstructure:"file"` + Log *shared.Log `mapstructure:"log"` + Debug Debug `mapstructure:"debug"` + Reva Reva `mapstructure:"reva"` + Tracing Tracing `mapstructure:"tracing"` + Asset Asset `mapstructure:"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: nil, + 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", + }, + 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", + }, + 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", + }, + AuthBearer: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9148", + DebugAddr: "127.0.0.1:9149", + }, + AuthMachine: Port{ + GRPCNetwork: "tcp", + GRPCAddr: "127.0.0.1:9166", + DebugAddr: "127.0.0.1:9167", + }, + 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", + }, + 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", + 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", + }, + 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", + }, + ExternalAddr: "127.0.0.1:9164", + WopiDriver: WopiDriver{}, + AppsURL: "/app/list", + OpenURL: "/app/open", + }, + Configs: nil, + UploadMaxChunkSize: 1e+8, + UploadHTTPMethodOverride: "", + ChecksumSupportedTypes: nil, + 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{ + { + 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, + }, + } +} From 097c8538946d597bf1a164efbaedcefe29d6edb4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 15 Nov 2021 19:52:40 +0100 Subject: [PATCH 106/147] populate checksum --- storage/pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index fef2ec62fc..82f86ae9e4 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -921,7 +921,7 @@ func DefaultConfig() *Config { Configs: nil, UploadMaxChunkSize: 1e+8, UploadHTTPMethodOverride: "", - ChecksumSupportedTypes: nil, + ChecksumSupportedTypes: []string{"sha1", "md5", "adler32"}, ChecksumPreferredUploadType: "", DefaultUploadProtocol: "tus", }, From 0d7be0d6adf0cf10c424852479c43e9d058b2fa3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 12:22:17 +0100 Subject: [PATCH 107/147] set all previously set on c.StringSlice values on the bootstrap config --- accounts/pkg/command/update_account.go | 3 +-- ocis/pkg/command/storageappprovider.go | 3 +-- ocis/pkg/command/storageauthbasic.go | 3 +-- ocis/pkg/command/storageauthbearer.go | 3 +-- ocis/pkg/command/storagefrontend.go | 3 +-- ocis/pkg/command/storagegateway.go | 3 +-- ocis/pkg/command/storagegroupprovider.go | 3 +-- ocis/pkg/command/storagehome.go | 3 +-- ocis/pkg/command/storagemetadata.go | 3 +-- ocis/pkg/command/storagepubliclink.go | 3 +-- ocis/pkg/command/storagesharing.go | 3 +-- ocis/pkg/command/storageuserprovider.go | 3 +-- ocis/pkg/command/storageusers.go | 3 +-- storage/pkg/command/appprovider.go | 2 +- storage/pkg/command/authbasic.go | 2 +- storage/pkg/command/authbearer.go | 3 --- storage/pkg/command/authmachine.go | 3 --- storage/pkg/command/frontend.go | 3 --- storage/pkg/command/gateway.go | 4 ++-- storage/pkg/command/groups.go | 3 --- storage/pkg/command/sharing.go | 2 +- storage/pkg/command/storagehome.go | 2 +- storage/pkg/command/storageusers.go | 2 +- storage/pkg/command/users.go | 2 +- storage/pkg/config/config.go | 9 ++++++++- storage/pkg/flagset/sharing.go | 2 +- 26 files changed, 30 insertions(+), 48 deletions(-) diff --git a/accounts/pkg/command/update_account.go b/accounts/pkg/command/update_account.go index 2d66fdd7ec..b3ed17f105 100644 --- a/accounts/pkg/command/update_account.go +++ b/accounts/pkg/command/update_account.go @@ -6,7 +6,6 @@ import ( "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" @@ -21,7 +20,7 @@ func UpdateAccount(cfg *config.Config) *cli.Command { Name: "update", Usage: "Make changes to an existing account", ArgsUsage: "id", - Flags: flagset.UpdateAccountWithConfig(cfg, a), + //Flags: flagset.UpdateAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { if len(c.StringSlice("password_policies")) > 0 { // StringSliceFlag doesn't support Destination diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index 6672282b6e..5202959659 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index 02446b4481..62cddc5c80 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index ab14a42368..329e644672 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 853a9bc44a..29fb13ee21 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index a9fe1a6f3b..4f24f3e494 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storagegroupprovider.go b/ocis/pkg/command/storagegroupprovider.go index 3500780beb..530e8148ce 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storagehome.go b/ocis/pkg/command/storagehome.go index 5ed11b581e..bae5c1c674 100644 --- a/ocis/pkg/command/storagehome.go +++ b/ocis/pkg/command/storagehome.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index 0729d6e311..d475da582d 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -4,7 +4,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -14,7 +13,7 @@ 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) }, diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index 07e7d94763..e4d9dc7501 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index 672e209e7a..3a15d90eea 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index 671d87ff9b..fc423737a3 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index c6c2b7700b..a7978fb69c 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -7,7 +7,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/storage/pkg/command" - "github.com/owncloud/ocis/storage/pkg/flagset" "github.com/urfave/cli/v2" ) @@ -17,7 +16,7 @@ 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) }, diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index a4d4b24a22..574304aee0 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -25,7 +25,7 @@ func AppProvider(cfg *config.Config) *cli.Command { Usage: "Start appprovider for providing apps", //Flags: flagset.AppProviderWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.AppProvider.Services = c.StringSlice("service") + //cfg.Reva.AppProvider.Services = c.StringSlice("service") return ParseConfig(c, cfg, "storage-app-provider") }, diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index 2bb7ff3af5..ef02699835 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -26,7 +26,7 @@ func AuthBasic(cfg *config.Config) *cli.Command { Usage: "Start authprovider for basic auth", //Flags: flagset.AuthBasicWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.AuthBasic.Services = c.StringSlice("service") + //cfg.Reva.AuthBasic.Services = c.StringSlice("service") return ParseConfig(c, cfg, "storage-auth-basic") }, diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 95270e0139..af60ccbdac 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -23,10 +23,7 @@ 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 ParseConfig(c, cfg, "storage-auth-bearer") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/authmachine.go b/storage/pkg/command/authmachine.go index 50df131765..eaaa97cbf6 100644 --- a/storage/pkg/command/authmachine.go +++ b/storage/pkg/command/authmachine.go @@ -23,10 +23,7 @@ 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 ParseConfig(c, cfg, "storage-auth-machine") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/frontend.go b/storage/pkg/command/frontend.go index 208d7dd442..4161d35c9f 100644 --- a/storage/pkg/command/frontend.go +++ b/storage/pkg/command/frontend.go @@ -27,10 +27,7 @@ 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") if err := loadUserAgent(c, cfg); err != nil { return err } diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index ede3f43a63..23de38db9b 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -33,8 +33,8 @@ func Gateway(cfg *config.Config) *cli.Command { 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") + //cfg.Reva.Gateway.Services = c.StringSlice("service") + //cfg.Reva.StorageRegistry.Rules = c.StringSlice("storage-registry-rule") if cfg.Reva.DataGateway.PublicURL == "" { cfg.Reva.DataGateway.PublicURL = strings.TrimRight(cfg.Reva.Frontend.PublicURL, "/") + "/data" diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 0acb622cf3..043c96fdcd 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -24,10 +24,7 @@ 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 ParseConfig(c, cfg, "storage-groups") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index 692631b58b..ac6dc55b59 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -28,7 +28,7 @@ func Sharing(cfg *config.Config) *cli.Command { Usage: "Start sharing service", //Flags: flagset.SharingWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Sharing.Services = c.StringSlice("service") + //cfg.Reva.Sharing.Services = c.StringSlice("service") return ParseConfig(c, cfg, "storage-sharing") }, diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index 72772be555..89eef388fb 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -27,7 +27,7 @@ func StorageHome(cfg *config.Config) *cli.Command { Usage: "Start storage-home service", //Flags: flagset.StorageHomeWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.StorageHome.Services = c.StringSlice("service") + //cfg.Reva.StorageHome.Services = c.StringSlice("service") return ParseConfig(c, cfg, "storage-home") }, diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 996655502b..47477939e2 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -26,7 +26,7 @@ func StorageUsers(cfg *config.Config) *cli.Command { Usage: "Start storage-users service", //Flags: flagset.StorageUsersWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.StorageHome.Services = c.StringSlice("service") + //cfg.Reva.StorageHome.Services = c.StringSlice("service") return ParseConfig(c, cfg, "storage-userprovider") }, diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 7f2cf88d9a..0586f7bfa0 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -26,7 +26,7 @@ func Users(cfg *config.Config) *cli.Command { Usage: "Start users service", //Flags: flagset.UsersWithConfig(cfg), Before: func(c *cli.Context) error { - cfg.Reva.Users.Services = c.StringSlice("service") + //cfg.Reva.Users.Services = c.StringSlice("service") return ParseConfig(c, cfg, "storage-users") }, diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 82f86ae9e4..04dff39c9b 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -733,7 +733,7 @@ func DefaultConfig() *Config { Protocol: "", Endpoint: "", DebugAddr: "127.0.0.1:9141", - Services: nil, + Services: []string{"datagateway", "ocdav", "ocs", "appprovider"}, Config: nil, Context: nil, Supervised: false, @@ -788,6 +788,7 @@ func DefaultConfig() *Config { Endpoint: "localhost:9144", GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9144", + Services: []string{"userprovider"}, }, Driver: "ldap", UserGroupsCacheExpiration: 5, @@ -798,6 +799,7 @@ func DefaultConfig() *Config { DebugAddr: "127.0.0.1:9161", GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9160", + Services: []string{"groupprovider"}, }, Driver: "ldap", GroupMembersCacheExpiration: 5, @@ -811,16 +813,19 @@ func DefaultConfig() *Config { GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9146", DebugAddr: "127.0.0.1:9147", + Services: []string{"authprovider"}, }, AuthBearer: Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9148", DebugAddr: "127.0.0.1:9149", + Services: []string{"authprovider"}, }, AuthMachine: Port{ GRPCNetwork: "tcp", GRPCAddr: "127.0.0.1:9166", DebugAddr: "127.0.0.1:9167", + Services: []string{"authprovider"}, }, AuthMachineConfig: AuthMachineConfig{ MachineAuthAPIKey: "change-me-please", @@ -831,6 +836,7 @@ func DefaultConfig() *Config { 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"), @@ -912,6 +918,7 @@ func DefaultConfig() *Config { 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{}, diff --git a/storage/pkg/flagset/sharing.go b/storage/pkg/flagset/sharing.go index 1f54a2f6ec..dc9198a88f 100644 --- a/storage/pkg/flagset/sharing.go +++ b/storage/pkg/flagset/sharing.go @@ -52,7 +52,7 @@ func SharingWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringSliceFlag{ Name: "service", - Value: cli.NewStringSlice("usershareprovider", "publicshareprovider"), // TODO osmshareprovider + Value: cli.NewStringSlice("usershareprovider", "publicshareprovider"), // accounted for Usage: "--service usershareprovider [--service publicshareprovider]", EnvVars: []string{"STORAGE_SHARING_SERVICES"}, }, From 2ebc0b4a412f8555f8e70e22209d4cedead40cd4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 13:11:51 +0100 Subject: [PATCH 108/147] add missing authprovider config --- storage/pkg/config/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 04dff39c9b..95a2584521 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -814,18 +814,21 @@ func DefaultConfig() *Config { 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", From 8c307ef2bf6eac5726a0bf8ee03ddc7e14bc5c98 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 13:43:54 +0100 Subject: [PATCH 109/147] add missing OCIS_INSECURE binding on PROXY_OIDC_INSECURE --- proxy/pkg/config/mappings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/pkg/config/mappings.go b/proxy/pkg/config/mappings.go index 106f16d6bd..582e391b4e 100644 --- a/proxy/pkg/config/mappings.go +++ b/proxy/pkg/config/mappings.go @@ -141,7 +141,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.OIDC.Issuer, }, { - EnvVars: []string{"PROXY_OIDC_INSECURE"}, + EnvVars: []string{"OCIS_INSECURE", "PROXY_OIDC_INSECURE"}, Destination: &cfg.OIDC.Insecure, }, { From 658bf9acce11ba7b5ccc0d81656bcea8402b97fa Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 14:12:01 +0100 Subject: [PATCH 110/147] increase logging level to see more on ci --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index f35df73228..1d2fefec49 100644 --- a/.drone.star +++ b/.drone.star @@ -1477,7 +1477,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []): "PROXY_ENABLE_BASIC_AUTH": True, "WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json", "IDP_IDENTIFIER_REGISTRATION_CONF": "/drone/src/tests/config/drone/identifier-registration.yml", - "OCIS_LOG_LEVEL": "error", + "OCIS_LOG_LEVEL": "info", "SETTINGS_DATA_PATH": "/srv/app/tmp/ocis/settings", "OCIS_INSECURE": "true", } From deba643a5bd67853f3c157af77655275d6503a12 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 14:16:18 +0100 Subject: [PATCH 111/147] add set of env variables used on ci to the bootstrap config env parsing --- storage/pkg/config/config.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 95a2584521..6776b9a8ae 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -1003,5 +1003,33 @@ func structMappings(cfg *Config) []shared.EnvBinding { 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, + }, } } From f4085f6dacbb0f108baddd0bdd4e6b1ca391abf4 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 14:16:46 +0100 Subject: [PATCH 112/147] revert ocis log level to error (CI) --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 1d2fefec49..f35df73228 100644 --- a/.drone.star +++ b/.drone.star @@ -1477,7 +1477,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []): "PROXY_ENABLE_BASIC_AUTH": True, "WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json", "IDP_IDENTIFIER_REGISTRATION_CONF": "/drone/src/tests/config/drone/identifier-registration.yml", - "OCIS_LOG_LEVEL": "info", + "OCIS_LOG_LEVEL": "error", "SETTINGS_DATA_PATH": "/srv/app/tmp/ocis/settings", "OCIS_INSECURE": "true", } From 7617ccaf410f283c6562c0fe8b04b4857469c24a Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 14:40:18 +0100 Subject: [PATCH 113/147] increase log level and remove dead lines --- .drone.star | 2 +- storage/pkg/command/appprovider.go | 3 --- storage/pkg/command/authbasic.go | 3 --- storage/pkg/command/gateway.go | 6 +----- storage/pkg/command/sharing.go | 3 --- storage/pkg/command/storagehome.go | 3 --- storage/pkg/command/storagemetadata.go | 2 -- storage/pkg/command/storagepubliclink.go | 1 - storage/pkg/command/storageusers.go | 3 --- storage/pkg/command/users.go | 3 --- 10 files changed, 2 insertions(+), 27 deletions(-) diff --git a/.drone.star b/.drone.star index f35df73228..1d2fefec49 100644 --- a/.drone.star +++ b/.drone.star @@ -1477,7 +1477,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []): "PROXY_ENABLE_BASIC_AUTH": True, "WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json", "IDP_IDENTIFIER_REGISTRATION_CONF": "/drone/src/tests/config/drone/identifier-registration.yml", - "OCIS_LOG_LEVEL": "error", + "OCIS_LOG_LEVEL": "info", "SETTINGS_DATA_PATH": "/srv/app/tmp/ocis/settings", "OCIS_INSECURE": "true", } diff --git a/storage/pkg/command/appprovider.go b/storage/pkg/command/appprovider.go index 574304aee0..80c8c523ba 100644 --- a/storage/pkg/command/appprovider.go +++ b/storage/pkg/command/appprovider.go @@ -23,10 +23,7 @@ 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 ParseConfig(c, cfg, "storage-app-provider") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/authbasic.go b/storage/pkg/command/authbasic.go index ef02699835..10268754a1 100644 --- a/storage/pkg/command/authbasic.go +++ b/storage/pkg/command/authbasic.go @@ -24,10 +24,7 @@ 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 ParseConfig(c, cfg, "storage-auth-basic") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 23de38db9b..3e40e3d431 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -31,16 +31,12 @@ 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 cfg.Reva.DataGateway.PublicURL == "" { cfg.Reva.DataGateway.PublicURL = strings.TrimRight(cfg.Reva.Frontend.PublicURL, "/") + "/data" } - return ParseConfig(c, cfg, "storage-gatway") + return ParseConfig(c, cfg, "storage-gateway") }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index ac6dc55b59..abace4d50b 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -26,10 +26,7 @@ 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 ParseConfig(c, cfg, "storage-sharing") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/storagehome.go b/storage/pkg/command/storagehome.go index 89eef388fb..bbeca4d705 100644 --- a/storage/pkg/command/storagehome.go +++ b/storage/pkg/command/storagehome.go @@ -25,10 +25,7 @@ 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 ParseConfig(c, cfg, "storage-home") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 74864e2c68..1c84313a37 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -29,8 +29,6 @@ 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: flagset.StorageMetadata(cfg), Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-metadata") }, diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index 467749aa03..d7a0a0773a 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -23,7 +23,6 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "storage-public-link", Usage: "Start storage-public-link service", - //Flags: flagset.StoragePublicLink(cfg), Before: func(c *cli.Context) error { return ParseConfig(c, cfg, "storage-public-link") }, diff --git a/storage/pkg/command/storageusers.go b/storage/pkg/command/storageusers.go index 47477939e2..7bb7aa6c0f 100644 --- a/storage/pkg/command/storageusers.go +++ b/storage/pkg/command/storageusers.go @@ -24,10 +24,7 @@ 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 ParseConfig(c, cfg, "storage-userprovider") }, Action: func(c *cli.Context) error { diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index 0586f7bfa0..34aee1d7c0 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -24,10 +24,7 @@ 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 ParseConfig(c, cfg, "storage-users") }, Action: func(c *cli.Context) error { From d30e776deb713a9f2d7472dceb00b1ea4de0e47b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 14:54:44 +0100 Subject: [PATCH 114/147] add more OCIS_URL missing spots in storage --- storage/pkg/config/config.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 6776b9a8ae..545d015574 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -1031,5 +1031,21 @@ func structMappings(cfg *Config) []shared.EnvBinding { 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, + }, } } From e139a09e499d5292d4dafa053853de1faa963ac0 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 14:55:19 +0100 Subject: [PATCH 115/147] change logging level back to error --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 1d2fefec49..f35df73228 100644 --- a/.drone.star +++ b/.drone.star @@ -1477,7 +1477,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = []): "PROXY_ENABLE_BASIC_AUTH": True, "WEB_UI_CONFIG": "/drone/src/tests/config/drone/ocis-config.json", "IDP_IDENTIFIER_REGISTRATION_CONF": "/drone/src/tests/config/drone/identifier-registration.yml", - "OCIS_LOG_LEVEL": "info", + "OCIS_LOG_LEVEL": "error", "SETTINGS_DATA_PATH": "/srv/app/tmp/ocis/settings", "OCIS_INSECURE": "true", } From 7f652ae3b4e10a0014b0e1d1befc93032f6fe392 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 16:07:00 +0100 Subject: [PATCH 116/147] migrate all flags to config binding mappings --- storage/pkg/config/config.go | 1202 ++++++++++++++++++++++++++++++++++ 1 file changed, 1202 insertions(+) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 545d015574..3087a4897c 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -963,6 +963,7 @@ func GetEnv(cfg *Config) []string { func structMappings(cfg *Config) []shared.EnvBinding { return []shared.EnvBinding{ + // Shared { EnvVars: []string{"OCIS_LOG_LEVEL", "STORAGE_FRONTEND_LOG_LEVEL"}, Destination: &cfg.Log.Level, @@ -1047,5 +1048,1206 @@ func structMappings(cfg *Config) []shared.EnvBinding { 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{"STORAGE_AUTH_MACHINE_AUTH_API_KEY", "OCIS_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{"STORAGE_JWT_SECRET", "OCIS_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, + }, } } From 26db9afb8a72d96aa9677905aded469ac00a44da Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 16:56:28 +0100 Subject: [PATCH 117/147] undo const... --- web/pkg/config/config.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index b48e020e0d..9859e91cac 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -6,8 +6,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) -const defaultIngressURL = "https://localhost:9200" - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -133,15 +131,15 @@ func DefaultConfig() *Config { }, Web: Web{ Path: "", - ThemeServer: defaultIngressURL, + ThemeServer: "https://localhost:9200", ThemePath: "/themes/owncloud/theme.json", Config: WebConfig{ - Server: defaultIngressURL, + Server: "https://localhost:9200", Theme: "", Version: "0.1.0", OpenIDConnect: OIDC{ MetadataURL: "", - Authority: defaultIngressURL, + Authority: "https://localhost:9200", ClientID: "web", ResponseType: "code", Scope: "openid profile email", From 5fe1be8611448a30315adacad0e87c9610c1e63f Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 16 Nov 2021 23:14:56 +0100 Subject: [PATCH 118/147] sneaky bug --- storage/pkg/command/gateway.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index 3e40e3d431..5e4df65133 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -32,11 +32,15 @@ func Gateway(cfg *config.Config) *cli.Command { Name: "gateway", Usage: "Start gateway", Before: func(c *cli.Context) error { + 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" } - return ParseConfig(c, cfg, "storage-gateway") + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From 9c7c2b6dc99c4e206a29f054530686ffeb99753a Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 00:10:40 +0100 Subject: [PATCH 119/147] empty commit to trigger full ci From 017eea8f2bc38d4f2b5ed5f2a7993683b8ed0699 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 09:47:00 +0100 Subject: [PATCH 120/147] delete storage flagsets --- storage/pkg/command/health.go | 5 +- storage/pkg/flagset/appprovider.go | 144 --------- storage/pkg/flagset/authbasic.go | 81 ----- storage/pkg/flagset/authbearer.go | 107 ------- storage/pkg/flagset/authmachine.go | 73 ----- storage/pkg/flagset/debug.go | 32 -- storage/pkg/flagset/frontend.go | 299 ----------------- storage/pkg/flagset/gateway.go | 300 ------------------ storage/pkg/flagset/groups.go | 94 ------ storage/pkg/flagset/health.go | 20 -- storage/pkg/flagset/ldap.go | 229 ------------- .../pkg/flagset/metadatadrivers/drivereos.go | 136 -------- .../flagset/metadatadrivers/driverlocal.go | 23 -- .../pkg/flagset/metadatadrivers/driverocis.go | 37 --- .../pkg/flagset/metadatadrivers/drivers3.go | 48 --- .../pkg/flagset/metadatadrivers/drivers3ng.go | 65 ---- storage/pkg/flagset/rest.go | 76 ----- storage/pkg/flagset/root.go | 37 --- storage/pkg/flagset/secret.go | 27 -- storage/pkg/flagset/sharing.go | 116 ------- storage/pkg/flagset/sharingsql.go | 48 --- storage/pkg/flagset/storagehome.go | 175 ---------- storage/pkg/flagset/storagemetadata.go | 114 ------- storage/pkg/flagset/storagepubliclink.go | 58 ---- storage/pkg/flagset/storageusers.go | 172 ---------- storage/pkg/flagset/tracing.go | 48 --- storage/pkg/flagset/userdrivers/drivereos.go | 136 -------- .../pkg/flagset/userdrivers/driverlocal.go | 37 --- storage/pkg/flagset/userdrivers/driverocis.go | 44 --- .../pkg/flagset/userdrivers/driverowncloud.go | 58 ---- .../flagset/userdrivers/driverowncloudsql.go | 79 ----- storage/pkg/flagset/userdrivers/drivers3.go | 48 --- storage/pkg/flagset/userdrivers/drivers3ng.go | 72 ----- storage/pkg/flagset/users.go | 167 ---------- 34 files changed, 3 insertions(+), 3202 deletions(-) delete mode 100644 storage/pkg/flagset/appprovider.go delete mode 100644 storage/pkg/flagset/authbasic.go delete mode 100644 storage/pkg/flagset/authbearer.go delete mode 100644 storage/pkg/flagset/authmachine.go delete mode 100644 storage/pkg/flagset/debug.go delete mode 100644 storage/pkg/flagset/frontend.go delete mode 100644 storage/pkg/flagset/gateway.go delete mode 100644 storage/pkg/flagset/groups.go delete mode 100644 storage/pkg/flagset/health.go delete mode 100644 storage/pkg/flagset/ldap.go delete mode 100644 storage/pkg/flagset/metadatadrivers/drivereos.go delete mode 100644 storage/pkg/flagset/metadatadrivers/driverlocal.go delete mode 100644 storage/pkg/flagset/metadatadrivers/driverocis.go delete mode 100644 storage/pkg/flagset/metadatadrivers/drivers3.go delete mode 100644 storage/pkg/flagset/metadatadrivers/drivers3ng.go delete mode 100644 storage/pkg/flagset/rest.go delete mode 100644 storage/pkg/flagset/root.go delete mode 100644 storage/pkg/flagset/secret.go delete mode 100644 storage/pkg/flagset/sharing.go delete mode 100644 storage/pkg/flagset/sharingsql.go delete mode 100644 storage/pkg/flagset/storagehome.go delete mode 100644 storage/pkg/flagset/storagemetadata.go delete mode 100644 storage/pkg/flagset/storagepubliclink.go delete mode 100644 storage/pkg/flagset/storageusers.go delete mode 100644 storage/pkg/flagset/tracing.go delete mode 100644 storage/pkg/flagset/userdrivers/drivereos.go delete mode 100644 storage/pkg/flagset/userdrivers/driverlocal.go delete mode 100644 storage/pkg/flagset/userdrivers/driverocis.go delete mode 100644 storage/pkg/flagset/userdrivers/driverowncloud.go delete mode 100644 storage/pkg/flagset/userdrivers/driverowncloudsql.go delete mode 100644 storage/pkg/flagset/userdrivers/drivers3.go delete mode 100644 storage/pkg/flagset/userdrivers/drivers3ng.go delete mode 100644 storage/pkg/flagset/users.go diff --git a/storage/pkg/command/health.go b/storage/pkg/command/health.go index 9398b3ba03..a3c3791a99 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/flagset/appprovider.go b/storage/pkg/flagset/appprovider.go deleted file mode 100644 index 781705586d..0000000000 --- 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 bbfcae1ee3..0000000000 --- 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 d41a89558a..0000000000 --- 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 f4a9d20f7a..0000000000 --- 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 4273f08865..0000000000 --- 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 09e3aee1d2..0000000000 --- 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{"OCIS_URL", "STORAGE_FRONTEND_PUBLIC_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 01de385663..0000000000 --- a/storage/pkg/flagset/gateway.go +++ /dev/null @@ -1,300 +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{"OCIS_URL", "STORAGE_FRONTEND_PUBLIC_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, - }, - // public-link has no mount id - } - - 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 50dab10901..0000000000 --- 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 3333622e52..0000000000 --- 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 94848dce28..0000000000 --- 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 c734e6c129..0000000000 --- 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 7ef4ddac3f..0000000000 --- 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 614b0bdaeb..0000000000 --- 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 5604775604..0000000000 --- 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 81e394aaa8..0000000000 --- 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 1755b0e0f2..0000000000 --- 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 6f6130d228..0000000000 --- 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{"OCIS_LOG_LEVEL", "STORAGE_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"OCIS_LOG_PRETTY", "STORAGE_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"OCIS_LOG_COLOR", "STORAGE_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 8504bd56b1..0000000000 --- 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 dc9198a88f..0000000000 --- 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"), // accounted for - 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 b152380fa7..0000000000 --- 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 76eb53d70b..0000000000 --- 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 4b80756f0a..0000000000 --- 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 5d884c79d7..0000000000 --- a/storage/pkg/flagset/storagepubliclink.go +++ /dev/null @@ -1,58 +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: "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 6be58bc33b..0000000000 --- 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 67c7eb0bae..0000000000 --- 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 a937307ef5..0000000000 --- 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 212b202e74..0000000000 --- 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 35aa986835..0000000000 --- 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 395b28325c..0000000000 --- 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 c0adb07dc2..0000000000 --- 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 72984e684b..0000000000 --- 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 1b21e2a9cd..0000000000 --- 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 182882ecd3..0000000000 --- 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 -} From 05825d8fe2546181d8b3357348f4bdab7e3c63cc Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 10:24:40 +0100 Subject: [PATCH 121/147] removed docs-generate build target from module storage --- storage/Makefile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/storage/Makefile b/storage/Makefile index c4827d0541..b177ccd0cd 100644 --- a/storage/Makefile +++ b/storage/Makefile @@ -14,12 +14,6 @@ include ../.make/go.mk ############ release ######### include ../.make/release.mk -############ docs generate ############ -include ../.make/docs.mk - -.PHONY: docs-generate -docs-generate: config-docs-generate - ############ generate ############ include ../.make/generate.mk From c7a43916e4485c6ee6fe7c53932ecaa9cbf24b59 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 11:21:02 +0100 Subject: [PATCH 122/147] disable docs pipeline --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index f35df73228..94f649c94e 100644 --- a/.drone.star +++ b/.drone.star @@ -146,7 +146,7 @@ def main(ctx): build_release_helpers = [ changelog(ctx), - docs(ctx), + # docs(ctx), ] test_pipelines.append( From f87b5bd66cf3f460e61dffcea74eda614e2a73af Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 11:36:28 +0100 Subject: [PATCH 123/147] removed all flagset packages --- glauth/pkg/command/health.go | 5 +-- glauth/pkg/flagset/flagset.go | 20 ------------ graph-explorer/pkg/command/health.go | 5 +-- graph-explorer/pkg/flagset/flagset.go | 20 ------------ graph/pkg/command/health.go | 5 +-- graph/pkg/flagset/flagset.go | 20 ------------ idp/pkg/command/health.go | 5 +-- idp/pkg/command/server.go | 20 +++--------- idp/pkg/command/version.go | 5 +-- idp/pkg/flagset/flagset.go | 39 ------------------------ ocs/pkg/command/health.go | 5 +-- ocs/pkg/command/version.go | 5 +-- ocs/pkg/flagset/flagset.go | 40 ------------------------ proxy/pkg/command/version.go | 5 +-- proxy/pkg/flagset/flagset.go | 27 ---------------- settings/pkg/command/health.go | 5 +-- settings/pkg/command/version.go | 5 +-- settings/pkg/flagset/flagset.go | 40 ------------------------ store/pkg/command/health.go | 5 +-- store/pkg/command/version.go | 5 +-- store/pkg/flagset/flagset.go | 39 ------------------------ thumbnails/pkg/command/health.go | 5 +-- thumbnails/pkg/command/version.go | 5 +-- thumbnails/pkg/flagset/flagset.go | 41 ------------------------- web/pkg/command/health.go | 5 +-- web/pkg/flagset/flagset.go | 44 --------------------------- webdav/pkg/command/health.go | 5 +-- webdav/pkg/command/version.go | 5 +-- webdav/pkg/flagset/flagset.go | 40 ------------------------ 29 files changed, 55 insertions(+), 420 deletions(-) delete mode 100644 glauth/pkg/flagset/flagset.go delete mode 100644 graph-explorer/pkg/flagset/flagset.go delete mode 100644 graph/pkg/flagset/flagset.go delete mode 100644 idp/pkg/flagset/flagset.go delete mode 100644 ocs/pkg/flagset/flagset.go delete mode 100644 proxy/pkg/flagset/flagset.go delete mode 100644 settings/pkg/flagset/flagset.go delete mode 100644 store/pkg/flagset/flagset.go delete mode 100644 thumbnails/pkg/flagset/flagset.go delete mode 100644 web/pkg/flagset/flagset.go delete mode 100644 webdav/pkg/flagset/flagset.go diff --git a/glauth/pkg/command/health.go b/glauth/pkg/command/health.go index 3deb2db70d..1ee1362ecd 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/flagset/flagset.go b/glauth/pkg/flagset/flagset.go deleted file mode 100644 index 4473813848..0000000000 --- a/glauth/pkg/flagset/flagset.go +++ /dev/null @@ -1,20 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/glauth/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/flags" - "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:9129"), - Usage: "Address to debug endpoint", - EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} diff --git a/graph-explorer/pkg/command/health.go b/graph-explorer/pkg/command/health.go index 2fc86dcc07..60f4cc925b 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/flagset/flagset.go b/graph-explorer/pkg/flagset/flagset.go deleted file mode 100644 index ef4c46e863..0000000000 --- a/graph-explorer/pkg/flagset/flagset.go +++ /dev/null @@ -1,20 +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" -) - -// 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, - }, - } -} diff --git a/graph/pkg/command/health.go b/graph/pkg/command/health.go index 8fd0bef9c0..509146e3fa 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/flagset/flagset.go b/graph/pkg/flagset/flagset.go deleted file mode 100644 index d660716e7b..0000000000 --- a/graph/pkg/flagset/flagset.go +++ /dev/null @@ -1,20 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/graph/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/flags" - "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:9124"), - Usage: "Address to debug endpoint", - EnvVars: []string{"GRAPH_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} diff --git a/idp/pkg/command/health.go b/idp/pkg/command/health.go index 7e03cabc72..813470bd48 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/server.go b/idp/pkg/command/server.go index cc33fe911e..c9f943ebca 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -20,26 +20,14 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - if cfg.HTTP.Root != "/" { - cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") - } - - //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 err := ParseConfig(ctx, cfg); err != nil { return err } + if cfg.HTTP.Root != "/" { + cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") + } + return nil }, Action: func(c *cli.Context) error { diff --git a/idp/pkg/command/version.go b/idp/pkg/command/version.go index 5f43da1321..7408d59f61 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/flagset/flagset.go b/idp/pkg/flagset/flagset.go deleted file mode 100644 index 5cbcde7019..0000000000 --- a/idp/pkg/flagset/flagset.go +++ /dev/null @@ -1,39 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/idp/pkg/config" - "github.com/owncloud/ocis/ocis-pkg/flags" - "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:9134"), - Usage: "Address to debug endpoint", - EnvVars: []string{"IDP_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// 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/ocs/pkg/command/health.go b/ocs/pkg/command/health.go index c84b6d2449..51474a3da2 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/version.go b/ocs/pkg/command/version.go index 10c1c17df7..2c1b64e0e7 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/flagset/flagset.go b/ocs/pkg/flagset/flagset.go deleted file mode 100644 index f210b31bc4..0000000000 --- a/ocs/pkg/flagset/flagset.go +++ /dev/null @@ -1,40 +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, - }, - } -} - -// 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/proxy/pkg/command/version.go b/proxy/pkg/command/version.go index 273db559cc..469abc6efe 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/flagset/flagset.go b/proxy/pkg/flagset/flagset.go deleted file mode 100644 index 5b7118623b..0000000000 --- a/proxy/pkg/flagset/flagset.go +++ /dev/null @@ -1,27 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/proxy/pkg/config" - "github.com/urfave/cli/v2" -) - -// 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/settings/pkg/command/health.go b/settings/pkg/command/health.go index 72e9ea7f7d..9b475f5e7a 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/version.go b/settings/pkg/command/version.go index fda866b626..55091cf81a 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/flagset/flagset.go b/settings/pkg/flagset/flagset.go deleted file mode 100644 index 73eb906a1b..0000000000 --- a/settings/pkg/flagset/flagset.go +++ /dev/null @@ -1,40 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/settings/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:9194"), - Usage: "Address to debug endpoint", - EnvVars: []string{"SETTINGS_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// 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/store/pkg/command/health.go b/store/pkg/command/health.go index 5768b00ecb..38461c9ac5 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/version.go b/store/pkg/command/version.go index 22b9997bba..b5bfef3b26 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/flagset/flagset.go b/store/pkg/flagset/flagset.go deleted file mode 100644 index a2085be67d..0000000000 --- a/store/pkg/flagset/flagset.go +++ /dev/null @@ -1,39 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/flags" - "github.com/owncloud/ocis/store/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:9464"), - Usage: "Address to debug endpoint", - EnvVars: []string{"STORE_DEBUG_ADDR"}, - Destination: &cfg.Debug.Addr, - }, - } -} - -// 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/pkg/command/health.go b/thumbnails/pkg/command/health.go index babd7d20aa..6b5c84939c 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/version.go b/thumbnails/pkg/command/version.go index 9a861db972..df3c0230f0 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/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go deleted file mode 100644 index 0640c730b3..0000000000 --- a/thumbnails/pkg/flagset/flagset.go +++ /dev/null @@ -1,41 +0,0 @@ -package flagset - -import ( - "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, - }, - } -} - -// 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/pkg/command/health.go b/web/pkg/command/health.go index 4719442e30..97206879bf 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/flagset/flagset.go b/web/pkg/flagset/flagset.go deleted file mode 100644 index c1aa3eae63..0000000000 --- a/web/pkg/flagset/flagset.go +++ /dev/null @@ -1,44 +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{"OCIS_LOG_LEVEL", "WEB_LOG_LEVEL"}, - Destination: &cfg.Log.Level, - }, - &cli.BoolFlag{ - Name: "log-pretty", - Usage: "Enable pretty logging", - EnvVars: []string{"OCIS_LOG_PRETTY", "WEB_LOG_PRETTY"}, - Destination: &cfg.Log.Pretty, - }, - &cli.BoolFlag{ - Name: "log-color", - Usage: "Enable colored logging", - EnvVars: []string{"OCIS_LOG_COLOR", "WEB_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, - }, - } -} diff --git a/webdav/pkg/command/health.go b/webdav/pkg/command/health.go index 42aa7964c3..58aca1e1d2 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/version.go b/webdav/pkg/command/version.go index 03ef51278d..813cc1c08c 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/flagset/flagset.go b/webdav/pkg/flagset/flagset.go deleted file mode 100644 index 87fc458249..0000000000 --- a/webdav/pkg/flagset/flagset.go +++ /dev/null @@ -1,40 +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, - }, - } -} - -// 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, - }, - } -} From c567eb6eea9dcf39ae25542594f4ef182fbfe17c Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 11:39:32 +0100 Subject: [PATCH 124/147] removed yet more flagsets --- accounts/pkg/command/add_account.go | 4 + accounts/pkg/command/inspect_account.go | 5 +- accounts/pkg/command/list_accounts.go | 5 +- accounts/pkg/command/remove_account.go | 5 +- accounts/pkg/command/version.go | 5 +- accounts/pkg/flagset/flagset.go | 144 ------------------------ ocis/pkg/command/health.go | 5 +- ocis/pkg/flagset/flagset.go | 19 ---- 8 files changed, 19 insertions(+), 173 deletions(-) delete mode 100644 ocis/pkg/flagset/flagset.go diff --git a/accounts/pkg/command/add_account.go b/accounts/pkg/command/add_account.go index 4003c46eed..386cb48648 100644 --- a/accounts/pkg/command/add_account.go +++ b/accounts/pkg/command/add_account.go @@ -21,6 +21,10 @@ func AddAccount(cfg *config.Config) *cli.Command { Aliases: []string{"create", "a"}, Flags: flagset.AddAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { + if err := ParseConfig(c, cfg); err != nil { + return err + } + // Write value of username to the flags beneath, as preferred name // and on-premises-sam-account-name is probably confusing for users. if username := c.String("username"); username != "" { diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index 6769cf0f82..ece3932d5e 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -8,7 +8,6 @@ import ( "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" ) @@ -19,7 +18,9 @@ func InspectAccount(cfg *config.Config) *cli.Command { Name: "inspect", Usage: "Show detailed data on an existing account", ArgsUsage: "id", - Flags: flagset.InspectAccountWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index 0ad3747612..fedac44c47 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -8,7 +8,6 @@ import ( "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" ) @@ -19,7 +18,9 @@ func ListAccounts(cfg *config.Config) *cli.Command { Name: "list", Usage: "List existing accounts", Aliases: []string{"ls"}, - Flags: flagset.ListAccountsWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index 086e50554e..88a18110cf 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -6,7 +6,6 @@ import ( "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" ) @@ -18,7 +17,9 @@ func RemoveAccount(cfg *config.Config) *cli.Command { Usage: "Removes an existing account", ArgsUsage: "id", Aliases: []string{"rm"}, - Flags: flagset.RemoveAccountWithConfig(cfg), + Before: func(c *cli.Context) error { + return ParseConfig(c, cfg) + }, Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index c89358db52..66867b6552 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,9 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - Flags: flagset.ListAccountsWithConfig(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.Server.Name) diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 3815f0784a..c633f11164 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -7,90 +7,6 @@ import ( "github.com/urfave/cli/v2" ) -// UpdateAccountWithConfig applies update command flags to cfg -func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { - if a.PasswordProfile == nil { - a.PasswordProfile = &accounts.PasswordProfile{} - } - - 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{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.BoolFlag{ - Name: "enabled", - Usage: "Enable the account", - Destination: &a.AccountEnabled, - }, - &cli.StringFlag{ - Name: "displayname", - Usage: "Set the displayname for the account", - Destination: &a.DisplayName, - }, - &cli.StringFlag{ - Name: "preferred-name", - Usage: "Set the preferred-name for the account", - Destination: &a.PreferredName, - }, - &cli.StringFlag{ - Name: "on-premises-sam-account-name", - Usage: "Set the on-premises-sam-account-name", - Destination: &a.OnPremisesSamAccountName, - }, - &cli.Int64Flag{ - Name: "uidnumber", - Usage: "Set the uidnumber for the account", - Destination: &a.UidNumber, - }, - &cli.Int64Flag{ - Name: "gidnumber", - Usage: "Set the gidnumber for the account", - Destination: &a.GidNumber, - }, - &cli.StringFlag{ - Name: "mail", - Usage: "Set the mail for the account", - Destination: &a.Mail, - }, - &cli.StringFlag{ - Name: "description", - Usage: "Set the description for the account", - Destination: &a.Description, - }, - &cli.StringFlag{ - Name: "password", - Usage: "Set the password for the account", - Destination: &a.PasswordProfile.Password, - // TODO read password from ENV? - }, - &cli.StringSliceFlag{ - Name: "password-policies", - Usage: "Possible policies: DisableStrongPassword, DisablePasswordExpiration", - }, - &cli.BoolFlag{ - Name: "force-password-change", - Usage: "Force password change on next sign-in", - Destination: &a.PasswordProfile.ForceChangePasswordNextSignIn, - }, - &cli.BoolFlag{ - Name: "force-password-change-mfa", - Usage: "Force password change on next sign-in with mfa", - Destination: &a.PasswordProfile.ForceChangePasswordNextSignInWithMfa, - }, - } -} - // AddAccountWithConfig applies create command flags to cfg func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { if a.PasswordProfile == nil { @@ -178,63 +94,3 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { }, } } - -// ListAccountsWithConfig applies list command flags to cfg -func ListAccountsWithConfig(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{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - } -} - -// RemoveAccountWithConfig applies remove command flags to cfg -func RemoveAccountWithConfig(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{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - } -} - -// InspectAccountWithConfig applies inspect command flags to cfg -func InspectAccountWithConfig(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{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - } -} diff --git a/ocis/pkg/command/health.go b/ocis/pkg/command/health.go index c65e295829..f293dbf8fa 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/flagset/flagset.go b/ocis/pkg/flagset/flagset.go deleted file mode 100644 index 1450838fca..0000000000 --- a/ocis/pkg/flagset/flagset.go +++ /dev/null @@ -1,19 +0,0 @@ -package flagset - -import ( - "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/urfave/cli/v2" -) - -// HealthWithConfig applies cfg to the root flag-set. -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, - }, - } -} From aa4112e2e24f6875bd928e06317b632ea0d90af3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 12:25:21 +0100 Subject: [PATCH 125/147] fixed code smells: string literal repetition + cyclomatic complexity --- ocis-pkg/config/config.go | 2 +- ocis/pkg/runtime/service/service.go | 40 ++++++++++--------- proxy/pkg/config/config.go | 51 ++++++++++++------------ proxy/pkg/server/debug/server.go | 6 ++- storage/pkg/config/config.go | 60 ++++++++++++++++------------- store/pkg/command/server.go | 25 +----------- web/pkg/config/config.go | 9 +++-- 7 files changed, 95 insertions(+), 98 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index a334797fc3..dbd3774be9 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -72,7 +72,7 @@ type Runtime struct { type Config struct { *shared.Commons `mapstructure:"shared"` - Mode Mode // DEPRECATED + Mode Mode File string OcisURL string `mapstructure:"ocis_url"` diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index a725b04bf8..10e66ae48c 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -124,10 +124,6 @@ func NewService(options ...Option) (*Service, error) { // Start an rpc service. By default the package scope Start will run all default extensions to provide with a working // oCIS instance. func Start(o ...Option) error { - // Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect - // from the caller, the previous statement holds truth. - - // prepare a new rpc Service struct. s, err := NewService(o...) if err != nil { return err @@ -171,10 +167,7 @@ func Start(o ...Option) error { 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 + propagateLoggingCommonsToStorages(s) if err = rpc.Register(s); err != nil { if s != nil { @@ -188,16 +181,7 @@ func Start(o ...Option) error { s.Log.Fatal().Err(err) } - defer func() { - if r := recover(); r != nil { - reason := strings.Builder{} - if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { - reason.WriteString("runtime address already in use") - } - - fmt.Println(reason.String()) - } - }() + defer gracefulRecovery(s) // prepare the set of services to run s.generateRunSet(s.cfg) @@ -222,6 +206,26 @@ func Start(o ...Option) error { return http.Serve(l, nil) } +func propagateLoggingCommonsToStorages(s *Service) { + 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 +} + +func gracefulRecovery(s *Service) { + func() { + if r := recover(); r != nil { + reason := strings.Builder{} + if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { + reason.WriteString("runtime address already in use") + } + + fmt.Println(reason.String()) + } + }() +} + // scheduleServiceTokens adds service tokens to the service supervisor. func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) { for _, name := range runset { diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 18a20ba1da..1bc71c8e57 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -256,6 +256,10 @@ func DefaultConfig() *Config { } func defaultPolicies() []Policy { + const idpBackend = "http://localhost:9130" + const revaBackend = "http://localhost:9140" + const ingressBackendURL = "https://demo.owncloud.com" + return []Policy{ { Name: "ocis", @@ -266,19 +270,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: RegexRoute, @@ -287,7 +291,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: QueryRoute, @@ -296,31 +300,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/dav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/webdav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/status.php", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/index.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/data", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/app/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/graph/", @@ -335,7 +339,6 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, - // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -359,53 +362,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: revaBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/data", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index b4106f2a8c..05a0204fdc 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,10 +27,12 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } +const contentTypeHeader = "Content-Type" + // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -44,7 +46,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 3087a4897c..a03986edfd 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -518,9 +518,17 @@ func New() *Config { return &Config{} } +const ( + defaultLocalIngressURL = "https://localhost:9200" + defaultSharesFolder = "/Shares" + defaultEOSMasterURL = "root://eos-mgm1.eoscluster.cern.ch:1094" + defaultGatewaySVCAddr = "127.0.0.1:9142" + defaultUserLayout = "{{.Id.OpaqueId}}" +) + func DefaultConfig() *Config { + return &Config{ - // log is inherited Debug: Debug{ Addr: "127.0.0.1:9109", }, @@ -530,7 +538,7 @@ func DefaultConfig() *Config { TransferSecret: "replace-me-with-a-transfer-secret", TransferExpires: 24 * 60 * 60, OIDC: OIDC{ - Issuer: "https://localhost:9200", + Issuer: defaultLocalIngressURL, Insecure: false, IDClaim: "preferred_username", }, @@ -551,7 +559,7 @@ func DefaultConfig() *Config { GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", BindPassword: "reva", - IDP: "https://localhost:9200", + IDP: defaultLocalIngressURL, UserSchema: LDAPUserSchema{ UID: "ownclouduuid", Mail: "mail", @@ -577,7 +585,7 @@ func DefaultConfig() *Config { DBHost: "mysql", DBPort: 3306, DBName: "owncloud", - Idp: "https://localhost:9200", + Idp: defaultLocalIngressURL, Nobody: 90, JoinUsername: false, JoinOwnCloudUUID: false, @@ -596,29 +604,29 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, 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", + MasterURL: defaultEOSMasterURL, + SlaveURL: defaultEOSMasterURL, CacheDirectory: os.TempDir(), - GatewaySVC: "127.0.0.1:9142", + GatewaySVC: defaultGatewaySVCAddr, }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, UserLayout: "{{.Username}}", EnableHome: false, }, OwnCloud: DriverOwnCloud{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", + ShareFolder: defaultSharesFolder, + UserLayout: defaultUserLayout, EnableHome: false, }, UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), @@ -628,7 +636,7 @@ func DefaultConfig() *Config { OwnCloudSQL: DriverOwnCloudSQL{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, UserLayout: "{{.Username}}", EnableHome: false, }, @@ -650,8 +658,8 @@ func DefaultConfig() *Config { S3NG: DriverS3NG{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", + ShareFolder: defaultSharesFolder, + UserLayout: defaultUserLayout, EnableHome: false, }, Region: "default", @@ -663,8 +671,8 @@ func DefaultConfig() *Config { OCIS: DriverOCIS{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", + ShareFolder: defaultSharesFolder, + UserLayout: defaultUserLayout, }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", }, @@ -673,7 +681,7 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", EnableHome: false, }, @@ -681,9 +689,9 @@ func DefaultConfig() *Config { UploadsNamespace: "", EosBinary: "/usr/bin/eos", XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + MasterURL: defaultEOSMasterURL, GrpcURI: "", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: defaultEOSMasterURL, CacheDirectory: os.TempDir(), EnableLogging: false, ShowHiddenSysFiles: false, @@ -692,7 +700,7 @@ func DefaultConfig() *Config { SecProtocol: "", Keytab: "", SingleUsername: "", - GatewaySVC: "127.0.0.1:9142", + GatewaySVC: defaultGatewaySVCAddr, }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), @@ -707,7 +715,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", + UserLayout: defaultUserLayout, EnableHome: false, }, Region: "default", @@ -716,7 +724,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", + UserLayout: defaultUserLayout, EnableHome: false, }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", @@ -747,9 +755,9 @@ func DefaultConfig() *Config { OCDavInsecure: false, OCDavPrefix: "", OCSPrefix: "ocs", - OCSSharePrefix: "/Shares", + OCSSharePrefix: defaultSharesFolder, OCSHomeNamespace: "/home", - PublicURL: "https://localhost:9200", + PublicURL: defaultLocalIngressURL, OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", OCSResourceInfoCacheTTL: 0, @@ -761,10 +769,10 @@ func DefaultConfig() *Config { }, Gateway: Gateway{ Port: Port{ - Endpoint: "127.0.0.1:9142", + Endpoint: defaultGatewaySVCAddr, DebugAddr: "127.0.0.1:9143", GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9142", + GRPCAddr: defaultGatewaySVCAddr, }, CommitShareToStorageGrant: true, CommitShareToStorageRef: true, diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 6227198742..a8677eb169 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,10 +3,6 @@ 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" @@ -25,26 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // 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 - } - } - - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 9859e91cac..194b56366f 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -6,6 +6,8 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) +const defaultIngressURL = "https://localhost:9200" + // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -106,6 +108,7 @@ func New() *Config { } func DefaultConfig() *Config { + return &Config{ Debug: Debug{ Addr: "127.0.0.1:9104", @@ -131,15 +134,15 @@ func DefaultConfig() *Config { }, Web: Web{ Path: "", - ThemeServer: "https://localhost:9200", + ThemeServer: defaultIngressURL, ThemePath: "/themes/owncloud/theme.json", Config: WebConfig{ - Server: "https://localhost:9200", + Server: defaultIngressURL, Theme: "", Version: "0.1.0", OpenIDConnect: OIDC{ MetadataURL: "", - Authority: "https://localhost:9200", + Authority: defaultIngressURL, ClientID: "web", ResponseType: "code", Scope: "openid profile email", From ff611633f597a5dc14ed993cfbe9c29a3eada5de Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 13:19:31 +0100 Subject: [PATCH 126/147] Revert "fixed code smells: string literal repetition + cyclomatic complexity" This reverts commit aa4112e2e24f6875bd928e06317b632ea0d90af3. --- ocis-pkg/config/config.go | 2 +- ocis/pkg/runtime/service/service.go | 40 +++++++++---------- proxy/pkg/config/config.go | 51 ++++++++++++------------ proxy/pkg/server/debug/server.go | 6 +-- storage/pkg/config/config.go | 60 +++++++++++++---------------- store/pkg/command/server.go | 25 +++++++++++- web/pkg/config/config.go | 9 ++--- 7 files changed, 98 insertions(+), 95 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index dbd3774be9..a334797fc3 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -72,7 +72,7 @@ type Runtime struct { type Config struct { *shared.Commons `mapstructure:"shared"` - Mode Mode + Mode Mode // DEPRECATED File string OcisURL string `mapstructure:"ocis_url"` diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 10e66ae48c..a725b04bf8 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -124,6 +124,10 @@ func NewService(options ...Option) (*Service, error) { // Start an rpc service. By default the package scope Start will run all default extensions to provide with a working // oCIS instance. func Start(o ...Option) error { + // Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect + // from the caller, the previous statement holds truth. + + // prepare a new rpc Service struct. s, err := NewService(o...) if err != nil { return err @@ -167,7 +171,10 @@ func Start(o ...Option) error { s.cfg.Storage.Log = &shared.Log{} } - propagateLoggingCommonsToStorages(s) + 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 s != nil { @@ -181,7 +188,16 @@ func Start(o ...Option) error { s.Log.Fatal().Err(err) } - defer gracefulRecovery(s) + defer func() { + if r := recover(); r != nil { + reason := strings.Builder{} + if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { + reason.WriteString("runtime address already in use") + } + + fmt.Println(reason.String()) + } + }() // prepare the set of services to run s.generateRunSet(s.cfg) @@ -206,26 +222,6 @@ func Start(o ...Option) error { return http.Serve(l, nil) } -func propagateLoggingCommonsToStorages(s *Service) { - 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 -} - -func gracefulRecovery(s *Service) { - func() { - if r := recover(); r != nil { - reason := strings.Builder{} - if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { - reason.WriteString("runtime address already in use") - } - - fmt.Println(reason.String()) - } - }() -} - // scheduleServiceTokens adds service tokens to the service supervisor. func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) { for _, name := range runset { diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 1bc71c8e57..18a20ba1da 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -256,10 +256,6 @@ func DefaultConfig() *Config { } func defaultPolicies() []Policy { - const idpBackend = "http://localhost:9130" - const revaBackend = "http://localhost:9140" - const ingressBackendURL = "https://demo.owncloud.com" - return []Policy{ { Name: "ocis", @@ -270,19 +266,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/konnect/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/signin/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/archiver", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Type: RegexRoute, @@ -291,7 +287,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Type: QueryRoute, @@ -300,31 +296,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/dav/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/webdav/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/status.php", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/index.php/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/data", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/app/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/graph/", @@ -339,6 +335,7 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, + // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -362,53 +359,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/konnect/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/signin/", - Backend: revaBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/archiver", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/ocs/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/data", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 05a0204fdc..b4106f2a8c 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,12 +27,10 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } -const contentTypeHeader = "Content-Type" - // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentTypeHeader, "text/plain") + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -46,7 +44,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentTypeHeader, "text/plain") + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index a03986edfd..3087a4897c 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -518,17 +518,9 @@ func New() *Config { return &Config{} } -const ( - defaultLocalIngressURL = "https://localhost:9200" - defaultSharesFolder = "/Shares" - defaultEOSMasterURL = "root://eos-mgm1.eoscluster.cern.ch:1094" - defaultGatewaySVCAddr = "127.0.0.1:9142" - defaultUserLayout = "{{.Id.OpaqueId}}" -) - func DefaultConfig() *Config { - return &Config{ + // log is inherited Debug: Debug{ Addr: "127.0.0.1:9109", }, @@ -538,7 +530,7 @@ func DefaultConfig() *Config { TransferSecret: "replace-me-with-a-transfer-secret", TransferExpires: 24 * 60 * 60, OIDC: OIDC{ - Issuer: defaultLocalIngressURL, + Issuer: "https://localhost:9200", Insecure: false, IDClaim: "preferred_username", }, @@ -559,7 +551,7 @@ func DefaultConfig() *Config { GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", BindPassword: "reva", - IDP: defaultLocalIngressURL, + IDP: "https://localhost:9200", UserSchema: LDAPUserSchema{ UID: "ownclouduuid", Mail: "mail", @@ -585,7 +577,7 @@ func DefaultConfig() *Config { DBHost: "mysql", DBPort: 3306, DBName: "owncloud", - Idp: defaultLocalIngressURL, + Idp: "https://localhost:9200", Nobody: 90, JoinUsername: false, JoinOwnCloudUUID: false, @@ -604,29 +596,29 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: defaultSharesFolder, + 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: defaultEOSMasterURL, - SlaveURL: defaultEOSMasterURL, + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", CacheDirectory: os.TempDir(), - GatewaySVC: defaultGatewaySVCAddr, + GatewaySVC: "127.0.0.1:9142", }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: defaultSharesFolder, + ShareFolder: "/Shares", UserLayout: "{{.Username}}", EnableHome: false, }, OwnCloud: DriverOwnCloud{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: defaultSharesFolder, - UserLayout: defaultUserLayout, + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), @@ -636,7 +628,7 @@ func DefaultConfig() *Config { OwnCloudSQL: DriverOwnCloudSQL{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: defaultSharesFolder, + ShareFolder: "/Shares", UserLayout: "{{.Username}}", EnableHome: false, }, @@ -658,8 +650,8 @@ func DefaultConfig() *Config { S3NG: DriverS3NG{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: defaultSharesFolder, - UserLayout: defaultUserLayout, + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, Region: "default", @@ -671,8 +663,8 @@ func DefaultConfig() *Config { OCIS: DriverOCIS{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: defaultSharesFolder, - UserLayout: defaultUserLayout, + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", }, @@ -681,7 +673,7 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: defaultSharesFolder, + ShareFolder: "/Shares", UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", EnableHome: false, }, @@ -689,9 +681,9 @@ func DefaultConfig() *Config { UploadsNamespace: "", EosBinary: "/usr/bin/eos", XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: defaultEOSMasterURL, + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", GrpcURI: "", - SlaveURL: defaultEOSMasterURL, + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", CacheDirectory: os.TempDir(), EnableLogging: false, ShowHiddenSysFiles: false, @@ -700,7 +692,7 @@ func DefaultConfig() *Config { SecProtocol: "", Keytab: "", SingleUsername: "", - GatewaySVC: defaultGatewaySVCAddr, + GatewaySVC: "127.0.0.1:9142", }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), @@ -715,7 +707,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: defaultUserLayout, + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, Region: "default", @@ -724,7 +716,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: defaultUserLayout, + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", @@ -755,9 +747,9 @@ func DefaultConfig() *Config { OCDavInsecure: false, OCDavPrefix: "", OCSPrefix: "ocs", - OCSSharePrefix: defaultSharesFolder, + OCSSharePrefix: "/Shares", OCSHomeNamespace: "/home", - PublicURL: defaultLocalIngressURL, + PublicURL: "https://localhost:9200", OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", OCSResourceInfoCacheTTL: 0, @@ -769,10 +761,10 @@ func DefaultConfig() *Config { }, Gateway: Gateway{ Port: Port{ - Endpoint: defaultGatewaySVCAddr, + Endpoint: "127.0.0.1:9142", DebugAddr: "127.0.0.1:9143", GRPCNetwork: "tcp", - GRPCAddr: defaultGatewaySVCAddr, + GRPCAddr: "127.0.0.1:9142", }, CommitShareToStorageGrant: true, CommitShareToStorageRef: true, diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index a8677eb169..6227198742 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,6 +3,10 @@ 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" @@ -21,7 +25,26 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 194b56366f..9859e91cac 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -6,8 +6,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) -const defaultIngressURL = "https://localhost:9200" - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -108,7 +106,6 @@ func New() *Config { } func DefaultConfig() *Config { - return &Config{ Debug: Debug{ Addr: "127.0.0.1:9104", @@ -134,15 +131,15 @@ func DefaultConfig() *Config { }, Web: Web{ Path: "", - ThemeServer: defaultIngressURL, + ThemeServer: "https://localhost:9200", ThemePath: "/themes/owncloud/theme.json", Config: WebConfig{ - Server: defaultIngressURL, + Server: "https://localhost:9200", Theme: "", Version: "0.1.0", OpenIDConnect: OIDC{ MetadataURL: "", - Authority: defaultIngressURL, + Authority: "https://localhost:9200", ClientID: "web", ResponseType: "code", Scope: "openid profile email", From f53504158bfc4f967a60886f09b599c6a379fb5d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 13:43:23 +0100 Subject: [PATCH 127/147] refactor config values to constants --- proxy/pkg/config/config.go | 59 +++++++++++++++---------------- proxy/pkg/server/debug/server.go | 6 ++-- storage/pkg/config/config.go | 60 ++++++++++++++++++-------------- store/pkg/command/server.go | 25 +------------ web/pkg/config/config.go | 9 +++-- 5 files changed, 74 insertions(+), 85 deletions(-) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 18a20ba1da..a30d0bb3aa 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -226,7 +226,6 @@ func DefaultConfig() *Config { OIDC: OIDC{ Issuer: "https://localhost:9200", Insecure: true, - //Insecure: true, UserinfoCache: Cache{ Size: 1024, TTL: 10, @@ -247,15 +246,16 @@ func DefaultConfig() *Config { UserOIDCClaim: "email", UserCS3Claim: "mail", MachineAuthAPIKey: "change-me-please", - //AutoprovisionAccounts: false, - //EnableBasicAuth: false, - //InsecureBackends: false, - Context: nil, - Policies: defaultPolicies(), + Context: nil, + Policies: defaultPolicies(), } } func defaultPolicies() []Policy { + const idpBackend = "http://localhost:9130" + const revaBackend = "http://localhost:9140" + const ingressBackendURL = "https://demo.owncloud.com" + return []Policy{ { Name: "ocis", @@ -266,19 +266,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: RegexRoute, @@ -287,7 +287,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Type: QueryRoute, @@ -296,31 +296,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/dav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/webdav/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/status.php", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/index.php/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/data", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/app/", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/graph/", @@ -335,7 +335,6 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, - // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -359,53 +358,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/konnect/", - Backend: "http://localhost:9130", + Backend: idpBackend, }, { Endpoint: "/signin/", - Backend: "http://localhost:9130", + Backend: revaBackend, }, { Endpoint: "/archiver", - Backend: "http://localhost:9140", + Backend: revaBackend, }, { Endpoint: "/ocs/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, { Endpoint: "/data", - Backend: "https://demo.owncloud.com", + Backend: ingressBackendURL, ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index b4106f2a8c..05a0204fdc 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,10 +27,12 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } +const contentTypeHeader = "Content-Type" + // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -44,7 +46,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set(contentTypeHeader, "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 3087a4897c..a03986edfd 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -518,9 +518,17 @@ func New() *Config { return &Config{} } +const ( + defaultLocalIngressURL = "https://localhost:9200" + defaultSharesFolder = "/Shares" + defaultEOSMasterURL = "root://eos-mgm1.eoscluster.cern.ch:1094" + defaultGatewaySVCAddr = "127.0.0.1:9142" + defaultUserLayout = "{{.Id.OpaqueId}}" +) + func DefaultConfig() *Config { + return &Config{ - // log is inherited Debug: Debug{ Addr: "127.0.0.1:9109", }, @@ -530,7 +538,7 @@ func DefaultConfig() *Config { TransferSecret: "replace-me-with-a-transfer-secret", TransferExpires: 24 * 60 * 60, OIDC: OIDC{ - Issuer: "https://localhost:9200", + Issuer: defaultLocalIngressURL, Insecure: false, IDClaim: "preferred_username", }, @@ -551,7 +559,7 @@ func DefaultConfig() *Config { GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", BindPassword: "reva", - IDP: "https://localhost:9200", + IDP: defaultLocalIngressURL, UserSchema: LDAPUserSchema{ UID: "ownclouduuid", Mail: "mail", @@ -577,7 +585,7 @@ func DefaultConfig() *Config { DBHost: "mysql", DBPort: 3306, DBName: "owncloud", - Idp: "https://localhost:9200", + Idp: defaultLocalIngressURL, Nobody: 90, JoinUsername: false, JoinOwnCloudUUID: false, @@ -596,29 +604,29 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, 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", + MasterURL: defaultEOSMasterURL, + SlaveURL: defaultEOSMasterURL, CacheDirectory: os.TempDir(), - GatewaySVC: "127.0.0.1:9142", + GatewaySVC: defaultGatewaySVCAddr, }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, UserLayout: "{{.Username}}", EnableHome: false, }, OwnCloud: DriverOwnCloud{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", + ShareFolder: defaultSharesFolder, + UserLayout: defaultUserLayout, EnableHome: false, }, UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), @@ -628,7 +636,7 @@ func DefaultConfig() *Config { OwnCloudSQL: DriverOwnCloudSQL{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, UserLayout: "{{.Username}}", EnableHome: false, }, @@ -650,8 +658,8 @@ func DefaultConfig() *Config { S3NG: DriverS3NG{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", + ShareFolder: defaultSharesFolder, + UserLayout: defaultUserLayout, EnableHome: false, }, Region: "default", @@ -663,8 +671,8 @@ func DefaultConfig() *Config { OCIS: DriverOCIS{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: "/Shares", - UserLayout: "{{.Id.OpaqueId}}", + ShareFolder: defaultSharesFolder, + UserLayout: defaultUserLayout, }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", }, @@ -673,7 +681,7 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: "/Shares", + ShareFolder: defaultSharesFolder, UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", EnableHome: false, }, @@ -681,9 +689,9 @@ func DefaultConfig() *Config { UploadsNamespace: "", EosBinary: "/usr/bin/eos", XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + MasterURL: defaultEOSMasterURL, GrpcURI: "", - SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: defaultEOSMasterURL, CacheDirectory: os.TempDir(), EnableLogging: false, ShowHiddenSysFiles: false, @@ -692,7 +700,7 @@ func DefaultConfig() *Config { SecProtocol: "", Keytab: "", SingleUsername: "", - GatewaySVC: "127.0.0.1:9142", + GatewaySVC: defaultGatewaySVCAddr, }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), @@ -707,7 +715,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", + UserLayout: defaultUserLayout, EnableHome: false, }, Region: "default", @@ -716,7 +724,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: "{{.Id.OpaqueId}}", + UserLayout: defaultUserLayout, EnableHome: false, }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", @@ -747,9 +755,9 @@ func DefaultConfig() *Config { OCDavInsecure: false, OCDavPrefix: "", OCSPrefix: "ocs", - OCSSharePrefix: "/Shares", + OCSSharePrefix: defaultSharesFolder, OCSHomeNamespace: "/home", - PublicURL: "https://localhost:9200", + PublicURL: defaultLocalIngressURL, OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", OCSResourceInfoCacheTTL: 0, @@ -761,10 +769,10 @@ func DefaultConfig() *Config { }, Gateway: Gateway{ Port: Port{ - Endpoint: "127.0.0.1:9142", + Endpoint: defaultGatewaySVCAddr, DebugAddr: "127.0.0.1:9143", GRPCNetwork: "tcp", - GRPCAddr: "127.0.0.1:9142", + GRPCAddr: defaultGatewaySVCAddr, }, CommitShareToStorageGrant: true, CommitShareToStorageRef: true, diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 6227198742..a8677eb169 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,10 +3,6 @@ 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" @@ -25,26 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // 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 - } - } - - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 9859e91cac..194b56366f 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -6,6 +6,8 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) +const defaultIngressURL = "https://localhost:9200" + // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -106,6 +108,7 @@ func New() *Config { } func DefaultConfig() *Config { + return &Config{ Debug: Debug{ Addr: "127.0.0.1:9104", @@ -131,15 +134,15 @@ func DefaultConfig() *Config { }, Web: Web{ Path: "", - ThemeServer: "https://localhost:9200", + ThemeServer: defaultIngressURL, ThemePath: "/themes/owncloud/theme.json", Config: WebConfig{ - Server: "https://localhost:9200", + Server: defaultIngressURL, Theme: "", Version: "0.1.0", OpenIDConnect: OIDC{ MetadataURL: "", - Authority: "https://localhost:9200", + Authority: defaultIngressURL, ClientID: "web", ResponseType: "code", Scope: "openid profile email", From a34f5b6434c219f81076ceb7a483ae2b931f3fcf Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 13:56:14 +0100 Subject: [PATCH 128/147] Revert "refactor config values to constants" This reverts commit f53504158bfc4f967a60886f09b599c6a379fb5d. --- proxy/pkg/config/config.go | 59 ++++++++++++++++--------------- proxy/pkg/server/debug/server.go | 6 ++-- storage/pkg/config/config.go | 60 ++++++++++++++------------------ store/pkg/command/server.go | 25 ++++++++++++- web/pkg/config/config.go | 9 ++--- 5 files changed, 85 insertions(+), 74 deletions(-) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index a30d0bb3aa..18a20ba1da 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -226,6 +226,7 @@ func DefaultConfig() *Config { OIDC: OIDC{ Issuer: "https://localhost:9200", Insecure: true, + //Insecure: true, UserinfoCache: Cache{ Size: 1024, TTL: 10, @@ -246,16 +247,15 @@ func DefaultConfig() *Config { UserOIDCClaim: "email", UserCS3Claim: "mail", MachineAuthAPIKey: "change-me-please", - Context: nil, - Policies: defaultPolicies(), + //AutoprovisionAccounts: false, + //EnableBasicAuth: false, + //InsecureBackends: false, + Context: nil, + Policies: defaultPolicies(), } } func defaultPolicies() []Policy { - const idpBackend = "http://localhost:9130" - const revaBackend = "http://localhost:9140" - const ingressBackendURL = "https://demo.owncloud.com" - return []Policy{ { Name: "ocis", @@ -266,19 +266,19 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/konnect/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/signin/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/archiver", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Type: RegexRoute, @@ -287,7 +287,7 @@ func defaultPolicies() []Policy { }, { Endpoint: "/ocs/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Type: QueryRoute, @@ -296,31 +296,31 @@ func defaultPolicies() []Policy { }, { Endpoint: "/remote.php/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/dav/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/webdav/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/status.php", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/index.php/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/data", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/app/", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/graph/", @@ -335,6 +335,7 @@ func defaultPolicies() []Policy { Endpoint: "/api/v0/accounts", Backend: "http://localhost:9181", }, + // TODO the lookup needs a better mechanism { Endpoint: "/accounts.js", Backend: "http://localhost:9181", @@ -358,53 +359,53 @@ func defaultPolicies() []Policy { }, { Endpoint: "/.well-known/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/konnect/", - Backend: idpBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/signin/", - Backend: revaBackend, + Backend: "http://localhost:9130", }, { Endpoint: "/archiver", - Backend: revaBackend, + Backend: "http://localhost:9140", }, { Endpoint: "/ocs/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/remote.php/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/dav/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/webdav/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/status.php", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/index.php/", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, { Endpoint: "/data", - Backend: ingressBackendURL, + Backend: "https://demo.owncloud.com", ApacheVHost: true, }, }, diff --git a/proxy/pkg/server/debug/server.go b/proxy/pkg/server/debug/server.go index 05a0204fdc..b4106f2a8c 100644 --- a/proxy/pkg/server/debug/server.go +++ b/proxy/pkg/server/debug/server.go @@ -27,12 +27,10 @@ func Server(opts ...Option) (*http.Server, error) { ), nil } -const contentTypeHeader = "Content-Type" - // health implements the health check. func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentTypeHeader, "text/plain") + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running @@ -46,7 +44,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // ready implements the ready check. func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set(contentTypeHeader, "text/plain") + w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) // TODO(tboerger): check if services are up and running diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index a03986edfd..3087a4897c 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -518,17 +518,9 @@ func New() *Config { return &Config{} } -const ( - defaultLocalIngressURL = "https://localhost:9200" - defaultSharesFolder = "/Shares" - defaultEOSMasterURL = "root://eos-mgm1.eoscluster.cern.ch:1094" - defaultGatewaySVCAddr = "127.0.0.1:9142" - defaultUserLayout = "{{.Id.OpaqueId}}" -) - func DefaultConfig() *Config { - return &Config{ + // log is inherited Debug: Debug{ Addr: "127.0.0.1:9109", }, @@ -538,7 +530,7 @@ func DefaultConfig() *Config { TransferSecret: "replace-me-with-a-transfer-secret", TransferExpires: 24 * 60 * 60, OIDC: OIDC{ - Issuer: defaultLocalIngressURL, + Issuer: "https://localhost:9200", Insecure: false, IDClaim: "preferred_username", }, @@ -559,7 +551,7 @@ func DefaultConfig() *Config { GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))", BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test", BindPassword: "reva", - IDP: defaultLocalIngressURL, + IDP: "https://localhost:9200", UserSchema: LDAPUserSchema{ UID: "ownclouduuid", Mail: "mail", @@ -585,7 +577,7 @@ func DefaultConfig() *Config { DBHost: "mysql", DBPort: 3306, DBName: "owncloud", - Idp: defaultLocalIngressURL, + Idp: "https://localhost:9200", Nobody: 90, JoinUsername: false, JoinOwnCloudUUID: false, @@ -604,29 +596,29 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: defaultSharesFolder, + 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: defaultEOSMasterURL, - SlaveURL: defaultEOSMasterURL, + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", CacheDirectory: os.TempDir(), - GatewaySVC: defaultGatewaySVCAddr, + GatewaySVC: "127.0.0.1:9142", }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"), - ShareFolder: defaultSharesFolder, + ShareFolder: "/Shares", UserLayout: "{{.Username}}", EnableHome: false, }, OwnCloud: DriverOwnCloud{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: defaultSharesFolder, - UserLayout: defaultUserLayout, + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"), @@ -636,7 +628,7 @@ func DefaultConfig() *Config { OwnCloudSQL: DriverOwnCloudSQL{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"), - ShareFolder: defaultSharesFolder, + ShareFolder: "/Shares", UserLayout: "{{.Username}}", EnableHome: false, }, @@ -658,8 +650,8 @@ func DefaultConfig() *Config { S3NG: DriverS3NG{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: defaultSharesFolder, - UserLayout: defaultUserLayout, + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, Region: "default", @@ -671,8 +663,8 @@ func DefaultConfig() *Config { OCIS: DriverOCIS{ DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "users"), - ShareFolder: defaultSharesFolder, - UserLayout: defaultUserLayout, + ShareFolder: "/Shares", + UserLayout: "{{.Id.OpaqueId}}", }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", }, @@ -681,7 +673,7 @@ func DefaultConfig() *Config { EOS: DriverEOS{ DriverCommon: DriverCommon{ Root: "/eos/dockertest/reva", - ShareFolder: defaultSharesFolder, + ShareFolder: "/Shares", UserLayout: "{{substr 0 1 .Username}}/{{.Username}}", EnableHome: false, }, @@ -689,9 +681,9 @@ func DefaultConfig() *Config { UploadsNamespace: "", EosBinary: "/usr/bin/eos", XrdcopyBinary: "/usr/bin/xrdcopy", - MasterURL: defaultEOSMasterURL, + MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094", GrpcURI: "", - SlaveURL: defaultEOSMasterURL, + SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094", CacheDirectory: os.TempDir(), EnableLogging: false, ShowHiddenSysFiles: false, @@ -700,7 +692,7 @@ func DefaultConfig() *Config { SecProtocol: "", Keytab: "", SingleUsername: "", - GatewaySVC: defaultGatewaySVCAddr, + GatewaySVC: "127.0.0.1:9142", }, Local: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"), @@ -715,7 +707,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: defaultUserLayout, + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, Region: "default", @@ -724,7 +716,7 @@ func DefaultConfig() *Config { DriverCommon: DriverCommon{ Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"), ShareFolder: "", - UserLayout: defaultUserLayout, + UserLayout: "{{.Id.OpaqueId}}", EnableHome: false, }, ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad", @@ -755,9 +747,9 @@ func DefaultConfig() *Config { OCDavInsecure: false, OCDavPrefix: "", OCSPrefix: "ocs", - OCSSharePrefix: defaultSharesFolder, + OCSSharePrefix: "/Shares", OCSHomeNamespace: "/home", - PublicURL: defaultLocalIngressURL, + PublicURL: "https://localhost:9200", OCSCacheWarmupDriver: "", OCSAdditionalInfoAttribute: "{{.Mail}}", OCSResourceInfoCacheTTL: 0, @@ -769,10 +761,10 @@ func DefaultConfig() *Config { }, Gateway: Gateway{ Port: Port{ - Endpoint: defaultGatewaySVCAddr, + Endpoint: "127.0.0.1:9142", DebugAddr: "127.0.0.1:9143", GRPCNetwork: "tcp", - GRPCAddr: defaultGatewaySVCAddr, + GRPCAddr: "127.0.0.1:9142", }, CommitShareToStorageGrant: true, CommitShareToStorageRef: true, diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index a8677eb169..6227198742 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,6 +3,10 @@ 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" @@ -21,7 +25,26 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 194b56366f..9859e91cac 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -6,8 +6,6 @@ import ( "github.com/owncloud/ocis/ocis-pkg/shared" ) -const defaultIngressURL = "https://localhost:9200" - // Debug defines the available debug configuration. type Debug struct { Addr string `mapstructure:"addr"` @@ -108,7 +106,6 @@ func New() *Config { } func DefaultConfig() *Config { - return &Config{ Debug: Debug{ Addr: "127.0.0.1:9104", @@ -134,15 +131,15 @@ func DefaultConfig() *Config { }, Web: Web{ Path: "", - ThemeServer: defaultIngressURL, + ThemeServer: "https://localhost:9200", ThemePath: "/themes/owncloud/theme.json", Config: WebConfig{ - Server: defaultIngressURL, + Server: "https://localhost:9200", Theme: "", Version: "0.1.0", OpenIDConnect: OIDC{ MetadataURL: "", - Authority: defaultIngressURL, + Authority: "https://localhost:9200", ClientID: "web", ResponseType: "code", Scope: "openid profile email", From 592a91053b97344377f1d09215c352d1e016c028 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 16:41:51 +0100 Subject: [PATCH 129/147] restore flags for some account commands --- accounts/pkg/command/add_account.go | 4 - accounts/pkg/command/inspect_account.go | 6 +- accounts/pkg/command/list_accounts.go | 6 +- accounts/pkg/command/remove_account.go | 3 + accounts/pkg/command/update_account.go | 5 +- accounts/pkg/flagset/flagset.go | 104 ++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 12 deletions(-) diff --git a/accounts/pkg/command/add_account.go b/accounts/pkg/command/add_account.go index 386cb48648..4003c46eed 100644 --- a/accounts/pkg/command/add_account.go +++ b/accounts/pkg/command/add_account.go @@ -21,10 +21,6 @@ func AddAccount(cfg *config.Config) *cli.Command { Aliases: []string{"create", "a"}, Flags: flagset.AddAccountWithConfig(cfg, a), Before: func(c *cli.Context) error { - if err := ParseConfig(c, cfg); err != nil { - return err - } - // Write value of username to the flags beneath, as preferred name // and on-premises-sam-account-name is probably confusing for users. if username := c.String("username"); username != "" { diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index ece3932d5e..baa3cb4b10 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -5,6 +5,8 @@ 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" @@ -18,9 +20,7 @@ func InspectAccount(cfg *config.Config) *cli.Command { Name: "inspect", Usage: "Show detailed data on an existing account", ArgsUsage: "id", - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, + Flags: flagset.Root(cfg), Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index fedac44c47..de352367f6 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -5,6 +5,8 @@ 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" @@ -18,9 +20,7 @@ func ListAccounts(cfg *config.Config) *cli.Command { Name: "list", Usage: "List existing accounts", Aliases: []string{"ls"}, - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, + Flags: flagset.Root(cfg), Action: func(c *cli.Context) error { accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index 88a18110cf..884244ed69 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -4,6 +4,8 @@ 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" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" @@ -17,6 +19,7 @@ func RemoveAccount(cfg *config.Config) *cli.Command { Usage: "Removes an existing account", ArgsUsage: "id", Aliases: []string{"rm"}, + Flags: flagset.Root(cfg), Before: func(c *cli.Context) error { return ParseConfig(c, cfg) }, diff --git a/accounts/pkg/command/update_account.go b/accounts/pkg/command/update_account.go index b3ed17f105..71f8c2c661 100644 --- a/accounts/pkg/command/update_account.go +++ b/accounts/pkg/command/update_account.go @@ -4,6 +4,8 @@ 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" accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0" @@ -20,10 +22,9 @@ func UpdateAccount(cfg *config.Config) *cli.Command { Name: "update", Usage: "Make changes to an existing account", ArgsUsage: "id", - //Flags: flagset.UpdateAccountWithConfig(cfg, a), + 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/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index c633f11164..69b33a957c 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -94,3 +94,107 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { }, } } + +// UpdateAccountWithConfig applies update command flags to cfg +func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { + if a.PasswordProfile == nil { + a.PasswordProfile = &accounts.PasswordProfile{} + } + + 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{"ACCOUNTS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + &cli.StringFlag{ + Name: "name", + Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Usage: "service name", + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + &cli.BoolFlag{ + Name: "enabled", + Usage: "Enable the account", + Destination: &a.AccountEnabled, + }, + &cli.StringFlag{ + Name: "displayname", + Usage: "Set the displayname for the account", + Destination: &a.DisplayName, + }, + &cli.StringFlag{ + Name: "preferred-name", + Usage: "Set the preferred-name for the account", + Destination: &a.PreferredName, + }, + &cli.StringFlag{ + Name: "on-premises-sam-account-name", + Usage: "Set the on-premises-sam-account-name", + Destination: &a.OnPremisesSamAccountName, + }, + &cli.Int64Flag{ + Name: "uidnumber", + Usage: "Set the uidnumber for the account", + Destination: &a.UidNumber, + }, + &cli.Int64Flag{ + Name: "gidnumber", + Usage: "Set the gidnumber for the account", + Destination: &a.GidNumber, + }, + &cli.StringFlag{ + Name: "mail", + Usage: "Set the mail for the account", + Destination: &a.Mail, + }, + &cli.StringFlag{ + Name: "description", + Usage: "Set the description for the account", + Destination: &a.Description, + }, + &cli.StringFlag{ + Name: "password", + Usage: "Set the password for the account", + Destination: &a.PasswordProfile.Password, + // TODO read password from ENV? + }, + &cli.StringSliceFlag{ + Name: "password-policies", + Usage: "Possible policies: DisableStrongPassword, DisablePasswordExpiration", + }, + &cli.BoolFlag{ + Name: "force-password-change", + Usage: "Force password change on next sign-in", + Destination: &a.PasswordProfile.ForceChangePasswordNextSignIn, + }, + &cli.BoolFlag{ + Name: "force-password-change-mfa", + Usage: "Force password change on next sign-in with mfa", + Destination: &a.PasswordProfile.ForceChangePasswordNextSignInWithMfa, + }, + } +} + +// Root applies remove command flags to cfg +func Root(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{"ACCOUNTS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + &cli.StringFlag{ + Name: "name", + Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Usage: "service name", + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + } +} From 1d127c8ab21ad50e35aea2cea87008b1a47a3df1 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 16:43:02 +0100 Subject: [PATCH 130/147] remove dead code from store regarding common propagation --- store/pkg/command/server.go | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index 6227198742..a8677eb169 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,10 +3,6 @@ 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" @@ -25,26 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - // 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 - } - } - - return nil + return ParseConfig(ctx, cfg) }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From 872cd807e710af4b8fe09af861aef4674a312614 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 17:07:25 +0100 Subject: [PATCH 131/147] Revert "remove dead code from store regarding common propagation" This reverts commit 1d127c8ab21ad50e35aea2cea87008b1a47a3df1. --- store/pkg/command/server.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/store/pkg/command/server.go b/store/pkg/command/server.go index a8677eb169..6227198742 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -3,6 +3,10 @@ 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" @@ -21,7 +25,26 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "Start integrated server", Before: func(ctx *cli.Context) error { - 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 + } + } + + return nil }, Action: func(c *cli.Context) error { logger := NewLogger(cfg) From ad4fb0e0f9a30d552deed525c0123c42fae3f4b5 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 19:37:15 +0100 Subject: [PATCH 132/147] attempt to revert to the old status. Just triggering a CI run --- accounts/pkg/command/inspect_account.go | 2 +- accounts/pkg/command/list_accounts.go | 2 +- accounts/pkg/command/remove_account.go | 5 +- accounts/pkg/command/version.go | 3 - accounts/pkg/flagset/flagset.go | 212 ++++++++++++++---------- 5 files changed, 129 insertions(+), 95 deletions(-) diff --git a/accounts/pkg/command/inspect_account.go b/accounts/pkg/command/inspect_account.go index baa3cb4b10..1ea262c31d 100644 --- a/accounts/pkg/command/inspect_account.go +++ b/accounts/pkg/command/inspect_account.go @@ -20,7 +20,7 @@ func InspectAccount(cfg *config.Config) *cli.Command { Name: "inspect", Usage: "Show detailed data on an existing account", ArgsUsage: "id", - Flags: flagset.Root(cfg), + Flags: flagset.InspectAccountWithConfig(cfg), Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/list_accounts.go b/accounts/pkg/command/list_accounts.go index de352367f6..87727b5762 100644 --- a/accounts/pkg/command/list_accounts.go +++ b/accounts/pkg/command/list_accounts.go @@ -20,7 +20,7 @@ func ListAccounts(cfg *config.Config) *cli.Command { Name: "list", Usage: "List existing accounts", Aliases: []string{"ls"}, - Flags: flagset.Root(cfg), + Flags: flagset.ListAccountsWithConfig(cfg), Action: func(c *cli.Context) error { accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient()) diff --git a/accounts/pkg/command/remove_account.go b/accounts/pkg/command/remove_account.go index 884244ed69..dfb723db9c 100644 --- a/accounts/pkg/command/remove_account.go +++ b/accounts/pkg/command/remove_account.go @@ -19,10 +19,7 @@ func RemoveAccount(cfg *config.Config) *cli.Command { Usage: "Removes an existing account", ArgsUsage: "id", Aliases: []string{"rm"}, - Flags: flagset.Root(cfg), - Before: func(c *cli.Context) error { - return ParseConfig(c, cfg) - }, + Flags: flagset.RemoveAccountWithConfig(cfg), Action: func(c *cli.Context) error { accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name if c.NArg() != 1 { diff --git a/accounts/pkg/command/version.go b/accounts/pkg/command/version.go index 66867b6552..e61530d16b 100644 --- a/accounts/pkg/command/version.go +++ b/accounts/pkg/command/version.go @@ -16,9 +16,6 @@ func PrintVersion(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "version", Usage: "Print the versions of the running instances", - 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.Server.Name) diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 69b33a957c..3815f0784a 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -7,6 +7,90 @@ import ( "github.com/urfave/cli/v2" ) +// UpdateAccountWithConfig applies update command flags to cfg +func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { + if a.PasswordProfile == nil { + a.PasswordProfile = &accounts.PasswordProfile{} + } + + 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{"ACCOUNTS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + &cli.StringFlag{ + Name: "name", + Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Usage: "service name", + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + &cli.BoolFlag{ + Name: "enabled", + Usage: "Enable the account", + Destination: &a.AccountEnabled, + }, + &cli.StringFlag{ + Name: "displayname", + Usage: "Set the displayname for the account", + Destination: &a.DisplayName, + }, + &cli.StringFlag{ + Name: "preferred-name", + Usage: "Set the preferred-name for the account", + Destination: &a.PreferredName, + }, + &cli.StringFlag{ + Name: "on-premises-sam-account-name", + Usage: "Set the on-premises-sam-account-name", + Destination: &a.OnPremisesSamAccountName, + }, + &cli.Int64Flag{ + Name: "uidnumber", + Usage: "Set the uidnumber for the account", + Destination: &a.UidNumber, + }, + &cli.Int64Flag{ + Name: "gidnumber", + Usage: "Set the gidnumber for the account", + Destination: &a.GidNumber, + }, + &cli.StringFlag{ + Name: "mail", + Usage: "Set the mail for the account", + Destination: &a.Mail, + }, + &cli.StringFlag{ + Name: "description", + Usage: "Set the description for the account", + Destination: &a.Description, + }, + &cli.StringFlag{ + Name: "password", + Usage: "Set the password for the account", + Destination: &a.PasswordProfile.Password, + // TODO read password from ENV? + }, + &cli.StringSliceFlag{ + Name: "password-policies", + Usage: "Possible policies: DisableStrongPassword, DisablePasswordExpiration", + }, + &cli.BoolFlag{ + Name: "force-password-change", + Usage: "Force password change on next sign-in", + Destination: &a.PasswordProfile.ForceChangePasswordNextSignIn, + }, + &cli.BoolFlag{ + Name: "force-password-change-mfa", + Usage: "Force password change on next sign-in with mfa", + Destination: &a.PasswordProfile.ForceChangePasswordNextSignInWithMfa, + }, + } +} + // AddAccountWithConfig applies create command flags to cfg func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { if a.PasswordProfile == nil { @@ -95,92 +179,48 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { } } -// UpdateAccountWithConfig applies update command flags to cfg -func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag { - if a.PasswordProfile == nil { - a.PasswordProfile = &accounts.PasswordProfile{} - } - - 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{"ACCOUNTS_GRPC_NAMESPACE"}, - Destination: &cfg.GRPC.Namespace, - }, - &cli.StringFlag{ - Name: "name", - Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), - Usage: "service name", - EnvVars: []string{"ACCOUNTS_NAME"}, - Destination: &cfg.Server.Name, - }, - &cli.BoolFlag{ - Name: "enabled", - Usage: "Enable the account", - Destination: &a.AccountEnabled, - }, - &cli.StringFlag{ - Name: "displayname", - Usage: "Set the displayname for the account", - Destination: &a.DisplayName, - }, - &cli.StringFlag{ - Name: "preferred-name", - Usage: "Set the preferred-name for the account", - Destination: &a.PreferredName, - }, - &cli.StringFlag{ - Name: "on-premises-sam-account-name", - Usage: "Set the on-premises-sam-account-name", - Destination: &a.OnPremisesSamAccountName, - }, - &cli.Int64Flag{ - Name: "uidnumber", - Usage: "Set the uidnumber for the account", - Destination: &a.UidNumber, - }, - &cli.Int64Flag{ - Name: "gidnumber", - Usage: "Set the gidnumber for the account", - Destination: &a.GidNumber, - }, - &cli.StringFlag{ - Name: "mail", - Usage: "Set the mail for the account", - Destination: &a.Mail, - }, - &cli.StringFlag{ - Name: "description", - Usage: "Set the description for the account", - Destination: &a.Description, - }, - &cli.StringFlag{ - Name: "password", - Usage: "Set the password for the account", - Destination: &a.PasswordProfile.Password, - // TODO read password from ENV? - }, - &cli.StringSliceFlag{ - Name: "password-policies", - Usage: "Possible policies: DisableStrongPassword, DisablePasswordExpiration", - }, - &cli.BoolFlag{ - Name: "force-password-change", - Usage: "Force password change on next sign-in", - Destination: &a.PasswordProfile.ForceChangePasswordNextSignIn, - }, - &cli.BoolFlag{ - Name: "force-password-change-mfa", - Usage: "Force password change on next sign-in with mfa", - Destination: &a.PasswordProfile.ForceChangePasswordNextSignInWithMfa, - }, - } -} - -// Root applies remove command flags to cfg -func Root(cfg *config.Config) []cli.Flag { +// ListAccountsWithConfig applies list command flags to cfg +func ListAccountsWithConfig(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{"ACCOUNTS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + &cli.StringFlag{ + Name: "name", + Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Usage: "service name", + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + } +} + +// RemoveAccountWithConfig applies remove command flags to cfg +func RemoveAccountWithConfig(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{"ACCOUNTS_GRPC_NAMESPACE"}, + Destination: &cfg.GRPC.Namespace, + }, + &cli.StringFlag{ + Name: "name", + Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"), + Usage: "service name", + EnvVars: []string{"ACCOUNTS_NAME"}, + Destination: &cfg.Server.Name, + }, + } +} + +// InspectAccountWithConfig applies inspect command flags to cfg +func InspectAccountWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "grpc-namespace", From fe61ad4154f18996764f6b6cc07b95fe745b7c1a Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Wed, 17 Nov 2021 23:08:04 +0100 Subject: [PATCH 133/147] reordered env var priorities --- storage/pkg/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 3087a4897c..111ffa6b51 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -1185,7 +1185,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { Destination: &cfg.Reva.AuthMachine.DebugAddr, }, { - EnvVars: []string{"STORAGE_AUTH_MACHINE_AUTH_API_KEY", "OCIS_MACHINE_AUTH_API_KEY"}, + EnvVars: []string{"OCIS_MACHINE_AUTH_API_KEY", "STORAGE_AUTH_MACHINE_AUTH_API_KEY"}, Destination: &cfg.Reva.AuthMachineConfig.MachineAuthAPIKey, }, { @@ -1610,7 +1610,7 @@ func structMappings(cfg *Config) []shared.EnvBinding { // secret { - EnvVars: []string{"STORAGE_JWT_SECRET", "OCIS_JWT_SECRET"}, + EnvVars: []string{"OCIS_JWT_SECRET", "STORAGE_JWT_SECRET"}, Destination: &cfg.Reva.JWTSecret, }, { From c22d3fc24d42d3b0374f81bdc7717bae23e8e5d8 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 18 Nov 2021 11:44:08 +0100 Subject: [PATCH 134/147] prevent gookit/config to merge proxy values with default values --- go.mod | 10 ++-------- go.sum | 33 --------------------------------- ocis-pkg/config/helpers.go | 2 ++ proxy/pkg/command/server.go | 4 ++++ proxy/pkg/config/config.go | 6 +++--- 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index 2800573234..1ce4594b4e 100644 --- a/go.mod +++ b/go.mod @@ -52,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 @@ -76,6 +75,7 @@ require ( ) 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 @@ -139,6 +139,7 @@ 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 @@ -149,7 +150,6 @@ require ( 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 @@ -163,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 @@ -192,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 @@ -216,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 diff --git a/go.sum b/go.sum index 8d316d5340..d0fbdefc60 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= @@ -130,7 +129,6 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC 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= @@ -655,7 +653,6 @@ 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= @@ -692,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= @@ -706,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= @@ -721,17 +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= @@ -817,7 +805,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= @@ -848,7 +835,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= @@ -867,7 +853,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= @@ -915,7 +900,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= @@ -1039,8 +1023,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= @@ -1054,7 +1036,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= @@ -1147,7 +1128,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= @@ -1188,12 +1168,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= @@ -1202,7 +1179,6 @@ 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= @@ -1214,8 +1190,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= @@ -1232,7 +1206,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= @@ -1406,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= @@ -1598,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= @@ -1648,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= @@ -1791,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= @@ -1856,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/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 6acb6654f7..645123f3bb 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -7,6 +7,7 @@ import ( "strings" gofig "github.com/gookit/config/v2" + goojson "github.com/gookit/config/v2/json" gooyaml "github.com/gookit/config/v2/yaml" ) @@ -69,6 +70,7 @@ func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, err sources := DefaultConfigSources(extension, supportedExtensions) cnf := gofig.NewWithOptions(extension, gofig.ParseEnv) cnf.AddDriver(gooyaml.Driver) + cnf.AddDriver(goojson.Driver) _ = cnf.LoadFiles(sources...) err := cnf.BindStruct("", &dst) diff --git a/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index 07a08baef8..fbc26bc39d 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -44,6 +44,10 @@ func Server(cfg *config.Config) *cli.Command { return err } + if cfg.Policies == nil { + cfg.Policies = config.DefaultPolicies() + } + if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 18a20ba1da..77895c819b 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -250,12 +250,12 @@ func DefaultConfig() *Config { //AutoprovisionAccounts: false, //EnableBasicAuth: false, //InsecureBackends: false, - Context: nil, - Policies: defaultPolicies(), + Context: nil, + //Policies: defaultPolicies(), } } -func defaultPolicies() []Policy { +func DefaultPolicies() []Policy { return []Policy{ { Name: "ocis", From c427e623efe926745018685425c0994d825dde44 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 18 Nov 2021 11:53:04 +0100 Subject: [PATCH 135/147] need to populate policies in the tests --- proxy/pkg/proxy/proxy_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proxy/pkg/proxy/proxy_test.go b/proxy/pkg/proxy/proxy_test.go index c0b584d6dc..a0300e64d1 100644 --- a/proxy/pkg/proxy/proxy_test.go +++ b/proxy/pkg/proxy/proxy_test.go @@ -14,6 +14,7 @@ type matchertest struct { func TestPrefixRouteMatcher(t *testing.T) { cfg := config.DefaultConfig() + cfg.Policies = config.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -33,6 +34,7 @@ func TestPrefixRouteMatcher(t *testing.T) { func TestQueryRouteMatcher(t *testing.T) { cfg := config.DefaultConfig() + cfg.Policies = config.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ @@ -60,6 +62,7 @@ func TestQueryRouteMatcher(t *testing.T) { func TestRegexRouteMatcher(t *testing.T) { cfg := config.DefaultConfig() + cfg.Policies = config.DefaultPolicies() p := NewMultiHostReverseProxy(Config(cfg)) table := []matchertest{ From 24347180faaf56b318e5969f4af9f74a02f6e9fd Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 19 Nov 2021 09:28:23 +0100 Subject: [PATCH 136/147] use ocisConfig as struct tagname to bind config files to strucg attributes --- accounts/pkg/config/config.go | 128 +++---- glauth/pkg/config/config.go | 74 ++-- graph-explorer/pkg/config/config.go | 50 +-- graph/pkg/config/config.go | 56 ++-- idp/pkg/config/config.go | 138 ++++---- ocis-pkg/config/config.go | 78 ++--- ocis-pkg/config/helpers.go | 3 + ocs/pkg/config/config.go | 68 ++-- proxy/pkg/config/config.go | 152 ++++----- settings/pkg/config/config.go | 68 ++-- storage/pkg/config/config.go | 504 ++++++++++++++-------------- store/pkg/config/config.go | 42 +-- thumbnails/pkg/config/config.go | 54 +-- web/pkg/config/config.go | 82 ++--- webdav/pkg/config/config.go | 54 +-- 15 files changed, 777 insertions(+), 774 deletions(-) diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 12e72d670c..4ae123db68 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -12,132 +12,132 @@ import ( // LDAP defines the available ldap configuration. type LDAP struct { - Hostname string `mapstructure:"hostname"` - Port int `mapstructure:"port"` - BaseDN string `mapstructure:"base_dn"` - UserFilter string `mapstructure:"user_filter"` - GroupFilter string `mapstructure:"group_filter"` - BindDN string `mapstructure:"bind_dn"` - BindPassword string `mapstructure:"bind_password"` - IDP string `mapstructure:"idp"` - Schema LDAPSchema `mapstructure:"schema"` + 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 `mapstructure:"account_id"` - Identities string `mapstructure:"identities"` - Username string `mapstructure:"username"` - DisplayName string `mapstructure:"display_name"` - Mail string `mapstructure:"mail"` - Groups string `mapstructure:"groups"` + 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 `mapstructure:"allowed_origins"` - AllowedMethods []string `mapstructure:"allowed_methods"` - AllowedHeaders []string `mapstructure:"allowed_headers"` - AllowCredentials bool `mapstructure:"allowed_credentials"` + 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 `mapstructure:"addr"` - Namespace string `mapstructure:"namespace"` - Root string `mapstructure:"root"` - CacheTTL int `mapstructure:"cache_ttl"` - CORS CORS `mapstructure:"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 `mapstructure:"addr"` - Namespace string `mapstructure:"namespace"` + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` } // Server configures a server. type Server struct { - Version string `mapstructure:"version"` - Name string `mapstructure:"name"` - HashDifficulty int `mapstructure:"hash_difficulty"` - DemoUsersAndGroups bool `mapstructure:"demo_users_and_groups"` + 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 `mapstructure:"path"` + Path string `ocisConfig:"path"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `mapstructure:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret"` } // Repo defines which storage implementation is to be used. type Repo struct { - Backend string `mapstructure:"backend"` - Disk Disk `mapstructure:"disk"` - CS3 CS3 `mapstructure:"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 `mapstructure:"path"` + Path string `ocisConfig:"path"` } // CS3 is the cs3 implementation of the storage. type CS3 struct { - ProviderAddr string `mapstructure:"provider_addr"` - DataURL string `mapstructure:"data_url"` - DataPrefix string `mapstructure:"data_prefix"` - JWTSecret string `mapstructure:"jwt_secret"` + 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 `mapstructure:"uuid"` - Username string `mapstructure:"username"` - UID int64 `mapstructure:"uid"` - GID int64 `mapstructure:"gid"` + 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 Bound `mapstructure:"uid"` - GID Bound `mapstructure:"gid"` + UID Bound `ocisConfig:"uid"` + GID Bound `ocisConfig:"gid"` } // Bound defines a lower and upper bound. type Bound struct { - Lower int64 `mapstructure:"lower"` - Upper int64 `mapstructure:"upper"` + Lower int64 `ocisConfig:"lower"` + Upper int64 `ocisConfig:"upper"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 { *shared.Commons - LDAP LDAP `mapstructure:"ldap"` - HTTP HTTP `mapstructure:"http"` - GRPC GRPC `mapstructure:"grpc"` - Server Server `mapstructure:"server"` - Asset Asset `mapstructure:"asset"` - Log *shared.Log `mapstructure:"log"` - TokenManager TokenManager `mapstructure:"token_manager"` - Repo Repo `mapstructure:"repo"` - Index Index `mapstructure:"index"` - ServiceUser ServiceUser `mapstructure:"service_user"` - Tracing Tracing `mapstructure:"tracing"` + 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 diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 3268e13274..d547180d7c 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -11,69 +11,69 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Namespace string `mapstructure:"namespace"` - Root string `mapstructure:"root"` + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Root string `ocisConfig:"root"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 { - Enabled bool `mapstructure:"enabled"` - Addr string `mapstructure:"addr"` + Enabled bool `ocisConfig:"enabled"` + Addr string `ocisConfig:"addr"` } // Ldaps defined the available LDAPS configuration. type Ldaps struct { - Addr string `mapstructure:"addr"` - Enabled bool `mapstructure:"enabled"` - Cert string `mapstructure:"cert"` - Key string `mapstructure:"key"` + 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 `mapstructure:"datastore"` - BaseDN string `mapstructure:"base_dn"` - Insecure bool `mapstructure:"insecure"` - NameFormat string `mapstructure:"name_format"` - GroupFormat string `mapstructure:"group_format"` - Servers []string `mapstructure:"servers"` - SSHKeyAttr string `mapstructure:"ssh_key_attr"` - UseGraphAPI bool `mapstructure:"use_graph_api"` + 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 { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Ldap Ldap `mapstructure:"ldap"` - Ldaps Ldaps `mapstructure:"ldaps"` - Backend Backend `mapstructure:"backend"` - Fallback Backend `mapstructure:"fallback"` - Version string `mapstructure:"version"` - RoleBundleUUID string `mapstructure:"role_bundle_uuid"` + 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 diff --git a/graph-explorer/pkg/config/config.go b/graph-explorer/pkg/config/config.go index 07d55dd484..c25d415de5 100644 --- a/graph-explorer/pkg/config/config.go +++ b/graph-explorer/pkg/config/config.go @@ -8,51 +8,51 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` - Namespace string `mapstructure:"namespace"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + Namespace string `ocisConfig:"namespace"` } // Server configures a server. type Server struct { - Version string `mapstructure:"version"` - Name string `mapstructure:"name"` + Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"client_id"` - Issuer string `mapstructure:"issuer"` - GraphURLBase string `mapstructure:"graph_url_base"` - GraphURLPath string `mapstructure:"graph_url_path"` + 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 `mapstructure:"file"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Server Server `mapstructure:"server"` - Tracing Tracing `mapstructure:"tracing"` - GraphExplorer GraphExplorer `mapstructure:"graph_explorer"` + 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 diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 57e2b0b803..71a5284551 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -8,63 +8,63 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Namespace string `mapstructure:"namespace"` - Root string `mapstructure:"root"` + Addr string `ocisConfig:"addr"` + Namespace string `ocisConfig:"namespace"` + Root string `ocisConfig:"root"` } // Server configures a server. type Server struct { - Version string `mapstructure:"version"` - Name string `mapstructure:"name"` + Version string `ocisConfig:"version"` + Name string `ocisConfig:"name"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"address"` + Address string `ocisConfig:"address"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `mapstructure:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret"` } type Spaces struct { - WebDavBase string `mapstructure:"webdav_base"` - WebDavPath string `mapstructure:"webdav_path"` - DefaultQuota string `mapstructure:"default_quota"` + WebDavBase string `ocisConfig:"webdav_base"` + WebDavPath string `ocisConfig:"webdav_path"` + DefaultQuota string `ocisConfig:"default_quota"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Server Server `mapstructure:"server"` - Tracing Tracing `mapstructure:"tracing"` - Reva Reva `mapstructure:"reva"` - TokenManager TokenManager `mapstructure:"token_manager"` - Spaces Spaces `mapstructure:"spaces"` + 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 diff --git a/idp/pkg/config/config.go b/idp/pkg/config/config.go index 6297a9af1e..ffb7e781e4 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -11,104 +11,104 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` - TLSCert string `mapstructure:"tls_cert"` - TLSKey string `mapstructure:"tls_key"` - TLS bool `mapstructure:"tls"` + 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 `mapstructure:"uri"` - BindDN string `mapstructure:"bind_dn"` - BindPassword string `mapstructure:"bind_password"` - BaseDN string `mapstructure:"base_dn"` - Scope string `mapstructure:"scope"` - LoginAttribute string `mapstructure:"login_attribute"` - EmailAttribute string `mapstructure:"email_attribute"` - NameAttribute string `mapstructure:"name_attribute"` - UUIDAttribute string `mapstructure:"uuid_attribute"` - UUIDAttributeType string `mapstructure:"uuid_attribute_type"` - Filter string `mapstructure:"filter"` + 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 `mapstructure:"name"` - Namespace string `mapstructure:"namespace"` - Version string `mapstructure:"version"` + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"asset"` + Path string `ocisConfig:"asset"` } type Settings struct { - Iss string `mapstructure:"iss"` - IdentityManager string `mapstructure:"identity_manager"` - URIBasePath string `mapstructure:"uri_base_path"` - SignInURI string `mapstructure:"sign_in_uri"` - SignedOutURI string `mapstructure:"signed_out_uri"` - AuthorizationEndpointURI string `mapstructure:"authorization_endpoint_uri"` - EndsessionEndpointURI string `mapstructure:"end_session_endpoint_uri"` - Insecure bool `mapstructure:"insecure"` - TrustedProxy []string `mapstructure:"trusted_proxy"` - AllowScope []string `mapstructure:"allow_scope"` - AllowClientGuests bool `mapstructure:"allow_client_guests"` - AllowDynamicClientRegistration bool `mapstructure:"allow_dynamic_client_registration"` - EncryptionSecretFile string `mapstructure:"encrypt_secret_file"` - Listen string `mapstructure:"listen"` - IdentifierClientDisabled bool `mapstructure:"identifier_client_disabled"` - IdentifierClientPath string `mapstructure:"identifier_client_path"` - IdentifierRegistrationConf string `mapstructure:"identifier_registration_conf"` - IdentifierScopesConf string `mapstructure:"identifier_scopes_conf"` - IdentifierDefaultBannerLogo string `mapstructure:"identifier_default_banner_logo"` - IdentifierDefaultSignInPageText string `mapstructure:"identifier_default_sign_in_page_text"` - IdentifierDefaultUsernameHintText string `mapstructure:"identifier_default_username_hint_text"` - SigningKid string `mapstructure:"sign_in_kid"` - SigningMethod string `mapstructure:"sign_in_method"` - SigningPrivateKeyFiles []string `mapstructure:"sign_in_private_key_files"` - ValidationKeysPath string `mapstructure:"validation_keys_path"` - CookieBackendURI string `mapstructure:"cookie_backend_uri"` - CookieNames []string `mapstructure:"cookie_names"` - AccessTokenDurationSeconds uint64 `mapstructure:"access_token_duration_seconds"` - IDTokenDurationSeconds uint64 `mapstructure:"id_token_duration_seconds"` - RefreshTokenDurationSeconds uint64 `mapstructure:"refresh_token_duration_seconds"` - DyamicClientSecretDurationSeconds uint64 `mapstructure:"dynamic_client_secret_duration_seconds"` + 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 { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` - IDP Settings `mapstructure:"idp"` - Ldap Ldap `mapstructure:"ldap"` - Service Service `mapstructure:"service"` + 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 diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index a334797fc3..c2c78541e9 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -20,35 +20,35 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` } // GRPC defines the available grpc configuration. type GRPC struct { - Addr string `mapstructure:"addr"` + Addr string `ocisConfig:"addr"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret"` } const ( @@ -63,41 +63,41 @@ type Mode int // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { - Port string `mapstructure:"port"` - Host string `mapstructure:"host"` - Extensions string `mapstructure:"extensions"` + Port string `ocisConfig:"port"` + Host string `ocisConfig:"host"` + Extensions string `ocisConfig:"extensions"` } // Config combines all available configuration parts. type Config struct { - *shared.Commons `mapstructure:"shared"` + *shared.Commons `ocisConfig:"shared"` Mode Mode // DEPRECATED File string - OcisURL string `mapstructure:"ocis_url"` + OcisURL string `ocisConfig:"ocis_url"` - Registry string `mapstructure:"registry"` - Log shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - GRPC GRPC `mapstructure:"grpc"` - Tracing Tracing `mapstructure:"tracing"` - TokenManager TokenManager `mapstructure:"token_manager"` - Runtime Runtime `mapstructure:"runtime"` + 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 `mapstructure:"accounts"` - GLAuth *glauth.Config `mapstructure:"glauth"` - Graph *graph.Config `mapstructure:"graph"` - GraphExplorer *graphExplorer.Config `mapstructure:"graph_explorer"` - IDP *idp.Config `mapstructure:"idp"` - OCS *ocs.Config `mapstructure:"ocs"` - Web *web.Config `mapstructure:"web"` - Proxy *proxy.Config `mapstructure:"proxy"` - Settings *settings.Config `mapstructure:"settings"` - Storage *storage.Config `mapstructure:"storage"` - Store *store.Config `mapstructure:"store"` - Thumbnails *thumbnails.Config `mapstructure:"thumbnails"` - WebDAV *webdav.Config `mapstructure:"webdav"` + 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. diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 645123f3bb..f89cdc5ddc 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -69,6 +69,9 @@ func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) [] 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...) diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index 48c9eb2281..01f2d65bbd 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -8,76 +8,76 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"allowed_origins"` - AllowedMethods []string `mapstructure:"allowed_methods"` - AllowedHeaders []string `mapstructure:"allowed_headers"` - AllowCredentials bool `mapstructure:"allow_credentials"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` - CORS CORS `mapstructure:"cors"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string `mapstructure:"name"` - Namespace string `mapstructure:"namespace"` - Version string `mapstructure:"version"` + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"address"` + Address string `ocisConfig:"address"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `mapstructure:"jwt_secret"` + 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 `mapstructure:"address"` + Address string `ocisConfig:"address"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - TokenManager TokenManager `mapstructure:"token_manager"` - Service Service `mapstructure:"service"` - AccountBackend string `mapstructure:"account_backend"` - Reva Reva `mapstructure:"reva"` - StorageUsersDriver string `mapstructure:"storage_users_driver"` - MachineAuthAPIKey string `mapstructure:"machine_auth_api_key"` - IdentityManagement IdentityManagement `mapstructure:"identity_management"` + 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 diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 77895c819b..bd21ee1e32 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -10,57 +10,57 @@ import ( // 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"` + 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 `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` - TLSCert string `mapstructure:"tls_cert"` - TLSKey string `mapstructure:"tls_key"` - TLS bool `mapstructure:"tls"` + 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 `mapstructure:"name"` - Namespace string `mapstructure:"namespace"` - Version string `mapstructure:"version"` + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"name"` - Routes []Route `mapstructure:"routes"` + Name string `ocisConfig:"name"` + Routes []Route `ocisConfig:"routes"` } // Route define forwarding routes type Route struct { - Type RouteType `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Backend string `mapstructure:"backend"` - 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 @@ -84,48 +84,48 @@ var ( // Reva defines all available REVA configuration. type Reva struct { - Address string `mapstructure:"address"` - Middleware Middleware `mapstructure:"middleware"` + Address string `ocisConfig:"address"` + Middleware Middleware `ocisConfig:"middleware"` } // Middleware configures proxy middlewares. type Middleware struct { - Auth Auth `mapstructure:"middleware"` + Auth Auth `ocisConfig:"middleware"` } // Auth configures proxy http auth middleware. type Auth struct { - CredentialsByUserAgent map[string]string `mapstructure:""` + CredentialsByUserAgent map[string]string `ocisConfig:""` } // Cache is a TTL cache configuration. type Cache struct { - Size int `mapstructure:"size"` - TTL int `mapstructure:"ttl"` + Size int `ocisConfig:"size"` + TTL int `ocisConfig:"ttl"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Service Service `mapstructure:"service"` - Tracing Tracing `mapstructure:"tracing"` - Policies []Policy `mapstructure:"policies"` - OIDC OIDC `mapstructure:"oidc"` - TokenManager TokenManager `mapstructure:"token_manager"` - PolicySelector *PolicySelector `mapstructure:"policy_selector"` - Reva Reva `mapstructure:"reva"` - PreSignedURL PreSignedURL `mapstructure:"pre_signed_url"` - AccountBackend string `mapstructure:"account_backend"` - UserOIDCClaim string `mapstructure:"user_oidc_claim"` - UserCS3Claim string `mapstructure:"user_cs3_claim"` - MachineAuthAPIKey string `mapstructure:"machine_auth_api_key"` - AutoprovisionAccounts bool `mapstructure:"auto_provision_accounts"` - EnableBasicAuth bool `mapstructure:"enable_basic_auth"` - InsecureBackends bool `mapstructure:"insecure_backends"` + 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 @@ -134,62 +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 `mapstructure:"issuer"` - Insecure bool `mapstructure:"insecure"` - UserinfoCache Cache `mapstructure:"user_info_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 `mapstructure:"static"` - Migration *MigrationSelectorConf `mapstructure:"migration"` - Claims *ClaimsSelectorConf `mapstructure:"claims"` - Regex *RegexSelectorConf `mapstructure:"regex"` + 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 `mapstructure:"policy"` + Policy string `ocisConfig:"policy"` } // TokenManager is the config for using the reva token manager type TokenManager struct { - JWTSecret string `mapstructure:"jwt_secret"` + JWTSecret string `ocisConfig:"jwt_secret"` } // PreSignedURL is the config for the presigned url middleware type PreSignedURL struct { - AllowedHTTPMethods []string `mapstructure:"allowed_http_methods"` - Enabled bool `mapstructure:"enabled"` + 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 diff --git a/settings/pkg/config/config.go b/settings/pkg/config/config.go index c41e2d8c90..4d91088b96 100644 --- a/settings/pkg/config/config.go +++ b/settings/pkg/config/config.go @@ -11,74 +11,74 @@ import ( // 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 { *shared.Commons - File string - Service Service - Log *shared.Log - Debug Debug - HTTP HTTP - GRPC GRPC - Tracing Tracing - Asset Asset - TokenManager TokenManager + 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 diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index 111ffa6b51..d047cbadcf 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -12,113 +12,113 @@ import ( // 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"` + 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 `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"commit_share_to_storage_grant"` - CommitShareToStorageRef bool `mapstructure:"commit_share_to_storage_ref"` - DisableHomeCreationOnLogin bool `mapstructure:"disable_home_creation_on_login"` - ShareFolder string `mapstructure:"share_folder"` - LinkGrants string `mapstructure:"link_grants"` - HomeMapping string `mapstructure:"home_mapping"` - EtagCacheTTL int `mapstructure:"etag_cache_ttl"` + 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 `mapstructure:"driver"` + 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 `mapstructure:"home_provider"` - Rules []string `mapstructure:"rules"` - JSON string `mapstructure:"json"` + 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 `mapstructure:"driver"` - MimetypesJSON string `mapstructure:"mime_types_json"` + Driver string `ocisConfig:"driver"` + MimetypesJSON string `ocisConfig:"mime_types_json"` } // AppProvider defines the available app provider configuration type AppProvider struct { Port - ExternalAddr string `mapstructure:"external_addr"` - Driver string `mapstructure:"driver"` - WopiDriver WopiDriver `mapstructure:"wopi_driver"` - AppsURL string `mapstructure:"apps_url"` - OpenURL string `mapstructure:"open_url"` + 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 `mapstructure:"app_api_key"` - AppDesktopOnly bool `mapstructure:"app_desktop_only"` - AppIconURI string `mapstructure:"app_icon_uri"` - AppInternalURL string `mapstructure:"app_internal_url"` - AppName string `mapstructure:"app_name"` - AppURL string `mapstructure:"app_url"` - Insecure bool `mapstructure:"insecure"` - IopSecret string `mapstructure:"ipo_secret"` - JWTSecret string `mapstructure:"jwt_secret"` - WopiURL string `mapstructure:"wopi_url"` + 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 `mapstructure:"user_driver"` - UserJSONFile string `mapstructure:"user_json_file"` - UserSQLUsername string `mapstructure:"user_sql_username"` - UserSQLPassword string `mapstructure:"user_sql_password"` - UserSQLHost string `mapstructure:"user_sql_host"` - UserSQLPort int `mapstructure:"user_sql_port"` - UserSQLName string `mapstructure:"user_sql_name"` - PublicDriver string `mapstructure:"public_driver"` - PublicJSONFile string `mapstructure:"public_json_file"` - PublicPasswordHashCost int `mapstructure:"public_password_hash_cost"` - PublicEnableExpiredSharesCleanup bool `mapstructure:"public_enable_expired_shares_cleanup"` - PublicJanitorRunInterval int `mapstructure:"public_janitor_run_interval"` - UserStorageMountID string `mapstructure:"user_storage_mount_id"` + 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 `mapstructure:"max_cpus"` - LogLevel string `mapstructure:"log_level"` + MaxCPUs string `ocisConfig:"max_cpus"` + LogLevel string `ocisConfig:"log_level"` // GRPCNetwork can be tcp, udp or unix - GRPCNetwork string `mapstructure:"grpc_network"` + 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 `mapstructure:"grpc_addr"` + GRPCAddr string `ocisConfig:"grpc_addr"` // Protocol can be grpc or http // HTTPNetwork can be tcp, udp or unix - HTTPNetwork string `mapstructure:"http_network"` + 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 `mapstructure:"http_addr"` + HTTPAddr string `ocisConfig:"http_addr"` // Protocol can be grpc or http - Protocol string `mapstructure:"protocol"` + Protocol string `ocisConfig:"protocol"` // Endpoint is used by the gateway and registries (eg localhost:9100 or cloud.example.com) - Endpoint string `mapstructure:"endpoint"` + Endpoint string `ocisConfig:"endpoint"` // DebugAddr for the debug endpoint to bind to - DebugAddr string `mapstructure:"debug_addr"` + DebugAddr string `ocisConfig:"debug_addr"` // Services can be used to give a list of services that should be started on this port - Services []string `mapstructure:"services"` + 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{} `mapstructure:"config"` + Config map[string]interface{} `ocisConfig:"config"` // Context allows for context cancellation and propagation Context context.Context @@ -130,113 +130,113 @@ type Port struct { // Users defines the available users configuration. type Users struct { Port - Driver string `mapstucture:"driver"` - JSON string `mapstucture:"json"` - UserGroupsCacheExpiration int `mapstucture:"user_groups_cache_expiration"` + 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 `mapstucture:"machine_auth_api_key"` + MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key"` } // Groups defines the available groups configuration. type Groups struct { Port - Driver string `mapstucture:"driver"` - JSON string `mapstucture:"json"` - GroupMembersCacheExpiration int `mapstucture:"group_members_cache_expiration"` + 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 `mapstucture:"app_provider_insecure"` - AppProviderPrefix string `mapstucture:"app_provider_prefix"` - ArchiverInsecure bool `mapstucture:"archiver_insecure"` - ArchiverPrefix string `mapstucture:"archiver_prefix"` - DatagatewayPrefix string `mapstucture:"data_gateway_prefix"` - Favorites bool `mapstucture:"favorites"` - OCDavInsecure bool `mapstucture:"ocdav_insecure"` - OCDavPrefix string `mapstucture:"ocdav_prefix"` - OCSPrefix string `mapstucture:"ocs_prefix"` - OCSSharePrefix string `mapstucture:"ocs_share_prefix"` - OCSHomeNamespace string `mapstucture:"ocs_home_namespace"` - PublicURL string `mapstucture:"public_url"` - OCSCacheWarmupDriver string `mapstucture:"ocs_cache_warmup_driver"` - OCSAdditionalInfoAttribute string `mapstucture:"ocs_additional_info_attribute"` - OCSResourceInfoCacheTTL int `mapstucture:"ocs_resource_info_cache_ttl"` - Middleware Middleware `mapstucture:"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 `mapstructure:"auth"` + Auth Auth `ocisConfig:"auth"` } // Auth configures reva http auth middleware. type Auth struct { - CredentialsByUserAgent map[string]string `mapstructure:"credentials_by_user_agenr"` + CredentialsByUserAgent map[string]string `ocisConfig:"credentials_by_user_agenr"` } // DataGatewayPort has a public url type DataGatewayPort struct { Port - PublicURL string `mapstructure:""` + PublicURL string `ocisConfig:""` } type DataProvider struct { - Insecure bool `mapstructure:"insecure"` + Insecure bool `ocisConfig:"insecure"` } // StoragePort defines the available storage configuration. type StoragePort struct { Port - Driver string `mapstructure:"driver"` - MountPath string `mapstructure:"mount_path"` - MountID string `mapstructure:"mount_id"` - ExposeDataServer bool `mapstructure:"expose_data_server"` + Driver string `ocisConfig:"driver"` + MountPath string `ocisConfig:"mount_path"` + MountID string `ocisConfig:"mount_id"` + ExposeDataServer bool `ocisConfig:"expose_data_server"` // url the data gateway will use to route requests - DataServerURL string `mapstructure:"data_server_url"` + DataServerURL string `ocisConfig:"data_server_url"` // for HTTP ports with only one http service - HTTPPrefix string `mapstructure:"http_prefix"` - TempFolder string `mapstructure:"temp_folder"` - ReadOnly bool `mapstructure:"read_only"` - DataProvider DataProvider `mapstructure:"data_provider"` + 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 `mapstructure:"public_share_provider_addr"` - UserProviderAddr string `mapstructure:"user_provider_addr"` + 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 `mapstructure:"eos"` - Local DriverCommon `mapstructure:"local"` - OwnCloud DriverOwnCloud `mapstructure:"owncloud"` - OwnCloudSQL DriverOwnCloudSQL `mapstructure:"owncloud_sql"` - S3 DriverS3 `mapstructure:"s3"` - S3NG DriverS3NG `mapstructure:"s3ng"` - OCIS DriverOCIS `mapstructure:"ocis"` + 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 `mapstructure:"root"` + Root string `ocisConfig:"root"` //ShareFolder defines the name of the folder jailing all shares - ShareFolder string `mapstructure:"share_folder"` + ShareFolder string `ocisConfig:"share_folder"` // UserLayout contains the template used to construct // the internal path, eg: `{{substr 0 1 .Username}}/{{.Username}}` - UserLayout string `mapstructure:"user_layout"` + UserLayout string `ocisConfig:"user_layout"` // EnableHome enables the creation of home directories. - EnableHome bool `mapstructure:"enable_home"` + EnableHome bool `ocisConfig:"enable_home"` } // DriverEOS defines the available EOS driver configuration. @@ -244,273 +244,273 @@ type DriverEOS struct { DriverCommon // ShadowNamespace for storing shadow data - ShadowNamespace string `mapstructure:"shadow_namespace"` + ShadowNamespace string `ocisConfig:"shadow_namespace"` // UploadsNamespace for storing upload data - UploadsNamespace string `mapstructure:"uploads_namespace"` + UploadsNamespace string `ocisConfig:"uploads_namespace"` // Location of the eos binary. // Default is /usr/bin/eos. - EosBinary string `mapstructure:"eos_binary"` + EosBinary string `ocisConfig:"eos_binary"` // Location of the xrdcopy binary. // Default is /usr/bin/xrdcopy. - XrdcopyBinary string `mapstructure:"xrd_copy_binary"` + XrdcopyBinary string `ocisConfig:"xrd_copy_binary"` // URL of the Master EOS MGM. // Default is root://eos-example.org - MasterURL string `mapstructure:"master_url"` + MasterURL string `ocisConfig:"master_url"` // URI of the EOS MGM grpc server // Default is empty - GrpcURI string `mapstructure:"grpc_uri"` + GrpcURI string `ocisConfig:"grpc_uri"` // URL of the Slave EOS MGM. // Default is root://eos-example.org - SlaveURL string `mapstructure:"slave_url"` + SlaveURL string `ocisConfig:"slave_url"` // Location on the local fs where to store reads. // Defaults to os.TempDir() - CacheDirectory string `mapstructure:"cache_directory"` + CacheDirectory string `ocisConfig:"cache_directory"` // Enables logging of the commands executed // Defaults to false - EnableLogging bool `mapstructure:"enable_logging"` + EnableLogging bool `ocisConfig:"enable_logging"` // ShowHiddenSysFiles shows internal EOS files like // .sys.v# and .sys.a# files. - ShowHiddenSysFiles bool `mapstructure:"shadow_hidden_files"` + ShowHiddenSysFiles bool `ocisConfig:"shadow_hidden_files"` // ForceSingleUserMode will force connections to EOS to use SingleUsername - ForceSingleUserMode bool `mapstructure:"force_single_user_mode"` + ForceSingleUserMode bool `ocisConfig:"force_single_user_mode"` // UseKeyTabAuth changes will authenticate requests by using an EOS keytab. - UseKeytab bool `mapstructure:"user_keytab"` + UseKeytab bool `ocisConfig:"user_keytab"` // SecProtocol specifies the xrootd security protocol to use between the server and EOS. - SecProtocol string `mapstructure:"sec_protocol"` + SecProtocol string `ocisConfig:"sec_protocol"` // Keytab specifies the location of the keytab to use to authenticate to EOS. - Keytab string `mapstructure:"keytab"` + Keytab string `ocisConfig:"keytab"` // SingleUsername is the username to use when SingleUserMode is enabled - SingleUsername string `mapstructure:"single_username"` + SingleUsername string `ocisConfig:"single_username"` // gateway service to use for uid lookups - GatewaySVC string `mapstructure:"gateway_svc"` + GatewaySVC string `ocisConfig:"gateway_svc"` } // DriverOCIS defines the available oCIS storage driver configuration. type DriverOCIS struct { DriverCommon - ServiceUserUUID string `mapstructure:"service_user_uuid"` + ServiceUserUUID string `ocisConfig:"service_user_uuid"` } // DriverOwnCloud defines the available ownCloud storage driver configuration. type DriverOwnCloud struct { DriverCommon - UploadInfoDir string `mapstructure:"upload_info_dir"` - Redis string `mapstructure:"redis"` - Scan bool `mapstructure:"scan"` + 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 `mapstructure:"upload_info_dir"` - DBUsername string `mapstructure:"db_username"` - DBPassword string `mapstructure:"db_password"` - DBHost string `mapstructure:"db_host"` - DBPort int `mapstructure:"db_port"` - DBName string `mapstructure:"db_name"` + 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 `mapstructure:"region"` - AccessKey string `mapstructure:"access_key"` - SecretKey string `mapstructure:"secret_key"` - Endpoint string `mapstructure:"endpoint"` - Bucket string `mapstructure:"bucket"` + 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 `mapstructure:"region"` - AccessKey string `mapstructure:"access_key"` - SecretKey string `mapstructure:"secret_key"` - Endpoint string `mapstructure:"endpoint"` - Bucket string `mapstructure:"bucket"` + 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 `mapstructure:"issuer"` - Insecure bool `mapstructure:"insecure"` - IDClaim string `mapstructure:"id_claim"` - UIDClaim string `mapstructure:"uid_claim"` - GIDClaim string `mapstructure:"gid_claim"` + 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 `mapstructure:"hostname"` - Port int `mapstructure:"port"` - CACert string `mapstructure:"ca_cert"` - Insecure bool `mapstructure:"insecure"` - BaseDN string `mapstructure:"base_dn"` - LoginFilter string `mapstructure:"login_filter"` - UserFilter string `mapstructure:"user_filter"` - UserAttributeFilter string `mapstructure:"user_attribute_filter"` - UserFindFilter string `mapstructure:"user_find_filter"` - UserGroupFilter string `mapstructure:"user_group_filter"` - GroupFilter string `mapstructure:"group_filter"` - GroupAttributeFilter string `mapstructure:"group_attribute_filter"` - GroupFindFilter string `mapstructure:"group_finder_filter"` - GroupMemberFilter string `mapstructure:"group_member_filter"` - BindDN string `mapstructure:"bind_dn"` - BindPassword string `mapstructure:"bind_password"` - IDP string `mapstructure:"idp"` - UserSchema LDAPUserSchema `mapstructure:"user_schema"` - GroupSchema LDAPGroupSchema `mapstructure:"group_schema"` + 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 `mapstructure:"client_id"` - ClientSecret string `mapstructure:"client_secret"` - RedisAddress string `mapstructure:"redis_address"` - RedisUsername string `mapstructure:"redis_username"` - RedisPassword string `mapstructure:"redis_password"` - IDProvider string `mapstructure:"idp_provider"` - APIBaseURL string `mapstructure:"api_base_url"` - OIDCTokenEndpoint string `mapstructure:"oidc_token_endpoint"` - TargetAPI string `mapstructure:"target_api"` + 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 `mapstructure:"db_username"` - DBPassword string `mapstructure:"db_password"` - DBHost string `mapstructure:"db_host"` - DBPort int `mapstructure:"db_port"` - DBName string `mapstructure:"db_name"` - Idp string `mapstructure:"idp"` - Nobody int64 `mapstructure:"nobody"` - JoinUsername bool `mapstructure:"join_username"` - JoinOwnCloudUUID bool `mapstructure:"join_owncloud_uuid"` - EnableMedialSearch bool `mapstructure:"enable_medial_search"` + 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 `mapstructure:"uid"` - Mail string `mapstructure:"mail"` - DisplayName string `mapstructure:"display_name"` - CN string `mapstructure:"cn"` - UIDNumber string `mapstructure:"uid_number"` - GIDNumber string `mapstructure:"gid_number"` + 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 `mapstructure:"gid"` - Mail string `mapstructure:"mail"` - DisplayName string `mapstructure:"display_name"` - CN string `mapstructure:"cn"` - GIDNumber string `mapstructure:"gid_number"` + 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 `mapstructure:"webdav_namespace"` - DavFilesNamespace string `mapstructure:"dav_files_namespace"` + WebdavNamespace string `ocisConfig:"webdav_namespace"` + DavFilesNamespace string `ocisConfig:"dav_files_namespace"` } // Archiver defines the available archiver configuration. type Archiver struct { - MaxNumFiles int64 `mapstructure:"max_num_files"` - MaxSize int64 `mapstructure:"max_size"` - ArchiverURL string `mapstructure:"archiver_url"` + 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 `mapstructure:"jwt_secret"` - SkipUserGroupsInToken bool `mapstructure:"skip_user_grooups_in_token"` - TransferSecret string `mapstructure:"transfer_secret"` - TransferExpires int `mapstructure:"transfer_expires"` - OIDC OIDC `mapstructure:"oidc"` - LDAP LDAP `mapstructure:"ldap"` - UserGroupRest UserGroupRest `mapstructure:"user_group_rest"` - UserOwnCloudSQL UserOwnCloudSQL `mapstructure:"user_owncloud_sql"` - OCDav OCDav `mapstructure:"ocdav"` - Archiver Archiver `mapstructure:"archiver"` - UserStorage StorageConfig `mapstructure:"user_storage"` - MetadataStorage StorageConfig `mapstructure:"metadata_storage"` + 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 `mapstructure:"frontend"` - DataGateway DataGatewayPort `mapstructure:"data_gateway"` - Gateway Gateway `mapstructure:"gateway"` - StorageRegistry StorageRegistry `mapstructure:"storage_registry"` - AppRegistry AppRegistry `mapstructure:"app_registry"` - Users Users `mapstructure:"users"` - Groups Groups `mapstructure:"groups"` - AuthProvider Users `mapstructure:"auth_provider"` - AuthBasic Port `mapstructure:"auth_basic"` - AuthBearer Port `mapstructure:"auth_bearer"` - AuthMachine Port `mapstructure:"auth_machine"` - AuthMachineConfig AuthMachineConfig `mapstructure:"auth_machine_config"` - Sharing Sharing `mapstructure:"sharing"` - StorageHome StoragePort `mapstructure:"storage_home"` - StorageUsers StoragePort `mapstructure:"storage_users"` - StoragePublicLink PublicStorage `mapstructure:"storage_public_link"` - StorageMetadata StoragePort `mapstructure:"storage_metadata"` - AppProvider AppProvider `mapstructure:"app_provider"` + 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{} `mapstructure:"configs"` + Configs map[string]interface{} `ocisConfig:"configs"` // chunking and resumable upload config (TUS) - UploadMaxChunkSize int `mapstructure:"uppload_max_chunk_size"` - UploadHTTPMethodOverride string `mapstructure:"upload_http_method_override"` + UploadMaxChunkSize int `ocisConfig:"uppload_max_chunk_size"` + UploadHTTPMethodOverride string `ocisConfig:"upload_http_method_override"` // checksumming capabilities - ChecksumSupportedTypes []string `mapstructure:"checksum_supported_types"` - ChecksumPreferredUploadType string `mapstructure:"checksum_preferred_upload_type"` - DefaultUploadProtocol string `mapstructure:"default_upload_protocol"` + 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 `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"path"` + Path string `ocisConfig:"path"` } // Config combines all available configuration parts. type Config struct { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - Reva Reva `mapstructure:"reva"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` + 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. diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index ad597bb480..a39cae29b5 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -10,43 +10,43 @@ import ( // 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 shared.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 diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index 8e5e52517b..6035038349 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -10,39 +10,39 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"name"` - Namespace string `mapstructure:"namespace"` - Address string `mapstructure:"address"` - Version string `mapstructure:"version"` + 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 `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - Server Server `mapstructure:"server"` - Tracing Tracing `mapstructure:"tracing"` - Thumbnail Thumbnail `mapstructure:"thumbnail"` + 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,22 +50,22 @@ type Config struct { // FileSystemStorage defines the available filesystem storage configuration. type FileSystemStorage struct { - RootDirectory string `mapstructure:"root_directory"` + RootDirectory string `ocisConfig:"root_directory"` } // FileSystemSource defines the available filesystem source configuration. type FileSystemSource struct { - BasePath string `mapstructure:"base_path"` + BasePath string `ocisConfig:"base_path"` } // Thumbnail defines the available thumbnail related configuration. type Thumbnail struct { - Resolutions []string `mapstructure:"resolutions"` - FileSystemStorage FileSystemStorage `mapstructure:"filesystem_storage"` - WebdavAllowInsecure bool `mapstructure:"webdav_allow_insecure"` - CS3AllowInsecure bool `mapstructure:"cs3_allow_insecure"` - RevaGateway string `mapstructure:"reva_gateway"` - WebdavNamespace string `mapstructure:"webdav_namespace"` + 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. diff --git a/web/pkg/config/config.go b/web/pkg/config/config.go index 9859e91cac..0054c9331a 100644 --- a/web/pkg/config/config.go +++ b/web/pkg/config/config.go @@ -8,52 +8,52 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` - Namespace string `mapstructure:"namespace"` - CacheTTL int `mapstructure:"cache_ttl"` + 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 `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 `mapstructure:"path"` + Path string `ocisConfig:"path"` } // WebConfig defines the available web configuration for a dynamically rendered config.json. type WebConfig struct { - Server string `json:"server,omitempty" mapstructure:"server"` - Theme string `json:"theme,omitempty" mapstructure:"theme"` - Version string `json:"version,omitempty" mapstructure:"version"` - OpenIDConnect OIDC `json:"openIdConnect,omitempty" mapstructure:"oids"` - Apps []string `json:"apps" mapstructure:"apps"` - ExternalApps []ExternalApp `json:"external_apps,omitempty" mapstructure:"external_apps"` - Options map[string]interface{} `json:"options,omitempty" mapstructure:"options"` + 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" mapstructure:"metadata_url"` - Authority string `json:"authority,omitempty" mapstructure:"authority"` - ClientID string `json:"client_id,omitempty" mapstructure:"client_id"` - ResponseType string `json:"response_type,omitempty" mapstructure:"response_type"` - Scope string `json:"scope,omitempty" mapstructure:"scope"` + 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. @@ -65,36 +65,36 @@ type OIDC struct { // } // } type ExternalApp struct { - ID string `json:"id,omitempty" mapstructure:"id"` - Path string `json:"path,omitempty" mapstructure:"path"` + 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" mapstructure:"config"` + Config map[string]interface{} `json:"config,omitempty" ocisConfig:"config"` } // ExternalAppConfig defines an external web app configuration. type ExternalAppConfig struct { - URL string `json:"url,omitempty" mapstructure:"url"` + URL string `json:"url,omitempty" ocisConfig:"url"` } // Web defines the available web configuration. type Web struct { - Path string `mapstructure:"path"` - ThemeServer string `mapstructure:"theme_server"` // used to build Theme in WebConfig - ThemePath string `mapstructure:"theme_path"` // used to build Theme in WebConfig - Config WebConfig `mapstructure:"config"` + 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 { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Asset Asset `mapstructure:"asset"` - Web Web `mapstructure:"web"` + 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 diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index b5b1d8eb4d..c08c8ea0f9 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -8,55 +8,55 @@ import ( // Debug defines the available debug configuration. type Debug struct { - Addr string `mapstructure:"addr"` - Token string `mapstructure:"token"` - Pprof bool `mapstructure:"pprof"` - Zpages bool `mapstructure:"zpages"` + 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 `mapstructure:"allowed_origins"` - AllowedMethods []string `mapstructure:"allowed_methods"` - AllowedHeaders []string `mapstructure:"allowed_headers"` - AllowCredentials bool `mapstructure:"allow_credentials"` + 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 `mapstructure:"addr"` - Root string `mapstructure:"root"` - CORS CORS `mapstructure:"cors"` + Addr string `ocisConfig:"addr"` + Root string `ocisConfig:"root"` + CORS CORS `ocisConfig:"cors"` } // Service defines the available service configuration. type Service struct { - Name string `mapstructure:"name"` - Namespace string `mapstructure:"namespace"` - Version string `mapstructure:"version"` + Name string `ocisConfig:"name"` + Namespace string `ocisConfig:"namespace"` + Version string `ocisConfig:"version"` } // Tracing defines the available tracing configuration. type Tracing struct { - Enabled bool `mapstructure:"enabled"` - Type string `mapstructure:"type"` - Endpoint string `mapstructure:"endpoint"` - Collector string `mapstructure:"collector"` - Service string `mapstructure:"service"` + 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 { *shared.Commons - File string `mapstructure:"file"` - Log *shared.Log `mapstructure:"log"` - Debug Debug `mapstructure:"debug"` - HTTP HTTP `mapstructure:"http"` - Tracing Tracing `mapstructure:"tracing"` - Service Service `mapstructure:"service"` - OcisPublicURL string `mapstructure:"ocis_public_url"` - WebdavNamespace string `mapstructure:"webdav_namespace"` + 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 From f64ca1f6bade69b0e6b3179d97d78700990176d7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 19 Nov 2021 16:21:55 +0100 Subject: [PATCH 137/147] introduce AlternativeID attribute, which needs some explanation --- go.sum | 3 +-- storage/pkg/command/gateway.go | 6 ++++-- storage/pkg/config/config.go | 3 +++ storage/pkg/flagset/gateway.go | 0 storage/pkg/flagset/storagepubliclink.go | 0 5 files changed, 8 insertions(+), 4 deletions(-) delete mode 100644 storage/pkg/flagset/gateway.go delete mode 100644 storage/pkg/flagset/storagepubliclink.go diff --git a/go.sum b/go.sum index 5037a0356b..5e9ece8fcb 100644 --- a/go.sum +++ b/go.sum @@ -298,8 +298,6 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.15.1-0.20211118124936-a73b194a134e h1:J1C1rlrSztBAbmufCGlRcsT9WrIP1YNjGwup4ygVUdA= -github.com/cs3org/reva v1.15.1-0.20211118124936-a73b194a134e/go.mod h1:9jmSVOnYv69pYbXfjcboTQaZPwHZ6NSD+2jjE9xx12U= github.com/cs3org/reva v1.15.1-0.20211119095816-7cfc6d3cc8c2 h1:QjnDztqGCLdYtiw6enAgrWZwc7UaZj7iJeT0L4oyHpk= github.com/cs3org/reva v1.15.1-0.20211119095816-7cfc6d3cc8c2/go.mod h1:9jmSVOnYv69pYbXfjcboTQaZPwHZ6NSD+2jjE9xx12U= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= @@ -807,6 +805,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= diff --git a/storage/pkg/command/gateway.go b/storage/pkg/command/gateway.go index adb0e15df5..63f158da1e 100644 --- a/storage/pkg/command/gateway.go +++ b/storage/pkg/command/gateway.go @@ -219,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}, @@ -229,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{} { diff --git a/storage/pkg/config/config.go b/storage/pkg/config/config.go index d047cbadcf..a9f6b5967c 100644 --- a/storage/pkg/config/config.go +++ b/storage/pkg/config/config.go @@ -196,6 +196,7 @@ type StoragePort struct { 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 `ocisConfig:"data_server_url"` @@ -867,6 +868,7 @@ func DefaultConfig() *Config { 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", @@ -897,6 +899,7 @@ func DefaultConfig() *Config { GRPCAddr: "127.0.0.1:9178", }, MountPath: "/public", + MountID: "e1a73ede-549b-4226-abdf-40e69ca8230d", }, PublicShareProviderAddr: "", UserProviderAddr: "", diff --git a/storage/pkg/flagset/gateway.go b/storage/pkg/flagset/gateway.go deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/storage/pkg/flagset/storagepubliclink.go b/storage/pkg/flagset/storagepubliclink.go deleted file mode 100644 index e69de29bb2..0000000000 From 1570e402216cd8291a6ba6fc2d91347d318896f0 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 19 Nov 2021 17:18:23 +0100 Subject: [PATCH 138/147] applied review comments by @wkloucek --- .drone.star | 2 +- .make/docs.mk | 10 +++++----- docs/ocis/config.md | 10 +++++++++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.drone.star b/.drone.star index a7f062f3f1..e982c75b53 100644 --- a/.drone.star +++ b/.drone.star @@ -146,7 +146,7 @@ def main(ctx): build_release_helpers = [ changelog(ctx), - # docs(ctx), + docs(ctx), ] test_pipelines.append( diff --git a/.make/docs.mk b/.make/docs.mk index 575d0ad4b7..b887b11c0f 100644 --- a/.make/docs.mk +++ b/.make/docs.mk @@ -2,11 +2,11 @@ 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; +#.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; .PHONY: grpc-docs-generate grpc-docs-generate: buf-generate diff --git a/docs/ocis/config.md b/docs/ocis/config.md index 11bc35bfd9..aa6a367bf8 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -19,7 +19,7 @@ In order to simplify deployments and development the configuration model from oC ## 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 shared values, such as config file sources (`--config-file`) or logging (`--log-level`, `--log-pretty`, `--log-file` or `--log-color`). +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: @@ -39,6 +39,14 @@ Let's explore the various flows with examples and workflows. 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: From 17081498204cfb8987c6260e3ddae5f42d073941 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 19 Nov 2021 17:31:27 +0100 Subject: [PATCH 139/147] comment docs pipeline again --- .drone.star | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index e982c75b53..288a40bb4b 100644 --- a/.drone.star +++ b/.drone.star @@ -146,7 +146,7 @@ def main(ctx): build_release_helpers = [ changelog(ctx), - docs(ctx), + #docs(ctx), ] test_pipelines.append( From 9c3fb1cf4cd6aa8e5ab021304f20bd79ba6ae7d3 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Sat, 20 Nov 2021 11:20:36 +0100 Subject: [PATCH 140/147] comment out .make/docs.mk config-docs-generate target --- .drone.star | 2 +- .make/docs.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.star b/.drone.star index 288a40bb4b..e982c75b53 100644 --- a/.drone.star +++ b/.drone.star @@ -146,7 +146,7 @@ def main(ctx): build_release_helpers = [ changelog(ctx), - #docs(ctx), + docs(ctx), ] test_pipelines.append( diff --git a/.make/docs.mk b/.make/docs.mk index b887b11c0f..3d2c515556 100644 --- a/.make/docs.mk +++ b/.make/docs.mk @@ -3,7 +3,7 @@ SKIP_CONFIG_DOCS_GENERATE ?= 0 CONFIG_DOCS_BASE_PATH ?= ../docs/extensions #.PHONY: config-docs-generate -#config-docs-generate: $(FLAEX) +config-docs-generate: $(FLAEX) # @if [ $(SKIP_CONFIG_DOCS_GENERATE) -ne 1 ]; then \ # $(FLAEX) >| $(CONFIG_DOCS_BASE_PATH)/$(NAME)/configuration.md \ # ; fi; From 45a559f7072f1cebcbb5de463d0d0bf3e4c0e9be Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Sat, 20 Nov 2021 11:40:47 +0100 Subject: [PATCH 141/147] Revert "comment out .make/docs.mk config-docs-generate target" This reverts commit 9c3fb1cf4cd6aa8e5ab021304f20bd79ba6ae7d3. --- .drone.star | 2 +- .make/docs.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.star b/.drone.star index e982c75b53..288a40bb4b 100644 --- a/.drone.star +++ b/.drone.star @@ -146,7 +146,7 @@ def main(ctx): build_release_helpers = [ changelog(ctx), - docs(ctx), + #docs(ctx), ] test_pipelines.append( diff --git a/.make/docs.mk b/.make/docs.mk index 3d2c515556..b887b11c0f 100644 --- a/.make/docs.mk +++ b/.make/docs.mk @@ -3,7 +3,7 @@ SKIP_CONFIG_DOCS_GENERATE ?= 0 CONFIG_DOCS_BASE_PATH ?= ../docs/extensions #.PHONY: config-docs-generate -config-docs-generate: $(FLAEX) +#config-docs-generate: $(FLAEX) # @if [ $(SKIP_CONFIG_DOCS_GENERATE) -ne 1 ]; then \ # $(FLAEX) >| $(CONFIG_DOCS_BASE_PATH)/$(NAME)/configuration.md \ # ; fi; From c700ccab1f808520f816f8e90c34d193359def21 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 22 Nov 2021 22:11:06 +0100 Subject: [PATCH 142/147] removed redundant ocis config parsing --- ocis/pkg/command/accounts.go | 4 ---- ocis/pkg/command/glauth.go | 4 ---- ocis/pkg/command/health.go | 3 --- ocis/pkg/command/idp.go | 4 ---- ocis/pkg/command/ocs.go | 4 ---- ocis/pkg/command/proxy.go | 4 ---- ocis/pkg/command/server.go | 2 +- ocis/pkg/command/settings.go | 4 ---- ocis/pkg/command/store.go | 18 ------------------ ocis/pkg/command/thumbnails.go | 4 ---- ocis/pkg/command/web.go | 4 ---- ocis/pkg/command/webdav.go | 4 ---- 12 files changed, 1 insertion(+), 58 deletions(-) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 1cacd70d0a..7597ae2a21 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -25,10 +25,6 @@ func AccountsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Accounts), }, Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.Accounts.Commons = cfg.Commons } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index c6baacfdeb..da059c0cf0 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -14,10 +14,6 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Usage: "Start glauth server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.GLAuth.Commons = cfg.Commons } diff --git a/ocis/pkg/command/health.go b/ocis/pkg/command/health.go index f293dbf8fa..c5d46ceacb 100644 --- a/ocis/pkg/command/health.go +++ b/ocis/pkg/command/health.go @@ -14,9 +14,6 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", - 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 7b35c15ba8..c6d9c86be2 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -17,10 +17,6 @@ func IDPCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.IDP), }, Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.IDP.Commons = cfg.Commons } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 17f2d927e6..e53f01fa77 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -17,10 +17,6 @@ func OCSCommand(cfg *config.Config) *cli.Command { Usage: "Start ocs server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.OCS.Commons = cfg.Commons } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 321298689b..570a450463 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -20,10 +20,6 @@ func ProxyCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Proxy), }, Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.Proxy.Commons = cfg.Commons } diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 336a39e87a..728ca9f854 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -25,7 +25,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return ParseConfig(c, cfg) + return nil }, Action: func(c *cli.Context) error { diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index adb37be5b0..b7fe0c09ba 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -20,10 +20,6 @@ func SettingsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Settings), }, Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.Settings.Commons = cfg.Commons } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index 6394621179..b41c37b517 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -5,7 +5,6 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" - "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/store/pkg/command" "github.com/urfave/cli/v2" @@ -13,8 +12,6 @@ import ( // 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", @@ -22,22 +19,7 @@ func StoreCommand(cfg *config.Config) *cli.Command { Subcommands: []*cli.Command{ command.PrintVersion(cfg.Store), }, - Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - - globalLog = cfg.Log - - return nil - }, Action: func(c *cli.Context) error { - // 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) }, diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 0562b5d617..480ca4dcb0 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -20,10 +20,6 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Thumbnails), }, Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.Thumbnails.Commons = cfg.Commons } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index c3f2df2eaf..8085e0dd62 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -14,10 +14,6 @@ func WebCommand(cfg *config.Config) *cli.Command { Usage: "Start web server", Category: "Extensions", Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.Web.Commons = cfg.Commons } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 0502642bb2..2dee0070b3 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -21,10 +21,6 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.WebDAV), }, Before: func(ctx *cli.Context) error { - if err := ParseConfig(ctx, cfg); err != nil { - return err - } - if cfg.Commons != nil { cfg.WebDAV.Commons = cfg.Commons } From 8797cf3b5a0d1026270d8ddada850de87148ac29 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 22 Nov 2021 22:27:29 +0100 Subject: [PATCH 143/147] Revert "removed redundant ocis config parsing" This reverts commit c700ccab1f808520f816f8e90c34d193359def21. --- ocis/pkg/command/accounts.go | 4 ++++ ocis/pkg/command/glauth.go | 4 ++++ ocis/pkg/command/health.go | 3 +++ ocis/pkg/command/idp.go | 4 ++++ ocis/pkg/command/ocs.go | 4 ++++ ocis/pkg/command/proxy.go | 4 ++++ ocis/pkg/command/server.go | 2 +- ocis/pkg/command/settings.go | 4 ++++ ocis/pkg/command/store.go | 18 ++++++++++++++++++ ocis/pkg/command/thumbnails.go | 4 ++++ ocis/pkg/command/web.go | 4 ++++ ocis/pkg/command/webdav.go | 4 ++++ 12 files changed, 58 insertions(+), 1 deletion(-) diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index 7597ae2a21..1cacd70d0a 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -25,6 +25,10 @@ func AccountsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Accounts), }, Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.Accounts.Commons = cfg.Commons } diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index da059c0cf0..c6baacfdeb 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -14,6 +14,10 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Usage: "Start glauth server", Category: "Extensions", Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.GLAuth.Commons = cfg.Commons } diff --git a/ocis/pkg/command/health.go b/ocis/pkg/command/health.go index c5d46ceacb..f293dbf8fa 100644 --- a/ocis/pkg/command/health.go +++ b/ocis/pkg/command/health.go @@ -14,6 +14,9 @@ func Health(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "health", Usage: "Check health status", + 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 c6d9c86be2..7b35c15ba8 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -17,6 +17,10 @@ func IDPCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.IDP), }, Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.IDP.Commons = cfg.Commons } diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index e53f01fa77..17f2d927e6 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -17,6 +17,10 @@ func OCSCommand(cfg *config.Config) *cli.Command { Usage: "Start ocs server", Category: "Extensions", Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.OCS.Commons = cfg.Commons } diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 570a450463..321298689b 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -20,6 +20,10 @@ func ProxyCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Proxy), }, Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.Proxy.Commons = cfg.Commons } diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 728ca9f854..336a39e87a 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -25,7 +25,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") } - return nil + return ParseConfig(c, cfg) }, Action: func(c *cli.Context) error { diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index b7fe0c09ba..adb37be5b0 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -20,6 +20,10 @@ func SettingsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Settings), }, Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.Settings.Commons = cfg.Commons } diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index b41c37b517..6394621179 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -5,6 +5,7 @@ package command import ( "github.com/owncloud/ocis/ocis-pkg/config" + "github.com/owncloud/ocis/ocis-pkg/shared" "github.com/owncloud/ocis/ocis/pkg/register" "github.com/owncloud/ocis/store/pkg/command" "github.com/urfave/cli/v2" @@ -12,6 +13,8 @@ import ( // 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", @@ -19,7 +22,22 @@ func StoreCommand(cfg *config.Config) *cli.Command { Subcommands: []*cli.Command{ command.PrintVersion(cfg.Store), }, + Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + + globalLog = cfg.Log + + return nil + }, Action: func(c *cli.Context) error { + // 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) }, diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 480ca4dcb0..0562b5d617 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -20,6 +20,10 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.Thumbnails), }, Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.Thumbnails.Commons = cfg.Commons } diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 8085e0dd62..c3f2df2eaf 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -14,6 +14,10 @@ func WebCommand(cfg *config.Config) *cli.Command { Usage: "Start web server", Category: "Extensions", Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.Web.Commons = cfg.Commons } diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 2dee0070b3..0502642bb2 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -21,6 +21,10 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { command.PrintVersion(cfg.WebDAV), }, Before: func(ctx *cli.Context) error { + if err := ParseConfig(ctx, cfg); err != nil { + return err + } + if cfg.Commons != nil { cfg.WebDAV.Commons = cfg.Commons } From ca555761696298bc2f0d321150077b00ca31975c Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 23 Nov 2021 11:19:51 +0100 Subject: [PATCH 144/147] fix doc generation and reenable docs pipeline in CI --- .drone.star | 2 +- .make/docs.mk | 6 ++++-- docs/ocis/deployment/basic-remote-setup.md | 2 +- docs/ocis/getting-started/_index.md | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.drone.star b/.drone.star index 288a40bb4b..e982c75b53 100644 --- a/.drone.star +++ b/.drone.star @@ -146,7 +146,7 @@ def main(ctx): build_release_helpers = [ changelog(ctx), - #docs(ctx), + docs(ctx), ] test_pipelines.append( diff --git a/.make/docs.mk b/.make/docs.mk index b887b11c0f..1b1ea2e9aa 100644 --- a/.make/docs.mk +++ b/.make/docs.mk @@ -2,8 +2,10 @@ SKIP_CONFIG_DOCS_GENERATE ?= 0 CONFIG_DOCS_BASE_PATH ?= ../docs/extensions -#.PHONY: config-docs-generate -#config-docs-generate: $(FLAEX) +.PHONY: config-docs-generate +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; diff --git a/docs/ocis/deployment/basic-remote-setup.md b/docs/ocis/deployment/basic-remote-setup.md index 6569309ab6..efa76e1fdf 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 b602fcadab..92e00c4390 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: From 552a79c23fb23b270075ac5686fd238f252d905d Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 23 Nov 2021 11:20:54 +0100 Subject: [PATCH 145/147] added changelog --- changelog/unreleased/revamp-config.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 changelog/unreleased/revamp-config.md diff --git a/changelog/unreleased/revamp-config.md b/changelog/unreleased/revamp-config.md new file mode 100644 index 0000000000..b4c510c29f --- /dev/null +++ b/changelog/unreleased/revamp-config.md @@ -0,0 +1,14 @@ +Change: Restructure Configuration Parsing + +Tags: ocis + +- Adds a new dependency that does roughly what I started to do on a side project. Not reinventing the wheel. MIT license. +- Remove cli flags on subcommands, not on ocis root command. +- Sane default propagation. +- Lays the foundation for easy config dump and service restart on config watch. +- Support for environment variables. +- Support for merging config values. +- Support for defaults. +- And technically speaking, the most important aspect is that it is thread safe, as I can create as many config.Config structs as desired. + +https://github.com/owncloud/ocis/pull/2708 From 889f37f37c4d27648022f42917ca6a7e5d6c5187 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 23 Nov 2021 11:34:36 +0100 Subject: [PATCH 146/147] reimport docs makefile in storage --- storage/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storage/Makefile b/storage/Makefile index b177ccd0cd..c4827d0541 100644 --- a/storage/Makefile +++ b/storage/Makefile @@ -14,6 +14,12 @@ include ../.make/go.mk ############ release ######### include ../.make/release.mk +############ docs generate ############ +include ../.make/docs.mk + +.PHONY: docs-generate +docs-generate: config-docs-generate + ############ generate ############ include ../.make/generate.mk From 43af041a04d53ac4217bfa6d064ec0cf9306655e Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 23 Nov 2021 12:33:16 +0100 Subject: [PATCH 147/147] reword changelog --- changelog/unreleased/revamp-config.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/changelog/unreleased/revamp-config.md b/changelog/unreleased/revamp-config.md index b4c510c29f..d57114543b 100644 --- a/changelog/unreleased/revamp-config.md +++ b/changelog/unreleased/revamp-config.md @@ -2,13 +2,6 @@ Change: Restructure Configuration Parsing Tags: ocis -- Adds a new dependency that does roughly what I started to do on a side project. Not reinventing the wheel. MIT license. -- Remove cli flags on subcommands, not on ocis root command. -- Sane default propagation. -- Lays the foundation for easy config dump and service restart on config watch. -- Support for environment variables. -- Support for merging config values. -- Support for defaults. -- And technically speaking, the most important aspect is that it is thread safe, as I can create as many config.Config structs as desired. +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