Skip to content

Commit

Permalink
Merge pull request #30 from Yeuoly/main
Browse files Browse the repository at this point in the history
implement reset password command
  • Loading branch information
shanghaikid authored Jul 4, 2023
2 parents 29c0e15 + cf3d07d commit 5be0a05
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
41 changes: 41 additions & 0 deletions milvus_cli/scripts/milvus_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions milvus_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5be0a05

Please sign in to comment.