move config parsing in separate package for each service

This commit is contained in:
Willy Kloucek
2022-01-03 15:21:56 +01:00
parent e0656daaa0
commit 55bf175bea
66 changed files with 705 additions and 623 deletions

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/config/parser"
"github.com/owncloud/ocis/accounts/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,15 +2,12 @@ package command
import (
"context"
"errors"
"os"
"strings"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -40,12 +37,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-accounts",
Usage: "Provide accounts and groups for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -57,42 +51,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend)
return nil
}
// SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -5,6 +5,7 @@ import (
"github.com/oklog/run"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/config/parser"
"github.com/owncloud/ocis/accounts/pkg/logging"
"github.com/owncloud/ocis/accounts/pkg/metrics"
"github.com/owncloud/ocis/accounts/pkg/server/debug"
@@ -22,7 +23,7 @@ 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 {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,47 @@
package parser
import (
"errors"
"strings"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend)
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/glauth/pkg/config"
"github.com/owncloud/ocis/glauth/pkg/config/parser"
"github.com/owncloud/ocis/glauth/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/glauth/pkg/config"
"github.com/owncloud/ocis/glauth/pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-glauth",
Usage: "Serve GLAuth API for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads glauth configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the glauth command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -7,6 +7,7 @@ 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/config/parser"
"github.com/owncloud/ocis/glauth/pkg/logging"
"github.com/owncloud/ocis/glauth/pkg/metrics"
"github.com/owncloud/ocis/glauth/pkg/server/debug"
@@ -24,7 +25,7 @@ func Server(cfg *config.Config) *cli.Command {
Usage: "Start integrated server",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,42 @@
package parser
import (
"errors"
"github.com/owncloud/ocis/glauth/pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/graph-explorer/pkg/config"
"github.com/owncloud/ocis/graph-explorer/pkg/config/parser"
"github.com/owncloud/ocis/graph-explorer/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig( cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/graph-explorer/pkg/config"
"github.com/owncloud/ocis/graph-explorer/pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "graph-explorer",
Usage: "Serve Graph-Explorer for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads graph configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the graph-explorer command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -2,10 +2,10 @@ package command
import (
"context"
"strings"
"github.com/oklog/run"
"github.com/owncloud/ocis/graph-explorer/pkg/config"
"github.com/owncloud/ocis/graph-explorer/pkg/config/parser"
"github.com/owncloud/ocis/graph-explorer/pkg/logging"
"github.com/owncloud/ocis/graph-explorer/pkg/metrics"
"github.com/owncloud/ocis/graph-explorer/pkg/server/debug"
@@ -20,11 +20,7 @@ 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, "/")
}
return ParseConfig(ctx, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -0,0 +1,46 @@
package parser
import (
"errors"
"strings"
"github.com/owncloud/ocis/graph-explorer/pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/graph/pkg/config"
"github.com/owncloud/ocis/graph/pkg/config/parser"
"github.com/owncloud/ocis/graph/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,16 +2,14 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/graph/pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"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/version"
"github.com/urfave/cli/v2"
)
@@ -34,12 +32,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-graph",
Usage: "Serve Graph API for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
cli.HelpFlag = &cli.BoolFlag{
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads graph configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the graph command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -2,10 +2,10 @@ package command
import (
"context"
"strings"
"github.com/oklog/run"
"github.com/owncloud/ocis/graph/pkg/config"
"github.com/owncloud/ocis/graph/pkg/config/parser"
"github.com/owncloud/ocis/graph/pkg/logging"
"github.com/owncloud/ocis/graph/pkg/metrics"
"github.com/owncloud/ocis/graph/pkg/server/debug"
@@ -20,11 +20,8 @@ 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 err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,46 @@
package parser
import (
"errors"
"strings"
"github.com/owncloud/ocis/graph/pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/idp/pkg/config/parser"
"github.com/owncloud/ocis/idp/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/idp/pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-idp",
Usage: "Serve IDP API for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads idp configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the idp command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -2,10 +2,10 @@ package command
import (
"context"
"strings"
"github.com/oklog/run"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/idp/pkg/config/parser"
"github.com/owncloud/ocis/idp/pkg/logging"
"github.com/owncloud/ocis/idp/pkg/metrics"
"github.com/owncloud/ocis/idp/pkg/server/debug"
@@ -20,14 +20,10 @@ 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 {
if err := parser.ParseConfig(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 {

View File

@@ -0,0 +1,46 @@
package parser
import (
"errors"
"strings"
"github.com/owncloud/ocis/idp/pkg/config"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}

View File

@@ -0,0 +1,39 @@
package parser
import (
"errors"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/shared"
)
// ParseConfig loads ocis configuration.
func ParseConfig(cfg *config.Config) error {
_, err := config.BindSourcesToStructs("ocis", 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.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}

View File

@@ -3,6 +3,7 @@ package command
import (
"github.com/owncloud/ocis/accounts/pkg/command"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/urfave/cli/v2"
)
@@ -14,7 +15,7 @@ func AccountsCommand(cfg *config.Config) *cli.Command {
Usage: "Start accounts server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -3,6 +3,7 @@ package command
import (
"github.com/owncloud/ocis/glauth/pkg/command"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/urfave/cli/v2"
)
@@ -14,7 +15,7 @@ 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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -3,6 +3,7 @@ package command
import (
"github.com/owncloud/ocis/graph/pkg/command"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/urfave/cli/v2"
)
@@ -14,7 +15,7 @@ func GraphCommand(cfg *config.Config) *cli.Command {
Usage: "Start graph server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -3,6 +3,7 @@ package command
import (
"github.com/owncloud/ocis/graph-explorer/pkg/command"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/urfave/cli/v2"
)
@@ -14,7 +15,7 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command {
Usage: "Start graph-explorer server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -3,6 +3,7 @@ package command
import (
"github.com/owncloud/ocis/idp/pkg/command"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/urfave/cli/v2"
)
@@ -14,7 +15,7 @@ func IDPCommand(cfg *config.Config) *cli.Command {
Usage: "Start idp server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/ocs/pkg/command"
"github.com/urfave/cli/v2"
@@ -14,7 +15,7 @@ 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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/proxy/pkg/command"
"github.com/urfave/cli/v2"
@@ -14,7 +15,7 @@ func ProxyCommand(cfg *config.Config) *cli.Command {
Usage: "Start proxy server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -1,13 +1,11 @@
package command
import (
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/urfave/cli/v2"
)
@@ -19,11 +17,8 @@ func Execute() error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis",
Usage: "ownCloud Infinite Scale Stack",
Before: func(c *cli.Context) error {
// TODO: what do do?
//cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
})
@@ -41,33 +36,3 @@ func Execute() error {
return app.Run(os.Args)
}
// ParseConfig loads ocis configuration.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := config.BindSourcesToStructs("ocis", 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.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}

View File

@@ -2,6 +2,8 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/ocis/pkg/runtime"
"github.com/urfave/cli/v2"
@@ -14,14 +16,13 @@ func Server(cfg *config.Config) *cli.Command {
Usage: "Start fullstack server",
Category: "Fullstack",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
// what to do
//cfg.Commons = &shared.Commons{
// Log: &cfg.Log,
//}
cfg.Commons = &shared.Commons{
Log: cfg.Log,
}
r := runtime.New(cfg)
return r.Start()

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/settings/pkg/command"
"github.com/urfave/cli/v2"
@@ -14,7 +15,7 @@ func SettingsCommand(cfg *config.Config) *cli.Command {
Usage: "Start settings server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/store/pkg/command"
"github.com/urfave/cli/v2"
@@ -15,7 +16,7 @@ func StoreCommand(cfg *config.Config) *cli.Command {
Usage: "Start a go-micro store",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/thumbnails/pkg/command"
"github.com/urfave/cli/v2"
@@ -14,7 +15,7 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command {
Usage: "Start thumbnails server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,12 +2,13 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/web/pkg/command"
"github.com/urfave/cli/v2"
@@ -14,7 +15,7 @@ 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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package command
import (
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/parser"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/webdav/pkg/command"
"github.com/urfave/cli/v2"
@@ -15,7 +16,7 @@ func WebDAVCommand(cfg *config.Config) *cli.Command {
Usage: "Start webdav server",
Category: "Extensions",
Before: func(ctx *cli.Context) error {
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocs/pkg/config/parser"
"github.com/owncloud/ocis/ocs/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocs/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-ocs",
Usage: "Serve OCS API for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads idp configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the ocs command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -2,8 +2,8 @@ package command
import (
"context"
"strings"
"github.com/owncloud/ocis/ocs/pkg/config/parser"
"github.com/owncloud/ocis/ocs/pkg/logging"
"github.com/owncloud/ocis/ocs/pkg/tracing"
@@ -21,11 +21,7 @@ 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 err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,46 @@
package parser
import (
"errors"
"strings"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/proxy/pkg/config"
"github.com/owncloud/ocis/proxy/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-proxy",
Usage: "proxy for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -3,9 +3,7 @@ package command
import (
"context"
"crypto/tls"
"fmt"
"net/http"
"strings"
"time"
"github.com/coreos/go-oidc/v3/oidc"
@@ -14,11 +12,11 @@ import (
"github.com/justinas/alice"
"github.com/oklog/run"
acc "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/conversions"
"github.com/owncloud/ocis/ocis-pkg/log"
pkgmiddleware "github.com/owncloud/ocis/ocis-pkg/middleware"
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/proxy/pkg/config"
"github.com/owncloud/ocis/proxy/pkg/config/parser"
"github.com/owncloud/ocis/proxy/pkg/cs3"
"github.com/owncloud/ocis/proxy/pkg/logging"
"github.com/owncloud/ocis/proxy/pkg/metrics"
@@ -40,26 +38,9 @@ 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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}
if cfg.Policies == nil {
cfg.Policies = config.DefaultPolicies()
}
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
if len(ctx.StringSlice("presignedurl-allow-method")) > 0 {
cfg.PreSignedURL.AllowedHTTPMethods = ctx.StringSlice("presignedurl-allow-method")
}
if err := loadUserAgent(ctx, cfg); err != nil {
return err
}
return nil
},
Action: func(c *cli.Context) error {
@@ -218,7 +199,7 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config)
middleware.OIDCIss(cfg.OIDC.Issuer),
middleware.UserOIDCClaim(cfg.UserOIDCClaim),
middleware.UserCS3Claim(cfg.UserCS3Claim),
middleware.CredentialsByUserAgent(cfg.Reva.Middleware.Auth.CredentialsByUserAgent),
middleware.CredentialsByUserAgent(cfg.AuthMiddleware.CredentialsByUserAgent),
),
middleware.SignedURLAuth(
middleware.Logger(logger),
@@ -253,28 +234,3 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config)
),
)
}
// loadUserAgent reads the proxy-user-agent-lock-in, since it is a string flag, and attempts to construct a map of
// "user-agent":"challenge" locks in for Reva.
// Modifies cfg. Spaces don't need to be trimmed as urfavecli takes care of it. User agents with spaces are valid. i.e:
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:83.0) Gecko/20100101 Firefox/83.0
// This function works by relying in our format of specifying [user-agent:challenge] and the fact that the user agent
// might contain ":" (colon), so the original string is reversed, split in two parts, by the time it is split we
// have the indexes reversed and the tuple is in the format of [challenge:user-agent], then the same process is applied
// in reverse for each individual part
func loadUserAgent(c *cli.Context, cfg *config.Config) error {
cfg.Reva.Middleware.Auth.CredentialsByUserAgent = make(map[string]string)
locks := c.StringSlice("proxy-user-agent-lock-in")
for _, v := range locks {
vv := conversions.Reverse(v)
parts := strings.SplitN(vv, ":", 2)
if len(parts) != 2 {
return fmt.Errorf("unexpected config value for user-agent lock-in: %v, expected format is user-agent:challenge", v)
}
cfg.Reva.Middleware.Auth.CredentialsByUserAgent[conversions.Reverse(parts[1])] = conversions.Reverse(parts[0])
}
return nil
}

View File

@@ -18,11 +18,12 @@ type Config struct {
HTTP HTTP `ocisConfig:"http"`
Reva Reva `ocisConfig:"reva"`
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" env:"PROXY_ACCOUNT_BACKEND_TYPE"`
UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"`
@@ -31,6 +32,7 @@ type Config struct {
AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"`
EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"`
InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"`
AuthMiddleware AuthMiddleware `ocisConfig:"auth_middleware"`
Context context.Context
}
@@ -68,21 +70,9 @@ var (
RouteTypes = []RouteType{QueryRoute, RegexRoute, PrefixRoute}
)
// TODO: use reva config here
// Reva defines all available REVA configuration.
type Reva struct {
Address string `ocisConfig:"address" env:"REVA_GATEWAY"`
Middleware Middleware `ocisConfig:"middleware"`
}
// Middleware configures proxy middlewares.
type Middleware struct {
Auth Auth `ocisConfig:"middleware"`
}
// Auth configures proxy http auth middleware.
type Auth struct {
CredentialsByUserAgent map[string]string `ocisConfig:""`
// AuthMiddleware configures the proxy http auth middleware.
type AuthMiddleware struct {
CredentialsByUserAgent map[string]string `ocisConfig:"credentials_by_user_agent"`
}
// OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request

View File

@@ -0,0 +1,51 @@
package parser
import (
"errors"
"strings"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/proxy/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.Policies == nil {
cfg.Policies = config.DefaultPolicies()
}
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}

6
proxy/pkg/config/reva.go Normal file
View File

@@ -0,0 +1,6 @@
package config
// Reva defines all available REVA configuration.
type Reva struct {
Address string `ocisConfig:"address" env:"REVA_GATEWAY"`
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/settings/pkg/config"
"github.com/owncloud/ocis/settings/pkg/config/parser"
"github.com/owncloud/ocis/settings/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/settings/pkg/config"
"github.com/owncloud/ocis/settings/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-settings",
Usage: "Provide settings and permissions for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads idp configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -2,10 +2,10 @@ package command
import (
"context"
"strings"
"github.com/oklog/run"
"github.com/owncloud/ocis/settings/pkg/config"
"github.com/owncloud/ocis/settings/pkg/config/parser"
"github.com/owncloud/ocis/settings/pkg/logging"
"github.com/owncloud/ocis/settings/pkg/metrics"
"github.com/owncloud/ocis/settings/pkg/server/debug"
@@ -21,11 +21,7 @@ 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 err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,46 @@
package parser
import (
"errors"
"strings"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/settings/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/store/pkg/config"
"github.com/owncloud/ocis/store/pkg/config/parser"
"github.com/owncloud/ocis/store/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/store/pkg/config"
"github.com/owncloud/ocis/store/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-store",
Usage: "Service to store values for ocis extensions",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the store command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -3,14 +3,15 @@ package command
import (
"context"
"github.com/owncloud/ocis/store/pkg/logging"
"github.com/owncloud/ocis/store/pkg/tracing"
"github.com/oklog/run"
"github.com/owncloud/ocis/store/pkg/config"
"github.com/owncloud/ocis/store/pkg/config/parser"
"github.com/owncloud/ocis/store/pkg/logging"
"github.com/owncloud/ocis/store/pkg/metrics"
"github.com/owncloud/ocis/store/pkg/server/debug"
"github.com/owncloud/ocis/store/pkg/server/grpc"
"github.com/owncloud/ocis/store/pkg/tracing"
"github.com/urfave/cli/v2"
)
@@ -20,7 +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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,42 @@
package parser
import (
"errors"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/store/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/config/parser"
"github.com/owncloud/ocis/thumbnails/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "ocis-thumbnails",
Usage: "Example usage",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,35 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the thumbnails command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -6,6 +6,7 @@ import (
"github.com/oklog/run"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/config/parser"
"github.com/owncloud/ocis/thumbnails/pkg/logging"
"github.com/owncloud/ocis/thumbnails/pkg/metrics"
"github.com/owncloud/ocis/thumbnails/pkg/server/debug"
@@ -20,7 +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 {
if err := parser.ParseConfig(cfg); err != nil {
return err
}
return nil

View File

@@ -0,0 +1,42 @@
package parser
import (
"errors"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/thumbnails/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/web/pkg/config"
"github.com/owncloud/ocis/web/pkg/config/parser"
"github.com/owncloud/ocis/web/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/web/pkg/config"
"github.com/owncloud/ocis/web/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "web",
Usage: "Serve ownCloud Web for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,37 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
// TODO: remove cli.Context
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the web command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -8,6 +8,7 @@ import (
"github.com/oklog/run"
"github.com/owncloud/ocis/web/pkg/config"
"github.com/owncloud/ocis/web/pkg/config/parser"
"github.com/owncloud/ocis/web/pkg/logging"
"github.com/owncloud/ocis/web/pkg/metrics"
"github.com/owncloud/ocis/web/pkg/server/debug"
@@ -26,7 +27,7 @@ func Server(cfg *config.Config) *cli.Command {
cfg.HTTP.Root = strings.TrimRight(cfg.HTTP.Root, "/")
}
if err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -1,5 +1,7 @@
package config
import "github.com/owncloud/ocis/ocis-pkg/version"
func DefaultConfig() *Config {
return &Config{
Debug: Debug{
@@ -15,7 +17,8 @@ func DefaultConfig() *Config {
CacheTTL: 604800, // 7 days
},
Service: Service{
Name: "web",
Name: "web",
Version: version.String, // TODO: ensure everywhere or remove
},
Tracing: Tracing{
Enabled: false,

View File

@@ -0,0 +1,42 @@
package parser
import (
"errors"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/web/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
return nil
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/webdav/pkg/config"
"github.com/owncloud/ocis/webdav/pkg/config/parser"
"github.com/owncloud/ocis/webdav/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -15,7 +16,7 @@ func Health(cfg *config.Config) *cli.Command {
Name: "health",
Usage: "Check health status",
Before: func(c *cli.Context) error {
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

View File

@@ -2,14 +2,12 @@ package command
import (
"context"
"errors"
"os"
"github.com/owncloud/ocis/ocis-pkg/clihelper"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/webdav/pkg/config"
"github.com/owncloud/ocis/webdav/pkg/config/parser"
"github.com/thejerf/suture/v4"
"github.com/urfave/cli/v2"
)
@@ -33,12 +31,9 @@ func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "webdav",
Usage: "Serve WebDAV API for oCIS",
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
return parser.ParseConfig(cfg)
},
Commands: GetCommands(cfg),
})
@@ -50,36 +45,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// ParseConfig loads graph configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
return nil
}
// SutureService allows for the webdav command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
cfg *config.Config

View File

@@ -2,10 +2,10 @@ package command
import (
"context"
"strings"
"github.com/oklog/run"
"github.com/owncloud/ocis/webdav/pkg/config"
"github.com/owncloud/ocis/webdav/pkg/config/parser"
"github.com/owncloud/ocis/webdav/pkg/logging"
"github.com/owncloud/ocis/webdav/pkg/metrics"
"github.com/owncloud/ocis/webdav/pkg/server/debug"
@@ -20,11 +20,8 @@ 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 err := ParseConfig(ctx, cfg); err != nil {
if err := parser.ParseConfig(cfg); err != nil {
return err
}

View File

@@ -0,0 +1,46 @@
package parser
import (
"errors"
"strings"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/webdav/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
)
// ParseConfig loads accounts configuration from known paths.
func ParseConfig(cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, 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 = &config.Log{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Log == nil && cfg.Commons == nil {
cfg.Log = &config.Log{}
}
// load all env variables relevant to the config in the current context.
if err := envdecode.Decode(cfg); err != nil {
// no environment variable set for this config is an expected "error"
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
return err
}
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
}