add secret versioning support
This commit is contained in:
@@ -35,15 +35,19 @@ func newAddCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
func newGetCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
cmd := &cobra.Command{
|
||||
Use: "get <secret-name>",
|
||||
Short: "Retrieve a secret from the vault",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
version, _ := cmd.Flags().GetString("version")
|
||||
cli := NewCLIInstance()
|
||||
return cli.GetSecret(args[0])
|
||||
return cli.GetSecretWithVersion(args[0], version)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringP("version", "v", "", "Get a specific version (default: current)")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func newListCmd() *cobra.Command {
|
||||
@@ -132,6 +136,11 @@ func (cli *CLIInstance) AddSecret(secretName string, force bool) error {
|
||||
|
||||
// GetSecret retrieves and prints a secret from the current vault
|
||||
func (cli *CLIInstance) GetSecret(secretName string) error {
|
||||
return cli.GetSecretWithVersion(secretName, "")
|
||||
}
|
||||
|
||||
// GetSecretWithVersion retrieves and prints a specific version of a secret
|
||||
func (cli *CLIInstance) GetSecretWithVersion(secretName string, version string) error {
|
||||
// Get current vault
|
||||
vlt, err := vault.GetCurrentVault(cli.fs, cli.stateDir)
|
||||
if err != nil {
|
||||
@@ -139,7 +148,12 @@ func (cli *CLIInstance) GetSecret(secretName string) error {
|
||||
}
|
||||
|
||||
// Get the secret value
|
||||
value, err := vlt.GetSecret(secretName)
|
||||
var value []byte
|
||||
if version == "" {
|
||||
value, err = vlt.GetSecret(secretName)
|
||||
} else {
|
||||
value, err = vlt.GetSecretVersion(secretName, version)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user