add glauth

This commit is contained in:
A.Unger
2021-03-04 13:04:37 +01:00
parent 742b571a5b
commit 08e3eea6b7
5 changed files with 42 additions and 7 deletions

View File

@@ -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)
}
}

View File

@@ -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()
}

View File

@@ -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.

View File

@@ -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,
},
}

View File

@@ -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 {