Debian Codegraph @

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