Skip to content

Commit

Permalink
OPS-6558 Fix bug where files in fields of a 1PW item never get updated
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncolincap committed Oct 1, 2024
1 parent f3229dd commit 76214e5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion onepwd/plugins/action/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def run(self, tmp=None, task_vars=None, **kwargs):

def run_present(self, op:onepwd.OnePwd, category, name, vault, fields, generate_password, overwrite, check):
assignment_statements = ""
# Dry-run doesn't recognize changes in files so we always update items containing files
overwrite_file_fields = False
for field in fields:
if 'overwrite' in field and field['overwrite'] is False:
labels = op.get('item', item_name=name, vault=vault)
Expand All @@ -59,14 +61,16 @@ def run_present(self, op:onepwd.OnePwd, category, name, vault, fields, generate_
if not label_existing:
assignment_statements += " " + onepwd.build_assignment_statement(field)
else:
if lowercase(field['type']) == 'file':
overwrite_file_fields = True
assignment_statements += " " + onepwd.build_assignment_statement(field)

result = {}
diff = {}
try:
get_result = op.get('item', item_name=name, vault=vault)
edit_result = op.edit_item(name, assignment_statements, vault=vault, generate_password=generate_password, dry_run=True)
changed = not items_equal(get_result, edit_result) and overwrite
changed = (not items_equal(get_result, edit_result) or overwrite_file_fields) and overwrite
if changed:
if not check:
edit_result = op.edit_item(name, assignment_statements, vault=vault, generate_password=generate_password)
Expand Down

0 comments on commit 76214e5

Please sign in to comment.