Add config CLI command and encrypt/decrypt sub-commands (#77)
This commit is contained in:
1 parent
8de5371499
commit
8afcbd4c8e
12 files changed
+509
-49
No files matched your search
@@ -8,9 +8,11 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/hashicorp/watchtower/api"
|
||||
"github.com/mitchellh/cli"
|
||||
@@ -56,6 +58,38 @@ type Command struct {
|
||||
client *api.Client
|
||||
}
|
||||
|
||||
// New returns a new instance of a base.Command type
|
||||
func New(ui cli.Ui) *Command {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ret := &Command{
|
||||
UI: ui,
|
||||
ShutdownCh: MakeShutdownCh(),
|
||||
Context: ctx,
|
||||
}
|
||||
|
||||
go func() {
|
||||
<-ret.ShutdownCh
|
||||
cancel()
|
||||
}()
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// MakeShutdownCh returns a channel that can be used for shutdown
|
||||
// notifications for commands. This channel will send a message for every
|
||||
// SIGINT or SIGTERM received.
|
||||
func MakeShutdownCh() chan struct{} {
|
||||
resultCh := make(chan struct{})
|
||||
|
||||
shutdownCh := make(chan os.Signal, 4)
|
||||
signal.Notify(shutdownCh, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-shutdownCh
|
||||
close(resultCh)
|
||||
}()
|
||||
return resultCh
|
||||
}
|
||||
|
||||
// Client returns the HTTP API client. The client is cached on the command to
|
||||
// save performance on future calls.
|
||||
func (c *Command) Client() (*api.Client, error) {
|
||||
|
||||
@@ -314,7 +314,7 @@ func (b *Server) SetupKMSes(ui cli.Ui, config *configutil.SharedConfig, purposes
|
||||
switch purpose {
|
||||
case "":
|
||||
return errors.New("KMS block missing 'purpose'")
|
||||
case "controller", "worker-auth":
|
||||
case "controller", "worker-auth", "config":
|
||||
default:
|
||||
return fmt.Errorf("Unknown KMS purpose %q", kms.Purpose)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user