From 7eea714633a29b956b2aba77dbe5410f122fc580 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 13:10:18 +0100 Subject: [PATCH] add idp --- accounts/pkg/command/root.go | 4 ++-- accounts/pkg/flagset/flagset.go | 3 --- glauth/pkg/command/root.go | 4 ++-- idp/cmd/idp/main.go | 3 ++- idp/pkg/command/root.go | 33 ++++++++++++++++++++++++++++++--- idp/pkg/config/config.go | 4 ++++ idp/pkg/flagset/flagset.go | 9 +++------ ocis/pkg/runtime/runtime.go | 5 ++++- 8 files changed, 47 insertions(+), 18 deletions(-) diff --git a/accounts/pkg/command/root.go b/accounts/pkg/command/root.go index ae56aa388..6f64a6605 100644 --- a/accounts/pkg/command/root.go +++ b/accounts/pkg/command/root.go @@ -119,14 +119,14 @@ 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. +// SutureService allows for the accounts 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 +// NewSutureService creates a new accounts.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. diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 8c984204c..e5abc5410 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -11,20 +11,17 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", EnvVars: []string{"ACCOUNTS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ - Value: true, Name: "log-pretty", Usage: "Enable pretty logging", EnvVars: []string{"ACCOUNTS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ - Value: true, Name: "log-color", Usage: "Enable colored logging", EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"}, diff --git a/glauth/pkg/command/root.go b/glauth/pkg/command/root.go index 6d7283bc4..97c9ae95d 100644 --- a/glauth/pkg/command/root.go +++ b/glauth/pkg/command/root.go @@ -107,14 +107,14 @@ 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. +// SutureService allows for the glauth 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 +// NewSutureService creates a new glauth.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. diff --git a/idp/cmd/idp/main.go b/idp/cmd/idp/main.go index deeb7ea4d..10bf21ffe 100644 --- a/idp/cmd/idp/main.go +++ b/idp/cmd/idp/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/idp/pkg/command" + "github.com/owncloud/ocis/idp/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/idp/pkg/command/root.go b/idp/pkg/command/root.go index aa365be4f..08e4023f3 100644 --- a/idp/pkg/command/root.go +++ b/idp/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-idp command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "ocis-idp", Version: version.String, @@ -108,3 +107,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } + +// SutureService allows for the idp 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 idp.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/idp/pkg/config/config.go b/idp/pkg/config/config.go index 9e051be63..7551d0c96 100644 --- a/idp/pkg/config/config.go +++ b/idp/pkg/config/config.go @@ -1,6 +1,8 @@ package config import ( + "context" + "stash.kopano.io/kc/konnect/bootstrap" ) @@ -75,6 +77,8 @@ type Config struct { IDP bootstrap.Config Ldap Ldap Service Service + + Context context.Context } // New initializes a new configuration with or without defaults. diff --git a/idp/pkg/flagset/flagset.go b/idp/pkg/flagset/flagset.go index 68b2561a8..6845bca51 100644 --- a/idp/pkg/flagset/flagset.go +++ b/idp/pkg/flagset/flagset.go @@ -10,23 +10,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", - EnvVars: []string{"IDP_LOG_LEVEL"}, + EnvVars: []string{"IDP_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ - Value: true, Name: "log-pretty", Usage: "Enable pretty logging", - EnvVars: []string{"IDP_LOG_PRETTY"}, + EnvVars: []string{"IDP_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ - Value: true, Name: "log-color", Usage: "Enable colored logging", - EnvVars: []string{"IDP_LOG_COLOR"}, + EnvVars: []string{"IDP_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, } diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 98108c3d1..f8b57895f 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -7,6 +7,7 @@ import ( accounts "github.com/owncloud/ocis/accounts/pkg/command" glauth "github.com/owncloud/ocis/glauth/pkg/command" + idp "github.com/owncloud/ocis/idp/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" "github.com/thejerf/suture" @@ -33,7 +34,7 @@ var ( // Extensions are oCIS extension services Extensions = []string{ - "glauth", + "glauth", // done "idp", "ocs", "onlyoffice", @@ -102,6 +103,7 @@ func (r *Runtime) Start() error { // - replace occurrences of log.Fatal in favor of panic() since the supervisor relies on panics. // - the runtime should ideally run as an rpc service one can do requests, like the good ol' pman, rest in pieces. // - establish on suture a max number of retries before all initialization comes to a halt. + // - remove default log flagset values. // propagate reva log config to storage services r.c.Storage.Log.Level = r.c.Log.Level @@ -112,6 +114,7 @@ func (r *Runtime) Start() error { 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))) + addServiceToken("idp", supervisor.Add(idp.NewSutureService(globalCtx, r.c.IDP))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground()