From f2660dd608e1e6e1e610ba931f93cb7f901b4d5c Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 15:28:21 +0100 Subject: [PATCH] add storage-sharing --- ocis/pkg/runtime/runtime.go | 9 ++++---- storage/pkg/command/sharing.go | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 4734bed150..442d487a24 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -52,10 +52,10 @@ var ( "storage-auth-bearer", // done "storage-home", // done "storage-users", // done - "storage-public-link", - "thumbnails", // done - "web", // done - "webdav", // done + "storage-public-link", // done + "thumbnails", // done + "web", // done + "webdav", // done } dependants = []string{ @@ -136,6 +136,7 @@ func (r *Runtime) Start() error { addServiceToken("storage-home", supervisor.Add(storage.NewStorageHome(globalCtx, r.c.Storage))) addServiceToken("storage-users", supervisor.Add(storage.NewStorageUsers(globalCtx, r.c.Storage))) addServiceToken("storage-public-link", supervisor.Add(storage.NewStoragePublicLink(globalCtx, r.c.Storage))) + addServiceToken("storage-sharing", supervisor.Add(storage.NewSharing(globalCtx, r.c.Storage))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/storage/pkg/command/sharing.go b/storage/pkg/command/sharing.go index e53a1baa54..b0b6c8de69 100644 --- a/storage/pkg/command/sharing.go +++ b/storage/pkg/command/sharing.go @@ -2,6 +2,7 @@ package command import ( "context" + "flag" "os" "os/signal" "path" @@ -188,3 +189,43 @@ func Sharing(cfg *config.Config) *cli.Command { }, } } + +// SharingSutureService allows for the storage-sharing command to be embedded and supervised by a suture supervisor tree. +type SharingSutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewSharingSutureService creates a new store.SharingSutureService +func NewSharing(ctx context.Context, cfg *config.Config) SharingSutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx + return SharingSutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s SharingSutureService) Serve() { + f := &flag.FlagSet{} + for k := range Sharing(s.cfg).Flags { + if err := Sharing(s.cfg).Flags[k].Apply(f); err != nil { + return + } + } + ctx := cli.NewContext(nil, f, nil) + if Sharing(s.cfg).Before != nil { + if err := Sharing(s.cfg).Before(ctx); err != nil { + return + } + } + if err := Sharing(s.cfg).Action(ctx); err != nil { + return + } +} + +func (s SharingSutureService) Stop() { + s.cancel() +}