Debian Codegraph @

src/auth0/management/flows/executions/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.too_many_requests_error import TooManyRequestsError
17 from ...errors.unauthorized_error import UnauthorizedError
18 from ...types.flow_execution_summary import FlowExecutionSummary
19 from ...types.get_flow_execution_request_parameters_hydrate_enum import GetFlowExecutionRequestParametersHydrateEnum
20 from ...types.get_flow_execution_response_content import GetFlowExecutionResponseContent
21 from ...types.list_flow_executions_paginated_response_content import ListFlowExecutionsPaginatedResponseContent
22 from pydantic import ValidationError
23
24
25 class RawExecutionsClient:
26 def __init__(self, *, client_wrapper: SyncClientWrapper):
27 self._client_wrapper = client_wrapper
28
29 def list(
30 self,
31 flow_id: str,
32 *,
33 from_: typing.Optional[str] = None,
34 take: typing.Optional[int] = 50,
35 request_options: typing.Optional[RequestOptions] = None,
36 ) -> SyncPager[FlowExecutionSummary, ListFlowExecutionsPaginatedResponseContent]:
37 """
38 Parameters
39 ----------
40 flow_id : str
41 Flow id
42
43 from_ : typing.Optional[str]
44 Optional Id from which to start selection.
45
46 take : typing.Optional[int]
47 Number of results per page. Defaults to 50.
48
49 request_options : typing.Optional[RequestOptions]
50 Request-specific configuration.
51
52 Returns
53 -------
54 SyncPager[FlowExecutionSummary, ListFlowExecutionsPaginatedResponseContent]
55 Flow executions successfully retrieved.
56 """
57 _response = self._client_wrapper.httpx_client.request(
58 f"flows/{encode_path_param(flow_id)}/executions",
59 method="GET",
60 params={
61 "from": from_,
62 "take": take,
63 },
64 request_options=request_options,
65 )
66 try:
67 if 200 <= _response.status_code < 300:
68 _parsed_response = typing.cast(
69 ListFlowExecutionsPaginatedResponseContent,
70 parse_obj_as(
71 type_=ListFlowExecutionsPaginatedResponseContent, # type: ignore
72 object_=_response.json(),
73 ),
74 )
75 _items = _parsed_response.executions
76 _parsed_next = _parsed_response.next
77 _has_next = _parsed_next is not None and _parsed_next != ""
78 _get_next = lambda: self.list(
79 flow_id,
80 from_=_parsed_next,
81 take=take,
82 request_options=request_options,
83 )
84 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
85 if _response.status_code == 400:
86 raise BadRequestError(
87 headers=dict(_response.headers),
88 body=typing.cast(
89 typing.Any,
90 parse_obj_as(
91 type_=typing.Any, # type: ignore
92 object_=_response.json(),
93 ),
94 ),
95 )
96 if _response.status_code == 401:
97 raise UnauthorizedError(
98 headers=dict(_response.headers),
99 body=typing.cast(
100 typing.Any,
101 parse_obj_as(
102 type_=typing.Any, # type: ignore
103 object_=_response.json(),
104 ),
105 ),
106 )
107 if _response.status_code == 403:
108 raise ForbiddenError(
109 headers=dict(_response.headers),
110 body=typing.cast(
111 typing.Any,
112 parse_obj_as(
113 type_=typing.Any, # type: ignore
114 object_=_response.json(),
115 ),
116 ),
117 )
118 if _response.status_code == 429:
119 raise TooManyRequestsError(
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 _response_json = _response.json()
130 except JSONDecodeError:
131 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
132 except ValidationError as e:
133 raise ParsingError(
134 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
135 )
136 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
137
138 def get(
139 self,
140 flow_id: str,
141 execution_id: str,
142 *,
143 hydrate: typing.Optional[
144 typing.Union[
145 GetFlowExecutionRequestParametersHydrateEnum,
146 typing.Sequence[GetFlowExecutionRequestParametersHydrateEnum],
147 ]
148 ] = None,
149 request_options: typing.Optional[RequestOptions] = None,
150 ) -> HttpResponse[GetFlowExecutionResponseContent]:
151 """
152 Parameters
153 ----------
154 flow_id : str
155 Flow id
156
157 execution_id : str
158 Flow execution id
159
160 hydrate : typing.Optional[typing.Union[GetFlowExecutionRequestParametersHydrateEnum, typing.Sequence[GetFlowExecutionRequestParametersHydrateEnum]]]
161 Hydration param
162
163 request_options : typing.Optional[RequestOptions]
164 Request-specific configuration.
165
166 Returns
167 -------
168 HttpResponse[GetFlowExecutionResponseContent]
169 Flow execution successfully retrieved.
170 """
171 _response = self._client_wrapper.httpx_client.request(
172 f"flows/{encode_path_param(flow_id)}/executions/{encode_path_param(execution_id)}",
173 method="GET",
174 params={
175 "hydrate": hydrate,
176 },
177 request_options=request_options,
178 )
179 try:
180 if 200 <= _response.status_code < 300:
181 _data = typing.cast(
182 GetFlowExecutionResponseContent,
183 parse_obj_as(
184 type_=GetFlowExecutionResponseContent, # type: ignore
185 object_=_response.json(),
186 ),
187 )
188 return HttpResponse(response=_response, data=_data)
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 == 429:
223 raise TooManyRequestsError(
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 _response_json = _response.json()
234 except JSONDecodeError:
235 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
236 except ValidationError as e:
237 raise ParsingError(
238 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
239 )
240 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
241
242 def delete(
243 self, flow_id: str, execution_id: str, *, request_options: typing.Optional[RequestOptions] = None
244 ) -> HttpResponse[None]:
245 """
246 Parameters
247 ----------
248 flow_id : str
249 Flows id
250
251 execution_id : str
252 Flow execution identifier
253
254 request_options : typing.Optional[RequestOptions]
255 Request-specific configuration.
256
257 Returns
258 -------
259 HttpResponse[None]
260 """
261 _response = self._client_wrapper.httpx_client.request(
262 f"flows/{encode_path_param(flow_id)}/executions/{encode_path_param(execution_id)}",
263 method="DELETE",
264 request_options=request_options,
265 )
266 try:
267 if 200 <= _response.status_code < 300:
268 return HttpResponse(response=_response, data=None)
269 if _response.status_code == 400:
270 raise BadRequestError(
271 headers=dict(_response.headers),
272 body=typing.cast(
273 typing.Any,
274 parse_obj_as(
275 type_=typing.Any, # type: ignore
276 object_=_response.json(),
277 ),
278 ),
279 )
280 if _response.status_code == 401:
281 raise UnauthorizedError(
282 headers=dict(_response.headers),
283 body=typing.cast(
284 typing.Any,
285 parse_obj_as(
286 type_=typing.Any, # type: ignore
287 object_=_response.json(),
288 ),
289 ),
290 )
291 if _response.status_code == 403:
292 raise ForbiddenError(
293 headers=dict(_response.headers),
294 body=typing.cast(
295 typing.Any,
296 parse_obj_as(
297 type_=typing.Any, # type: ignore
298 object_=_response.json(),
299 ),
300 ),
301 )
302 if _response.status_code == 429:
303 raise TooManyRequestsError(
304 headers=dict(_response.headers),
305 body=typing.cast(
306 typing.Any,
307 parse_obj_as(
308 type_=typing.Any, # type: ignore
309 object_=_response.json(),
310 ),
311 ),
312 )
313 _response_json = _response.json()
314 except JSONDecodeError:
315 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
316 except ValidationError as e:
317 raise ParsingError(
318 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
319 )
320 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
321
322
323 class AsyncRawExecutionsClient:
324 def __init__(self, *, client_wrapper: AsyncClientWrapper):
325 self._client_wrapper = client_wrapper
326
327 async def list(
328 self,
329 flow_id: str,
330 *,
331 from_: typing.Optional[str] = None,
332 take: typing.Optional[int] = 50,
333 request_options: typing.Optional[RequestOptions] = None,
334 ) -> AsyncPager[FlowExecutionSummary, ListFlowExecutionsPaginatedResponseContent]:
335 """
336 Parameters
337 ----------
338 flow_id : str
339 Flow id
340
341 from_ : typing.Optional[str]
342 Optional Id from which to start selection.
343
344 take : typing.Optional[int]
345 Number of results per page. Defaults to 50.
346
347 request_options : typing.Optional[RequestOptions]
348 Request-specific configuration.
349
350 Returns
351 -------
352 AsyncPager[FlowExecutionSummary, ListFlowExecutionsPaginatedResponseContent]
353 Flow executions successfully retrieved.
354 """
355 _response = await self._client_wrapper.httpx_client.request(
356 f"flows/{encode_path_param(flow_id)}/executions",
357 method="GET",
358 params={
359 "from": from_,
360 "take": take,
361 },
362 request_options=request_options,
363 )
364 try:
365 if 200 <= _response.status_code < 300:
366 _parsed_response = typing.cast(
367 ListFlowExecutionsPaginatedResponseContent,
368 parse_obj_as(
369 type_=ListFlowExecutionsPaginatedResponseContent, # type: ignore
370 object_=_response.json(),
371 ),
372 )
373 _items = _parsed_response.executions
374 _parsed_next = _parsed_response.next
375 _has_next = _parsed_next is not None and _parsed_next != ""
376
377 async def _get_next():
378 return await self.list(
379 flow_id,
380 from_=_parsed_next,
381 take=take,
382 request_options=request_options,
383 )
384
385 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
386 if _response.status_code == 400:
387 raise BadRequestError(
388 headers=dict(_response.headers),
389 body=typing.cast(
390 typing.Any,
391 parse_obj_as(
392 type_=typing.Any, # type: ignore
393 object_=_response.json(),
394 ),
395 ),
396 )
397 if _response.status_code == 401:
398 raise UnauthorizedError(
399 headers=dict(_response.headers),
400 body=typing.cast(
401 typing.Any,
402 parse_obj_as(
403 type_=typing.Any, # type: ignore
404 object_=_response.json(),
405 ),
406 ),
407 )
408 if _response.status_code == 403:
409 raise ForbiddenError(
410 headers=dict(_response.headers),
411 body=typing.cast(
412 typing.Any,
413 parse_obj_as(
414 type_=typing.Any, # type: ignore
415 object_=_response.json(),
416 ),
417 ),
418 )
419 if _response.status_code == 429:
420 raise TooManyRequestsError(
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 _response_json = _response.json()
431 except JSONDecodeError:
432 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
433 except ValidationError as e:
434 raise ParsingError(
435 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
436 )
437 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
438
439 async def get(
440 self,
441 flow_id: str,
442 execution_id: str,
443 *,
444 hydrate: typing.Optional[
445 typing.Union[
446 GetFlowExecutionRequestParametersHydrateEnum,
447 typing.Sequence[GetFlowExecutionRequestParametersHydrateEnum],
448 ]
449 ] = None,
450 request_options: typing.Optional[RequestOptions] = None,
451 ) -> AsyncHttpResponse[GetFlowExecutionResponseContent]:
452 """
453 Parameters
454 ----------
455 flow_id : str
456 Flow id
457
458 execution_id : str
459 Flow execution id
460
461 hydrate : typing.Optional[typing.Union[GetFlowExecutionRequestParametersHydrateEnum, typing.Sequence[GetFlowExecutionRequestParametersHydrateEnum]]]
462 Hydration param
463
464 request_options : typing.Optional[RequestOptions]
465 Request-specific configuration.
466
467 Returns
468 -------
469 AsyncHttpResponse[GetFlowExecutionResponseContent]
470 Flow execution successfully retrieved.
471 """
472 _response = await self._client_wrapper.httpx_client.request(
473 f"flows/{encode_path_param(flow_id)}/executions/{encode_path_param(execution_id)}",
474 method="GET",
475 params={
476 "hydrate": hydrate,
477 },
478 request_options=request_options,
479 )
480 try:
481 if 200 <= _response.status_code < 300:
482 _data = typing.cast(
483 GetFlowExecutionResponseContent,
484 parse_obj_as(
485 type_=GetFlowExecutionResponseContent, # type: ignore
486 object_=_response.json(),
487 ),
488 )
489 return AsyncHttpResponse(response=_response, data=_data)
490 if _response.status_code == 400:
491 raise BadRequestError(
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 == 401:
502 raise UnauthorizedError(
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 if _response.status_code == 403:
513 raise ForbiddenError(
514 headers=dict(_response.headers),
515 body=typing.cast(
516 typing.Any,
517 parse_obj_as(
518 type_=typing.Any, # type: ignore
519 object_=_response.json(),
520 ),
521 ),
522 )
523 if _response.status_code == 429:
524 raise TooManyRequestsError(
525 headers=dict(_response.headers),
526 body=typing.cast(
527 typing.Any,
528 parse_obj_as(
529 type_=typing.Any, # type: ignore
530 object_=_response.json(),
531 ),
532 ),
533 )
534 _response_json = _response.json()
535 except JSONDecodeError:
536 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
537 except ValidationError as e:
538 raise ParsingError(
539 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
540 )
541 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
542
543 async def delete(
544 self, flow_id: str, execution_id: str, *, request_options: typing.Optional[RequestOptions] = None
545 ) -> AsyncHttpResponse[None]:
546 """
547 Parameters
548 ----------
549 flow_id : str
550 Flows id
551
552 execution_id : str
553 Flow execution identifier
554
555 request_options : typing.Optional[RequestOptions]
556 Request-specific configuration.
557
558 Returns
559 -------
560 AsyncHttpResponse[None]
561 """
562 _response = await self._client_wrapper.httpx_client.request(
563 f"flows/{encode_path_param(flow_id)}/executions/{encode_path_param(execution_id)}",
564 method="DELETE",
565 request_options=request_options,
566 )
567 try:
568 if 200 <= _response.status_code < 300:
569 return AsyncHttpResponse(response=_response, data=None)
570 if _response.status_code == 400:
571 raise BadRequestError(
572 headers=dict(_response.headers),
573 body=typing.cast(
574 typing.Any,
575 parse_obj_as(
576 type_=typing.Any, # type: ignore
577 object_=_response.json(),
578 ),
579 ),
580 )
581 if _response.status_code == 401:
582 raise UnauthorizedError(
583 headers=dict(_response.headers),
584 body=typing.cast(
585 typing.Any,
586 parse_obj_as(
587 type_=typing.Any, # type: ignore
588 object_=_response.json(),
589 ),
590 ),
591 )
592 if _response.status_code == 403:
593 raise ForbiddenError(
594 headers=dict(_response.headers),
595 body=typing.cast(
596 typing.Any,
597 parse_obj_as(
598 type_=typing.Any, # type: ignore
599 object_=_response.json(),
600 ),
601 ),
602 )
603 if _response.status_code == 429:
604 raise TooManyRequestsError(
605 headers=dict(_response.headers),
606 body=typing.cast(
607 typing.Any,
608 parse_obj_as(
609 type_=typing.Any, # type: ignore
610 object_=_response.json(),
611 ),
612 ),
613 )
614 _response_json = _response.json()
615 except JSONDecodeError:
616 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
617 except ValidationError as e:
618 raise ParsingError(
619 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
620 )
621 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)