@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",
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",
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,
\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)
# 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:
"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