diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 1ed8b7e840..39633d0e2a 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -130,6 +130,7 @@ func (r *Runtime) Start() error { addServiceToken("frontend", supervisor.Add(storage.NewFrontend(globalCtx, r.c.Storage))) addServiceToken("gateway", supervisor.Add(storage.NewGateway(globalCtx, r.c.Storage))) addServiceToken("users", supervisor.Add(storage.NewUsersProviderService(globalCtx, r.c.Storage))) + addServiceToken("groups-provider", supervisor.Add(storage.NewGroupsProvider(globalCtx, r.c.Storage))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/storage/pkg/command/groups.go b/storage/pkg/command/groups.go index 89d4c7fc87..dcde2f8830 100644 --- a/storage/pkg/command/groups.go +++ b/storage/pkg/command/groups.go @@ -2,6 +2,7 @@ package command import ( "context" + "flag" "os" "os/signal" "path" @@ -204,3 +205,43 @@ func Groups(cfg *config.Config) *cli.Command { }, } } + +// GroupsProvider allows for the storage-groupsprovider command to be embedded and supervised by a suture supervisor tree. +type GroupsProvider struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewGroupsProvider creates a new storage.GroupsProvider +func NewGroupsProvider(ctx context.Context, cfg *config.Config) GroupsProvider { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx + return GroupsProvider{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s GroupsProvider) Serve() { + f := &flag.FlagSet{} + for k := range Groups(s.cfg).Flags { + if err := Groups(s.cfg).Flags[k].Apply(f); err != nil { + return + } + } + ctx := cli.NewContext(nil, f, nil) + if Groups(s.cfg).Before != nil { + if err := Groups(s.cfg).Before(ctx); err != nil { + return + } + } + if err := Groups(s.cfg).Action(ctx); err != nil { + return + } +} + +func (s GroupsProvider) Stop() { + s.cancel() +} diff --git a/storage/pkg/command/users.go b/storage/pkg/command/users.go index bad94a4c8f..67004ac80a 100644 --- a/storage/pkg/command/users.go +++ b/storage/pkg/command/users.go @@ -214,7 +214,7 @@ type UsersProviderService struct { cfg *config.Config } -// NewUsersProviderService creates a new gateway.UsersProviderService +// NewUsersProviderService creates a new storage.UsersProviderService func NewUsersProviderService(ctx context.Context, cfg *config.Config) UsersProviderService { sctx, cancel := context.WithCancel(ctx) cfg.Context = sctx