Skip to content

Commit

Permalink
add write --skip-unchanged flag (#175)
Browse files Browse the repository at this point in the history
By default a write attempt results in a new history entry even when the value is unchanged. Under most use this is no big deal but I've run into cases where we update secrets through automation, for example syncing during transitions between systems, and the history is filled with a bunch of non-changes. This adds a simple option to ignore writing the secret if the value is unchanged.
  • Loading branch information
q3aiml authored and nickatsegment committed Nov 28, 2018
1 parent b12d154 commit ab51432
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

var (
singleline bool
singleline bool
skipUnchanged bool

// writeCmd represents the write command
writeCmd = &cobra.Command{
Expand All @@ -26,6 +27,7 @@ var (

func init() {
writeCmd.Flags().BoolVarP(&singleline, "singleline", "s", false, "Insert single line parameter (end with \\n)")
writeCmd.Flags().BoolVarP(&skipUnchanged, "skip-unchanged", "", false, "Skip writing secret if value is unchanged")
RootCmd.AddCommand(writeCmd)
}

Expand Down Expand Up @@ -82,5 +84,12 @@ func write(cmd *cobra.Command, args []string) error {
Key: key,
}

if skipUnchanged {
currentSecret, err := secretStore.Read(secretId, -1)
if err == nil && value == *currentSecret.Value {
return nil
}
}

return secretStore.Write(secretId, value)
}

0 comments on commit ab51432

Please sign in to comment.