Skip to content

Commit

Permalink
Merge pull request #842 from owncloud/ocis-root-config
Browse files Browse the repository at this point in the history
Ocis root config
  • Loading branch information
kulmann authored Nov 11, 2020
2 parents dc61b11 + 295b945 commit f19acad
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 32 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/ocis-root-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Change: Move ocis default config to root level

Tags: ocis

We moved the tracing config to the `root` flagset so that they are parsed on all commands. We also introduced a `JWTSecret` flag in the root flagset, in order to apply a common default JWTSecret to all services that have one.

https://github.com/owncloud/ocis/pull/842
7 changes: 7 additions & 0 deletions ocis/pkg/command/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func configureAccounts(cfg *config.Config) *svcconfig.Config {
cfg.Accounts.Log.Color = cfg.Log.Color
cfg.Accounts.Server.Version = version.String

// TODO: we need tracing on the accounts service as well. when we have it, apply default config from OCIS here.

if cfg.TokenManager.JWTSecret != "" {
cfg.Accounts.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret
cfg.Accounts.Repo.CS3.JWTSecret = cfg.TokenManager.JWTSecret
}

return cfg.Accounts
}

Expand Down
9 changes: 6 additions & 3 deletions ocis/pkg/command/ocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package command

import (
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis/pkg/config"
"github.com/owncloud/ocis/ocis/pkg/register"
"github.com/owncloud/ocis/ocis/pkg/version"
"github.com/owncloud/ocis/ocs/pkg/command"
svcconfig "github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocs/pkg/flagset"
"github.com/owncloud/ocis/ocis/pkg/config"
"github.com/owncloud/ocis/ocis/pkg/register"
)

// OCSCommand is the entrypoint for the ocs command.
Expand Down Expand Up @@ -48,10 +48,13 @@ func configureOCS(cfg *config.Config) *svcconfig.Config {
cfg.OCS.Tracing.Service = cfg.Tracing.Service
}

if cfg.TokenManager.JWTSecret != "" {
cfg.OCS.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret
}

return cfg.OCS
}

func init() {
register.AddCommand(OCSCommand)
}

4 changes: 2 additions & 2 deletions ocis/pkg/command/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func configureProxy(cfg *config.Config) *svcconfig.Config {
cfg.Proxy.Tracing.Service = cfg.Tracing.Service
}

if cfg.Storage.Reva.JWTSecret != "" {
cfg.Proxy.TokenManager.JWTSecret = cfg.Storage.Reva.JWTSecret
if cfg.TokenManager.JWTSecret != "" {
cfg.Proxy.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret
}

return cfg.Proxy
Expand Down
4 changes: 2 additions & 2 deletions ocis/pkg/command/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func configureSettings(cfg *config.Config) *svcconfig.Config {
cfg.Settings.Tracing.Service = cfg.Tracing.Service
}

if cfg.Storage.Reva.JWTSecret != "" {
cfg.Settings.TokenManager.JWTSecret = cfg.Storage.Reva.JWTSecret
if cfg.TokenManager.JWTSecret != "" {
cfg.Settings.TokenManager.JWTSecret = cfg.TokenManager.JWTSecret
}

return cfg.Settings
Expand Down
18 changes: 12 additions & 6 deletions ocis/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ type Tracing struct {
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 {
File string
Log Log
Debug Debug
HTTP HTTP
GRPC GRPC
Tracing Tracing
File string
Log Log
Debug Debug
HTTP HTTP
GRPC GRPC
Tracing Tracing
TokenManager TokenManager

Accounts *accounts.Config
Graph *graph.Config
Expand Down
45 changes: 26 additions & 19 deletions ocis/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
}
}

// HealthWithConfig applies cfg to the root flagset
func HealthWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "debug-addr",
Value: "0.0.0.0:9010",
Usage: "Address to debug endpoint",
EnvVars: []string{"OCIS_DEBUG_ADDR"},
Destination: &cfg.Debug.Addr,
},
}
}

// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",
Expand Down Expand Up @@ -89,6 +70,32 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
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,
},
}
}

// HealthWithConfig applies cfg to the root flagset
func HealthWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "debug-addr",
Value: "0.0.0.0:9010",
Usage: "Address to debug endpoint",
EnvVars: []string{"OCIS_DEBUG_ADDR"},
Destination: &cfg.Debug.Addr,
},
}
}

// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "debug-addr",
Value: "0.0.0.0:9010",
Expand Down

0 comments on commit f19acad

Please sign in to comment.