Debian Codegraph @

src/auth0/management/roles/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import typing
4 from json.decoder import JSONDecodeError
5
6 from ..core.api_error import ApiError
7 from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8 from ..core.http_response import AsyncHttpResponse, HttpResponse
9 from ..core.jsonable_encoder import encode_path_param
10 from ..core.pagination import AsyncPager, SyncPager
11 from ..core.parse_error import ParsingError
12 from ..core.pydantic_utilities import parse_obj_as
13 from ..core.request_options import RequestOptions
14 from ..errors.bad_request_error import BadRequestError
15 from ..errors.conflict_error import ConflictError
16 from ..errors.forbidden_error import ForbiddenError
17 from ..errors.not_found_error import NotFoundError
18 from ..errors.too_many_requests_error import TooManyRequestsError
19 from ..errors.unauthorized_error import UnauthorizedError
20 from ..types.create_role_response_content import CreateRoleResponseContent
21 from ..types.get_role_response_content import GetRoleResponseContent
22 from ..types.list_roles_offset_paginated_response_content import ListRolesOffsetPaginatedResponseContent
23 from ..types.role import Role
24 from ..types.update_role_response_content import UpdateRoleResponseContent
25 from pydantic import ValidationError
26
27 # this is used as the default value for optional parameters
28 OMIT = typing.cast(typing.Any, ...)
29
30
31 class RawRolesClient:
32 def __init__(self, *, client_wrapper: SyncClientWrapper):
33 self._client_wrapper = client_wrapper
34
35 def list(
36 self,
37 *,
38 per_page: typing.Optional[int] = 50,
39 page: typing.Optional[int] = 0,
40 include_totals: typing.Optional[bool] = True,
41 name_filter: typing.Optional[str] = None,
42 request_options: typing.Optional[RequestOptions] = None,
43 ) -> SyncPager[Role, ListRolesOffsetPaginatedResponseContent]:
44 """
45 Retrieve detailed list of user roles created in your tenant.
46
47 **Note**: The returned list does not include standard roles available for tenant members, such as Admin or Support Access.
48
49 Parameters
50 ----------
51 per_page : typing.Optional[int]
52 Number of results per page. Defaults to 50.
53
54 page : typing.Optional[int]
55 Page index of the results to return. First page is 0.
56
57 include_totals : typing.Optional[bool]
58 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
59
60 name_filter : typing.Optional[str]
61 Optional filter on name (case-insensitive).
62
63 request_options : typing.Optional[RequestOptions]
64 Request-specific configuration.
65
66 Returns
67 -------
68 SyncPager[Role, ListRolesOffsetPaginatedResponseContent]
69 Roles successfully retrieved.
70 """
71 page = page if page is not None else 0
72
73 _response = self._client_wrapper.httpx_client.request(
74 "roles",
75 method="GET",
76 params={
77 "per_page": per_page,
78 "page": page,
79 "include_totals": include_totals,
80 "name_filter": name_filter,
81 },
82 request_options=request_options,
83 )
84 try:
85 if 200 <= _response.status_code < 300:
86 _parsed_response = typing.cast(
87 ListRolesOffsetPaginatedResponseContent,
88 parse_obj_as(
89 type_=ListRolesOffsetPaginatedResponseContent, # type: ignore
90 object_=_response.json(),
91 ),
92 )
93 _items = _parsed_response.roles
94 _has_next = len(_items or []) > 0
95 _get_next = lambda: self.list(
96 per_page=per_page,
97 page=page + 1,
98 include_totals=include_totals,
99 name_filter=name_filter,
100 request_options=request_options,
101 )
102 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
103 if _response.status_code == 400:
104 raise BadRequestError(
105 headers=dict(_response.headers),
106 body=typing.cast(
107 typing.Any,
108 parse_obj_as(
109 type_=typing.Any, # type: ignore
110 object_=_response.json(),
111 ),
112 ),
113 )
114 if _response.status_code == 401:
115 raise UnauthorizedError(
116 headers=dict(_response.headers),
117 body=typing.cast(
118 typing.Any,
119 parse_obj_as(
120 type_=typing.Any, # type: ignore
121 object_=_response.json(),
122 ),
123 ),
124 )
125 if _response.status_code == 403:
126 raise ForbiddenError(
127 headers=dict(_response.headers),
128 body=typing.cast(
129 typing.Any,
130 parse_obj_as(
131 type_=typing.Any, # type: ignore
132 object_=_response.json(),
133 ),
134 ),
135 )
136 if _response.status_code == 429:
137 raise TooManyRequestsError(
138 headers=dict(_response.headers),
139 body=typing.cast(
140 typing.Any,
141 parse_obj_as(
142 type_=typing.Any, # type: ignore
143 object_=_response.json(),
144 ),
145 ),
146 )
147 _response_json = _response.json()
148 except JSONDecodeError:
149 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
150 except ValidationError as e:
151 raise ParsingError(
152 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
153 )
154 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
155
156 def create(
157 self,
158 *,
159 name: str,
160 description: typing.Optional[str] = OMIT,
161 request_options: typing.Optional[RequestOptions] = None,
162 ) -> HttpResponse[CreateRoleResponseContent]:
163 """
164 Create a user role for [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac).
165
166 **Note**: New roles are not associated with any permissions by default. To assign existing permissions to your role, review Associate Permissions with a Role. To create new permissions, review Add API Permissions.
167
168 Parameters
169 ----------
170 name : str
171 Name of the role.
172
173 description : typing.Optional[str]
174 Description of the role.
175
176 request_options : typing.Optional[RequestOptions]
177 Request-specific configuration.
178
179 Returns
180 -------
181 HttpResponse[CreateRoleResponseContent]
182 Role successfully created.
183 """
184 _response = self._client_wrapper.httpx_client.request(
185 "roles",
186 method="POST",
187 json={
188 "name": name,
189 "description": description,
190 },
191 headers={
192 "content-type": "application/json",
193 },
194 request_options=request_options,
195 omit=OMIT,
196 )
197 try:
198 if 200 <= _response.status_code < 300:
199 _data = typing.cast(
200 CreateRoleResponseContent,
201 parse_obj_as(
202 type_=CreateRoleResponseContent, # type: ignore
203 object_=_response.json(),
204 ),
205 )
206 return HttpResponse(response=_response, data=_data)
207 if _response.status_code == 400:
208 raise BadRequestError(
209 headers=dict(_response.headers),
210 body=typing.cast(
211 typing.Any,
212 parse_obj_as(
213 type_=typing.Any, # type: ignore
214 object_=_response.json(),
215 ),
216 ),
217 )
218 if _response.status_code == 401:
219 raise UnauthorizedError(
220 headers=dict(_response.headers),
221 body=typing.cast(
222 typing.Any,
223 parse_obj_as(
224 type_=typing.Any, # type: ignore
225 object_=_response.json(),
226 ),
227 ),
228 )
229 if _response.status_code == 403:
230 raise ForbiddenError(
231 headers=dict(_response.headers),
232 body=typing.cast(
233 typing.Any,
234 parse_obj_as(
235 type_=typing.Any, # type: ignore
236 object_=_response.json(),
237 ),
238 ),
239 )
240 if _response.status_code == 409:
241 raise ConflictError(
242 headers=dict(_response.headers),
243 body=typing.cast(
244 typing.Any,
245 parse_obj_as(
246 type_=typing.Any, # type: ignore
247 object_=_response.json(),
248 ),
249 ),
250 )
251 if _response.status_code == 429:
252 raise TooManyRequestsError(
253 headers=dict(_response.headers),
254 body=typing.cast(
255 typing.Any,
256 parse_obj_as(
257 type_=typing.Any, # type: ignore
258 object_=_response.json(),
259 ),
260 ),
261 )
262 _response_json = _response.json()
263 except JSONDecodeError:
264 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
265 except ValidationError as e:
266 raise ParsingError(
267 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
268 )
269 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
270
271 def get(
272 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
273 ) -> HttpResponse[GetRoleResponseContent]:
274 """
275 Retrieve details about a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.
276
277 Parameters
278 ----------
279 id : str
280 ID of the role to retrieve.
281
282 request_options : typing.Optional[RequestOptions]
283 Request-specific configuration.
284
285 Returns
286 -------
287 HttpResponse[GetRoleResponseContent]
288 Role successfully retrieved.
289 """
290 _response = self._client_wrapper.httpx_client.request(
291 f"roles/{encode_path_param(id)}",
292 method="GET",
293 request_options=request_options,
294 )
295 try:
296 if 200 <= _response.status_code < 300:
297 _data = typing.cast(
298 GetRoleResponseContent,
299 parse_obj_as(
300 type_=GetRoleResponseContent, # type: ignore
301 object_=_response.json(),
302 ),
303 )
304 return HttpResponse(response=_response, data=_data)
305 if _response.status_code == 400:
306 raise BadRequestError(
307 headers=dict(_response.headers),
308 body=typing.cast(
309 typing.Any,
310 parse_obj_as(
311 type_=typing.Any, # type: ignore
312 object_=_response.json(),
313 ),
314 ),
315 )
316 if _response.status_code == 401:
317 raise UnauthorizedError(
318 headers=dict(_response.headers),
319 body=typing.cast(
320 typing.Any,
321 parse_obj_as(
322 type_=typing.Any, # type: ignore
323 object_=_response.json(),
324 ),
325 ),
326 )
327 if _response.status_code == 403:
328 raise ForbiddenError(
329 headers=dict(_response.headers),
330 body=typing.cast(
331 typing.Any,
332 parse_obj_as(
333 type_=typing.Any, # type: ignore
334 object_=_response.json(),
335 ),
336 ),
337 )
338 if _response.status_code == 404:
339 raise NotFoundError(
340 headers=dict(_response.headers),
341 body=typing.cast(
342 typing.Any,
343 parse_obj_as(
344 type_=typing.Any, # type: ignore
345 object_=_response.json(),
346 ),
347 ),
348 )
349 if _response.status_code == 429:
350 raise TooManyRequestsError(
351 headers=dict(_response.headers),
352 body=typing.cast(
353 typing.Any,
354 parse_obj_as(
355 type_=typing.Any, # type: ignore
356 object_=_response.json(),
357 ),
358 ),
359 )
360 _response_json = _response.json()
361 except JSONDecodeError:
362 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
363 except ValidationError as e:
364 raise ParsingError(
365 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
366 )
367 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
368
369 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
370 """
371 Delete a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) from your tenant. Once deleted, it is removed from any user who was previously assigned that role. This action cannot be undone.
372
373 Parameters
374 ----------
375 id : str
376 ID of the role to delete.
377
378 request_options : typing.Optional[RequestOptions]
379 Request-specific configuration.
380
381 Returns
382 -------
383 HttpResponse[None]
384 """
385 _response = self._client_wrapper.httpx_client.request(
386 f"roles/{encode_path_param(id)}",
387 method="DELETE",
388 request_options=request_options,
389 )
390 try:
391 if 200 <= _response.status_code < 300:
392 return HttpResponse(response=_response, data=None)
393 if _response.status_code == 400:
394 raise BadRequestError(
395 headers=dict(_response.headers),
396 body=typing.cast(
397 typing.Any,
398 parse_obj_as(
399 type_=typing.Any, # type: ignore
400 object_=_response.json(),
401 ),
402 ),
403 )
404 if _response.status_code == 401:
405 raise UnauthorizedError(
406 headers=dict(_response.headers),
407 body=typing.cast(
408 typing.Any,
409 parse_obj_as(
410 type_=typing.Any, # type: ignore
411 object_=_response.json(),
412 ),
413 ),
414 )
415 if _response.status_code == 403:
416 raise ForbiddenError(
417 headers=dict(_response.headers),
418 body=typing.cast(
419 typing.Any,
420 parse_obj_as(
421 type_=typing.Any, # type: ignore
422 object_=_response.json(),
423 ),
424 ),
425 )
426 if _response.status_code == 404:
427 raise NotFoundError(
428 headers=dict(_response.headers),
429 body=typing.cast(
430 typing.Any,
431 parse_obj_as(
432 type_=typing.Any, # type: ignore
433 object_=_response.json(),
434 ),
435 ),
436 )
437 if _response.status_code == 429:
438 raise TooManyRequestsError(
439 headers=dict(_response.headers),
440 body=typing.cast(
441 typing.Any,
442 parse_obj_as(
443 type_=typing.Any, # type: ignore
444 object_=_response.json(),
445 ),
446 ),
447 )
448 _response_json = _response.json()
449 except JSONDecodeError:
450 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
451 except ValidationError as e:
452 raise ParsingError(
453 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
454 )
455 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
456
457 def update(
458 self,
459 id: str,
460 *,
461 name: typing.Optional[str] = OMIT,
462 description: typing.Optional[str] = OMIT,
463 request_options: typing.Optional[RequestOptions] = None,
464 ) -> HttpResponse[UpdateRoleResponseContent]:
465 """
466 Modify the details of a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.
467
468 Parameters
469 ----------
470 id : str
471 ID of the role to update.
472
473 name : typing.Optional[str]
474 Name of this role.
475
476 description : typing.Optional[str]
477 Description of this role.
478
479 request_options : typing.Optional[RequestOptions]
480 Request-specific configuration.
481
482 Returns
483 -------
484 HttpResponse[UpdateRoleResponseContent]
485 Role successfully updated.
486 """
487 _response = self._client_wrapper.httpx_client.request(
488 f"roles/{encode_path_param(id)}",
489 method="PATCH",
490 json={
491 "name": name,
492 "description": description,
493 },
494 headers={
495 "content-type": "application/json",
496 },
497 request_options=request_options,
498 omit=OMIT,
499 )
500 try:
501 if 200 <= _response.status_code < 300:
502 _data = typing.cast(
503 UpdateRoleResponseContent,
504 parse_obj_as(
505 type_=UpdateRoleResponseContent, # type: ignore
506 object_=_response.json(),
507 ),
508 )
509 return HttpResponse(response=_response, data=_data)
510 if _response.status_code == 400:
511 raise BadRequestError(
512 headers=dict(_response.headers),
513 body=typing.cast(
514 typing.Any,
515 parse_obj_as(
516 type_=typing.Any, # type: ignore
517 object_=_response.json(),
518 ),
519 ),
520 )
521 if _response.status_code == 401:
522 raise UnauthorizedError(
523 headers=dict(_response.headers),
524 body=typing.cast(
525 typing.Any,
526 parse_obj_as(
527 type_=typing.Any, # type: ignore
528 object_=_response.json(),
529 ),
530 ),
531 )
532 if _response.status_code == 403:
533 raise ForbiddenError(
534 headers=dict(_response.headers),
535 body=typing.cast(
536 typing.Any,
537 parse_obj_as(
538 type_=typing.Any, # type: ignore
539 object_=_response.json(),
540 ),
541 ),
542 )
543 if _response.status_code == 429:
544 raise TooManyRequestsError(
545 headers=dict(_response.headers),
546 body=typing.cast(
547 typing.Any,
548 parse_obj_as(
549 type_=typing.Any, # type: ignore
550 object_=_response.json(),
551 ),
552 ),
553 )
554 _response_json = _response.json()
555 except JSONDecodeError:
556 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
557 except ValidationError as e:
558 raise ParsingError(
559 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
560 )
561 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
562
563
564 class AsyncRawRolesClient:
565 def __init__(self, *, client_wrapper: AsyncClientWrapper):
566 self._client_wrapper = client_wrapper
567
568 async def list(
569 self,
570 *,
571 per_page: typing.Optional[int] = 50,
572 page: typing.Optional[int] = 0,
573 include_totals: typing.Optional[bool] = True,
574 name_filter: typing.Optional[str] = None,
575 request_options: typing.Optional[RequestOptions] = None,
576 ) -> AsyncPager[Role, ListRolesOffsetPaginatedResponseContent]:
577 """
578 Retrieve detailed list of user roles created in your tenant.
579
580 **Note**: The returned list does not include standard roles available for tenant members, such as Admin or Support Access.
581
582 Parameters
583 ----------
584 per_page : typing.Optional[int]
585 Number of results per page. Defaults to 50.
586
587 page : typing.Optional[int]
588 Page index of the results to return. First page is 0.
589
590 include_totals : typing.Optional[bool]
591 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
592
593 name_filter : typing.Optional[str]
594 Optional filter on name (case-insensitive).
595
596 request_options : typing.Optional[RequestOptions]
597 Request-specific configuration.
598
599 Returns
600 -------
601 AsyncPager[Role, ListRolesOffsetPaginatedResponseContent]
602 Roles successfully retrieved.
603 """
604 page = page if page is not None else 0
605
606 _response = await self._client_wrapper.httpx_client.request(
607 "roles",
608 method="GET",
609 params={
610 "per_page": per_page,
611 "page": page,
612 "include_totals": include_totals,
613 "name_filter": name_filter,
614 },
615 request_options=request_options,
616 )
617 try:
618 if 200 <= _response.status_code < 300:
619 _parsed_response = typing.cast(
620 ListRolesOffsetPaginatedResponseContent,
621 parse_obj_as(
622 type_=ListRolesOffsetPaginatedResponseContent, # type: ignore
623 object_=_response.json(),
624 ),
625 )
626 _items = _parsed_response.roles
627 _has_next = len(_items or []) > 0
628
629 async def _get_next():
630 return await self.list(
631 per_page=per_page,
632 page=page + 1,
633 include_totals=include_totals,
634 name_filter=name_filter,
635 request_options=request_options,
636 )
637
638 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
639 if _response.status_code == 400:
640 raise BadRequestError(
641 headers=dict(_response.headers),
642 body=typing.cast(
643 typing.Any,
644 parse_obj_as(
645 type_=typing.Any, # type: ignore
646 object_=_response.json(),
647 ),
648 ),
649 )
650 if _response.status_code == 401:
651 raise UnauthorizedError(
652 headers=dict(_response.headers),
653 body=typing.cast(
654 typing.Any,
655 parse_obj_as(
656 type_=typing.Any, # type: ignore
657 object_=_response.json(),
658 ),
659 ),
660 )
661 if _response.status_code == 403:
662 raise ForbiddenError(
663 headers=dict(_response.headers),
664 body=typing.cast(
665 typing.Any,
666 parse_obj_as(
667 type_=typing.Any, # type: ignore
668 object_=_response.json(),
669 ),
670 ),
671 )
672 if _response.status_code == 429:
673 raise TooManyRequestsError(
674 headers=dict(_response.headers),
675 body=typing.cast(
676 typing.Any,
677 parse_obj_as(
678 type_=typing.Any, # type: ignore
679 object_=_response.json(),
680 ),
681 ),
682 )
683 _response_json = _response.json()
684 except JSONDecodeError:
685 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
686 except ValidationError as e:
687 raise ParsingError(
688 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
689 )
690 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
691
692 async def create(
693 self,
694 *,
695 name: str,
696 description: typing.Optional[str] = OMIT,
697 request_options: typing.Optional[RequestOptions] = None,
698 ) -> AsyncHttpResponse[CreateRoleResponseContent]:
699 """
700 Create a user role for [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac).
701
702 **Note**: New roles are not associated with any permissions by default. To assign existing permissions to your role, review Associate Permissions with a Role. To create new permissions, review Add API Permissions.
703
704 Parameters
705 ----------
706 name : str
707 Name of the role.
708
709 description : typing.Optional[str]
710 Description of the role.
711
712 request_options : typing.Optional[RequestOptions]
713 Request-specific configuration.
714
715 Returns
716 -------
717 AsyncHttpResponse[CreateRoleResponseContent]
718 Role successfully created.
719 """
720 _response = await self._client_wrapper.httpx_client.request(
721 "roles",
722 method="POST",
723 json={
724 "name": name,
725 "description": description,
726 },
727 headers={
728 "content-type": "application/json",
729 },
730 request_options=request_options,
731 omit=OMIT,
732 )
733 try:
734 if 200 <= _response.status_code < 300:
735 _data = typing.cast(
736 CreateRoleResponseContent,
737 parse_obj_as(
738 type_=CreateRoleResponseContent, # type: ignore
739 object_=_response.json(),
740 ),
741 )
742 return AsyncHttpResponse(response=_response, data=_data)
743 if _response.status_code == 400:
744 raise BadRequestError(
745 headers=dict(_response.headers),
746 body=typing.cast(
747 typing.Any,
748 parse_obj_as(
749 type_=typing.Any, # type: ignore
750 object_=_response.json(),
751 ),
752 ),
753 )
754 if _response.status_code == 401:
755 raise UnauthorizedError(
756 headers=dict(_response.headers),
757 body=typing.cast(
758 typing.Any,
759 parse_obj_as(
760 type_=typing.Any, # type: ignore
761 object_=_response.json(),
762 ),
763 ),
764 )
765 if _response.status_code == 403:
766 raise ForbiddenError(
767 headers=dict(_response.headers),
768 body=typing.cast(
769 typing.Any,
770 parse_obj_as(
771 type_=typing.Any, # type: ignore
772 object_=_response.json(),
773 ),
774 ),
775 )
776 if _response.status_code == 409:
777 raise ConflictError(
778 headers=dict(_response.headers),
779 body=typing.cast(
780 typing.Any,
781 parse_obj_as(
782 type_=typing.Any, # type: ignore
783 object_=_response.json(),
784 ),
785 ),
786 )
787 if _response.status_code == 429:
788 raise TooManyRequestsError(
789 headers=dict(_response.headers),
790 body=typing.cast(
791 typing.Any,
792 parse_obj_as(
793 type_=typing.Any, # type: ignore
794 object_=_response.json(),
795 ),
796 ),
797 )
798 _response_json = _response.json()
799 except JSONDecodeError:
800 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
801 except ValidationError as e:
802 raise ParsingError(
803 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
804 )
805 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
806
807 async def get(
808 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
809 ) -> AsyncHttpResponse[GetRoleResponseContent]:
810 """
811 Retrieve details about a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.
812
813 Parameters
814 ----------
815 id : str
816 ID of the role to retrieve.
817
818 request_options : typing.Optional[RequestOptions]
819 Request-specific configuration.
820
821 Returns
822 -------
823 AsyncHttpResponse[GetRoleResponseContent]
824 Role successfully retrieved.
825 """
826 _response = await self._client_wrapper.httpx_client.request(
827 f"roles/{encode_path_param(id)}",
828 method="GET",
829 request_options=request_options,
830 )
831 try:
832 if 200 <= _response.status_code < 300:
833 _data = typing.cast(
834 GetRoleResponseContent,
835 parse_obj_as(
836 type_=GetRoleResponseContent, # type: ignore
837 object_=_response.json(),
838 ),
839 )
840 return AsyncHttpResponse(response=_response, data=_data)
841 if _response.status_code == 400:
842 raise BadRequestError(
843 headers=dict(_response.headers),
844 body=typing.cast(
845 typing.Any,
846 parse_obj_as(
847 type_=typing.Any, # type: ignore
848 object_=_response.json(),
849 ),
850 ),
851 )
852 if _response.status_code == 401:
853 raise UnauthorizedError(
854 headers=dict(_response.headers),
855 body=typing.cast(
856 typing.Any,
857 parse_obj_as(
858 type_=typing.Any, # type: ignore
859 object_=_response.json(),
860 ),
861 ),
862 )
863 if _response.status_code == 403:
864 raise ForbiddenError(
865 headers=dict(_response.headers),
866 body=typing.cast(
867 typing.Any,
868 parse_obj_as(
869 type_=typing.Any, # type: ignore
870 object_=_response.json(),
871 ),
872 ),
873 )
874 if _response.status_code == 404:
875 raise NotFoundError(
876 headers=dict(_response.headers),
877 body=typing.cast(
878 typing.Any,
879 parse_obj_as(
880 type_=typing.Any, # type: ignore
881 object_=_response.json(),
882 ),
883 ),
884 )
885 if _response.status_code == 429:
886 raise TooManyRequestsError(
887 headers=dict(_response.headers),
888 body=typing.cast(
889 typing.Any,
890 parse_obj_as(
891 type_=typing.Any, # type: ignore
892 object_=_response.json(),
893 ),
894 ),
895 )
896 _response_json = _response.json()
897 except JSONDecodeError:
898 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
899 except ValidationError as e:
900 raise ParsingError(
901 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
902 )
903 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
904
905 async def delete(
906 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
907 ) -> AsyncHttpResponse[None]:
908 """
909 Delete a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) from your tenant. Once deleted, it is removed from any user who was previously assigned that role. This action cannot be undone.
910
911 Parameters
912 ----------
913 id : str
914 ID of the role to delete.
915
916 request_options : typing.Optional[RequestOptions]
917 Request-specific configuration.
918
919 Returns
920 -------
921 AsyncHttpResponse[None]
922 """
923 _response = await self._client_wrapper.httpx_client.request(
924 f"roles/{encode_path_param(id)}",
925 method="DELETE",
926 request_options=request_options,
927 )
928 try:
929 if 200 <= _response.status_code < 300:
930 return AsyncHttpResponse(response=_response, data=None)
931 if _response.status_code == 400:
932 raise BadRequestError(
933 headers=dict(_response.headers),
934 body=typing.cast(
935 typing.Any,
936 parse_obj_as(
937 type_=typing.Any, # type: ignore
938 object_=_response.json(),
939 ),
940 ),
941 )
942 if _response.status_code == 401:
943 raise UnauthorizedError(
944 headers=dict(_response.headers),
945 body=typing.cast(
946 typing.Any,
947 parse_obj_as(
948 type_=typing.Any, # type: ignore
949 object_=_response.json(),
950 ),
951 ),
952 )
953 if _response.status_code == 403:
954 raise ForbiddenError(
955 headers=dict(_response.headers),
956 body=typing.cast(
957 typing.Any,
958 parse_obj_as(
959 type_=typing.Any, # type: ignore
960 object_=_response.json(),
961 ),
962 ),
963 )
964 if _response.status_code == 404:
965 raise NotFoundError(
966 headers=dict(_response.headers),
967 body=typing.cast(
968 typing.Any,
969 parse_obj_as(
970 type_=typing.Any, # type: ignore
971 object_=_response.json(),
972 ),
973 ),
974 )
975 if _response.status_code == 429:
976 raise TooManyRequestsError(
977 headers=dict(_response.headers),
978 body=typing.cast(
979 typing.Any,
980 parse_obj_as(
981 type_=typing.Any, # type: ignore
982 object_=_response.json(),
983 ),
984 ),
985 )
986 _response_json = _response.json()
987 except JSONDecodeError:
988 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
989 except ValidationError as e:
990 raise ParsingError(
991 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
992 )
993 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
994
995 async def update(
996 self,
997 id: str,
998 *,
999 name: typing.Optional[str] = OMIT,
1000 description: typing.Optional[str] = OMIT,
1001 request_options: typing.Optional[RequestOptions] = None,
1002 ) -> AsyncHttpResponse[UpdateRoleResponseContent]:
1003 """
1004 Modify the details of a specific [user role](https://auth0.com/docs/manage-users/access-control/rbac) specified by ID.
1005
1006 Parameters
1007 ----------
1008 id : str
1009 ID of the role to update.
1010
1011 name : typing.Optional[str]
1012 Name of this role.
1013
1014 description : typing.Optional[str]
1015 Description of this role.
1016
1017 request_options : typing.Optional[RequestOptions]
1018 Request-specific configuration.
1019
1020 Returns
1021 -------
1022 AsyncHttpResponse[UpdateRoleResponseContent]
1023 Role successfully updated.
1024 """
1025 _response = await self._client_wrapper.httpx_client.request(
1026 f"roles/{encode_path_param(id)}",
1027 method="PATCH",
1028 json={
1029 "name": name,
1030 "description": description,
1031 },
1032 headers={
1033 "content-type": "application/json",
1034 },
1035 request_options=request_options,
1036 omit=OMIT,
1037 )
1038 try:
1039 if 200 <= _response.status_code < 300:
1040 _data = typing.cast(
1041 UpdateRoleResponseContent,
1042 parse_obj_as(
1043 type_=UpdateRoleResponseContent, # type: ignore
1044 object_=_response.json(),
1045 ),
1046 )
1047 return AsyncHttpResponse(response=_response, data=_data)
1048 if _response.status_code == 400:
1049 raise BadRequestError(
1050 headers=dict(_response.headers),
1051 body=typing.cast(
1052 typing.Any,
1053 parse_obj_as(
1054 type_=typing.Any, # type: ignore
1055 object_=_response.json(),
1056 ),
1057 ),
1058 )
1059 if _response.status_code == 401:
1060 raise UnauthorizedError(
1061 headers=dict(_response.headers),
1062 body=typing.cast(
1063 typing.Any,
1064 parse_obj_as(
1065 type_=typing.Any, # type: ignore
1066 object_=_response.json(),
1067 ),
1068 ),
1069 )
1070 if _response.status_code == 403:
1071 raise ForbiddenError(
1072 headers=dict(_response.headers),
1073 body=typing.cast(
1074 typing.Any,
1075 parse_obj_as(
1076 type_=typing.Any, # type: ignore
1077 object_=_response.json(),
1078 ),
1079 ),
1080 )
1081 if _response.status_code == 429:
1082 raise TooManyRequestsError(
1083 headers=dict(_response.headers),
1084 body=typing.cast(
1085 typing.Any,
1086 parse_obj_as(
1087 type_=typing.Any, # type: ignore
1088 object_=_response.json(),
1089 ),
1090 ),
1091 )
1092 _response_json = _response.json()
1093 except JSONDecodeError:
1094 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1095 except ValidationError as e:
1096 raise ParsingError(
1097 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1098 )
1099 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)