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

Method Run

command/patch.go:98–138  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

96}
97
98func (c *PatchCommand) Run(args []string) int {
99 f := c.Flags()
100
101 if err := f.Parse(args); err != nil {
102 c.UI.Error(err.Error())
103 return 1
104 }
105
106 args = f.Args()
107 switch {
108 case len(args) < 1:
109 c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
110 return 1
111 case len(args) == 1 && !c.flagForce:
112 c.UI.Error("Must supply data or use -force")
113 return 1
114 }
115
116 // Pull our fake stdin if needed
117 stdin := (io.Reader)(os.Stdin)
118 if c.testStdin != nil {
119 stdin = c.testStdin
120 }
121
122 path := sanitizePath(args[0])
123
124 data, err := parseArgsData(stdin, args[1:])
125 if err != nil {
126 c.UI.Error(fmt.Sprintf("Failed to parse K=V data: %s", err))
127 return 1
128 }
129
130 client, err := c.Client()
131 if err != nil {
132 c.UI.Error(err.Error())
133 return 2
134 }
135
136 secret, err := client.Logical().JSONMergePatch(context.Background(), path, data)
137 return handleWriteSecretOutput(c.BaseCommand, path, secret, err)
138}

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected