Files
threshold/internal/cmd/commands.go
T

186 lines
4.8 KiB
Go
Raw Normal View History

2020-02-12 13:53:27 -05:00
package cmd
import (
"os"
"os/signal"
"syscall"
"github.com/hashicorp/watchtower/internal/cmd/base"
"github.com/hashicorp/watchtower/internal/cmd/commands/authenticate"
"github.com/hashicorp/watchtower/internal/cmd/commands/config"
2020-02-12 13:53:27 -05:00
"github.com/hashicorp/watchtower/internal/cmd/commands/controller"
"github.com/hashicorp/watchtower/internal/cmd/commands/dev"
2020-05-04 23:04:55 -04:00
"github.com/hashicorp/watchtower/internal/cmd/commands/hosts"
"github.com/hashicorp/watchtower/internal/cmd/commands/roles"
2020-05-12 17:35:48 -07:00
"github.com/hashicorp/watchtower/internal/cmd/commands/scopes"
"github.com/hashicorp/watchtower/internal/cmd/commands/worker"
2020-02-12 13:53:27 -05:00
"github.com/mitchellh/cli"
)
// Commands is the mapping of all the available commands.
var Commands map[string]cli.CommandFactory
func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
Commands = map[string]cli.CommandFactory{
"controller": func() (cli.Command, error) {
2020-03-10 15:48:04 -04:00
return &controller.Command{
2020-05-11 17:03:23 -04:00
Server: base.NewServer(&base.Command{
2020-05-04 23:04:55 -04:00
UI: serverCmdUi,
ShutdownCh: base.MakeShutdownCh(),
2020-05-11 17:03:23 -04:00
}),
2020-05-04 23:04:55 -04:00
SighupCh: MakeSighupCh(),
SigUSR2Ch: MakeSigUSR2Ch(),
2020-02-12 13:53:27 -05:00
}, nil
},
"worker": func() (cli.Command, error) {
return &worker.Command{
2020-05-11 17:03:23 -04:00
Server: base.NewServer(&base.Command{
2020-05-04 23:04:55 -04:00
UI: serverCmdUi,
ShutdownCh: base.MakeShutdownCh(),
2020-05-11 17:03:23 -04:00
}),
2020-05-04 23:04:55 -04:00
SighupCh: MakeSighupCh(),
SigUSR2Ch: MakeSigUSR2Ch(),
}, nil
},
2020-02-12 13:53:27 -05:00
"dev": func() (cli.Command, error) {
2020-03-10 15:48:04 -04:00
return &dev.Command{
2020-05-11 17:03:23 -04:00
Server: base.NewServer(&base.Command{
2020-05-04 23:04:55 -04:00
UI: serverCmdUi,
ShutdownCh: base.MakeShutdownCh(),
2020-05-11 17:03:23 -04:00
}),
2020-05-04 23:04:55 -04:00
SighupCh: MakeSighupCh(),
SigUSR2Ch: MakeSigUSR2Ch(),
}, nil
},
"hosts create": func() (cli.Command, error) {
return &hosts.CreateCommand{
Command: base.NewCommand(ui),
2020-02-12 13:53:27 -05:00
}, nil
},
2020-05-12 17:35:48 -07:00
"projects create": func() (cli.Command, error) {
return &scopes.CreateProjectCommand{
Command: base.NewCommand(ui),
2020-05-12 17:35:48 -07:00
}, nil
},
"projects read": func() (cli.Command, error) {
return &scopes.ReadProjectCommand{
Command: base.NewCommand(ui),
}, nil
},
"config": func() (cli.Command, error) {
return &config.Command{
Command: base.NewCommand(ui),
}, nil
},
"config encrypt": func() (cli.Command, error) {
return &config.EncryptDecryptCommand{
Command: base.NewCommand(ui),
Encrypt: true,
}, nil
},
"config decrypt": func() (cli.Command, error) {
return &config.EncryptDecryptCommand{
Command: base.NewCommand(ui),
2020-05-12 17:35:48 -07:00
}, nil
},
"authenticate": func() (cli.Command, error) {
return &authenticate.Command{
Command: base.NewCommand(ui),
}, nil
},
"authenticate password": func() (cli.Command, error) {
return &authenticate.PasswordCommand{
Command: base.NewCommand(ui),
}, nil
},
"roles": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
}, nil
},
"roles create": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "create",
}, nil
},
"roles update": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "update",
}, nil
},
"roles read": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "read",
}, nil
},
"roles delete": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "delete",
}, nil
},
"roles list": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "list",
}, nil
},
"roles add-principals": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "add-principals",
}, nil
},
"roles set-principals": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "set-principals",
}, nil
},
"roles remove-principals": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "remove-principals",
}, nil
},
"roles add-grants": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "add-grants",
}, nil
},
"roles set-grants": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "set-grants",
}, nil
},
"roles remove-grants": func() (cli.Command, error) {
return &roles.Command{
Command: base.NewCommand(ui),
Func: "remove-grants",
}, nil
},
2020-02-12 13:53:27 -05:00
}
}
// MakeSighupCh returns a channel that can be used for SIGHUP
// reloading. This channel will send a message for every
// SIGHUP received.
func MakeSighupCh() chan struct{} {
resultCh := make(chan struct{})
signalCh := make(chan os.Signal, 4)
signal.Notify(signalCh, syscall.SIGHUP)
go func() {
for {
<-signalCh
resultCh <- struct{}{}
}
}()
return resultCh
}