2015-04-08 01:23:28 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2016-04-01 17:16:05 +00:00
|
|
|
|
2017-09-05 03:58:52 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/posener/complete"
|
2015-04-08 01:23:28 +00:00
|
|
|
)
|
|
|
|
|
2017-09-05 03:58:52 +00:00
|
|
|
var _ cli.Command = (*AuditDisableCommand)(nil)
|
|
|
|
var _ cli.CommandAutocomplete = (*AuditDisableCommand)(nil)
|
|
|
|
|
2015-04-08 01:23:28 +00:00
|
|
|
type AuditDisableCommand struct {
|
2017-09-05 03:58:52 +00:00
|
|
|
*BaseCommand
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuditDisableCommand) Synopsis() string {
|
2017-09-08 01:57:32 +00:00
|
|
|
return "Disables an audit device"
|
2017-09-05 03:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuditDisableCommand) Help() string {
|
|
|
|
helpText := `
|
2017-09-08 01:57:32 +00:00
|
|
|
Usage: vault audit disable [options] PATH
|
2017-09-05 03:58:52 +00:00
|
|
|
|
2017-09-08 01:57:32 +00:00
|
|
|
Disables an audit device. Once an audit device is disabled, no future audit
|
|
|
|
logs are dispatched to it. The data associated with the audit device is not
|
|
|
|
affected.
|
2017-09-05 03:58:52 +00:00
|
|
|
|
2017-09-08 01:57:32 +00:00
|
|
|
The argument corresponds to the PATH of audit device, not the TYPE!
|
2017-09-05 03:58:52 +00:00
|
|
|
|
2017-09-08 01:57:32 +00:00
|
|
|
Disable the audit device enabled at "file/":
|
2017-09-05 03:58:52 +00:00
|
|
|
|
2017-09-08 01:57:32 +00:00
|
|
|
$ vault audit disable file/
|
2017-09-05 03:58:52 +00:00
|
|
|
|
|
|
|
` + c.Flags().Help()
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuditDisableCommand) Flags() *FlagSets {
|
|
|
|
return c.flagSet(FlagSetHTTP)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuditDisableCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return c.PredictVaultAudits()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuditDisableCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return c.Flags().Completions()
|
2015-04-08 01:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuditDisableCommand) Run(args []string) int {
|
2017-09-05 03:58:52 +00:00
|
|
|
f := c.Flags()
|
|
|
|
|
|
|
|
if err := f.Parse(args); err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
2015-04-08 01:23:28 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-09-05 03:58:52 +00:00
|
|
|
args = f.Args()
|
2017-09-08 01:57:32 +00:00
|
|
|
switch {
|
|
|
|
case len(args) < 1:
|
|
|
|
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
|
2015-04-08 01:23:28 +00:00
|
|
|
return 1
|
2017-09-08 01:57:32 +00:00
|
|
|
case len(args) > 1:
|
2017-09-05 03:58:52 +00:00
|
|
|
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
|
|
|
|
return 1
|
|
|
|
}
|
2015-04-08 01:23:28 +00:00
|
|
|
|
2017-09-08 01:57:32 +00:00
|
|
|
path := ensureTrailingSlash(sanitizePath(args[0]))
|
|
|
|
|
2015-04-08 01:23:28 +00:00
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
2017-09-05 03:58:52 +00:00
|
|
|
c.UI.Error(err.Error())
|
2015-04-08 01:23:28 +00:00
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2017-09-05 03:58:52 +00:00
|
|
|
if err := client.Sys().DisableAudit(path); err != nil {
|
2017-09-08 01:57:32 +00:00
|
|
|
c.UI.Error(fmt.Sprintf("Error disabling audit device: %s", err))
|
2015-04-08 01:23:28 +00:00
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2017-09-08 01:57:32 +00:00
|
|
|
c.UI.Output(fmt.Sprintf("Success! Disabled audit device (if it was enabled) at: %s", path))
|
2016-09-19 17:02:25 +00:00
|
|
|
|
2015-04-08 01:23:28 +00:00
|
|
|
return 0
|
|
|
|
}
|