mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
refactor: added func to remove secrets from store
This commit is contained in:
parent
9e831914df
commit
35cf2222a0
3 changed files with 24 additions and 0 deletions
|
|
@ -197,6 +197,23 @@ var secretsListCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var secretsRemoveCmd = &cobra.Command{
|
||||||
|
Use: "remove secretIDs...",
|
||||||
|
Args: cobra.MinimumNArgs(2),
|
||||||
|
Short: "Remove secrets by IDs from secret store.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
for _, secretID := range args {
|
||||||
|
store, err := secrets.OpenStore(secretsFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
store.RemoveSecretByID(secretID)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
secretsCmd.Flags().StringVarP(&secretsFile, "file", "f", "nodes.json", "")
|
secretsCmd.Flags().StringVarP(&secretsFile, "file", "f", "nodes.json", "")
|
||||||
secretsStoreCmd.Flags().StringVar(&secretsStoreFormat, "format", "json", "set the input format for the secrets file (json|base64)")
|
secretsStoreCmd.Flags().StringVar(&secretsStoreFormat, "format", "json", "set the input format for the secrets file (json|base64)")
|
||||||
|
|
@ -206,6 +223,7 @@ func init() {
|
||||||
secretsCmd.AddCommand(secretsStoreCmd)
|
secretsCmd.AddCommand(secretsStoreCmd)
|
||||||
secretsCmd.AddCommand(secretsRetrieveCmd)
|
secretsCmd.AddCommand(secretsRetrieveCmd)
|
||||||
secretsCmd.AddCommand(secretsListCmd)
|
secretsCmd.AddCommand(secretsListCmd)
|
||||||
|
secretsCmd.AddCommand(secretsRemoveCmd)
|
||||||
|
|
||||||
rootCmd.AddCommand(secretsCmd)
|
rootCmd.AddCommand(secretsCmd)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,11 @@ func (l *LocalSecretStore) ListSecrets() (map[string]string, error) {
|
||||||
return secretsCopy, nil
|
return secretsCopy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveSecretByID removes the specified secretID stored locally
|
||||||
|
func (l *LocalSecretStore) RemoveSecretByID(secretID string) {
|
||||||
|
delete(l.Secrets, secretID)
|
||||||
|
}
|
||||||
|
|
||||||
// openStore tries to create or open the LocalSecretStore based on the environment
|
// openStore tries to create or open the LocalSecretStore based on the environment
|
||||||
// variable MASTER_KEY. If not found, it prints an error.
|
// variable MASTER_KEY. If not found, it prints an error.
|
||||||
func OpenStore(filename string) (SecretStore, error) {
|
func OpenStore(filename string) (SecretStore, error) {
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ type SecretStore interface {
|
||||||
GetSecretByID(secretID string) (string, error)
|
GetSecretByID(secretID string) (string, error)
|
||||||
StoreSecretByID(secretID, secret string) error
|
StoreSecretByID(secretID, secret string) error
|
||||||
ListSecrets() (map[string]string, error)
|
ListSecrets() (map[string]string, error)
|
||||||
|
RemoveSecretByID(secretID string)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue