make storage publiclink config similar to other services
This commit is contained in:
+35
-26
@@ -9,11 +9,12 @@ import (
|
||||
"github.com/cs3org/reva/v2/cmd/revad/runtime"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/extensions/storage/pkg/config"
|
||||
"github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config"
|
||||
"github.com/owncloud/ocis/extensions/storage/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/extensions/storage/pkg/tracing"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@@ -23,13 +24,19 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "storage-public-link",
|
||||
Usage: "start storage-public-link service",
|
||||
Before: func(c *cli.Context) error {
|
||||
return ParseConfig(c, cfg, "storage-public-link")
|
||||
},
|
||||
// Before: func(c *cli.Context) error {
|
||||
// return ParseConfig(c, cfg, "storage-public-link")
|
||||
// },
|
||||
Category: "extensions",
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
tracing.Configure(cfg, logger)
|
||||
logCfg := cfg.Logging
|
||||
logger := log.NewLogger(
|
||||
log.Level(logCfg.Level),
|
||||
log.File(logCfg.File),
|
||||
log.Pretty(logCfg.Pretty),
|
||||
log.Color(logCfg.Color),
|
||||
)
|
||||
tracing.Configure(cfg.Tracing.Enabled, cfg.Tracing.Type, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -54,10 +61,12 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
|
||||
|
||||
debugServer, err := debug.Server(
|
||||
debug.Name(c.Command.Name+"-debug"),
|
||||
debug.Addr(cfg.Reva.StoragePublicLink.DebugAddr),
|
||||
debug.Addr(cfg.Debug.Addr),
|
||||
debug.Logger(logger),
|
||||
debug.Context(ctx),
|
||||
debug.Config(cfg),
|
||||
debug.Pprof(cfg.Debug.Pprof),
|
||||
debug.Zpages(cfg.Debug.Zpages),
|
||||
debug.Token(cfg.Debug.Token),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@@ -69,7 +78,7 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
|
||||
cancel()
|
||||
})
|
||||
|
||||
if !cfg.Reva.StoragePublicLink.Supervised {
|
||||
if !cfg.Supervised {
|
||||
sync.Trap(&gr, cancel)
|
||||
}
|
||||
|
||||
@@ -82,33 +91,32 @@ func StoragePublicLink(cfg *config.Config) *cli.Command {
|
||||
func storagePublicLinkConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
|
||||
rcfg := map[string]interface{}{
|
||||
"core": map[string]interface{}{
|
||||
"max_cpus": cfg.Reva.StoragePublicLink.MaxCPUs,
|
||||
"tracing_enabled": cfg.Tracing.Enabled,
|
||||
"tracing_endpoint": cfg.Tracing.Endpoint,
|
||||
"tracing_collector": cfg.Tracing.Collector,
|
||||
"tracing_service_name": c.Command.Name,
|
||||
},
|
||||
"shared": map[string]interface{}{
|
||||
"jwt_secret": cfg.Reva.JWTSecret,
|
||||
"gatewaysvc": cfg.Reva.Gateway.Endpoint,
|
||||
"skip_user_groups_in_token": cfg.Reva.SkipUserGroupsInToken,
|
||||
"jwt_secret": cfg.JWTSecret,
|
||||
"gatewaysvc": cfg.GatewayEndpoint,
|
||||
"skip_user_groups_in_token": cfg.SkipUserGroupsInToken,
|
||||
},
|
||||
"grpc": map[string]interface{}{
|
||||
"network": cfg.Reva.StoragePublicLink.GRPCNetwork,
|
||||
"address": cfg.Reva.StoragePublicLink.GRPCAddr,
|
||||
"network": cfg.GRPC.Protocol,
|
||||
"address": cfg.GRPC.Addr,
|
||||
"interceptors": map[string]interface{}{
|
||||
"log": map[string]interface{}{},
|
||||
},
|
||||
"services": map[string]interface{}{
|
||||
"publicstorageprovider": map[string]interface{}{
|
||||
"mount_id": cfg.Reva.StoragePublicLink.MountID,
|
||||
"gateway_addr": cfg.Reva.Gateway.Endpoint,
|
||||
"mount_id": cfg.StorageProvider.MountID,
|
||||
"gateway_addr": cfg.StorageProvider.GatewayEndpoint,
|
||||
},
|
||||
"authprovider": map[string]interface{}{
|
||||
"auth_manager": "publicshares",
|
||||
"auth_managers": map[string]interface{}{
|
||||
"publicshares": map[string]interface{}{
|
||||
"gateway_addr": cfg.Reva.Gateway.Endpoint,
|
||||
"gateway_addr": cfg.AuthProvider.GatewayEndpoint,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -125,28 +133,29 @@ type StoragePublicLinkSutureService struct {
|
||||
|
||||
// NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService
|
||||
func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.Storage.Commons = cfg.Commons
|
||||
cfg.StoragePublicLink.Commons = cfg.Commons
|
||||
return StoragePublicLinkSutureService{
|
||||
cfg: cfg.Storage,
|
||||
cfg: cfg.StoragePublicLink,
|
||||
}
|
||||
}
|
||||
|
||||
func (s StoragePublicLinkSutureService) Serve(ctx context.Context) error {
|
||||
s.cfg.Reva.StoragePublicLink.Context = ctx
|
||||
// s.cfg.Reva.StoragePublicLink.Context = ctx
|
||||
cmd := StoragePublicLink(s.cfg)
|
||||
f := &flag.FlagSet{}
|
||||
cmdFlags := StoragePublicLink(s.cfg).Flags
|
||||
cmdFlags := cmd.Flags
|
||||
for k := range cmdFlags {
|
||||
if err := cmdFlags[k].Apply(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cliCtx := cli.NewContext(nil, f, nil)
|
||||
if StoragePublicLink(s.cfg).Before != nil {
|
||||
if err := StoragePublicLink(s.cfg).Before(cliCtx); err != nil {
|
||||
if cmd.Before != nil {
|
||||
if err := cmd.Before(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := StoragePublicLink(s.cfg).Action(cliCtx); err != nil {
|
||||
if err := cmd.Action(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
*shared.Commons `yaml:"-"`
|
||||
Service Service `yaml:"-"`
|
||||
Tracing *Tracing `yaml:"tracing"`
|
||||
Logging *Logging `yaml:"log"`
|
||||
Debug Debug `yaml:"debug"`
|
||||
Supervised bool
|
||||
|
||||
GRPC GRPCConfig `yaml:"grpc"`
|
||||
|
||||
Context context.Context
|
||||
JWTSecret string
|
||||
GatewayEndpoint string
|
||||
SkipUserGroupsInToken bool
|
||||
AuthProvider AuthProvider
|
||||
StorageProvider StorageProvider
|
||||
}
|
||||
type Tracing struct {
|
||||
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;STORAGE_METADATA_TRACING_ENABLED" desc:"Activates tracing."`
|
||||
Type string `yaml:"type" env:"OCIS_TRACING_TYPE;STORAGE_METADATA_TRACING_TYPE"`
|
||||
Endpoint string `yaml:"endpoint" env:"OCIS_TRACING_ENDPOINT;STORAGE_METADATA_TRACING_ENDPOINT" desc:"The endpoint to the tracing collector."`
|
||||
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;STORAGE_METADATA_TRACING_COLLECTOR"`
|
||||
}
|
||||
|
||||
type Logging struct {
|
||||
Level string `yaml:"level" env:"OCIS_LOG_LEVEL;STORAGE_METADATA_LOG_LEVEL" desc:"The log level."`
|
||||
Pretty bool `yaml:"pretty" env:"OCIS_LOG_PRETTY;STORAGE_METADATA_LOG_PRETTY" desc:"Activates pretty log output."`
|
||||
Color bool `yaml:"color" env:"OCIS_LOG_COLOR;STORAGE_METADATA_LOG_COLOR" desc:"Activates colorized log output."`
|
||||
File string `yaml:"file" env:"OCIS_LOG_FILE;STORAGE_METADATA_LOG_FILE" desc:"The target log file."`
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Name string `yaml:"-"`
|
||||
}
|
||||
|
||||
type Debug struct {
|
||||
Addr string `yaml:"addr" env:"STORAGE_METADATA_DEBUG_ADDR"`
|
||||
Token string `yaml:"token" env:"STORAGE_METADATA_DEBUG_TOKEN"`
|
||||
Pprof bool `yaml:"pprof" env:"STORAGE_METADATA_DEBUG_PPROF"`
|
||||
Zpages bool `yaml:"zpages" env:"STORAGE_METADATA_DEBUG_ZPAGES"`
|
||||
}
|
||||
|
||||
type GRPCConfig struct {
|
||||
Addr string `yaml:"addr" env:"STORAGE_METADATA_GRPC_ADDR" desc:"The address of the grpc service."`
|
||||
Protocol string `yaml:"protocol" env:"STORAGE_METADATA_GRPC_PROTOCOL" desc:"The transport protocol of the grpc service."`
|
||||
}
|
||||
|
||||
type AuthProvider struct {
|
||||
GatewayEndpoint string
|
||||
}
|
||||
|
||||
type StorageProvider struct {
|
||||
MountID string
|
||||
GatewayEndpoint string
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package defaults
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config"
|
||||
)
|
||||
|
||||
func FullDefaultConfig() *config.Config {
|
||||
cfg := DefaultConfig()
|
||||
|
||||
EnsureDefaults(cfg)
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func DefaultConfig() *config.Config {
|
||||
return &config.Config{
|
||||
Debug: config.Debug{
|
||||
Addr: "127.0.0.1:9179",
|
||||
Token: "",
|
||||
Pprof: false,
|
||||
Zpages: false,
|
||||
},
|
||||
GRPC: config.GRPCConfig{
|
||||
Addr: "127.0.0.1:9178",
|
||||
Protocol: "tcp",
|
||||
},
|
||||
Service: config.Service{
|
||||
Name: "storage-publiclink",
|
||||
},
|
||||
GatewayEndpoint: "127.0.0.1:9142",
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
AuthProvider: config.AuthProvider{
|
||||
GatewayEndpoint: "127.0.0.1:9142",
|
||||
},
|
||||
StorageProvider: config.StorageProvider{
|
||||
MountID: "7993447f-687f-490d-875c-ac95e89a62a4",
|
||||
GatewayEndpoint: "127.0.0.1:9142",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func EnsureDefaults(cfg *config.Config) {
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Logging == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Logging = &config.Logging{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Logging == nil {
|
||||
cfg.Logging = &config.Logging{}
|
||||
}
|
||||
// provide with defaults for shared tracing, since we need a valid destination address for BindEnv.
|
||||
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
|
||||
cfg.Tracing = &config.Tracing{
|
||||
Enabled: cfg.Commons.Tracing.Enabled,
|
||||
Type: cfg.Commons.Tracing.Type,
|
||||
Endpoint: cfg.Commons.Tracing.Endpoint,
|
||||
Collector: cfg.Commons.Tracing.Collector,
|
||||
}
|
||||
} else if cfg.Tracing == nil {
|
||||
cfg.Tracing = &config.Tracing{}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ func GetCommands(cfg *config.Config) cli.Commands {
|
||||
// AuthBearer(cfg),
|
||||
// AuthMachine(cfg),
|
||||
// Sharing(cfg),
|
||||
StoragePublicLink(cfg),
|
||||
// StoragePublicLink(cfg),
|
||||
StorageShares(cfg),
|
||||
StorageUsers(cfg),
|
||||
// StorageMetadata(cfg),
|
||||
|
||||
Reference in New Issue
Block a user