(args []string)
| 63 | } |
| 64 | |
| 65 | func (c *UnwrapCommand) Run(args []string) int { |
| 66 | f := c.Flags() |
| 67 | |
| 68 | if err := f.Parse(args); err != nil { |
| 69 | c.UI.Error(err.Error()) |
| 70 | return 1 |
| 71 | } |
| 72 | |
| 73 | args = f.Args() |
| 74 | token := "" |
| 75 | switch len(args) { |
| 76 | case 0: |
| 77 | // Leave token as "", that will use the local token |
| 78 | case 1: |
| 79 | token = strings.TrimSpace(args[0]) |
| 80 | default: |
| 81 | c.UI.Error(fmt.Sprintf("Too many arguments (expected 0-1, got %d)", len(args))) |
| 82 | return 1 |
| 83 | } |
| 84 | |
| 85 | client, err := c.Client() |
| 86 | if err != nil { |
| 87 | c.UI.Error(err.Error()) |
| 88 | return 2 |
| 89 | } |
| 90 | |
| 91 | secret, err := client.Logical().Unwrap(token) |
| 92 | if err != nil { |
| 93 | c.UI.Error(fmt.Sprintf("Error unwrapping: %s", err)) |
| 94 | return 2 |
| 95 | } |
| 96 | if secret == nil { |
| 97 | if Format(c.UI) == "table" { |
| 98 | c.UI.Info("Successfully unwrapped. There was no data in the wrapped secret.") |
| 99 | } |
| 100 | return 0 |
| 101 | } |
| 102 | |
| 103 | // Handle single field output |
| 104 | if c.flagField != "" { |
| 105 | return PrintRawField(c.UI, secret, c.flagField) |
| 106 | } |
| 107 | |
| 108 | // Check if the original was a list response and format as a list |
| 109 | if _, ok := extractListData(secret); ok { |
| 110 | return OutputList(c.UI, secret) |
| 111 | } |
| 112 | return OutputSecret(c.UI, secret) |
| 113 | } |
nothing calls this directly
no test coverage detected