Meta API endpoint wich returns information about the currently authenticated user. Handle: GET /v1/user
(self, requester_user, auth_info)
| 22 | |
| 23 | class UserController(object): |
| 24 | def get(self, requester_user, auth_info): |
| 25 | """ |
| 26 | Meta API endpoint wich returns information about the currently authenticated user. |
| 27 | |
| 28 | Handle: |
| 29 | GET /v1/user |
| 30 | """ |
| 31 | |
| 32 | data = {} |
| 33 | |
| 34 | rbac_utils = get_rbac_backend().get_utils_class() |
| 35 | rbac_service = get_rbac_backend().get_service_class() |
| 36 | |
| 37 | if cfg.CONF.rbac.enable and requester_user: |
| 38 | role_dbs = rbac_service.get_roles_for_user(user_db=requester_user) |
| 39 | roles = [role_db.name for role_db in role_dbs] |
| 40 | else: |
| 41 | roles = [] |
| 42 | |
| 43 | data = { |
| 44 | "username": requester_user.name, |
| 45 | "authentication": { |
| 46 | "method": auth_info["method"], |
| 47 | "location": auth_info["location"], |
| 48 | }, |
| 49 | "rbac": { |
| 50 | "enabled": cfg.CONF.rbac.enable, |
| 51 | "roles": roles, |
| 52 | "is_admin": rbac_utils.user_is_admin(user_db=requester_user), |
| 53 | }, |
| 54 | } |
| 55 | |
| 56 | if auth_info.get("token_expire", None): |
| 57 | token_expire = auth_info["token_expire"].strftime("%Y-%m-%dT%H:%M:%SZ") |
| 58 | data["authentication"]["token_expire"] = token_expire |
| 59 | |
| 60 | return data |
| 61 | |
| 62 | |
| 63 | user_controller = UserController() |