(args []string)
| 149 | } |
| 150 | |
| 151 | func (c *KVMetadataPatchCommand) Run(args []string) int { |
| 152 | f := c.Flags() |
| 153 | |
| 154 | if err := f.Parse(args); err != nil { |
| 155 | c.UI.Error(err.Error()) |
| 156 | return 1 |
| 157 | } |
| 158 | |
| 159 | args = f.Args() |
| 160 | |
| 161 | switch { |
| 162 | case len(args) < 1: |
| 163 | c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args))) |
| 164 | return 1 |
| 165 | case len(args) > 1: |
| 166 | c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args))) |
| 167 | return 1 |
| 168 | } |
| 169 | |
| 170 | client, err := c.Client() |
| 171 | if err != nil { |
| 172 | c.UI.Error(err.Error()) |
| 173 | return 2 |
| 174 | } |
| 175 | |
| 176 | // If true, we're working with "-mount=secret foo" syntax. |
| 177 | // If false, we're using "secret/foo" syntax. |
| 178 | mountFlagSyntax := c.flagMount != "" |
| 179 | |
| 180 | var ( |
| 181 | mountPath string |
| 182 | partialPath string |
| 183 | v2 bool |
| 184 | ) |
| 185 | |
| 186 | // Parse the paths and grab the KV version |
| 187 | if mountFlagSyntax { |
| 188 | // In this case, this arg is the secret path (e.g. "foo"). |
| 189 | partialPath = sanitizePath(args[0]) |
| 190 | mountPath, v2, err = isKVv2(sanitizePath(c.flagMount), client) |
| 191 | if err != nil { |
| 192 | c.UI.Error(err.Error()) |
| 193 | return 2 |
| 194 | } |
| 195 | |
| 196 | if v2 { |
| 197 | partialPath = path.Join(mountPath, partialPath) |
| 198 | } |
| 199 | } else { |
| 200 | // In this case, this arg is a path-like combination of mountPath/secretPath. |
| 201 | // (e.g. "secret/foo") |
| 202 | partialPath = sanitizePath(args[0]) |
| 203 | mountPath, v2, err = isKVv2(partialPath, client) |
| 204 | if err != nil { |
| 205 | c.UI.Error(err.Error()) |
| 206 | return 2 |
| 207 | } |
| 208 | } |
nothing calls this directly
no test coverage detected