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(
+ "--new_password",
+ "new_password",
+ help="user's new password to update in expiry condition"
+)
@click.pass_context
def user_update(
ctx,
remove_project,
add_project_role,
remove_project_role,
+ change_password,
+ new_password,
):
"""Update a user information
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
"""
logger.debug("")
user = {}
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["new_password"] = new_password
# try:
check_client_version(ctx.obj, ctx.command.name)
- ctx.obj.user.update(username, user)
+ if not user.get("change_password"):
+ ctx.obj.user.update(username, user)
+ else:
+ ctx.obj.user.update(username, user, pwd_change=True)
# except ClientException as e:
# print(str(e))
# exit(1)
from osmclient.sol005 import osmrepo
from osmclient.sol005 import subscription
from osmclient.common import package_tool
+from osmclient.common.exceptions import ClientException
import json
import logging
self.utils = utils.Utils(http_client, **kwargs)
"""
- def get_token(self):
+ def get_token(self, pwd_change=None):
self._logger.debug("")
if self._token is None:
postfields_dict = {
# raise ClientException(message)
token = json.loads(resp) if resp else None
+ if token.get("message") == "change_password" and not pwd_change:
+ raise ClientException("Password Expired. Please update the password using change_password option")
self._token = token["id"]
if self._token is not None:
# msg = resp
# raise ClientException("failed to create user {} - {}".format(name, msg))
- def update(self, name, user):
+ def update(self, name, user, pwd_change=None):
"""Updates an existing OSM user identified by name"""
self._logger.debug("")
- self._client.get_token()
+ if pwd_change:
+ self._client.get_token(pwd_change)
+ else:
+ self._client.get_token()
# print(user)
myuser = self.get(name)
update_user = {
"remove_project_role_mappings": [],
}
- # if password is defined, update the password
- if user["password"]:
- update_user["password"] = user["password"]
- if user["username"]:
- update_user["username"] = user["username"]
+ 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"]
+ update_user["password"] = user["new_password"]
- if user["set-project"]:
+ if user.get("set-project"):
# Remove project and insert project role mapping
for set_project in user["set-project"]:
mapping = {"project": project, "role": role}
update_user["add_project_role_mappings"].append(mapping)
- if user["remove-project"]:
+ if user.get("remove-project"):
for remove_project in user["remove-project"]:
update_user["remove_project_role_mappings"].append(
{"project": remove_project}
)
- if user["add-project-role"]:
+ if user.get("add-project-role"):
for add_project_role in user["add-project-role"]:
add_project_role_clean = [
m.strip() for m in add_project_role.split(",")
mapping = {"project": project, "role": role}
update_user["add_project_role_mappings"].append(mapping)
- if user["remove-project-role"]:
+ if user.get("remove-project-role"):
for remove_project_role in user["remove-project-role"]:
remove_project_role_clean = [
m.strip() for m in remove_project_role.split(",")