async def get_role(self, groupId, roleId): """ Args: group_id {str} role_id {str} Returns: Role """ http_method = "get".upper() api_url = format_url(f""" {self._base_url} /api/v1/groups/{groupId}/roles/{roleId} """) body = {} headers = {} request, error = await self._request_executor.create_request( http_method, api_url, body, headers) if error: return (None, None, error) response, error = await self._request_executor\ .execute(request, Role) if error: return (None, response, error) try: result = Role(self.form_response_body(response.get_body())) except Exception as error: return (None, response, error) return (result, response, None)
async def assign_role_to_group(self, groupId, assign_role_request, query_params={}, keep_empty_params=False): """ Assigns a Role to a Group Args: group_id {str} {assign_role_request} query_params {dict}: Map of query parameters for request [query_params.disableNotifications] {str} Returns: Role """ http_method = "post".upper() api_url = format_url(f""" {self._base_url} /api/v1/groups/{groupId}/roles """) if query_params: encoded_query_params = urlencode(query_params) api_url += f"/?{encoded_query_params}" if isinstance(assign_role_request, dict): body = assign_role_request else: body = assign_role_request.as_dict() headers = { "Accept": "application/json", "Content-Type": "application/json" } form = {} request, error = await self._request_executor.create_request( http_method, api_url, body, headers, form, keep_empty_params=keep_empty_params) if error: return (None, None, error) response, error = await self._request_executor\ .execute(request, Role) if error: return (None, response, error) try: result = Role(self.form_response_body(response.get_body())) except Exception as error: return (None, response, error) return (result, response, None)
async def list_group_assigned_roles(self, groupId, query_params={}, keep_empty_params=False): """ Args: group_id {str} query_params {dict}: Map of query parameters for request [query_params.expand] {str} Returns: list: Collection of Role instances. """ http_method = "get".upper() api_url = format_url(f""" {self._base_url} /api/v1/groups/{groupId}/roles """) if query_params: encoded_query_params = urlencode(query_params) api_url += f"/?{encoded_query_params}" body = {} headers = {} form = {} request, error = await self._request_executor.create_request( http_method, api_url, body, headers, form, keep_empty_params=keep_empty_params) if error: return (None, None, error) response, error = await self._request_executor\ .execute(request, Role) if error: return (None, response, error) try: result = [] for item in response.get_body(): result.append(Role(self.form_response_body(item))) except Exception as error: return (None, response, error) return (result, response, None)