Debian Codegraph @

src/auth0/management/user_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.forbidden_error import ForbiddenError
15 from ..errors.too_many_requests_error import TooManyRequestsError
16 from ..errors.unauthorized_error import UnauthorizedError
17 from ..types.list_user_grants_offset_paginated_response_content import ListUserGrantsOffsetPaginatedResponseContent
18 from ..types.user_grant import UserGrant
19 from pydantic import ValidationError
20
21
22 class RawUserGrantsClient:
23 def __init__(self, *, client_wrapper: SyncClientWrapper):
24 self._client_wrapper = client_wrapper
25
26 def list(
27 self,
28 *,
29 per_page: typing.Optional[int] = 50,
30 page: typing.Optional[int] = 0,
31 include_totals: typing.Optional[bool] = True,
32 user_id: typing.Optional[str] = None,
33 client_id: typing.Optional[str] = None,
34 audience: typing.Optional[str] = None,
35 request_options: typing.Optional[RequestOptions] = None,
36 ) -> SyncPager[UserGrant, ListUserGrantsOffsetPaginatedResponseContent]:
37 """
38 Retrieve the [grants](https://auth0.com/docs/api-auth/which-oauth-flow-to-use) associated with your account.
39
40 Parameters
41 ----------
42 per_page : typing.Optional[int]
43 Number of results per page.
44
45 page : typing.Optional[int]
46 Page index of the results to return. First page is 0.
47
48 include_totals : typing.Optional[bool]
49 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
50
51 user_id : typing.Optional[str]
52 user_id of the grants to retrieve.
53
54 client_id : typing.Optional[str]
55 client_id of the grants to retrieve.
56
57 audience : typing.Optional[str]
58 audience of the grants to retrieve.
59
60 request_options : typing.Optional[RequestOptions]
61 Request-specific configuration.
62
63 Returns
64 -------
65 SyncPager[UserGrant, ListUserGrantsOffsetPaginatedResponseContent]
66 Grants successfully retrieved.
67 """
68 page = page if page is not None else 0
69
70 _response = self._client_wrapper.httpx_client.request(
71 "grants",
72 method="GET",
73 params={
74 "per_page": per_page,
75 "page": page,
76 "include_totals": include_totals,
77 "user_id": user_id,
78 "client_id": client_id,
79 "audience": audience,
80 },
81 request_options=request_options,
82 )
83 try:
84 if 200 <= _response.status_code < 300:
85 _parsed_response = typing.cast(
86 ListUserGrantsOffsetPaginatedResponseContent,
87 parse_obj_as(
88 type_=ListUserGrantsOffsetPaginatedResponseContent, # type: ignore
89 object_=_response.json(),
90 ),
91 )
92 _items = _parsed_response.grants
93 _has_next = len(_items or []) > 0
94 _get_next = lambda: self.list(
95 per_page=per_page,
96 page=page + 1,
97 include_totals=include_totals,
98 user_id=user_id,
99 client_id=client_id,
100 audience=audience,
101 request_options=request_options,
102 )
103 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
104 if _response.status_code == 401:
105 raise UnauthorizedError(
106 headers=dict(_response.headers),
107 body=typing.cast(
108 typing.Any,
109 parse_obj_as(
110 type_=typing.Any, # type: ignore
111 object_=_response.json(),
112 ),
113 ),
114 )
115 if _response.status_code == 403:
116 raise ForbiddenError(
117 headers=dict(_response.headers),
118 body=typing.cast(
119 typing.Any,
120 parse_obj_as(
121 type_=typing.Any, # type: ignore
122 object_=_response.json(),
123 ),
124 ),
125 )
126 if _response.status_code == 429:
127 raise TooManyRequestsError(
128 headers=dict(_response.headers),
129 body=typing.cast(
130 typing.Any,
131 parse_obj_as(
132 type_=typing.Any, # type: ignore
133 object_=_response.json(),
134 ),
135 ),
136 )
137 _response_json = _response.json()
138 except JSONDecodeError:
139 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
140 except ValidationError as e:
141 raise ParsingError(
142 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
143 )
144 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
145
146 def delete_by_user_id(
147 self, *, user_id: str, request_options: typing.Optional[RequestOptions] = None
148 ) -> HttpResponse[None]:
149 """
150 Delete a grant associated with your account.
151
152 Parameters
153 ----------
154 user_id : str
155 user_id of the grant to delete.
156
157 request_options : typing.Optional[RequestOptions]
158 Request-specific configuration.
159
160 Returns
161 -------
162 HttpResponse[None]
163 """
164 _response = self._client_wrapper.httpx_client.request(
165 "grants",
166 method="DELETE",
167 params={
168 "user_id": user_id,
169 },
170 request_options=request_options,
171 )
172 try:
173 if 200 <= _response.status_code < 300:
174 return HttpResponse(response=_response, data=None)
175 if _response.status_code == 401:
176 raise UnauthorizedError(
177 headers=dict(_response.headers),
178 body=typing.cast(
179 typing.Any,
180 parse_obj_as(
181 type_=typing.Any, # type: ignore
182 object_=_response.json(),
183 ),
184 ),
185 )
186 if _response.status_code == 403:
187 raise ForbiddenError(
188 headers=dict(_response.headers),
189 body=typing.cast(
190 typing.Any,
191 parse_obj_as(
192 type_=typing.Any, # type: ignore
193 object_=_response.json(),
194 ),
195 ),
196 )
197 if _response.status_code == 429:
198 raise TooManyRequestsError(
199 headers=dict(_response.headers),
200 body=typing.cast(
201 typing.Any,
202 parse_obj_as(
203 type_=typing.Any, # type: ignore
204 object_=_response.json(),
205 ),
206 ),
207 )
208 _response_json = _response.json()
209 except JSONDecodeError:
210 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
211 except ValidationError as e:
212 raise ParsingError(
213 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
214 )
215 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
216
217 def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
218 """
219 Delete a grant associated with your account.
220
221 Parameters
222 ----------
223 id : str
224 ID of the grant to delete.
225
226 request_options : typing.Optional[RequestOptions]
227 Request-specific configuration.
228
229 Returns
230 -------
231 HttpResponse[None]
232 """
233 _response = self._client_wrapper.httpx_client.request(
234 f"grants/{encode_path_param(id)}",
235 method="DELETE",
236 request_options=request_options,
237 )
238 try:
239 if 200 <= _response.status_code < 300:
240 return HttpResponse(response=_response, data=None)
241 if _response.status_code == 401:
242 raise UnauthorizedError(
243 headers=dict(_response.headers),
244 body=typing.cast(
245 typing.Any,
246 parse_obj_as(
247 type_=typing.Any, # type: ignore
248 object_=_response.json(),
249 ),
250 ),
251 )
252 if _response.status_code == 403:
253 raise ForbiddenError(
254 headers=dict(_response.headers),
255 body=typing.cast(
256 typing.Any,
257 parse_obj_as(
258 type_=typing.Any, # type: ignore
259 object_=_response.json(),
260 ),
261 ),
262 )
263 if _response.status_code == 429:
264 raise TooManyRequestsError(
265 headers=dict(_response.headers),
266 body=typing.cast(
267 typing.Any,
268 parse_obj_as(
269 type_=typing.Any, # type: ignore
270 object_=_response.json(),
271 ),
272 ),
273 )
274 _response_json = _response.json()
275 except JSONDecodeError:
276 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
277 except ValidationError as e:
278 raise ParsingError(
279 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
280 )
281 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
282
283
284 class AsyncRawUserGrantsClient:
285 def __init__(self, *, client_wrapper: AsyncClientWrapper):
286 self._client_wrapper = client_wrapper
287
288 async def list(
289 self,
290 *,
291 per_page: typing.Optional[int] = 50,
292 page: typing.Optional[int] = 0,
293 include_totals: typing.Optional[bool] = True,
294 user_id: typing.Optional[str] = None,
295 client_id: typing.Optional[str] = None,
296 audience: typing.Optional[str] = None,
297 request_options: typing.Optional[RequestOptions] = None,
298 ) -> AsyncPager[UserGrant, ListUserGrantsOffsetPaginatedResponseContent]:
299 """
300 Retrieve the [grants](https://auth0.com/docs/api-auth/which-oauth-flow-to-use) associated with your account.
301
302 Parameters
303 ----------
304 per_page : typing.Optional[int]
305 Number of results per page.
306
307 page : typing.Optional[int]
308 Page index of the results to return. First page is 0.
309
310 include_totals : typing.Optional[bool]
311 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
312
313 user_id : typing.Optional[str]
314 user_id of the grants to retrieve.
315
316 client_id : typing.Optional[str]
317 client_id of the grants to retrieve.
318
319 audience : typing.Optional[str]
320 audience of the grants to retrieve.
321
322 request_options : typing.Optional[RequestOptions]
323 Request-specific configuration.
324
325 Returns
326 -------
327 AsyncPager[UserGrant, ListUserGrantsOffsetPaginatedResponseContent]
328 Grants successfully retrieved.
329 """
330 page = page if page is not None else 0
331
332 _response = await self._client_wrapper.httpx_client.request(
333 "grants",
334 method="GET",
335 params={
336 "per_page": per_page,
337 "page": page,
338 "include_totals": include_totals,
339 "user_id": user_id,
340 "client_id": client_id,
341 "audience": audience,
342 },
343 request_options=request_options,
344 )
345 try:
346 if 200 <= _response.status_code < 300:
347 _parsed_response = typing.cast(
348 ListUserGrantsOffsetPaginatedResponseContent,
349 parse_obj_as(
350 type_=ListUserGrantsOffsetPaginatedResponseContent, # type: ignore
351 object_=_response.json(),
352 ),
353 )
354 _items = _parsed_response.grants
355 _has_next = len(_items or []) > 0
356
357 async def _get_next():
358 return await self.list(
359 per_page=per_page,
360 page=page + 1,
361 include_totals=include_totals,
362 user_id=user_id,
363 client_id=client_id,
364 audience=audience,
365 request_options=request_options,
366 )
367
368 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
369 if _response.status_code == 401:
370 raise UnauthorizedError(
371 headers=dict(_response.headers),
372 body=typing.cast(
373 typing.Any,
374 parse_obj_as(
375 type_=typing.Any, # type: ignore
376 object_=_response.json(),
377 ),
378 ),
379 )
380 if _response.status_code == 403:
381 raise ForbiddenError(
382 headers=dict(_response.headers),
383 body=typing.cast(
384 typing.Any,
385 parse_obj_as(
386 type_=typing.Any, # type: ignore
387 object_=_response.json(),
388 ),
389 ),
390 )
391 if _response.status_code == 429:
392 raise TooManyRequestsError(
393 headers=dict(_response.headers),
394 body=typing.cast(
395 typing.Any,
396 parse_obj_as(
397 type_=typing.Any, # type: ignore
398 object_=_response.json(),
399 ),
400 ),
401 )
402 _response_json = _response.json()
403 except JSONDecodeError:
404 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
405 except ValidationError as e:
406 raise ParsingError(
407 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
408 )
409 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
410
411 async def delete_by_user_id(
412 self, *, user_id: str, request_options: typing.Optional[RequestOptions] = None
413 ) -> AsyncHttpResponse[None]:
414 """
415 Delete a grant associated with your account.
416
417 Parameters
418 ----------
419 user_id : str
420 user_id of the grant to delete.
421
422 request_options : typing.Optional[RequestOptions]
423 Request-specific configuration.
424
425 Returns
426 -------
427 AsyncHttpResponse[None]
428 """
429 _response = await self._client_wrapper.httpx_client.request(
430 "grants",
431 method="DELETE",
432 params={
433 "user_id": user_id,
434 },
435 request_options=request_options,
436 )
437 try:
438 if 200 <= _response.status_code < 300:
439 return AsyncHttpResponse(response=_response, data=None)
440 if _response.status_code == 401:
441 raise UnauthorizedError(
442 headers=dict(_response.headers),
443 body=typing.cast(
444 typing.Any,
445 parse_obj_as(
446 type_=typing.Any, # type: ignore
447 object_=_response.json(),
448 ),
449 ),
450 )
451 if _response.status_code == 403:
452 raise ForbiddenError(
453 headers=dict(_response.headers),
454 body=typing.cast(
455 typing.Any,
456 parse_obj_as(
457 type_=typing.Any, # type: ignore
458 object_=_response.json(),
459 ),
460 ),
461 )
462 if _response.status_code == 429:
463 raise TooManyRequestsError(
464 headers=dict(_response.headers),
465 body=typing.cast(
466 typing.Any,
467 parse_obj_as(
468 type_=typing.Any, # type: ignore
469 object_=_response.json(),
470 ),
471 ),
472 )
473 _response_json = _response.json()
474 except JSONDecodeError:
475 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
476 except ValidationError as e:
477 raise ParsingError(
478 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
479 )
480 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
481
482 async def delete(
483 self, id: str, *, request_options: typing.Optional[RequestOptions] = None
484 ) -> AsyncHttpResponse[None]:
485 """
486 Delete a grant associated with your account.
487
488 Parameters
489 ----------
490 id : str
491 ID of the grant to delete.
492
493 request_options : typing.Optional[RequestOptions]
494 Request-specific configuration.
495
496 Returns
497 -------
498 AsyncHttpResponse[None]
499 """
500 _response = await self._client_wrapper.httpx_client.request(
501 f"grants/{encode_path_param(id)}",
502 method="DELETE",
503 request_options=request_options,
504 )
505 try:
506 if 200 <= _response.status_code < 300:
507 return AsyncHttpResponse(response=_response, data=None)
508 if _response.status_code == 401:
509 raise UnauthorizedError(
510 headers=dict(_response.headers),
511 body=typing.cast(
512 typing.Any,
513 parse_obj_as(
514 type_=typing.Any, # type: ignore
515 object_=_response.json(),
516 ),
517 ),
518 )
519 if _response.status_code == 403:
520 raise ForbiddenError(
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 == 429:
531 raise TooManyRequestsError(
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 _response_json = _response.json()
542 except JSONDecodeError:
543 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
544 except ValidationError as e:
545 raise ParsingError(
546 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
547 )
548 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)