Compare commits
No commits in common. "3d84f46112cc8cac7b264e0c462f72e88017447d" and "f011825e765c186f7a8e5e1bb74d69f222dee35d" have entirely different histories.
3d84f46112
...
f011825e76
@ -34,15 +34,9 @@ var Diff = &command.Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"redacted": {
|
|
||||||
Description: "Compare redacted versions",
|
|
||||||
Type: "bool",
|
|
||||||
Default: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Action: func(cmd *command.Command) error {
|
Action: func(cmd *command.Command) error {
|
||||||
paths := cmd.Arguments[0].ToValue().([]string)
|
paths := cmd.Arguments[0].ToValue().([]string)
|
||||||
redacted := cmd.Options["redacted"].ToValue().(bool)
|
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
|
|
||||||
local, err := config.Load(path, false)
|
local, err := config.Load(path, false)
|
||||||
@ -50,7 +44,7 @@ var Diff = &command.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := local.DiffRemote(path, redacted, cmd.Cobra.OutOrStdout(), cmd.Cobra.OutOrStderr()); err != nil {
|
if err := local.DiffRemote(path, cmd.Cobra.OutOrStdout(), cmd.Cobra.OutOrStderr()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ var Flush = &command.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cmd.Options["redact"].ToValue().(bool) {
|
if cmd.Options["redact"].ToValue().(bool) {
|
||||||
if err := cfg.AsFile(path, config.OutputModeRedacted); err != nil {
|
if err := cfg.AsFile(path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,7 @@ func Update(vault, name string, item *op.Item) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if remote.GetValue("password") == item.GetValue("password") {
|
if remote.GetValue("password") == item.GetValue("password") {
|
||||||
logrus.Debugf("remote %s\nlocal %s", remote.GetValue("password"), item.GetValue("password"))
|
logrus.Warn("item is already up to date")
|
||||||
logrus.Warnf("item %s/%s is already up to date", item.Vault.ID, item.Title)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,19 +156,13 @@ func (cfg *Config) Merge(other *Config) error {
|
|||||||
return cfg.Tree.Merge(other.Tree)
|
return cfg.Tree.Merge(other.Tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Config) DiffRemote(path string, redacted bool, stdout, stderr io.Writer) error {
|
func (cfg *Config) DiffRemote(path string, stdout io.Writer, stderr io.Writer) error {
|
||||||
logrus.Debugf("loading remote for %s", path)
|
|
||||||
remote, err := Load(path, true)
|
remote, err := Load(path, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
modes := []OutputMode{OutputModeNoComments, OutputModeSorted, OutputModeNoConfig, OutputModeStandardYAML}
|
localBytes, err := cfg.AsYAML(OutputModeNoComments, OutputModeSorted, OutputModeNoConfig)
|
||||||
if redacted {
|
|
||||||
modes = append(modes, OutputModeRedacted)
|
|
||||||
}
|
|
||||||
|
|
||||||
localBytes, err := cfg.AsYAML(modes...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -179,7 +173,7 @@ func (cfg *Config) DiffRemote(path string, redacted bool, stdout, stderr io.Writ
|
|||||||
}
|
}
|
||||||
defer cleanupLocalDiff()
|
defer cleanupLocalDiff()
|
||||||
|
|
||||||
remoteBytes, err := remote.AsYAML(modes...)
|
remoteBytes, err := remote.AsYAML(OutputModeNoComments, OutputModeSorted)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -195,23 +195,6 @@ func (e *Entry) asNode() *yaml.Node {
|
|||||||
n.FootComment = e.FootComment
|
n.FootComment = e.FootComment
|
||||||
}
|
}
|
||||||
|
|
||||||
if yamlOutput.Has(OutputModeStandardYAML) {
|
|
||||||
if e.IsScalar() {
|
|
||||||
if len(e.Path) >= 0 {
|
|
||||||
if !strings.Contains(n.Value, "\n") {
|
|
||||||
n.Style &= yaml.FoldedStyle
|
|
||||||
} else {
|
|
||||||
n.Style &= yaml.FlowStyle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
n.Style = yaml.FoldedStyle | yaml.LiteralStyle
|
|
||||||
for _, v := range n.Content {
|
|
||||||
v.Style = yaml.FlowStyle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +209,7 @@ func (e *Entry) MarshalYAML() (*yaml.Node, error) {
|
|||||||
}
|
}
|
||||||
n.Content = append(n.Content, node)
|
n.Content = append(n.Content, node)
|
||||||
}
|
}
|
||||||
} else if e.Kind == yaml.MappingNode || e.Kind == yaml.DocumentNode {
|
} else {
|
||||||
entries := e.Contents()
|
entries := e.Contents()
|
||||||
if len(entries)%2 != 0 {
|
if len(entries)%2 != 0 {
|
||||||
return nil, fmt.Errorf("cannot decode odd numbered contents list: %s", e.Path)
|
return nil, fmt.Errorf("cannot decode odd numbered contents list: %s", e.Path)
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const warnChecksumMismatch = `1Password item %s changed and checksum was not updated.
|
const warnChecksumMismatch = `1Password item changed and checksum was not updated.
|
||||||
Expected: %s
|
Expected: %s
|
||||||
found : %s`
|
found : %s`
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ func FromOP(item *op.Item) (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cs := checksum(item.Fields); cs != item.GetValue("password") {
|
if cs := checksum(item.Fields); cs != item.GetValue("password") {
|
||||||
logrus.Warnf(warnChecksumMismatch, fmt.Sprintf("%s/%s", item.Vault.ID, item.Title), cs, item.GetValue("password"))
|
logrus.Warnf(warnChecksumMismatch, cs, item.GetValue("password"))
|
||||||
}
|
}
|
||||||
err := cfg.Tree.FromOP(item.Fields)
|
err := cfg.Tree.FromOP(item.Fields)
|
||||||
return cfg, err
|
return cfg, err
|
||||||
|
@ -43,8 +43,6 @@ const (
|
|||||||
OutputModeSorted OutputMode = 4
|
OutputModeSorted OutputMode = 4
|
||||||
// OutputModeNoConfig does not output the _config key if any.
|
// OutputModeNoConfig does not output the _config key if any.
|
||||||
OutputModeNoConfig OutputMode = 8
|
OutputModeNoConfig OutputMode = 8
|
||||||
// OutputModeStandardYAML formats strings and arrays uniformly
|
|
||||||
OutputModeStandardYAML OutputMode = 16
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultYamlOutput = &outputOptions{OutputModeRoundTrip}
|
var defaultYamlOutput = &outputOptions{OutputModeRoundTrip}
|
||||||
|
@ -97,6 +97,7 @@ func checksum(fields []*op.ItemField) string {
|
|||||||
sort.Strings(df)
|
sort.Strings(df)
|
||||||
newHash.Write([]byte(strings.Join(df, "")))
|
newHash.Write([]byte(strings.Join(df, "")))
|
||||||
checksum := newHash.Sum(nil)
|
checksum := newHash.Sum(nil)
|
||||||
|
|
||||||
return fmt.Sprintf("%x", checksum)
|
return fmt.Sprintf("%x", checksum)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user