From 24d356b0c98610e69ad154e8d9c3ff916c519903 Mon Sep 17 00:00:00 2001 From: Ivan Dimov <78815270+idimov-keeper@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:35:26 -0600 Subject: [PATCH] KSM-493 Added CLI options to update title and notes --- .../keeper_secrets_manager_cli/__main__.py | 8 ++++++-- .../keeper_secrets_manager_cli/secret.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/__main__.py b/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/__main__.py index 80fa6c92..6ba719b7 100644 --- a/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/__main__.py +++ b/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/__main__.py @@ -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 ) diff --git a/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/secret.py b/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/secret.py index 40dad3cb..90c7984f 100644 --- a/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/secret.py +++ b/integration/keeper_secrets_manager_cli/keeper_secrets_manager_cli/secret.py @@ -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: @@ -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", [])],