diff --git a/integration/keeper_secrets_manager_cli/README.md b/integration/keeper_secrets_manager_cli/README.md index 49e18136..6c3fadff 100644 --- a/integration/keeper_secrets_manager_cli/README.md +++ b/integration/keeper_secrets_manager_cli/README.md @@ -8,7 +8,8 @@ For more information see our official documentation page https://docs.keeper.io/ ## 1.1.4 -- KSM-507: Added `ksm secret delete` functionality +- KSM-507: Added `ksm secret delete` command +- KSM-508: Added search by title to `ksm secret list` command ## 1.1.3 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 8ad2a931..3605a88d 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 @@ -552,21 +552,20 @@ def secret_command(ctx): @click.option('--recursive', '-r', is_flag=True, help='List recursively all records including subfolders of the folder UID') @click.option('--query', '-q', type=str, help='List records matching the JSONPath query') @click.option('--show-value', '-v', is_flag=True, help='Print matching value instead of record title') +@click.option('--title', '-t', type=str, help='List only records with title matching the regex') @click.option('--json', is_flag=True, help='Return secret as JSON') @click.pass_context -def secret_list_command(ctx, uid, folder, recursive, query, show_value, json): +def secret_list_command(ctx, uid, folder, recursive, query, show_value, title, json): """List all secrets""" - output = "text" - if json is True: - output = "json" - + output = "json" if json is True else "text" ctx.obj["secret"].secret_list( uids=uid, folder=folder, recursive=recursive, query=query, show_value=show_value, + title=title, output_format=output, use_color=ctx.obj["cli"].use_color ) 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 a5ad4b0c..e4b222b3 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 @@ -472,13 +472,19 @@ def _format_list(record_dict, use_color=True, columns=None): table.add_row([record["uid"], record["type"], record["title"]]) return "\n" + table.get_string() + "\n" - def secret_list(self, uids=None, folder=None, recursive=False, query=None, show_value=False, output_format='json', use_color=None): + def secret_list(self, uids=None, folder=None, recursive=False, query=None, show_value=False, title="", output_format='json', use_color=None): if use_color is None: use_color = self.cli.use_color loadrefs = True if query else False # to load fields[] and custom[] record_dict = self.query(uids=uids, folder=folder, recursive=recursive, output_format='dict', load_references=loadrefs, unmask=True, use_color=use_color) + if title: + try: + filtered = [x for x in record_dict if re.search(title, x.get("title", ""), re.IGNORECASE)] + record_dict = filtered + except Exception as err: + raise KsmCliException(f"Check your regex '{title}' - error: {str(err)}") if query: items = self._query_jsonpath_list(query, record_dict) if output_format == 'text':