mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-19 19:41:00 -05:00
move config parsing in separate package for each service
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user