fix the mystery of the changing checksums
This commit is contained in:
parent
55e393f86f
commit
37e2e6bb9b
|
@ -20,8 +20,14 @@ func Checksum(fields []*op.ItemField) string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
label := field.Label
|
label := field.Label
|
||||||
if field.Section != nil && field.Section.ID != "" {
|
if field.Section != nil {
|
||||||
label = field.Section.ID + "." + label
|
sectionId := field.Section.Label
|
||||||
|
if sectionId == "" {
|
||||||
|
sectionId = field.Section.ID
|
||||||
|
}
|
||||||
|
if sectionId != "" {
|
||||||
|
label = sectionId + "." + label
|
||||||
|
}
|
||||||
}
|
}
|
||||||
df = append(df, label+field.Value)
|
df = append(df, label+field.Value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,15 @@ type CLI struct {
|
||||||
DryRun bool // Won't write to 1Password
|
DryRun bool // Won't write to 1Password
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CLI) invoke(vault string, stdin *bytes.Buffer, args ...string) (bytes.Buffer, error) {
|
func invoke(dryRun bool, vault string, stdin *bytes.Buffer, args ...string) (bytes.Buffer, error) {
|
||||||
if vault != "" {
|
if vault != "" {
|
||||||
args = append([]string{"--vault", shellescape.Quote(vault)}, args...)
|
args = append([]string{"--vault", shellescape.Quote(vault)}, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
argString := strings.Join(args, " ")
|
argString := strings.Join(args, " ")
|
||||||
if b.DryRun {
|
if dryRun {
|
||||||
logrus.Warnf("dry-run: Would have invoked `op %s`", argString)
|
logrus.Warnf("dry-run: Would have invoked `op %s`", argString)
|
||||||
logrus.Warnf("dry-run: stdin `%s %s`", Path, stdin)
|
logrus.Warnf("dry-run: stdin `%s`", stdin)
|
||||||
return bytes.Buffer{}, nil
|
return bytes.Buffer{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (b *CLI) invoke(vault string, stdin *bytes.Buffer, args ...string) (bytes.B
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CLI) Get(vault, name string) (*op.Item, error) {
|
func (b *CLI) Get(vault, name string) (*op.Item, error) {
|
||||||
stdout, err := b.invoke(vault, nil, "item", "--format", "json", "get", name)
|
stdout, err := invoke(false, vault, nil, "item", "--format", "json", "get", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func (b *CLI) Create(item *op.Item) error {
|
||||||
|
|
||||||
stdin := bytes.NewBuffer(itemJSON)
|
stdin := bytes.NewBuffer(itemJSON)
|
||||||
|
|
||||||
_, err = b.invoke(item.Vault.ID, stdin, "item", "create")
|
_, err = invoke(b.DryRun, item.Vault.ID, stdin, "item", "create")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create item: %w", err)
|
return fmt.Errorf("could not create item: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -95,13 +95,14 @@ func (b *CLI) Create(item *op.Item) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CLI) Update(item *op.Item, remote *op.Item) error {
|
func (b *CLI) Update(item *op.Item, remote *op.Item) error {
|
||||||
res, err := b.invoke("", nil, "--version")
|
res, err := invoke(false, "", nil, "--version")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
current, err := version.NewVersion(res.String())
|
v := strings.TrimSpace(res.String())
|
||||||
|
current, err := version.NewVersion(v)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
probedVersionModern = versionConstraint.Check(current)
|
probedVersionModern = versionConstraint.Check(current)
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("Failed parsing version <%s>: %s", res.String(), err)
|
logrus.Debugf("Failed parsing version <%s>: %s", v, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,20 +114,18 @@ func (b *CLI) Update(item *op.Item, remote *op.Item) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CLI) UpdateModern(updated *op.Item, original *op.Item) error {
|
func (b *CLI) UpdateModern(updated *op.Item, original *op.Item) error {
|
||||||
logrus.Infof("Creating new item: %s/%s", updated.Vault.ID, updated.Title)
|
|
||||||
|
|
||||||
itemJSON, err := json.Marshal(updated)
|
itemJSON, err := json.Marshal(updated)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not serialize op item into json: %w", err)
|
return fmt.Errorf("could not serialize op item into json: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stdin := bytes.NewBuffer(itemJSON)
|
stdin := bytes.NewBuffer(itemJSON)
|
||||||
_, err = b.invoke(updated.Vault.ID, stdin, "item", "edit", original.Title)
|
_, err = invoke(b.DryRun, updated.Vault.ID, stdin, "item", "edit", original.Title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create item: %w", err)
|
return fmt.Errorf("could not create item: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Item %s/%s created", updated.Vault.ID, updated.Title)
|
logrus.Infof("Item %s/%s updated", updated.Vault.ID, updated.Title)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +159,7 @@ func (b *CLI) DeprecatedUpdate(updated *op.Item, original *op.Item) error {
|
||||||
logrus.Warnf("dry-run: Would have invoked op %v", args)
|
logrus.Warnf("dry-run: Would have invoked op %v", args)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
stdout, err := b.invoke(updated.Vault.ID, nil, args...)
|
stdout, err := invoke(b.DryRun, updated.Vault.ID, nil, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("op stderr: %s", stdout.String())
|
logrus.Errorf("op stderr: %s", stdout.String())
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue