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

Method Run

command/write.go:112–152  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

110}
111
112func (c *WriteCommand) Run(args []string) int {
113 f := c.Flags()
114
115 if err := f.Parse(args); err != nil {
116 c.UI.Error(err.Error())
117 return 1
118 }
119
120 args = f.Args()
121 switch {
122 case len(args) < 1:
123 c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
124 return 1
125 case len(args) == 1 && !c.flagForce:
126 c.UI.Error("Must supply data or use -force")
127 return 1
128 }
129
130 // Pull our fake stdin if needed
131 stdin := (io.Reader)(os.Stdin)
132 if c.testStdin != nil {
133 stdin = c.testStdin
134 }
135
136 path := sanitizePath(args[0])
137
138 data, err := parseArgsData(stdin, args[1:])
139 if err != nil {
140 c.UI.Error(fmt.Sprintf("Failed to parse K=V data: %s", err))
141 return 1
142 }
143
144 client, err := c.Client()
145 if err != nil {
146 c.UI.Error(err.Error())
147 return 2
148 }
149
150 secret, err := client.Logical().Write(path, data)
151 return handleWriteSecretOutput(c.BaseCommand, path, secret, err)
152}
153
154func handleWriteSecretOutput(c *BaseCommand, path string, secret *api.Secret, err error) int {
155 if err != nil {

Callers

nothing calls this directly

Calls 10

FlagsMethod · 0.95
parseArgsDataFunction · 0.85
handleWriteSecretOutputFunction · 0.85
ArgsMethod · 0.80
LogicalMethod · 0.80
sanitizePathFunction · 0.70
ParseMethod · 0.65
ErrorMethod · 0.65
ClientMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected