From 7e834c11d6536a4ff9949f567a8a0dd776e04864 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 15:18:35 +0100 Subject: [PATCH] add storage-auth-bearer --- ocis/pkg/runtime/runtime.go | 3 ++- storage/pkg/command/authbearer.go | 41 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 82fabf461e..96fe3a0245 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -49,7 +49,7 @@ var ( "storage-userprovider", // done "storage-groupprovider", // done "storage-auth-basic", // done - "storage-auth-bearer", + "storage-auth-bearer", // done "storage-home", "storage-users", "storage-public-link", @@ -132,6 +132,7 @@ func (r *Runtime) Start() error { addServiceToken("users", supervisor.Add(storage.NewUsersProviderService(globalCtx, r.c.Storage))) addServiceToken("groupsprovider", supervisor.Add(storage.NewGroupsProvider(globalCtx, r.c.Storage))) // TODO(refs) panic? are we sending to a nil / closed channel? addServiceToken("authbasic", supervisor.Add(storage.NewAuthBasic(globalCtx, r.c.Storage))) + addServiceToken("authbearer", supervisor.Add(storage.NewAuthBearer(globalCtx, r.c.Storage))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/storage/pkg/command/authbearer.go b/storage/pkg/command/authbearer.go index 6d44eef27d..2398892cbc 100644 --- a/storage/pkg/command/authbearer.go +++ b/storage/pkg/command/authbearer.go @@ -2,6 +2,7 @@ package command import ( "context" + "flag" "os" "os/signal" "path" @@ -178,3 +179,43 @@ func AuthBearer(cfg *config.Config) *cli.Command { }, } } + +// AuthBearerSutureService allows for the storage-gateway command to be embedded and supervised by a suture supervisor tree. +type AuthBearerSutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewAuthBearerSutureService creates a new gateway.AuthBearerSutureService +func NewAuthBearer(ctx context.Context, cfg *config.Config) AuthBearerSutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx + return AuthBearerSutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s AuthBearerSutureService) Serve() { + f := &flag.FlagSet{} + for k := range AuthBearer(s.cfg).Flags { + if err := AuthBearer(s.cfg).Flags[k].Apply(f); err != nil { + return + } + } + ctx := cli.NewContext(nil, f, nil) + if AuthBearer(s.cfg).Before != nil { + if err := AuthBearer(s.cfg).Before(ctx); err != nil { + return + } + } + if err := AuthBearer(s.cfg).Action(ctx); err != nil { + return + } +} + +func (s AuthBearerSutureService) Stop() { + s.cancel() +}