Skip to content

Commit

Permalink
KSM-493 Added CLI options to update title and notes (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
idimov-keeper authored Apr 12, 2024
1 parent 6725b7c commit 5462570
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,19 @@ def secret_notation_command(ctx, text):
@click.option('--field-json', type=str, multiple=True, help="Update value in field section of vault using JSON")
@click.option('--custom-field-json', type=str, multiple=True,
help="Update value in custom field section of vault using JSON")
@click.option('--title', '-t', type=str, help="Update record title.")
@click.option('--notes', '-n', type=str, help="Update record notes.")
@click.pass_context
def secret_update_command(ctx, uid, field, custom_field, field_json, custom_field_json):
def secret_update_command(ctx, uid, field, custom_field, field_json, custom_field_json, title, notes):
"""Update an existing record"""
ctx.obj["secret"].update(
uid=uid,
fields=field,
custom_fields=custom_field,
fields_json=field_json,
custom_fields_json=custom_field_json
custom_fields_json=custom_field_json,
title=title,
notes=notes
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _split_kv(text, is_json=False, labels=None):

return key, value

def update(self, uid, fields=None, custom_fields=None, fields_json=None, custom_fields_json=None):
def update(self, uid, fields=None, custom_fields=None, fields_json=None, custom_fields_json=None, title=None, notes=None):

record = self.cli.client.get_secrets(uids=[uid])
if len(record) == 0:
Expand All @@ -568,6 +568,15 @@ def _get_label(x):
label = x.get("type")
return label

if title is not None:
record[0].title = str(title)

if notes is not None:
record[0].dict["notes"] = str(notes)

if title is not None or notes is not None:
record[0]._update()

# Get a list of all labels/type allowed.
labels = {
"field": [_get_label(x) for x in record[0].dict.get("fields", [])],
Expand Down

0 comments on commit 5462570

Please sign in to comment.