load reva gateway and token manager from common config

This commit is contained in:
Willy Kloucek
2022-04-27 13:58:59 +02:00
parent 48a6978e24
commit 9095b11d6c
86 changed files with 1209 additions and 250 deletions
+8 -4
View File
@@ -15,6 +15,7 @@ import (
"github.com/gofrs/uuid"
"github.com/oklog/run"
"github.com/owncloud/ocis/extensions/sharing/pkg/config"
"github.com/owncloud/ocis/extensions/sharing/pkg/config/parser"
"github.com/owncloud/ocis/extensions/storage/pkg/server/debug"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/thejerf/suture/v4"
@@ -26,6 +27,9 @@ func Sharing(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "sharing",
Usage: "start sharing service",
Before: func(ctx *cli.Context) error {
return parser.ParseConfig(cfg)
},
Action: func(c *cli.Context) error {
logCfg := cfg.Logging
logger := log.NewLogger(
@@ -109,8 +113,8 @@ func sharingConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
"tracing_service_name": c.Command.Name,
},
"shared": map[string]interface{}{
"jwt_secret": cfg.JWTSecret,
"gatewaysvc": cfg.GatewayEndpoint,
"jwt_secret": cfg.TokenManager.JWTSecret,
"gatewaysvc": cfg.Reva.Address,
"skip_user_groups_in_token": cfg.SkipUserGroupsInToken,
},
"grpc": map[string]interface{}{
@@ -123,7 +127,7 @@ func sharingConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
"drivers": map[string]interface{}{
"json": map[string]interface{}{
"file": cfg.UserSharingDrivers.JSON.File,
"gateway_addr": cfg.GatewayEndpoint,
"gateway_addr": cfg.Reva.Address,
},
"sql": map[string]interface{}{ // cernbox sql
"db_username": cfg.UserSharingDrivers.SQL.DBUsername,
@@ -156,7 +160,7 @@ func sharingConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]inte
"drivers": map[string]interface{}{
"json": map[string]interface{}{
"file": cfg.PublicSharingDrivers.JSON.File,
"gateway_addr": cfg.GatewayEndpoint,
"gateway_addr": cfg.Reva.Address,
},
"sql": map[string]interface{}{
"db_username": cfg.PublicSharingDrivers.SQL.DBUsername,
+3 -2
View File
@@ -12,8 +12,9 @@ type Config struct {
GRPC GRPCConfig `yaml:"grpc,omitempty"`
JWTSecret string `yaml:"jwt_secret,omitempty"`
GatewayEndpoint string `yaml:"gateway_endpoint,omitempty"`
TokenManager *TokenManager `yaml:"token_manager,omitempty"`
Reva *Reva `yaml:"reva,omitempty"`
SkipUserGroupsInToken bool `yaml:"skip_user_groups_in_token,omitempty"`
UserSharingDriver string `yaml:"user_sharing_driver,omitempty"`
UserSharingDrivers UserSharingDrivers `yaml:"user_sharin_drivers,omitempty"`
@@ -30,8 +30,9 @@ func DefaultConfig() *config.Config {
Service: config.Service{
Name: "sharing",
},
GatewayEndpoint: "127.0.0.1:9142",
JWTSecret: "Pive-Fumkiu4",
Reva: &config.Reva{
Address: "127.0.0.1:9142",
},
UserSharingDriver: "json",
UserSharingDrivers: config.UserSharingDrivers{
JSON: config.UserSharingJSONDriver{
@@ -104,6 +105,22 @@ func EnsureDefaults(cfg *config.Config) {
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}
if cfg.Reva == nil && cfg.Commons != nil && cfg.Commons.Reva != nil {
cfg.Reva = &config.Reva{
Address: cfg.Commons.Reva.Address,
}
} else if cfg.Reva == nil {
cfg.Reva = &config.Reva{}
}
if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &config.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else if cfg.TokenManager == nil {
cfg.TokenManager = &config.TokenManager{}
}
}
func Sanitize(cfg *config.Config) {
@@ -0,0 +1,33 @@
package parser
import (
"errors"
"github.com/owncloud/ocis/extensions/sharing/pkg/config"
"github.com/owncloud/ocis/extensions/sharing/pkg/config/defaults"
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
}
defaults.EnsureDefaults(cfg)
// 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
}
}
defaults.Sanitize(cfg)
return nil
}
+11
View File
@@ -0,0 +1,11 @@
package config
// Reva defines all available REVA configuration.
type Reva struct {
Address string `yaml:"address" env:"REVA_GATEWAY"`
}
// TokenManager is the config for using the reva token manager
type TokenManager struct {
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET;OCS_JWT_SECRET"`
}