mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-03 19:00:05 -06:00
185 lines
4.8 KiB
Go
185 lines
4.8 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/cs3org/reva/cmd/revad/runtime"
|
|
"github.com/gofrs/uuid"
|
|
"github.com/micro/cli/v2"
|
|
"github.com/oklog/run"
|
|
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
|
"github.com/owncloud/ocis/ocis-pkg/sync"
|
|
"github.com/owncloud/ocis/storage/pkg/config"
|
|
"github.com/owncloud/ocis/storage/pkg/flagset"
|
|
"github.com/owncloud/ocis/storage/pkg/server/debug"
|
|
"github.com/thejerf/suture/v4"
|
|
)
|
|
|
|
// StoragePublicLink is the entrypoint for the reva-storage-public-link command.
|
|
func StoragePublicLink(cfg *config.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "storage-public-link",
|
|
Usage: "Start storage-public-link service",
|
|
Flags: flagset.StoragePublicLink(cfg),
|
|
Category: "Extensions",
|
|
Action: func(c *cli.Context) error {
|
|
logger := NewLogger(cfg)
|
|
|
|
if cfg.Tracing.Enabled {
|
|
switch t := cfg.Tracing.Type; t {
|
|
case "agent":
|
|
logger.Error().
|
|
Str("type", t).
|
|
Msg("Reva only supports the jaeger tracing backend")
|
|
|
|
case "jaeger":
|
|
logger.Info().
|
|
Str("type", t).
|
|
Msg("configuring storage to use the jaeger tracing backend")
|
|
|
|
case "zipkin":
|
|
logger.Error().
|
|
Str("type", t).
|
|
Msg("Reva only supports the jaeger tracing backend")
|
|
|
|
default:
|
|
logger.Warn().
|
|
Str("type", t).
|
|
Msg("Unknown tracing backend")
|
|
}
|
|
|
|
} else {
|
|
logger.Debug().
|
|
Msg("Tracing is not enabled")
|
|
}
|
|
|
|
var (
|
|
gr = run.Group{}
|
|
ctx, cancel = context.WithCancel(context.Background())
|
|
//metrics = metrics.New()
|
|
)
|
|
|
|
defer cancel()
|
|
|
|
{
|
|
uuid := uuid.Must(uuid.NewV4())
|
|
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
|
|
|
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,
|
|
},
|
|
"grpc": map[string]interface{}{
|
|
"network": cfg.Reva.StoragePublicLink.GRPCNetwork,
|
|
"address": cfg.Reva.StoragePublicLink.GRPCAddr,
|
|
"interceptors": map[string]interface{}{
|
|
"log": map[string]interface{}{},
|
|
},
|
|
"services": map[string]interface{}{
|
|
"publicstorageprovider": map[string]interface{}{
|
|
"mount_path": cfg.Reva.StoragePublicLink.MountPath,
|
|
"gateway_addr": cfg.Reva.Gateway.Endpoint,
|
|
},
|
|
"authprovider": map[string]interface{}{
|
|
"auth_manager": "publicshares",
|
|
"auth_managers": map[string]interface{}{
|
|
"publicshares": map[string]interface{}{
|
|
"gateway_addr": cfg.Reva.Gateway.Endpoint,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
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()
|
|
})
|
|
}
|
|
|
|
{
|
|
server, err := debug.Server(
|
|
debug.Name(c.Command.Name+"-debug"),
|
|
debug.Addr(cfg.Reva.StoragePublicLink.DebugAddr),
|
|
debug.Logger(logger),
|
|
debug.Context(ctx),
|
|
debug.Config(cfg),
|
|
)
|
|
|
|
if err != nil {
|
|
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
|
|
return err
|
|
}
|
|
|
|
gr.Add(server.ListenAndServe, func(_ error) {
|
|
cancel()
|
|
})
|
|
}
|
|
|
|
if !cfg.Reva.StorageMetadata.Supervised {
|
|
sync.Trap(&gr, cancel)
|
|
}
|
|
|
|
return gr.Run()
|
|
},
|
|
}
|
|
}
|
|
|
|
// StoragePublicLinkSutureService allows for the storage-public-link command to be embedded and supervised by a suture supervisor tree.
|
|
type StoragePublicLinkSutureService struct {
|
|
cfg *config.Config
|
|
}
|
|
|
|
// NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService
|
|
func NewStoragePublicLink(cfg *ociscfg.Config) suture.Service {
|
|
if cfg.Mode == 0 {
|
|
cfg.Storage.Reva.StoragePublicLink.Supervised = true
|
|
}
|
|
return StoragePublicLinkSutureService{
|
|
cfg: cfg.Storage,
|
|
}
|
|
}
|
|
|
|
func (s StoragePublicLinkSutureService) Serve(ctx context.Context) error {
|
|
s.cfg.Reva.StoragePublicLink.Context = ctx
|
|
f := &flag.FlagSet{}
|
|
for k := range StoragePublicLink(s.cfg).Flags {
|
|
if err := StoragePublicLink(s.cfg).Flags[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 {
|
|
return err
|
|
}
|
|
}
|
|
if err := StoragePublicLink(s.cfg).Action(cliCtx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|