from prettytable import PrettyTable
import json
import logging
+import time
logger = logging.getLogger("osmclient")
"new_password",
help="user's new password to update in expiry condition",
)
+@click.option(
+ "--unlock",
+ is_flag=True,
+ help="unlock user",
+)
+@click.option(
+ "--renew",
+ is_flag=True,
+ help="renew user",
+)
@click.pass_context
def user_update(
ctx,
remove_project_role,
change_password,
new_password,
+ unlock,
+ renew,
):
"""Update a user information
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
+ UNLOCK: unlock user
+ RENEW: renew user
"""
logger.debug("")
user = {}
user["remove-project-role"] = remove_project_role
user["change_password"] = change_password
user["new_password"] = new_password
+ user["unlock"] = unlock
+ user["renew"] = renew
utils.check_client_version(ctx.obj, ctx.command.name)
ctx.obj.user.update(username, user)
utils.check_client_version(ctx.obj, ctx.command.name)
if filter:
filter = "&".join(filter)
- resp = ctx.obj.user.list(filter)
- table = PrettyTable(["name", "id"])
+ resp, admin_show = ctx.obj.user.list(filter)
for user in resp:
- table.add_row([user["username"], user["_id"]])
+ if user["username"] == "admin":
+ user["_admin"]["account_expire_time"] = "N/A"
+ if admin_show:
+ table = PrettyTable(["name", "id", "user_status", "expires_in"])
+ for user in resp:
+ table.add_row(
+ [
+ user["username"],
+ user["_id"],
+ user["_admin"]["user_status"].upper(),
+ time.strftime(
+ "%b-%d-%Y %X",
+ time.gmtime(user["_admin"]["account_expire_time"]),
+ )
+ if not user["username"] == "admin"
+ else user["_admin"]["account_expire_time"],
+ ]
+ )
+ else:
+ table = PrettyTable(["name", "id"])
+ for user in resp:
+ table.add_row([user["username"], user["_id"]])
table.align = "l"
print(table)