From 08e3eea6b7ea15467aaa6daf8c542719e7dee04b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 13:04:37 +0100 Subject: [PATCH] add glauth --- glauth/cmd/glauth/main.go | 3 ++- glauth/pkg/command/root.go | 33 ++++++++++++++++++++++++++++++--- glauth/pkg/config/config.go | 4 ++++ glauth/pkg/flagset/flagset.go | 6 +++--- ocis/pkg/runtime/runtime.go | 3 +++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/glauth/cmd/glauth/main.go b/glauth/cmd/glauth/main.go index 7aaf51c22a..f2abd5e20a 100644 --- a/glauth/cmd/glauth/main.go +++ b/glauth/cmd/glauth/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/glauth/pkg/command" + "github.com/owncloud/ocis/glauth/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index bccefd6d68..6d7283bc45 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -1,6 +1,7 @@ package command import ( + "context" "os" "strings" @@ -13,9 +14,7 @@ import ( ) // Execute is the entry point for the ocis-glauth command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "ocis-glauth", Version: version.String, @@ -107,3 +106,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } + +// SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree. +type SutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewSutureService creates a new settings.SutureService +func NewSutureService(ctx context.Context, cfg *config.Config) SutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx // propagate the context down to the go-micro services. + return SutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s SutureService) Serve() { + if err := Execute(s.cfg); err != nil { + return + } +} + +func (s SutureService) Stop() { + s.cancel() +} diff --git a/glauth/pkg/config/config.go b/glauth/pkg/config/config.go index 12576b75cc..0a40458b5c 100644 --- a/glauth/pkg/config/config.go +++ b/glauth/pkg/config/config.go @@ -1,5 +1,7 @@ package config +import "context" + // Log defines the available logging configuration. type Log struct { Level string @@ -69,6 +71,8 @@ type Config struct { Fallback Backend Version string RoleBundleUUID string + + Context context.Context } // New initializes a new configuration with or without defaults. diff --git a/glauth/pkg/flagset/flagset.go b/glauth/pkg/flagset/flagset.go index 573c68e031..e5d79e97bb 100644 --- a/glauth/pkg/flagset/flagset.go +++ b/glauth/pkg/flagset/flagset.go @@ -12,21 +12,21 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { Name: "log-level", Value: "info", Usage: "Set logging level", - EnvVars: []string{"GLAUTH_LOG_LEVEL"}, + EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Value: true, Name: "log-pretty", Usage: "Enable pretty logging", - EnvVars: []string{"GLAUTH_LOG_PRETTY"}, + EnvVars: []string{"GLAUTH_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Value: true, Name: "log-color", Usage: "Enable colored logging", - EnvVars: []string{"GLAUTH_LOG_COLOR"}, + EnvVars: []string{"GLAUTH_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, } diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 8c7dc9adfc..98108c3d13 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -6,6 +6,7 @@ import ( "os/signal" accounts "github.com/owncloud/ocis/accounts/pkg/command" + glauth "github.com/owncloud/ocis/glauth/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" "github.com/thejerf/suture" @@ -110,7 +111,9 @@ func (r *Runtime) Start() error { addServiceToken("settings", supervisor.Add(settings.NewSutureService(globalCtx, r.c.Settings))) addServiceToken("storagemetadata", supervisor.Add(storage.NewStorageMetadata(globalCtx, r.c.Storage))) addServiceToken("accounts", supervisor.Add(accounts.NewSutureService(globalCtx, r.c.Accounts))) + addServiceToken("glauth", supervisor.Add(glauth.NewSutureService(globalCtx, r.c.GLAuth))) + // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() select {