From 01b507c4dcce10cc7f9238e188593ae42de09f80 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 15:25:21 +0100 Subject: [PATCH] add storage-public-link --- ocis/pkg/runtime/runtime.go | 3 +- storage/pkg/command/storagepubliclink.go | 41 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 4d39843c23..4734bed150 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -51,7 +51,7 @@ var ( "storage-auth-basic", // done "storage-auth-bearer", // done "storage-home", // done - "storage-users", + "storage-users", // done "storage-public-link", "thumbnails", // done "web", // done @@ -135,6 +135,7 @@ func (r *Runtime) Start() error { addServiceToken("authbearer", supervisor.Add(storage.NewAuthBearer(globalCtx, r.c.Storage))) 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))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/storage/pkg/command/storagepubliclink.go b/storage/pkg/command/storagepubliclink.go index badbc24535..8b17da98eb 100644 --- a/storage/pkg/command/storagepubliclink.go +++ b/storage/pkg/command/storagepubliclink.go @@ -2,6 +2,7 @@ package command import ( "context" + "flag" "os" "os/signal" "path" @@ -175,3 +176,43 @@ func StoragePublicLink(cfg *config.Config) *cli.Command { }, } } + +// StoragePublicLinkSutureService allows for the storage-public-link command to be embedded and supervised by a suture supervisor tree. +type StoragePublicLinkSutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewStoragePublicLinkSutureService creates a new storage.StoragePublicLinkSutureService +func NewStoragePublicLink(ctx context.Context, cfg *config.Config) StoragePublicLinkSutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx + return StoragePublicLinkSutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s StoragePublicLinkSutureService) Serve() { + f := &flag.FlagSet{} + for k := range StoragePublicLink(s.cfg).Flags { + if err := StoragePublicLink(s.cfg).Flags[k].Apply(f); err != nil { + return + } + } + ctx := cli.NewContext(nil, f, nil) + if StoragePublicLink(s.cfg).Before != nil { + if err := StoragePublicLink(s.cfg).Before(ctx); err != nil { + return + } + } + if err := StoragePublicLink(s.cfg).Action(ctx); err != nil { + return + } +} + +func (s StoragePublicLinkSutureService) Stop() { + s.cancel() +}