Debian Codegraph @

src/auth0/management/organizations/client_grants/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.associate_organization_client_grant_response_content import (
21 AssociateOrganizationClientGrantResponseContent,
22 )
23 from ...types.list_organization_client_grants_offset_paginated_response_content import (
24 ListOrganizationClientGrantsOffsetPaginatedResponseContent,
25 )
26 from ...types.organization_client_grant import OrganizationClientGrant
27 from pydantic import ValidationError
28
29 # this is used as the default value for optional parameters
30 OMIT = typing.cast(typing.Any, ...)
31
32
33 class RawClientGrantsClient:
34 def __init__(self, *, client_wrapper: SyncClientWrapper):
35 self._client_wrapper = client_wrapper
36
37 def list(
38 self,
39 id: str,
40 *,
41 audience: typing.Optional[str] = None,
42 client_id: typing.Optional[str] = None,
43 grant_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
44 page: typing.Optional[int] = 0,
45 per_page: typing.Optional[int] = 50,
46 include_totals: typing.Optional[bool] = True,
47 request_options: typing.Optional[RequestOptions] = None,
48 ) -> SyncPager[OrganizationClientGrant, ListOrganizationClientGrantsOffsetPaginatedResponseContent]:
49 """
50 Parameters
51 ----------
52 id : str
53 Organization identifier.
54
55 audience : typing.Optional[str]
56 Optional filter on audience of the client grant.
57
58 client_id : typing.Optional[str]
59 Optional filter on client_id of the client grant.
60
61 grant_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
62 Optional filter on the ID of the client grant. Must be URL encoded and may be specified multiple times (max 10).<br /><b>e.g.</b> <i>../client-grants?grant_ids=id1&grant_ids=id2</i>
63
64 page : typing.Optional[int]
65 Page index of the results to return. First page is 0.
66
67 per_page : typing.Optional[int]
68 Number of results per page. Defaults to 50.
69
70 include_totals : typing.Optional[bool]
71 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
72
73 request_options : typing.Optional[RequestOptions]
74 Request-specific configuration.
75
76 Returns
77 -------
78 SyncPager[OrganizationClientGrant, ListOrganizationClientGrantsOffsetPaginatedResponseContent]
79 Client grants successfully retrieved.
80 """
81 page = page if page is not None else 0
82
83 _response = self._client_wrapper.httpx_client.request(
84 f"organizations/{encode_path_param(id)}/client-grants",
85 method="GET",
86 params={
87 "audience": audience,
88 "client_id": client_id,
89 "grant_ids": grant_ids,
90 "page": page,
91 "per_page": per_page,
92 "include_totals": include_totals,
93 },
94 request_options=request_options,
95 )
96 try:
97 if 200 <= _response.status_code < 300:
98 _parsed_response = typing.cast(
99 ListOrganizationClientGrantsOffsetPaginatedResponseContent,
100 parse_obj_as(
101 type_=ListOrganizationClientGrantsOffsetPaginatedResponseContent, # type: ignore
102 object_=_response.json(),
103 ),
104 )
105 _items = _parsed_response.client_grants
106 _has_next = len(_items or []) > 0
107 _get_next = lambda: self.list(
108 id,
109 audience=audience,
110 client_id=client_id,
111 grant_ids=grant_ids,
112 page=page + 1,
113 per_page=per_page,
114 include_totals=include_totals,
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 create(
172 self, id: str, *, grant_id: str, request_options: typing.Optional[RequestOptions] = None
173 ) -> HttpResponse[AssociateOrganizationClientGrantResponseContent]:
174 """
175 Parameters
176 ----------
177 id : str
178 Organization identifier.
179
180 grant_id : str
181 A Client Grant ID to add to the organization.
182
183 request_options : typing.Optional[RequestOptions]
184 Request-specific configuration.
185
186 Returns
187 -------
188 HttpResponse[AssociateOrganizationClientGrantResponseContent]
189 Client Grant successfully associated with Organization.
190 """
191 _response = self._client_wrapper.httpx_client.request(
192 f"organizations/{encode_path_param(id)}/client-grants",
193 method="POST",
194 json={
195 "grant_id": grant_id,
196 },
197 headers={
198 "content-type": "application/json",
199 },
200 request_options=request_options,
201 omit=OMIT,
202 )
203 try:
204 if 200 <= _response.status_code < 300:
205 _data = typing.cast(
206 AssociateOrganizationClientGrantResponseContent,
207 parse_obj_as(
208 type_=AssociateOrganizationClientGrantResponseContent, # type: ignore
209 object_=_response.json(),
210 ),
211 )
212 return HttpResponse(response=_response, data=_data)
213 if _response.status_code == 400:
214 raise BadRequestError(
215 headers=dict(_response.headers),
216 body=typing.cast(
217 typing.Any,
218 parse_obj_as(
219 type_=typing.Any, # type: ignore
220 object_=_response.json(),
221 ),
222 ),
223 )
224 if _response.status_code == 401:
225 raise UnauthorizedError(
226 headers=dict(_response.headers),
227 body=typing.cast(
228 typing.Any,
229 parse_obj_as(
230 type_=typing.Any, # type: ignore
231 object_=_response.json(),
232 ),
233 ),
234 )
235 if _response.status_code == 403:
236 raise ForbiddenError(
237 headers=dict(_response.headers),
238 body=typing.cast(
239 typing.Any,
240 parse_obj_as(
241 type_=typing.Any, # type: ignore
242 object_=_response.json(),
243 ),
244 ),
245 )
246 if _response.status_code == 404:
247 raise NotFoundError(
248 headers=dict(_response.headers),
249 body=typing.cast(
250 typing.Any,
251 parse_obj_as(
252 type_=typing.Any, # type: ignore
253 object_=_response.json(),
254 ),
255 ),
256 )
257 if _response.status_code == 409:
258 raise ConflictError(
259 headers=dict(_response.headers),
260 body=typing.cast(
261 typing.Any,
262 parse_obj_as(
263 type_=typing.Any, # type: ignore
264 object_=_response.json(),
265 ),
266 ),
267 )
268 if _response.status_code == 429:
269 raise TooManyRequestsError(
270 headers=dict(_response.headers),
271 body=typing.cast(
272 typing.Any,
273 parse_obj_as(
274 type_=typing.Any, # type: ignore
275 object_=_response.json(),
276 ),
277 ),
278 )
279 _response_json = _response.json()
280 except JSONDecodeError:
281 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
282 except ValidationError as e:
283 raise ParsingError(
284 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
285 )
286 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
287
288 def delete(
289 self, id: str, grant_id: str, *, request_options: typing.Optional[RequestOptions] = None
290 ) -> HttpResponse[None]:
291 """
292 Parameters
293 ----------
294 id : str
295 Organization identifier.
296
297 grant_id : str
298 The Client Grant ID to remove from the organization
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(id)}/client-grants/{encode_path_param(grant_id)}",
309 method="DELETE",
310 request_options=request_options,
311 )
312 try:
313 if 200 <= _response.status_code < 300:
314 return HttpResponse(response=_response, data=None)
315 if _response.status_code == 400:
316 raise BadRequestError(
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 == 401:
327 raise UnauthorizedError(
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 if _response.status_code == 403:
338 raise ForbiddenError(
339 headers=dict(_response.headers),
340 body=typing.cast(
341 typing.Any,
342 parse_obj_as(
343 type_=typing.Any, # type: ignore
344 object_=_response.json(),
345 ),
346 ),
347 )
348 if _response.status_code == 404:
349 raise NotFoundError(
350 headers=dict(_response.headers),
351 body=typing.cast(
352 typing.Any,
353 parse_obj_as(
354 type_=typing.Any, # type: ignore
355 object_=_response.json(),
356 ),
357 ),
358 )
359 if _response.status_code == 429:
360 raise TooManyRequestsError(
361 headers=dict(_response.headers),
362 body=typing.cast(
363 typing.Any,
364 parse_obj_as(
365 type_=typing.Any, # type: ignore
366 object_=_response.json(),
367 ),
368 ),
369 )
370 _response_json = _response.json()
371 except JSONDecodeError:
372 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
373 except ValidationError as e:
374 raise ParsingError(
375 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
376 )
377 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
378
379
380 class AsyncRawClientGrantsClient:
381 def __init__(self, *, client_wrapper: AsyncClientWrapper):
382 self._client_wrapper = client_wrapper
383
384 async def list(
385 self,
386 id: str,
387 *,
388 audience: typing.Optional[str] = None,
389 client_id: typing.Optional[str] = None,
390 grant_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
391 page: typing.Optional[int] = 0,
392 per_page: typing.Optional[int] = 50,
393 include_totals: typing.Optional[bool] = True,
394 request_options: typing.Optional[RequestOptions] = None,
395 ) -> AsyncPager[OrganizationClientGrant, ListOrganizationClientGrantsOffsetPaginatedResponseContent]:
396 """
397 Parameters
398 ----------
399 id : str
400 Organization identifier.
401
402 audience : typing.Optional[str]
403 Optional filter on audience of the client grant.
404
405 client_id : typing.Optional[str]
406 Optional filter on client_id of the client grant.
407
408 grant_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
409 Optional filter on the ID of the client grant. Must be URL encoded and may be specified multiple times (max 10).<br /><b>e.g.</b> <i>../client-grants?grant_ids=id1&grant_ids=id2</i>
410
411 page : typing.Optional[int]
412 Page index of the results to return. First page is 0.
413
414 per_page : typing.Optional[int]
415 Number of results per page. Defaults to 50.
416
417 include_totals : typing.Optional[bool]
418 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
419
420 request_options : typing.Optional[RequestOptions]
421 Request-specific configuration.
422
423 Returns
424 -------
425 AsyncPager[OrganizationClientGrant, ListOrganizationClientGrantsOffsetPaginatedResponseContent]
426 Client grants successfully retrieved.
427 """
428 page = page if page is not None else 0
429
430 _response = await self._client_wrapper.httpx_client.request(
431 f"organizations/{encode_path_param(id)}/client-grants",
432 method="GET",
433 params={
434 "audience": audience,
435 "client_id": client_id,
436 "grant_ids": grant_ids,
437 "page": page,
438 "per_page": per_page,
439 "include_totals": include_totals,
440 },
441 request_options=request_options,
442 )
443 try:
444 if 200 <= _response.status_code < 300:
445 _parsed_response = typing.cast(
446 ListOrganizationClientGrantsOffsetPaginatedResponseContent,
447 parse_obj_as(
448 type_=ListOrganizationClientGrantsOffsetPaginatedResponseContent, # type: ignore
449 object_=_response.json(),
450 ),
451 )
452 _items = _parsed_response.client_grants
453 _has_next = len(_items or []) > 0
454
455 async def _get_next():
456 return await self.list(
457 id,
458 audience=audience,
459 client_id=client_id,
460 grant_ids=grant_ids,
461 page=page + 1,
462 per_page=per_page,
463 include_totals=include_totals,
464 request_options=request_options,
465 )
466
467 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
468 if _response.status_code == 400:
469 raise BadRequestError(
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 == 401:
480 raise UnauthorizedError(
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 == 403:
491 raise ForbiddenError(
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, id: str, *, grant_id: str, request_options: typing.Optional[RequestOptions] = None
523 ) -> AsyncHttpResponse[AssociateOrganizationClientGrantResponseContent]:
524 """
525 Parameters
526 ----------
527 id : str
528 Organization identifier.
529
530 grant_id : str
531 A Client Grant ID to add to the organization.
532
533 request_options : typing.Optional[RequestOptions]
534 Request-specific configuration.
535
536 Returns
537 -------
538 AsyncHttpResponse[AssociateOrganizationClientGrantResponseContent]
539 Client Grant successfully associated with Organization.
540 """
541 _response = await self._client_wrapper.httpx_client.request(
542 f"organizations/{encode_path_param(id)}/client-grants",
543 method="POST",
544 json={
545 "grant_id": grant_id,
546 },
547 headers={
548 "content-type": "application/json",
549 },
550 request_options=request_options,
551 omit=OMIT,
552 )
553 try:
554 if 200 <= _response.status_code < 300:
555 _data = typing.cast(
556 AssociateOrganizationClientGrantResponseContent,
557 parse_obj_as(
558 type_=AssociateOrganizationClientGrantResponseContent, # type: ignore
559 object_=_response.json(),
560 ),
561 )
562 return AsyncHttpResponse(response=_response, data=_data)
563 if _response.status_code == 400:
564 raise BadRequestError(
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 == 401:
575 raise UnauthorizedError(
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 if _response.status_code == 403:
586 raise ForbiddenError(
587 headers=dict(_response.headers),
588 body=typing.cast(
589 typing.Any,
590 parse_obj_as(
591 type_=typing.Any, # type: ignore
592 object_=_response.json(),
593 ),
594 ),
595 )
596 if _response.status_code == 404:
597 raise NotFoundError(
598 headers=dict(_response.headers),
599 body=typing.cast(
600 typing.Any,
601 parse_obj_as(
602 type_=typing.Any, # type: ignore
603 object_=_response.json(),
604 ),
605 ),
606 )
607 if _response.status_code == 409:
608 raise ConflictError(
609 headers=dict(_response.headers),
610 body=typing.cast(
611 typing.Any,
612 parse_obj_as(
613 type_=typing.Any, # type: ignore
614 object_=_response.json(),
615 ),
616 ),
617 )
618 if _response.status_code == 429:
619 raise TooManyRequestsError(
620 headers=dict(_response.headers),
621 body=typing.cast(
622 typing.Any,
623 parse_obj_as(
624 type_=typing.Any, # type: ignore
625 object_=_response.json(),
626 ),
627 ),
628 )
629 _response_json = _response.json()
630 except JSONDecodeError:
631 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
632 except ValidationError as e:
633 raise ParsingError(
634 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
635 )
636 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
637
638 async def delete(
639 self, id: str, grant_id: str, *, request_options: typing.Optional[RequestOptions] = None
640 ) -> AsyncHttpResponse[None]:
641 """
642 Parameters
643 ----------
644 id : str
645 Organization identifier.
646
647 grant_id : str
648 The Client Grant ID to remove from the organization
649
650 request_options : typing.Optional[RequestOptions]
651 Request-specific configuration.
652
653 Returns
654 -------
655 AsyncHttpResponse[None]
656 """
657 _response = await self._client_wrapper.httpx_client.request(
658 f"organizations/{encode_path_param(id)}/client-grants/{encode_path_param(grant_id)}",
659 method="DELETE",
660 request_options=request_options,
661 )
662 try:
663 if 200 <= _response.status_code < 300:
664 return AsyncHttpResponse(response=_response, data=None)
665 if _response.status_code == 400:
666 raise BadRequestError(
667 headers=dict(_response.headers),
668 body=typing.cast(
669 typing.Any,
670 parse_obj_as(
671 type_=typing.Any, # type: ignore
672 object_=_response.json(),
673 ),
674 ),
675 )
676 if _response.status_code == 401:
677 raise UnauthorizedError(
678 headers=dict(_response.headers),
679 body=typing.cast(
680 typing.Any,
681 parse_obj_as(
682 type_=typing.Any, # type: ignore
683 object_=_response.json(),
684 ),
685 ),
686 )
687 if _response.status_code == 403:
688 raise ForbiddenError(
689 headers=dict(_response.headers),
690 body=typing.cast(
691 typing.Any,
692 parse_obj_as(
693 type_=typing.Any, # type: ignore
694 object_=_response.json(),
695 ),
696 ),
697 )
698 if _response.status_code == 404:
699 raise NotFoundError(
700 headers=dict(_response.headers),
701 body=typing.cast(
702 typing.Any,
703 parse_obj_as(
704 type_=typing.Any, # type: ignore
705 object_=_response.json(),
706 ),
707 ),
708 )
709 if _response.status_code == 429:
710 raise TooManyRequestsError(
711 headers=dict(_response.headers),
712 body=typing.cast(
713 typing.Any,
714 parse_obj_as(
715 type_=typing.Any, # type: ignore
716 object_=_response.json(),
717 ),
718 ),
719 )
720 _response_json = _response.json()
721 except JSONDecodeError:
722 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
723 except ValidationError as e:
724 raise ParsingError(
725 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
726 )
727 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)