Debian Codegraph @

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