Debian Codegraph @

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