-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from thingful/delete-entries
Delete entries
- Loading branch information
Showing
5 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/segmentio/chamber/store" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// deleteCmd represents the delete command | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete <service> <key>", | ||
Short: "Delete a secret, including all versions", | ||
RunE: delete, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(deleteCmd) | ||
} | ||
|
||
func delete(cmd *cobra.Command, args []string) error { | ||
if len(args) < 2 { | ||
return ErrTooFewArguments | ||
} | ||
if len(args) > 2 { | ||
return ErrTooManyArguments | ||
} | ||
|
||
service := strings.ToLower(args[0]) | ||
if err := validateService(service); err != nil { | ||
return errors.Wrap(err, "Failed to validate service") | ||
} | ||
|
||
key := strings.ToLower(args[1]) | ||
if err := validateKey(key); err != nil { | ||
return errors.Wrap(err, "Failed to validate key") | ||
} | ||
|
||
secretStore := store.NewSSMStore(numRetries) | ||
secretId := store.SecretId{ | ||
Service: service, | ||
Key: key, | ||
} | ||
|
||
return secretStore.Delete(secretId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters