X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fcli_commands%2Frbac.py;h=d8f2068342e4efb38660b580e9c92b766ae7b4c9;hb=fca1247748bdd66f7d461ad7f03be260ef1e9e18;hp=57809bf89db04254fa23b2ed10ab623c92f677dd;hpb=3f3faa30b7341acd221fd580b00418b4684ae85c;p=osm%2Fosmclient.git diff --git a/osmclient/cli_commands/rbac.py b/osmclient/cli_commands/rbac.py index 57809bf..d8f2068 100755 --- a/osmclient/cli_commands/rbac.py +++ b/osmclient/cli_commands/rbac.py @@ -19,6 +19,7 @@ from osmclient.cli_commands import utils from prettytable import PrettyTable import json import logging +import time logger = logging.getLogger("osmclient") @@ -374,6 +375,16 @@ def user_create(ctx, username, password, projects, project_role_mappings, domain "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, @@ -386,6 +397,8 @@ def user_update( remove_project_role, change_password, new_password, + unlock, + renew, ): """Update a user information @@ -399,6 +412,8 @@ def user_update( 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 = {} @@ -410,6 +425,8 @@ def user_update( 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) @@ -447,10 +464,30 @@ def user_list(ctx, filter): 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)