Skip to content

Commit

Permalink
Move meta into its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Apr 1, 2016
1 parent da00982 commit 33326b3
Show file tree
Hide file tree
Showing 79 changed files with 326 additions and 233 deletions.
86 changes: 43 additions & 43 deletions cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import (
"github.com/hashicorp/vault/audit"
"github.com/hashicorp/vault/command"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/meta"
"github.com/mitchellh/cli"
)

// Commands returns the mapping of CLI commands for Vault. The meta
// parameter lets you set meta options for all commands.
func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
func Commands(metaPtr *meta.Meta) map[string]cli.CommandFactory {
if metaPtr == nil {
metaPtr = new(command.Meta)
metaPtr = new(meta.Meta)
}

meta := *metaPtr
if meta.Ui == nil {
meta.Ui = &cli.BasicUi{
if metaPtr.Ui == nil {
metaPtr.Ui = &cli.BasicUi{
Writer: os.Stdout,
ErrorWriter: os.Stderr,
}
Expand All @@ -48,13 +48,13 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
return map[string]cli.CommandFactory{
"init": func() (cli.Command, error) {
return &command.InitCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"server": func() (cli.Command, error) {
return &command.ServerCommand{
Meta: meta,
Meta: *metaPtr,
AuditBackends: map[string]audit.Factory{
"file": auditFile.Factory,
"syslog": auditSyslog.Factory,
Expand Down Expand Up @@ -85,19 +85,19 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {

"ssh": func() (cli.Command, error) {
return &command.SSHCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"path-help": func() (cli.Command, error) {
return &command.PathHelpCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"auth": func() (cli.Command, error) {
return &command.AuthCommand{
Meta: meta,
Meta: *metaPtr,
Handlers: map[string]command.AuthHandler{
"github": &credGitHub.CLIHandler{},
"userpass": &credUserpass.CLIHandler{},
Expand All @@ -109,193 +109,193 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {

"auth-enable": func() (cli.Command, error) {
return &command.AuthEnableCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"auth-disable": func() (cli.Command, error) {
return &command.AuthDisableCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"audit-list": func() (cli.Command, error) {
return &command.AuditListCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"audit-disable": func() (cli.Command, error) {
return &command.AuditDisableCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"audit-enable": func() (cli.Command, error) {
return &command.AuditEnableCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"key-status": func() (cli.Command, error) {
return &command.KeyStatusCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"policies": func() (cli.Command, error) {
return &command.PolicyListCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"policy-delete": func() (cli.Command, error) {
return &command.PolicyDeleteCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"policy-write": func() (cli.Command, error) {
return &command.PolicyWriteCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"read": func() (cli.Command, error) {
return &command.ReadCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"list": func() (cli.Command, error) {
return &command.ListCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"write": func() (cli.Command, error) {
return &command.WriteCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"delete": func() (cli.Command, error) {
return &command.DeleteCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"rekey": func() (cli.Command, error) {
return &command.RekeyCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"generate-root": func() (cli.Command, error) {
return &command.GenerateRootCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"renew": func() (cli.Command, error) {
return &command.RenewCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"revoke": func() (cli.Command, error) {
return &command.RevokeCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"seal": func() (cli.Command, error) {
return &command.SealCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"status": func() (cli.Command, error) {
return &command.StatusCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"unseal": func() (cli.Command, error) {
return &command.UnsealCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"step-down": func() (cli.Command, error) {
return &command.StepDownCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"mount": func() (cli.Command, error) {
return &command.MountCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"mounts": func() (cli.Command, error) {
return &command.MountsCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"mount-tune": func() (cli.Command, error) {
return &command.MountTuneCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"remount": func() (cli.Command, error) {
return &command.RemountCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"rotate": func() (cli.Command, error) {
return &command.RotateCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"unmount": func() (cli.Command, error) {
return &command.UnmountCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"token-create": func() (cli.Command, error) {
return &command.TokenCreateCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"token-lookup": func() (cli.Command, error) {
return &command.TokenLookupCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"token-renew": func() (cli.Command, error) {
return &command.TokenRenewCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"token-revoke": func() (cli.Command, error) {
return &command.TokenRevokeCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

"capabilities": func() (cli.Command, error) {
return &command.CapabilitiesCommand{
Meta: meta,
Meta: *metaPtr,
}, nil
},

Expand All @@ -304,7 +304,7 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {

return &command.VersionCommand{
VersionInfo: versionInfo,
Ui: meta.Ui,
Ui: metaPtr.Ui,
}, nil
},
}
Expand Down
8 changes: 5 additions & 3 deletions command/audit_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package command
import (
"fmt"
"strings"

"github.com/hashicorp/vault/meta"
)

// AuditDisableCommand is a Command that mounts a new mount.
type AuditDisableCommand struct {
Meta
meta.Meta
}

func (c *AuditDisableCommand) Run(args []string) int {
flags := c.Meta.FlagSet("mount", FlagSetDefault)
flags := c.Meta.FlagSet("mount", meta.FlagSetDefault)
flags.Usage = func() { c.Ui.Error(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -64,6 +66,6 @@ Usage: vault audit-disable [options] id
General Options:
` + generalOptionsUsage()
` + meta.GeneralOptionsUsage()
return strings.TrimSpace(helpText)
}
3 changes: 2 additions & 1 deletion command/audit_disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/meta"
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/cli"
)
Expand All @@ -15,7 +16,7 @@ func TestAuditDisable(t *testing.T) {

ui := new(cli.MockUi)
c := &AuditDisableCommand{
Meta: Meta{
Meta: meta.Meta{
ClientToken: token,
Ui: ui,
},
Expand Down
7 changes: 4 additions & 3 deletions command/audit_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import (
"strings"

"github.com/hashicorp/vault/helper/kv-builder"
"github.com/hashicorp/vault/meta"
"github.com/mitchellh/mapstructure"
)

// AuditEnableCommand is a Command that mounts a new mount.
type AuditEnableCommand struct {
Meta
meta.Meta

// A test stdin that can be used for tests
testStdin io.Reader
}

func (c *AuditEnableCommand) Run(args []string) int {
var desc, path string
flags := c.Meta.FlagSet("audit-enable", FlagSetDefault)
flags := c.Meta.FlagSet("audit-enable", meta.FlagSetDefault)
flags.StringVar(&desc, "description", "", "")
flags.StringVar(&path, "path", "", "")
flags.Usage = func() { c.Ui.Error(c.Help()) }
Expand Down Expand Up @@ -96,7 +97,7 @@ Usage: vault audit-enable [options] type [config...]
General Options:
` + generalOptionsUsage() + `
` + meta.GeneralOptionsUsage() + `
Audit Enable Options:
Expand Down
3 changes: 2 additions & 1 deletion command/audit_enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/hashicorp/vault/http"
"github.com/hashicorp/vault/meta"
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/cli"
)
Expand All @@ -16,7 +17,7 @@ func TestAuditEnable(t *testing.T) {

ui := new(cli.MockUi)
c := &AuditEnableCommand{
Meta: Meta{
Meta: meta.Meta{
ClientToken: token,
Ui: ui,
},
Expand Down
Loading

0 comments on commit 33326b3

Please sign in to comment.