2020-01-30 15:55:40 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
|
|
import (
|
2021-03-04 10:50:06 +01:00
|
|
|
"context"
|
2020-01-30 15:55:40 +01:00
|
|
|
"os"
|
2021-11-02 12:09:21 +01:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
"github.com/owncloud/ocis/accounts/pkg/config"
|
2022-01-03 15:21:56 +01:00
|
|
|
"github.com/owncloud/ocis/accounts/pkg/config/parser"
|
2022-01-03 13:53:27 +01:00
|
|
|
"github.com/owncloud/ocis/ocis-pkg/clihelper"
|
2021-03-10 11:10:46 +01:00
|
|
|
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
2021-03-11 15:50:01 +01:00
|
|
|
"github.com/thejerf/suture/v4"
|
2021-09-14 16:05:03 +02:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-01-30 15:55:40 +01:00
|
|
|
)
|
|
|
|
|
|
2022-01-03 13:53:27 +01:00
|
|
|
// GetCommands provides all commands for this service
|
|
|
|
|
func GetCommands(cfg *config.Config) cli.Commands {
|
|
|
|
|
return []*cli.Command{
|
|
|
|
|
// start this service
|
|
|
|
|
Server(cfg),
|
|
|
|
|
|
|
|
|
|
// interaction with this service
|
|
|
|
|
AddAccount(cfg),
|
|
|
|
|
UpdateAccount(cfg),
|
|
|
|
|
ListAccounts(cfg),
|
|
|
|
|
InspectAccount(cfg),
|
|
|
|
|
RemoveAccount(cfg),
|
|
|
|
|
RebuildIndex(cfg),
|
|
|
|
|
|
|
|
|
|
// infos about this service
|
|
|
|
|
Health(cfg),
|
|
|
|
|
Version(cfg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 15:55:40 +01:00
|
|
|
// Execute is the entry point for the ocis-accounts command.
|
2021-03-04 10:50:06 +01:00
|
|
|
func Execute(cfg *config.Config) error {
|
2022-01-03 13:53:27 +01:00
|
|
|
app := clihelper.DefaultApp(&cli.App{
|
|
|
|
|
Name: "ocis-accounts",
|
|
|
|
|
Usage: "Provide accounts and groups for oCIS",
|
2020-06-30 12:50:39 +02:00
|
|
|
Before: func(c *cli.Context) error {
|
2022-01-03 15:21:56 +01:00
|
|
|
return parser.ParseConfig(cfg)
|
2020-06-30 12:50:39 +02:00
|
|
|
},
|
2022-01-03 13:53:27 +01:00
|
|
|
Commands: GetCommands(cfg),
|
|
|
|
|
})
|
2020-01-30 15:55:40 +01:00
|
|
|
|
|
|
|
|
cli.HelpFlag = &cli.BoolFlag{
|
|
|
|
|
Name: "help,h",
|
|
|
|
|
Usage: "Show the help",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return app.Run(os.Args)
|
|
|
|
|
}
|
2020-03-18 13:11:04 +01:00
|
|
|
|
2021-03-04 13:10:18 +01:00
|
|
|
// SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree.
|
2021-03-04 10:50:06 +01:00
|
|
|
type SutureService struct {
|
2021-03-11 15:50:01 +01:00
|
|
|
cfg *config.Config
|
2021-03-04 10:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-04 13:10:18 +01:00
|
|
|
// NewSutureService creates a new accounts.SutureService
|
2021-03-11 15:50:01 +01:00
|
|
|
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
2021-12-17 16:30:57 +01:00
|
|
|
cfg.Accounts.Commons = cfg.Commons
|
2021-03-04 10:50:06 +01:00
|
|
|
return SutureService{
|
2021-03-11 15:50:01 +01:00
|
|
|
cfg: cfg.Accounts,
|
2021-03-04 10:50:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 15:50:01 +01:00
|
|
|
func (s SutureService) Serve(ctx context.Context) error {
|
|
|
|
|
s.cfg.Context = ctx
|
2021-03-04 10:50:06 +01:00
|
|
|
if err := Execute(s.cfg); err != nil {
|
2021-03-11 15:50:01 +01:00
|
|
|
return err
|
2021-03-04 10:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-11 15:50:01 +01:00
|
|
|
return nil
|
2021-03-04 10:50:06 +01:00
|
|
|
}
|