diff --git a/cmd/diff.go b/cmd/diff.go index fb937dc..edd61ca 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -34,9 +34,15 @@ var Diff = &command.Command{ }, }, }, + "redacted": { + Description: "Compare redacted versions", + Type: "bool", + Default: false, + }, }, Action: func(cmd *command.Command) error { paths := cmd.Arguments[0].ToValue().([]string) + redacted := cmd.Options["redacted"].ToValue().(bool) for _, path := range paths { local, err := config.Load(path, false) @@ -44,7 +50,7 @@ var Diff = &command.Command{ return err } - if err := local.DiffRemote(path, cmd.Cobra.OutOrStdout(), cmd.Cobra.OutOrStderr()); err != nil { + if err := local.DiffRemote(path, redacted, cmd.Cobra.OutOrStdout(), cmd.Cobra.OutOrStderr()); err != nil { return err } } diff --git a/internal/op-client/op.go b/internal/op-client/op.go index a1dc038..70753ca 100644 --- a/internal/op-client/op.go +++ b/internal/op-client/op.go @@ -42,6 +42,7 @@ func Update(vault, name string, item *op.Item) error { } if remote.GetValue("password") == item.GetValue("password") { + logrus.Debugf("remote %s\nlocal %s", remote.GetValue("password"), item.GetValue("password")) logrus.Warnf("item %s/%s is already up to date", item.Vault.ID, item.Title) return nil } diff --git a/pkg/config/config.go b/pkg/config/config.go index 5079c8b..6958d23 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -156,13 +156,19 @@ func (cfg *Config) Merge(other *Config) error { return cfg.Tree.Merge(other.Tree) } -func (cfg *Config) DiffRemote(path string, stdout io.Writer, stderr io.Writer) error { +func (cfg *Config) DiffRemote(path string, redacted bool, stdout, stderr io.Writer) error { + logrus.Debugf("loading remote for %s", path) remote, err := Load(path, true) if err != nil { return err } - localBytes, err := cfg.AsYAML(OutputModeNoComments, OutputModeSorted, OutputModeNoConfig, OutputModeStandardYAML) + modes := []OutputMode{OutputModeNoComments, OutputModeSorted, OutputModeNoConfig, OutputModeStandardYAML} + if redacted { + modes = append(modes, OutputModeRedacted) + } + + localBytes, err := cfg.AsYAML(modes...) if err != nil { return err } @@ -173,7 +179,7 @@ func (cfg *Config) DiffRemote(path string, stdout io.Writer, stderr io.Writer) e } defer cleanupLocalDiff() - remoteBytes, err := remote.AsYAML(OutputModeNoComments, OutputModeSorted, OutputModeStandardYAML) + remoteBytes, err := remote.AsYAML(modes...) if err != nil { return err } diff --git a/pkg/config/util.go b/pkg/config/util.go index 44bfbaa..baffe69 100644 --- a/pkg/config/util.go +++ b/pkg/config/util.go @@ -97,7 +97,6 @@ func checksum(fields []*op.ItemField) string { sort.Strings(df) newHash.Write([]byte(strings.Join(df, ""))) checksum := newHash.Sum(nil) - return fmt.Sprintf("%x", checksum) }