Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure a linebreak after config validation errors and do not parse config for help #4405

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-help-config-newline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Show help for some commands when unconfigured

We've fixed some commands to show the help also when oCIS is not yet configured.
Previously the help was not displayed to the user but instead a configuration validation error.

https://github.com/owncloud/ocis/pull/4405
30 changes: 30 additions & 0 deletions ocis-pkg/config/configlog/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package configlog

import (
"fmt"
"os"
)

// Error logs the error
func Error(err error) {
if err != nil {
fmt.Printf("%v\n", err)
}
}

// ReturnError logs the error and returns it unchanged
func ReturnError(err error) error {
if err != nil {
fmt.Printf("%v\n", err)
}
return err
}

// ReturnFatal logs the error and calls os.Exit(1) and returns nil if no error is passed
func ReturnFatal(err error) error {
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
return nil
}
7 changes: 2 additions & 5 deletions ocis/pkg/command/app-provider.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func AppProviderCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.AppProvider.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.AppProvider.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/app-registry.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func AppRegistryCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.AppRegistry.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.AppRegistry.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/audit.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func AuditCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.Audit.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.Audit.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/auth-basic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func AuthBasicCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.AuthBasic.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.AuthBasic.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/auth-bearer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func AuthBearerCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.AuthBearer.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.AuthBearer.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/auth-machine.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func AuthMachineCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.AuthMachine.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.AuthMachine.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/frontend.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func FrontendCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.Frontend.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.Frontend.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/gateway.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func GatewayCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.Gateway.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.Gateway.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/graph-explorer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.GraphExplorer.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.GraphExplorer.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/graph.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func GraphCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.Graph.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.Graph.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/groups.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func GroupsCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.Groups.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.Groups.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/idm.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func IDMCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.IDM.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.IDM.Commons = cfg.Commons
return nil
},
Expand Down
7 changes: 2 additions & 5 deletions ocis/pkg/command/idp.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
Expand All @@ -18,9 +17,7 @@ func IDPCommand(cfg *config.Config) *cli.Command {
Usage: helper.SubcommandDescription(cfg.IDP.Service.Name),
Category: "services",
Before: func(c *cli.Context) error {
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
}
configlog.Error(parser.ParseConfig(cfg, true))
cfg.IDP.Commons = cfg.Commons
return nil
},
Expand Down
37 changes: 21 additions & 16 deletions ocis/pkg/command/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"fmt"
"os"
"sync"

Expand All @@ -13,6 +12,7 @@ import (
"github.com/cs3org/reva/v2/pkg/share/manager/registry"

"github.com/owncloud/ocis/v2/ocis-pkg/config"
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog"
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser"
"github.com/owncloud/ocis/v2/ocis/pkg/register"
sharing "github.com/owncloud/ocis/v2/services/sharing/pkg/config"
Expand All @@ -27,21 +27,6 @@ func Migrate(cfg *config.Config) *cli.Command {
Name: "migrate",
Usage: "migrate data from an existing to another instance",
Category: "migration",
Before: func(c *cli.Context) error {
// Parse base config
if err := parser.ParseConfig(cfg, true); err != nil {
fmt.Printf("%v", err)
return err
}

// Parse sharing config
cfg.Sharing.Commons = cfg.Commons
if err := sharingparser.ParseConfig(cfg.Sharing); err != nil {
fmt.Printf("%v", err)
return err
}
return nil
},
Subcommands: []*cli.Command{
MigrateShares(cfg),
MigratePublicShares(cfg),
Expand Down Expand Up @@ -69,6 +54,16 @@ func MigrateShares(cfg *config.Config) *cli.Command {
Usage: "Share manager to import the data into",
},
},
Before: func(c *cli.Context) error {
// Parse base config
if err := parser.ParseConfig(cfg, true); err != nil {
return configlog.ReturnError(err)
}

// Parse sharing config
cfg.Sharing.Commons = cfg.Commons
return configlog.ReturnError(sharingparser.ParseConfig(cfg.Sharing))
},
Action: func(c *cli.Context) error {
log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger()
ctx := log.WithContext(context.Background())
Expand Down Expand Up @@ -154,6 +149,16 @@ func MigratePublicShares(cfg *config.Config) *cli.Command {
Usage: "Public share manager to import the data into",
},
},
Before: func(c *cli.Context) error {
// Parse base config
if err := parser.ParseConfig(cfg, true); err != nil {
return configlog.ReturnError(err)
}

// Parse sharing config
cfg.Sharing.Commons = cfg.Commons
return configlog.ReturnError(sharingparser.ParseConfig(cfg.Sharing))
},
Action: func(c *cli.Context) error {
log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger()
ctx := log.WithContext(context.Background())
Expand Down
Loading