mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 11:51:16 -06:00
add accounts
This commit is contained in:
@@ -4,10 +4,11 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/accounts/pkg/command"
|
||||
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := command.Execute(); err != nil {
|
||||
if err := command.Execute(config.New()); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -19,8 +20,7 @@ var (
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-accounts command.
|
||||
func Execute() error {
|
||||
cfg := config.New()
|
||||
func Execute(cfg *config.Config) error {
|
||||
app := &cli.App{
|
||||
Name: "ocis-accounts",
|
||||
Version: version.String,
|
||||
@@ -118,3 +118,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 {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s SutureService) Stop() {
|
||||
s.cancel()
|
||||
}
|
||||
|
||||
@@ -135,8 +135,6 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
http.Context(ctx),
|
||||
http.Config(cfg),
|
||||
http.Metrics(mtrcs),
|
||||
http.Flags(flagset.RootWithConfig(config.New())),
|
||||
http.Flags(flagset.ServerWithConfig(config.New())),
|
||||
http.Handler(handler),
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Package config should be moved to internal
|
||||
package config
|
||||
|
||||
import "context"
|
||||
|
||||
// LDAP defines the available ldap configuration.
|
||||
type LDAP struct {
|
||||
Hostname string
|
||||
@@ -121,6 +123,8 @@ type Config struct {
|
||||
Index Index
|
||||
ServiceUser ServiceUser
|
||||
Tracing Tracing
|
||||
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
// New returns a new config.
|
||||
|
||||
@@ -13,21 +13,21 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
|
||||
Name: "log-level",
|
||||
Value: "info",
|
||||
Usage: "Set logging level",
|
||||
EnvVars: []string{"ACCOUNTS_LOG_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"},
|
||||
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"},
|
||||
EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
accounts "github.com/owncloud/ocis/accounts/pkg/command"
|
||||
settings "github.com/owncloud/ocis/settings/pkg/command"
|
||||
|
||||
"github.com/thejerf/suture"
|
||||
@@ -78,14 +79,15 @@ func New(cfg *config.Config) Runtime {
|
||||
// within the service Stop() method. Services should cancel their context.
|
||||
type serviceTokens map[string][]suture.ServiceToken
|
||||
|
||||
// tokens are used to keep track of the services
|
||||
var tokens = serviceTokens{}
|
||||
|
||||
// Start rpc runtime
|
||||
func (r *Runtime) Start() error {
|
||||
setMicroLogger(r.c.Log)
|
||||
halt := make(chan os.Signal, 1)
|
||||
signal.Notify(halt, os.Interrupt)
|
||||
|
||||
// tokens are used to keep track of the services
|
||||
tokens := serviceTokens{}
|
||||
supervisor := suture.NewSimple("ocis")
|
||||
globalCtx, globalCancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -106,6 +108,7 @@ func (r *Runtime) Start() error {
|
||||
|
||||
tokens["settings"] = append(tokens["settings"], supervisor.Add(settings.NewSutureService(globalCtx, r.c.Settings)))
|
||||
tokens["storagemetadata"] = append(tokens["storagemetadata"], supervisor.Add(storage.NewStorageMetadata(globalCtx, r.c.Storage)))
|
||||
tokens["accounts"] = append(tokens["accounts"], supervisor.Add(accounts.NewSutureService(globalCtx, r.c.Accounts)))
|
||||
|
||||
go supervisor.ServeBackground()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user