MCPcopy Create free account
hub / github.com/hashicorp/vault / Run

Method Run

command/unwrap.go:65–113  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

63}
64
65func (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}

Callers

nothing calls this directly

Calls 13

FlagsMethod · 0.95
FormatFunction · 0.85
PrintRawFieldFunction · 0.85
extractListDataFunction · 0.85
OutputListFunction · 0.85
OutputSecretFunction · 0.85
ArgsMethod · 0.80
UnwrapMethod · 0.80
LogicalMethod · 0.80
ParseMethod · 0.65
ErrorMethod · 0.65
ClientMethod · 0.65

Tested by

no test coverage detected