From: garciadeblas Date: Wed, 21 Jun 2023 15:33:57 +0000 (+0200) Subject: Amend user-update operation to simplify options X-Git-Tag: release-v14.0-start~8 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F13561%2F3;p=osm%2Fosmclient.git Amend user-update operation to simplify options Change-Id: I447fcd86c2640af16637e9502569834f3efa0fe9 Signed-off-by: garciadeblas --- diff --git a/osmclient/cli_commands/rbac.py b/osmclient/cli_commands/rbac.py index 25e72d0..fcad963 100755 --- a/osmclient/cli_commands/rbac.py +++ b/osmclient/cli_commands/rbac.py @@ -333,13 +333,6 @@ def user_create(ctx, username, password, projects, project_role_mappings, domain @click.command(name="user-update", short_help="updates user information") @click.argument("username") -@click.option( - "--password", - # prompt=True, - # hide_input=True, - # confirmation_prompt=True, - help="user password", -) @click.option("--set-username", "set_username", default=None, help="change username") @click.option( "--set-project", @@ -369,11 +362,14 @@ def user_create(ctx, username, password, projects, project_role_mappings, domain multiple=True, help="remove role(s) in a project. Can be used several times: 'project,role1[,role2,...]'", ) -@click.option("--change_password", "change_password", help="user's current password") +@click.option("--current-password", "current_password", help="user's current password") @click.option( - "--new_password", + "--new-password", "new_password", - help="user's new password to update in expiry condition", + prompt=True, + hide_input=True, + confirmation_prompt=True, + help="new user password", ) @click.option( "--unlock", @@ -389,13 +385,12 @@ def user_create(ctx, username, password, projects, project_role_mappings, domain def user_update( ctx, username, - password, set_username, set_project, remove_project, add_project_role, remove_project_role, - change_password, + current_password, new_password, unlock, renew, @@ -404,34 +399,34 @@ def user_update( \b USERNAME: name of the user - PASSWORD: new password SET_USERNAME: new username SET_PROJECT: creating mappings for project/role(s) REMOVE_PROJECT: deleting mappings for project/role(s) ADD_PROJECT_ROLE: adding mappings for project/role(s) REMOVE_PROJECT_ROLE: removing mappings for project/role(s) - CHANGE_PASSWORD: user's current password to change - NEW_PASSWORD: user's new password to update in expiry condition + CURRENT_PASSWORD: user's current password to change + NEW_PASSWORD: user's new password to be updated UNLOCK: unlock user RENEW: renew user """ logger.debug("") user = {} - user["password"] = password user["username"] = set_username user["set-project"] = set_project user["remove-project"] = remove_project user["add-project-role"] = add_project_role user["remove-project-role"] = remove_project_role - user["change_password"] = change_password + user["current_password"] = current_password user["new_password"] = new_password user["unlock"] = unlock user["renew"] = renew utils.check_client_version(ctx.obj, ctx.command.name) - if not user.get("change_password"): + if not user.get("current_password"): + # In case the password is valid but the end user wants to update it ctx.obj.user.update(username, user) else: + # In case the password has expired (also applies in first login) ctx.obj.user.update(username, user, pwd_change=True) diff --git a/osmclient/sol005/client.py b/osmclient/sol005/client.py index b05dbcc..9f97c31 100644 --- a/osmclient/sol005/client.py +++ b/osmclient/sol005/client.py @@ -104,7 +104,7 @@ class Client(object): self.utils = utils.Utils(http_client, **kwargs) """ - def get_token(self, pwd_change=None): + def get_token(self, pwd_change=False): self._logger.debug("") if self._token is None: postfields_dict = { diff --git a/osmclient/sol005/user.py b/osmclient/sol005/user.py index 74a7c59..296bd55 100644 --- a/osmclient/sol005/user.py +++ b/osmclient/sol005/user.py @@ -84,7 +84,7 @@ class User(object): # msg = resp # raise ClientException("failed to create user {} - {}".format(name, msg)) - def update(self, name, user, pwd_change=None): + def update(self, name, user, pwd_change=False): """Updates an existing OSM user identified by name""" self._logger.debug("") if pwd_change: @@ -98,15 +98,12 @@ class User(object): "remove_project_role_mappings": [], } - if not user.get("change_password"): - # if password is defined, update the password - if user.get("password"): - update_user["password"] = user["password"] - if user.get("username"): - update_user["username"] = user["username"] - else: - update_user["old_password"] = user["change_password"] + if user.get("username"): + update_user["username"] = user["username"] + if user.get("new_password"): update_user["password"] = user["new_password"] + if pwd_change and user.get("current_password"): + update_user["old_password"] = user["current_password"] if user.get("set-project"): # Remove project and insert project role mapping