Debian Codegraph @

src/auth0/management/organizations/groups/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.list_organization_group_roles_response_content import ListOrganizationGroupRolesResponseContent
21 from ....types.role import Role
22 from pydantic import ValidationError
23
24 # this is used as the default value for optional parameters
25 OMIT = typing.cast(typing.Any, ...)
26
27
28 class RawRolesClient:
29 def __init__(self, *, client_wrapper: SyncClientWrapper):
30 self._client_wrapper = client_wrapper
31
32 def list(
33 self,
34 organization_id: str,
35 group_id: str,
36 *,
37 from_: typing.Optional[str] = None,
38 take: typing.Optional[int] = 50,
39 request_options: typing.Optional[RequestOptions] = None,
40 ) -> SyncPager[Role, ListOrganizationGroupRolesResponseContent]:
41 """
42 Lists the roles assigned to the specified group in the context of an organization.
43
44 Parameters
45 ----------
46 organization_id : str
47 ID of the organization
48
49 group_id : str
50 ID of the group
51
52 from_ : typing.Optional[str]
53 Optional Id from which to start selection.
54
55 take : typing.Optional[int]
56 Number of results per page. Defaults to 50.
57
58 request_options : typing.Optional[RequestOptions]
59 Request-specific configuration.
60
61 Returns
62 -------
63 SyncPager[Role, ListOrganizationGroupRolesResponseContent]
64 Organization group roles successfully retrieved.
65 """
66 _response = self._client_wrapper.httpx_client.request(
67 f"organizations/{encode_path_param(organization_id)}/groups/{encode_path_param(group_id)}/roles",
68 method="GET",
69 params={
70 "from": from_,
71 "take": take,
72 },
73 request_options=request_options,
74 )
75 try:
76 if 200 <= _response.status_code < 300:
77 _parsed_response = typing.cast(
78 ListOrganizationGroupRolesResponseContent,
79 parse_obj_as(
80 type_=ListOrganizationGroupRolesResponseContent, # type: ignore
81 object_=_response.json(),
82 ),
83 )
84 _items = _parsed_response.roles
85 _parsed_next = _parsed_response.next
86 _has_next = _parsed_next is not None and _parsed_next != ""
87 _get_next = lambda: self.list(
88 organization_id,
89 group_id,
90 from_=_parsed_next,
91 take=take,
92 request_options=request_options,
93 )
94 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
95 if _response.status_code == 400:
96 raise BadRequestError(
97 headers=dict(_response.headers),
98 body=typing.cast(
99 typing.Any,
100 parse_obj_as(
101 type_=typing.Any, # type: ignore
102 object_=_response.json(),
103 ),
104 ),
105 )
106 if _response.status_code == 401:
107 raise UnauthorizedError(
108 headers=dict(_response.headers),
109 body=typing.cast(
110 typing.Any,
111 parse_obj_as(
112 type_=typing.Any, # type: ignore
113 object_=_response.json(),
114 ),
115 ),
116 )
117 if _response.status_code == 403:
118 raise ForbiddenError(
119 headers=dict(_response.headers),
120 body=typing.cast(
121 typing.Any,
122 parse_obj_as(
123 type_=typing.Any, # type: ignore
124 object_=_response.json(),
125 ),
126 ),
127 )
128 if _response.status_code == 404:
129 raise NotFoundError(
130 headers=dict(_response.headers),
131 body=typing.cast(
132 typing.Any,
133 parse_obj_as(
134 type_=typing.Any, # type: ignore
135 object_=_response.json(),
136 ),
137 ),
138 )
139 if _response.status_code == 429:
140 raise TooManyRequestsError(
141 headers=dict(_response.headers),
142 body=typing.cast(
143 typing.Any,
144 parse_obj_as(
145 type_=typing.Any, # type: ignore
146 object_=_response.json(),
147 ),
148 ),
149 )
150 _response_json = _response.json()
151 except JSONDecodeError:
152 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
153 except ValidationError as e:
154 raise ParsingError(
155 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
156 )
157 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
158
159 def create(
160 self,
161 organization_id: str,
162 group_id: str,
163 *,
164 roles: typing.Sequence[str],
165 request_options: typing.Optional[RequestOptions] = None,
166 ) -> HttpResponse[None]:
167 """
168 Assign one or more roles to a specified group in the context of an organization.
169
170 Parameters
171 ----------
172 organization_id : str
173 ID of the organization
174
175 group_id : str
176 ID of the group
177
178 roles : typing.Sequence[str]
179 Array of role IDs to assign to organization group.
180
181 request_options : typing.Optional[RequestOptions]
182 Request-specific configuration.
183
184 Returns
185 -------
186 HttpResponse[None]
187 """
188 _response = self._client_wrapper.httpx_client.request(
189 f"organizations/{encode_path_param(organization_id)}/groups/{encode_path_param(group_id)}/roles",
190 method="POST",
191 json={
192 "roles": roles,
193 },
194 headers={
195 "content-type": "application/json",
196 },
197 request_options=request_options,
198 omit=OMIT,
199 )
200 try:
201 if 200 <= _response.status_code < 300:
202 return HttpResponse(response=_response, data=None)
203 if _response.status_code == 400:
204 raise BadRequestError(
205 headers=dict(_response.headers),
206 body=typing.cast(
207 typing.Any,
208 parse_obj_as(
209 type_=typing.Any, # type: ignore
210 object_=_response.json(),
211 ),
212 ),
213 )
214 if _response.status_code == 401:
215 raise UnauthorizedError(
216 headers=dict(_response.headers),
217 body=typing.cast(
218 typing.Any,
219 parse_obj_as(
220 type_=typing.Any, # type: ignore
221 object_=_response.json(),
222 ),
223 ),
224 )
225 if _response.status_code == 403:
226 raise ForbiddenError(
227 headers=dict(_response.headers),
228 body=typing.cast(
229 typing.Any,
230 parse_obj_as(
231 type_=typing.Any, # type: ignore
232 object_=_response.json(),
233 ),
234 ),
235 )
236 if _response.status_code == 404:
237 raise NotFoundError(
238 headers=dict(_response.headers),
239 body=typing.cast(
240 typing.Any,
241 parse_obj_as(
242 type_=typing.Any, # type: ignore
243 object_=_response.json(),
244 ),
245 ),
246 )
247 if _response.status_code == 409:
248 raise ConflictError(
249 headers=dict(_response.headers),
250 body=typing.cast(
251 typing.Any,
252 parse_obj_as(
253 type_=typing.Any, # type: ignore
254 object_=_response.json(),
255 ),
256 ),
257 )
258 if _response.status_code == 429:
259 raise TooManyRequestsError(
260 headers=dict(_response.headers),
261 body=typing.cast(
262 typing.Any,
263 parse_obj_as(
264 type_=typing.Any, # type: ignore
265 object_=_response.json(),
266 ),
267 ),
268 )
269 _response_json = _response.json()
270 except JSONDecodeError:
271 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
272 except ValidationError as e:
273 raise ParsingError(
274 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
275 )
276 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
277
278 def delete(
279 self,
280 organization_id: str,
281 group_id: str,
282 *,
283 roles: typing.Sequence[str],
284 request_options: typing.Optional[RequestOptions] = None,
285 ) -> HttpResponse[None]:
286 """
287 Unassign one or more roles from a specified group in the context of an organization.
288
289 Parameters
290 ----------
291 organization_id : str
292 ID of the organization
293
294 group_id : str
295 ID of the group
296
297 roles : typing.Sequence[str]
298 Array of role IDs to delete from organization group.
299
300 request_options : typing.Optional[RequestOptions]
301 Request-specific configuration.
302
303 Returns
304 -------
305 HttpResponse[None]
306 """
307 _response = self._client_wrapper.httpx_client.request(
308 f"organizations/{encode_path_param(organization_id)}/groups/{encode_path_param(group_id)}/roles",
309 method="DELETE",
310 json={
311 "roles": roles,
312 },
313 headers={
314 "content-type": "application/json",
315 },
316 request_options=request_options,
317 omit=OMIT,
318 )
319 try:
320 if 200 <= _response.status_code < 300:
321 return HttpResponse(response=_response, data=None)
322 if _response.status_code == 400:
323 raise BadRequestError(
324 headers=dict(_response.headers),
325 body=typing.cast(
326 typing.Any,
327 parse_obj_as(
328 type_=typing.Any, # type: ignore
329 object_=_response.json(),
330 ),
331 ),
332 )
333 if _response.status_code == 401:
334 raise UnauthorizedError(
335 headers=dict(_response.headers),
336 body=typing.cast(
337 typing.Any,
338 parse_obj_as(
339 type_=typing.Any, # type: ignore
340 object_=_response.json(),
341 ),
342 ),
343 )
344 if _response.status_code == 403:
345 raise ForbiddenError(
346 headers=dict(_response.headers),
347 body=typing.cast(
348 typing.Any,
349 parse_obj_as(
350 type_=typing.Any, # type: ignore
351 object_=_response.json(),
352 ),
353 ),
354 )
355 if _response.status_code == 404:
356 raise NotFoundError(
357 headers=dict(_response.headers),
358 body=typing.cast(
359 typing.Any,
360 parse_obj_as(
361 type_=typing.Any, # type: ignore
362 object_=_response.json(),
363 ),
364 ),
365 )
366 if _response.status_code == 429:
367 raise TooManyRequestsError(
368 headers=dict(_response.headers),
369 body=typing.cast(
370 typing.Any,
371 parse_obj_as(
372 type_=typing.Any, # type: ignore
373 object_=_response.json(),
374 ),
375 ),
376 )
377 _response_json = _response.json()
378 except JSONDecodeError:
379 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
380 except ValidationError as e:
381 raise ParsingError(
382 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
383 )
384 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
385
386
387 class AsyncRawRolesClient:
388 def __init__(self, *, client_wrapper: AsyncClientWrapper):
389 self._client_wrapper = client_wrapper
390
391 async def list(
392 self,
393 organization_id: str,
394 group_id: str,
395 *,
396 from_: typing.Optional[str] = None,
397 take: typing.Optional[int] = 50,
398 request_options: typing.Optional[RequestOptions] = None,
399 ) -> AsyncPager[Role, ListOrganizationGroupRolesResponseContent]:
400 """
401 Lists the roles assigned to the specified group in the context of an organization.
402
403 Parameters
404 ----------
405 organization_id : str
406 ID of the organization
407
408 group_id : str
409 ID of the group
410
411 from_ : typing.Optional[str]
412 Optional Id from which to start selection.
413
414 take : typing.Optional[int]
415 Number of results per page. Defaults to 50.
416
417 request_options : typing.Optional[RequestOptions]
418 Request-specific configuration.
419
420 Returns
421 -------
422 AsyncPager[Role, ListOrganizationGroupRolesResponseContent]
423 Organization group roles successfully retrieved.
424 """
425 _response = await self._client_wrapper.httpx_client.request(
426 f"organizations/{encode_path_param(organization_id)}/groups/{encode_path_param(group_id)}/roles",
427 method="GET",
428 params={
429 "from": from_,
430 "take": take,
431 },
432 request_options=request_options,
433 )
434 try:
435 if 200 <= _response.status_code < 300:
436 _parsed_response = typing.cast(
437 ListOrganizationGroupRolesResponseContent,
438 parse_obj_as(
439 type_=ListOrganizationGroupRolesResponseContent, # type: ignore
440 object_=_response.json(),
441 ),
442 )
443 _items = _parsed_response.roles
444 _parsed_next = _parsed_response.next
445 _has_next = _parsed_next is not None and _parsed_next != ""
446
447 async def _get_next():
448 return await self.list(
449 organization_id,
450 group_id,
451 from_=_parsed_next,
452 take=take,
453 request_options=request_options,
454 )
455
456 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
457 if _response.status_code == 400:
458 raise BadRequestError(
459 headers=dict(_response.headers),
460 body=typing.cast(
461 typing.Any,
462 parse_obj_as(
463 type_=typing.Any, # type: ignore
464 object_=_response.json(),
465 ),
466 ),
467 )
468 if _response.status_code == 401:
469 raise UnauthorizedError(
470 headers=dict(_response.headers),
471 body=typing.cast(
472 typing.Any,
473 parse_obj_as(
474 type_=typing.Any, # type: ignore
475 object_=_response.json(),
476 ),
477 ),
478 )
479 if _response.status_code == 403:
480 raise ForbiddenError(
481 headers=dict(_response.headers),
482 body=typing.cast(
483 typing.Any,
484 parse_obj_as(
485 type_=typing.Any, # type: ignore
486 object_=_response.json(),
487 ),
488 ),
489 )
490 if _response.status_code == 404:
491 raise NotFoundError(
492 headers=dict(_response.headers),
493 body=typing.cast(
494 typing.Any,
495 parse_obj_as(
496 type_=typing.Any, # type: ignore
497 object_=_response.json(),
498 ),
499 ),
500 )
501 if _response.status_code == 429:
502 raise TooManyRequestsError(
503 headers=dict(_response.headers),
504 body=typing.cast(
505 typing.Any,
506 parse_obj_as(
507 type_=typing.Any, # type: ignore
508 object_=_response.json(),
509 ),
510 ),
511 )
512 _response_json = _response.json()
513 except JSONDecodeError:
514 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
515 except ValidationError as e:
516 raise ParsingError(
517 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
518 )
519 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
520
521 async def create(
522 self,
523 organization_id: str,
524 group_id: str,
525 *,
526 roles: typing.Sequence[str],
527 request_options: typing.Optional[RequestOptions] = None,
528 ) -> AsyncHttpResponse[None]:
529 """
530 Assign one or more roles to a specified group in the context of an organization.
531
532 Parameters
533 ----------
534 organization_id : str
535 ID of the organization
536
537 group_id : str
538 ID of the group
539
540 roles : typing.Sequence[str]
541 Array of role IDs to assign to organization group.
542
543 request_options : typing.Optional[RequestOptions]
544 Request-specific configuration.
545
546 Returns
547 -------
548 AsyncHttpResponse[None]
549 """
550 _response = await self._client_wrapper.httpx_client.request(
551 f"organizations/{encode_path_param(organization_id)}/groups/{encode_path_param(group_id)}/roles",
552 method="POST",
553 json={
554 "roles": roles,
555 },
556 headers={
557 "content-type": "application/json",
558 },
559 request_options=request_options,
560 omit=OMIT,
561 )
562 try:
563 if 200 <= _response.status_code < 300:
564 return AsyncHttpResponse(response=_response, data=None)
565 if _response.status_code == 400:
566 raise BadRequestError(
567 headers=dict(_response.headers),
568 body=typing.cast(
569 typing.Any,
570 parse_obj_as(
571 type_=typing.Any, # type: ignore
572 object_=_response.json(),
573 ),
574 ),
575 )
576 if _response.status_code == 401:
577 raise UnauthorizedError(
578 headers=dict(_response.headers),
579 body=typing.cast(
580 typing.Any,
581 parse_obj_as(
582 type_=typing.Any, # type: ignore
583 object_=_response.json(),
584 ),
585 ),
586 )
587 if _response.status_code == 403:
588 raise ForbiddenError(
589 headers=dict(_response.headers),
590 body=typing.cast(
591 typing.Any,
592 parse_obj_as(
593 type_=typing.Any, # type: ignore
594 object_=_response.json(),
595 ),
596 ),
597 )
598 if _response.status_code == 404:
599 raise NotFoundError(
600 headers=dict(_response.headers),
601 body=typing.cast(
602 typing.Any,
603 parse_obj_as(
604 type_=typing.Any, # type: ignore
605 object_=_response.json(),
606 ),
607 ),
608 )
609 if _response.status_code == 409:
610 raise ConflictError(
611 headers=dict(_response.headers),
612 body=typing.cast(
613 typing.Any,
614 parse_obj_as(
615 type_=typing.Any, # type: ignore
616 object_=_response.json(),
617 ),
618 ),
619 )
620 if _response.status_code == 429:
621 raise TooManyRequestsError(
622 headers=dict(_response.headers),
623 body=typing.cast(
624 typing.Any,
625 parse_obj_as(
626 type_=typing.Any, # type: ignore
627 object_=_response.json(),
628 ),
629 ),
630 )
631 _response_json = _response.json()
632 except JSONDecodeError:
633 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
634 except ValidationError as e:
635 raise ParsingError(
636 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
637 )
638 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
639
640 async def delete(
641 self,
642 organization_id: str,
643 group_id: str,
644 *,
645 roles: typing.Sequence[str],
646 request_options: typing.Optional[RequestOptions] = None,
647 ) -> AsyncHttpResponse[None]:
648 """
649 Unassign one or more roles from a specified group in the context of an organization.
650
651 Parameters
652 ----------
653 organization_id : str
654 ID of the organization
655
656 group_id : str
657 ID of the group
658
659 roles : typing.Sequence[str]
660 Array of role IDs to delete from organization group.
661
662 request_options : typing.Optional[RequestOptions]
663 Request-specific configuration.
664
665 Returns
666 -------
667 AsyncHttpResponse[None]
668 """
669 _response = await self._client_wrapper.httpx_client.request(
670 f"organizations/{encode_path_param(organization_id)}/groups/{encode_path_param(group_id)}/roles",
671 method="DELETE",
672 json={
673 "roles": roles,
674 },
675 headers={
676 "content-type": "application/json",
677 },
678 request_options=request_options,
679 omit=OMIT,
680 )
681 try:
682 if 200 <= _response.status_code < 300:
683 return AsyncHttpResponse(response=_response, data=None)
684 if _response.status_code == 400:
685 raise BadRequestError(
686 headers=dict(_response.headers),
687 body=typing.cast(
688 typing.Any,
689 parse_obj_as(
690 type_=typing.Any, # type: ignore
691 object_=_response.json(),
692 ),
693 ),
694 )
695 if _response.status_code == 401:
696 raise UnauthorizedError(
697 headers=dict(_response.headers),
698 body=typing.cast(
699 typing.Any,
700 parse_obj_as(
701 type_=typing.Any, # type: ignore
702 object_=_response.json(),
703 ),
704 ),
705 )
706 if _response.status_code == 403:
707 raise ForbiddenError(
708 headers=dict(_response.headers),
709 body=typing.cast(
710 typing.Any,
711 parse_obj_as(
712 type_=typing.Any, # type: ignore
713 object_=_response.json(),
714 ),
715 ),
716 )
717 if _response.status_code == 404:
718 raise NotFoundError(
719 headers=dict(_response.headers),
720 body=typing.cast(
721 typing.Any,
722 parse_obj_as(
723 type_=typing.Any, # type: ignore
724 object_=_response.json(),
725 ),
726 ),
727 )
728 if _response.status_code == 429:
729 raise TooManyRequestsError(
730 headers=dict(_response.headers),
731 body=typing.cast(
732 typing.Any,
733 parse_obj_as(
734 type_=typing.Any, # type: ignore
735 object_=_response.json(),
736 ),
737 ),
738 )
739 _response_json = _response.json()
740 except JSONDecodeError:
741 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
742 except ValidationError as e:
743 raise ParsingError(
744 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
745 )
746 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)