Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSM-493 - KSM CLI: Added CLI options to update title and notes #566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,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 @@ -554,7 +554,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 @@ -566,6 +566,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
Loading