mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-25 21:48:28 -05:00
make storage users config similar to other services
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/cs3org/reva/v2/cmd/revad/runtime"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/extensions/storage-users/pkg/config"
|
||||
"github.com/owncloud/ocis/extensions/storage/pkg/server/debug"
|
||||
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"
|
||||
)
|
||||
|
||||
// StorageUsers is the entrypoint for the storage-users command.
|
||||
func StorageUsers(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "storage-users",
|
||||
Usage: "start storage-users service",
|
||||
// Before: func(c *cli.Context) error {
|
||||
// return ParseConfig(c, cfg, "storage-userprovider")
|
||||
// },
|
||||
Action: func(c *cli.Context) error {
|
||||
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()
|
||||
|
||||
uuid := uuid.Must(uuid.NewV4())
|
||||
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
||||
|
||||
rcfg := storageUsersConfigFromStruct(c, cfg)
|
||||
|
||||
gr.Add(func() error {
|
||||
runtime.RunWithOptions(
|
||||
rcfg,
|
||||
pidFile,
|
||||
runtime.WithLogger(&logger.Logger),
|
||||
)
|
||||
return nil
|
||||
}, func(_ error) {
|
||||
logger.Info().
|
||||
Str("server", c.Command.Name).
|
||||
Msg("Shutting down server")
|
||||
|
||||
cancel()
|
||||
})
|
||||
|
||||
debugServer, err := debug.Server(
|
||||
debug.Name(c.Command.Name+"-debug"),
|
||||
debug.Addr(cfg.Debug.Addr),
|
||||
debug.Logger(logger),
|
||||
debug.Context(ctx),
|
||||
debug.Pprof(cfg.Debug.Pprof),
|
||||
debug.Zpages(cfg.Debug.Zpages),
|
||||
debug.Token(cfg.Debug.Token),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
|
||||
return err
|
||||
}
|
||||
|
||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||
cancel()
|
||||
})
|
||||
|
||||
if !cfg.Supervised {
|
||||
sync.Trap(&gr, cancel)
|
||||
}
|
||||
|
||||
return gr.Run()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// storageUsersConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
||||
func storageUsersConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
|
||||
rcfg := map[string]interface{}{
|
||||
"core": map[string]interface{}{
|
||||
"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.JWTSecret,
|
||||
"gatewaysvc": cfg.GatewayEndpoint,
|
||||
"skip_user_groups_in_token": cfg.SkipUserGroupsInToken,
|
||||
},
|
||||
"grpc": map[string]interface{}{
|
||||
"network": cfg.GRPC.Protocol,
|
||||
"address": cfg.GRPC.Addr,
|
||||
// TODO build services dynamically
|
||||
"services": map[string]interface{}{
|
||||
"storageprovider": map[string]interface{}{
|
||||
"driver": cfg.Driver,
|
||||
"drivers": config.UserDrivers(cfg),
|
||||
"mount_id": cfg.MountID,
|
||||
"expose_data_server": cfg.ExposeDataServer,
|
||||
"data_server_url": cfg.DataServerURL,
|
||||
"tmp_folder": cfg.TempFolder,
|
||||
},
|
||||
},
|
||||
"interceptors": map[string]interface{}{
|
||||
"eventsmiddleware": map[string]interface{}{
|
||||
"group": "sharing",
|
||||
"type": "nats",
|
||||
"address": cfg.Events.Addr,
|
||||
"clusterID": cfg.Events.ClusterID,
|
||||
},
|
||||
},
|
||||
},
|
||||
"http": map[string]interface{}{
|
||||
"network": cfg.HTTP.Protocol,
|
||||
"address": cfg.HTTP.Addr,
|
||||
// TODO build services dynamically
|
||||
"services": map[string]interface{}{
|
||||
"dataprovider": map[string]interface{}{
|
||||
"prefix": cfg.HTTP.Prefix,
|
||||
"driver": cfg.Driver,
|
||||
"drivers": config.UserDrivers(cfg),
|
||||
"timeout": 86400,
|
||||
"insecure": cfg.DataProviderInsecure,
|
||||
"disable_tus": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if cfg.ReadOnly {
|
||||
gcfg := rcfg["grpc"].(map[string]interface{})
|
||||
gcfg["interceptors"] = map[string]interface{}{
|
||||
"readonly": map[string]interface{}{},
|
||||
}
|
||||
}
|
||||
return rcfg
|
||||
}
|
||||
|
||||
// StorageUsersSutureService allows for the storage-home command to be embedded and supervised by a suture supervisor tree.
|
||||
type StorageUsersSutureService struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewStorageUsersSutureService creates a new storage.StorageUsersSutureService
|
||||
func NewStorageUsers(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.StorageUsers.Commons = cfg.Commons
|
||||
return StorageUsersSutureService{
|
||||
cfg: cfg.StorageUsers,
|
||||
}
|
||||
}
|
||||
|
||||
func (s StorageUsersSutureService) Serve(ctx context.Context) error {
|
||||
// s.cfg.Reva.StorageUsers.Context = ctx
|
||||
cmd := StorageUsers(s.cfg)
|
||||
f := &flag.FlagSet{}
|
||||
cmdFlags := cmd.Flags
|
||||
for k := range cmdFlags {
|
||||
if err := cmdFlags[k].Apply(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cliCtx := cli.NewContext(nil, f, nil)
|
||||
if cmd.Before != nil {
|
||||
if err := cmd.Before(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := cmd.Action(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user