mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 10:37:56 +00:00 
			
		
		
		
	Update path-help command
This commit is contained in:
		| @@ -8,7 +8,6 @@ import ( | ||||
| 	"github.com/posener/complete" | ||||
| ) | ||||
|  | ||||
| // Ensure we are implementing the right interfaces. | ||||
| var _ cli.Command = (*PathHelpCommand)(nil) | ||||
| var _ cli.CommandAutocomplete = (*PathHelpCommand)(nil) | ||||
|  | ||||
| @@ -16,37 +15,34 @@ var pathHelpVaultSealedMessage = strings.TrimSpace(` | ||||
| Error: Vault is sealed. | ||||
|  | ||||
| The "path-help" command requires the Vault to be unsealed so that the mount | ||||
| points of the secret backends are known. | ||||
| points of the secret engines are known. | ||||
| `) | ||||
|  | ||||
| // PathHelpCommand is a Command that lists the mounts. | ||||
| type PathHelpCommand struct { | ||||
| 	*BaseCommand | ||||
| } | ||||
|  | ||||
| func (c *PathHelpCommand) Synopsis() string { | ||||
| 	return "Retrieves API help for paths" | ||||
| 	return "Retrieve API help for paths" | ||||
| } | ||||
|  | ||||
| func (c *PathHelpCommand) Help() string { | ||||
| 	helpText := ` | ||||
| Usage: vault path-help [options] path | ||||
| Usage: vault path-help [options] PATH | ||||
|  | ||||
|   Retrieves API help for paths. All endpoints in Vault provide built-in help | ||||
|   in markdown format. This includes system paths, secret paths, and credential | ||||
|   providers. | ||||
|   in markdown format. This includes system paths, secret engines, and auth | ||||
|   methods. | ||||
|  | ||||
|   A backend must be mounted before help is available: | ||||
|   Get help for the thing mounted at database/: | ||||
|  | ||||
|       $ vault mount database | ||||
|       $ vault path-help database/ | ||||
|  | ||||
|   The response object will return additional paths to retrieve help: | ||||
|  | ||||
|       $ vault path-help database/roles/ | ||||
|  | ||||
|   Each backend produces different help output. For additional information, | ||||
|   please view the online documentation. | ||||
|   Each secret engine produces different help output. | ||||
|  | ||||
| ` + c.Flags().Help() | ||||
|  | ||||
| @@ -74,13 +70,11 @@ func (c *PathHelpCommand) Run(args []string) int { | ||||
| 	} | ||||
|  | ||||
| 	args = f.Args() | ||||
| 	path, kvs, err := extractPath(args) | ||||
| 	if err != nil { | ||||
| 		c.UI.Error(err.Error()) | ||||
| 	switch { | ||||
| 	case len(args) < 1: | ||||
| 		c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args))) | ||||
| 		return 1 | ||||
| 	} | ||||
|  | ||||
| 	if len(kvs) > 0 { | ||||
| 	case len(args) > 1: | ||||
| 		c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args))) | ||||
| 		return 1 | ||||
| 	} | ||||
| @@ -91,6 +85,8 @@ func (c *PathHelpCommand) Run(args []string) int { | ||||
| 		return 2 | ||||
| 	} | ||||
|  | ||||
| 	path := sanitizePath(args[0]) | ||||
|  | ||||
| 	help, err := client.Help(path) | ||||
| 	if err != nil { | ||||
| 		if strings.Contains(err.Error(), "Vault is sealed") { | ||||
|   | ||||
| @@ -28,15 +28,15 @@ func TestPathHelpCommand_Run(t *testing.T) { | ||||
| 		code int | ||||
| 	}{ | ||||
| 		{ | ||||
| 			"empty", | ||||
| 			nil, | ||||
| 			"Missing PATH!", | ||||
| 			"not_enough_args", | ||||
| 			[]string{}, | ||||
| 			"Not enough arguments", | ||||
| 			1, | ||||
| 		}, | ||||
| 		{ | ||||
| 			"slash", | ||||
| 			[]string{"/"}, | ||||
| 			"Missing PATH!", | ||||
| 			"too_many_args", | ||||
| 			[]string{"foo", "bar"}, | ||||
| 			"Too many arguments", | ||||
| 			1, | ||||
| 		}, | ||||
| 		{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Seth Vargo
					Seth Vargo