From cf3d07d66c9f0e6eb1d17f6d441e88b99bd79cf5 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Mon, 3 Jul 2023 13:52:59 +0800 Subject: [PATCH] implement reset password command --- milvus_cli/scripts/milvus_cli.py | 41 ++++++++++++++++++++++++++++++++ milvus_cli/utils.py | 14 +++++++++++ 2 files changed, 55 insertions(+) diff --git a/milvus_cli/scripts/milvus_cli.py b/milvus_cli/scripts/milvus_cli.py index e310de1..9205f32 100644 --- a/milvus_cli/scripts/milvus_cli.py +++ b/milvus_cli/scripts/milvus_cli.py @@ -159,6 +159,47 @@ def connection(obj, showAll): else: click.echo(obj.showConnection(False,showAll=showAll)) +@cli.group(no_args_is_help=False) +@click.pass_obj +def reset(obj): + """Reset password.""" + pass + +@reset.command("password") +@click.option( + "-u", + "--username", + "username", + help="[Required] - Username.", + required=True, + type=str, +) +@click.option( + "-op", + "--old-password", + "old_password", + help="[Required] - Old password.", + required=True, + type=str, +) +@click.option( + "-p", + "--new-password", + "new_password", + help="[Required] - New password.", + required=True, + type=str, +) +@click.pass_obj +def resetPassword(obj, username, old_password, new_password): + """Reset password.""" + try: + obj.checkConnection() + obj.resetPassword(username, old_password, new_password) + except Exception as e: + click.echo(message=e, err=True) + else: + click.echo("Reset password successfully.") @show.command("loading_progress") @click.option("-c", diff --git a/milvus_cli/utils.py b/milvus_cli/utils.py index 4286dd1..0542981 100644 --- a/milvus_cli/utils.py +++ b/milvus_cli/utils.py @@ -93,6 +93,20 @@ def showConnection(self, alias, showAll=False): else: return "Connection not found!" + def _reset_password(self, username, old_password, password): + from pymilvus import utility + + username = None if username is None else username.strip() + password = None if password is None else password.strip() + + try: + utility.reset_password(username, old_password, password, using=self.alias) + except Exception as e: + raise ParameterException(f"Reset password error!{str(e)}") + + def resetPassword(self, username, old_password, password): + self._reset_password(username, old_password, password) + def _list_collection_names(self, timeout=None): from pymilvus import utility