Debian Codegraph @

src/auth0/management/actions/triggers/bindings/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.too_many_requests_error import TooManyRequestsError
18 from ....errors.unauthorized_error import UnauthorizedError
19 from ....types.action_binding import ActionBinding
20 from ....types.action_binding_with_ref import ActionBindingWithRef
21 from ....types.action_trigger_type_enum import ActionTriggerTypeEnum
22 from ....types.list_action_bindings_paginated_response_content import ListActionBindingsPaginatedResponseContent
23 from ....types.update_action_bindings_response_content import UpdateActionBindingsResponseContent
24 from pydantic import ValidationError
25
26 # this is used as the default value for optional parameters
27 OMIT = typing.cast(typing.Any, ...)
28
29
30 class RawBindingsClient:
31 def __init__(self, *, client_wrapper: SyncClientWrapper):
32 self._client_wrapper = client_wrapper
33
34 def list(
35 self,
36 trigger_id: ActionTriggerTypeEnum,
37 *,
38 page: typing.Optional[int] = 0,
39 per_page: typing.Optional[int] = 50,
40 request_options: typing.Optional[RequestOptions] = None,
41 ) -> SyncPager[ActionBinding, ListActionBindingsPaginatedResponseContent]:
42 """
43 Retrieve the actions that are bound to a trigger. Once an action is created and deployed, it must be attached (i.e. bound) to a trigger so that it will be executed as part of a flow. The list of actions returned reflects the order in which they will be executed during the appropriate flow.
44
45 Parameters
46 ----------
47 trigger_id : ActionTriggerTypeEnum
48 An actions extensibility point.
49
50 page : typing.Optional[int]
51 Use this field to request a specific page of the list results.
52
53 per_page : typing.Optional[int]
54 The maximum number of results to be returned in a single request. 20 by default
55
56 request_options : typing.Optional[RequestOptions]
57 Request-specific configuration.
58
59 Returns
60 -------
61 SyncPager[ActionBinding, ListActionBindingsPaginatedResponseContent]
62 The bindings were retrieved.
63 """
64 page = page if page is not None else 0
65
66 _response = self._client_wrapper.httpx_client.request(
67 f"actions/triggers/{encode_path_param(trigger_id)}/bindings",
68 method="GET",
69 params={
70 "page": page,
71 "per_page": per_page,
72 },
73 request_options=request_options,
74 )
75 try:
76 if 200 <= _response.status_code < 300:
77 _parsed_response = typing.cast(
78 ListActionBindingsPaginatedResponseContent,
79 parse_obj_as(
80 type_=ListActionBindingsPaginatedResponseContent, # type: ignore
81 object_=_response.json(),
82 ),
83 )
84 _items = _parsed_response.bindings
85 _has_next = len(_items or []) > 0
86 _get_next = lambda: self.list(
87 trigger_id,
88 page=page + 1,
89 per_page=per_page,
90 request_options=request_options,
91 )
92 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
93 if _response.status_code == 400:
94 raise BadRequestError(
95 headers=dict(_response.headers),
96 body=typing.cast(
97 typing.Any,
98 parse_obj_as(
99 type_=typing.Any, # type: ignore
100 object_=_response.json(),
101 ),
102 ),
103 )
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 update_many(
147 self,
148 trigger_id: ActionTriggerTypeEnum,
149 *,
150 bindings: typing.Optional[typing.Sequence[ActionBindingWithRef]] = OMIT,
151 request_options: typing.Optional[RequestOptions] = None,
152 ) -> HttpResponse[UpdateActionBindingsResponseContent]:
153 """
154 Update the actions that are bound (i.e. attached) to a trigger. Once an action is created and deployed, it must be attached (i.e. bound) to a trigger so that it will be executed as part of a flow. The order in which the actions are provided will determine the order in which they are executed.
155
156 Parameters
157 ----------
158 trigger_id : ActionTriggerTypeEnum
159 An actions extensibility point.
160
161 bindings : typing.Optional[typing.Sequence[ActionBindingWithRef]]
162 The actions that will be bound to this trigger. The order in which they are included will be the order in which they are executed.
163
164 request_options : typing.Optional[RequestOptions]
165 Request-specific configuration.
166
167 Returns
168 -------
169 HttpResponse[UpdateActionBindingsResponseContent]
170 The bindings were updated.
171 """
172 _response = self._client_wrapper.httpx_client.request(
173 f"actions/triggers/{encode_path_param(trigger_id)}/bindings",
174 method="PATCH",
175 json={
176 "bindings": convert_and_respect_annotation_metadata(
177 object_=bindings, annotation=typing.Sequence[ActionBindingWithRef], direction="write"
178 ),
179 },
180 headers={
181 "content-type": "application/json",
182 },
183 request_options=request_options,
184 omit=OMIT,
185 )
186 try:
187 if 200 <= _response.status_code < 300:
188 _data = typing.cast(
189 UpdateActionBindingsResponseContent,
190 parse_obj_as(
191 type_=UpdateActionBindingsResponseContent, # type: ignore
192 object_=_response.json(),
193 ),
194 )
195 return HttpResponse(response=_response, data=_data)
196 if _response.status_code == 400:
197 raise BadRequestError(
198 headers=dict(_response.headers),
199 body=typing.cast(
200 typing.Any,
201 parse_obj_as(
202 type_=typing.Any, # type: ignore
203 object_=_response.json(),
204 ),
205 ),
206 )
207 if _response.status_code == 401:
208 raise UnauthorizedError(
209 headers=dict(_response.headers),
210 body=typing.cast(
211 typing.Any,
212 parse_obj_as(
213 type_=typing.Any, # type: ignore
214 object_=_response.json(),
215 ),
216 ),
217 )
218 if _response.status_code == 403:
219 raise ForbiddenError(
220 headers=dict(_response.headers),
221 body=typing.cast(
222 typing.Any,
223 parse_obj_as(
224 type_=typing.Any, # type: ignore
225 object_=_response.json(),
226 ),
227 ),
228 )
229 if _response.status_code == 429:
230 raise TooManyRequestsError(
231 headers=dict(_response.headers),
232 body=typing.cast(
233 typing.Any,
234 parse_obj_as(
235 type_=typing.Any, # type: ignore
236 object_=_response.json(),
237 ),
238 ),
239 )
240 _response_json = _response.json()
241 except JSONDecodeError:
242 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
243 except ValidationError as e:
244 raise ParsingError(
245 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
246 )
247 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
248
249
250 class AsyncRawBindingsClient:
251 def __init__(self, *, client_wrapper: AsyncClientWrapper):
252 self._client_wrapper = client_wrapper
253
254 async def list(
255 self,
256 trigger_id: ActionTriggerTypeEnum,
257 *,
258 page: typing.Optional[int] = 0,
259 per_page: typing.Optional[int] = 50,
260 request_options: typing.Optional[RequestOptions] = None,
261 ) -> AsyncPager[ActionBinding, ListActionBindingsPaginatedResponseContent]:
262 """
263 Retrieve the actions that are bound to a trigger. Once an action is created and deployed, it must be attached (i.e. bound) to a trigger so that it will be executed as part of a flow. The list of actions returned reflects the order in which they will be executed during the appropriate flow.
264
265 Parameters
266 ----------
267 trigger_id : ActionTriggerTypeEnum
268 An actions extensibility point.
269
270 page : typing.Optional[int]
271 Use this field to request a specific page of the list results.
272
273 per_page : typing.Optional[int]
274 The maximum number of results to be returned in a single request. 20 by default
275
276 request_options : typing.Optional[RequestOptions]
277 Request-specific configuration.
278
279 Returns
280 -------
281 AsyncPager[ActionBinding, ListActionBindingsPaginatedResponseContent]
282 The bindings were retrieved.
283 """
284 page = page if page is not None else 0
285
286 _response = await self._client_wrapper.httpx_client.request(
287 f"actions/triggers/{encode_path_param(trigger_id)}/bindings",
288 method="GET",
289 params={
290 "page": page,
291 "per_page": per_page,
292 },
293 request_options=request_options,
294 )
295 try:
296 if 200 <= _response.status_code < 300:
297 _parsed_response = typing.cast(
298 ListActionBindingsPaginatedResponseContent,
299 parse_obj_as(
300 type_=ListActionBindingsPaginatedResponseContent, # type: ignore
301 object_=_response.json(),
302 ),
303 )
304 _items = _parsed_response.bindings
305 _has_next = len(_items or []) > 0
306
307 async def _get_next():
308 return await self.list(
309 trigger_id,
310 page=page + 1,
311 per_page=per_page,
312 request_options=request_options,
313 )
314
315 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
316 if _response.status_code == 400:
317 raise BadRequestError(
318 headers=dict(_response.headers),
319 body=typing.cast(
320 typing.Any,
321 parse_obj_as(
322 type_=typing.Any, # type: ignore
323 object_=_response.json(),
324 ),
325 ),
326 )
327 if _response.status_code == 401:
328 raise UnauthorizedError(
329 headers=dict(_response.headers),
330 body=typing.cast(
331 typing.Any,
332 parse_obj_as(
333 type_=typing.Any, # type: ignore
334 object_=_response.json(),
335 ),
336 ),
337 )
338 if _response.status_code == 403:
339 raise ForbiddenError(
340 headers=dict(_response.headers),
341 body=typing.cast(
342 typing.Any,
343 parse_obj_as(
344 type_=typing.Any, # type: ignore
345 object_=_response.json(),
346 ),
347 ),
348 )
349 if _response.status_code == 429:
350 raise TooManyRequestsError(
351 headers=dict(_response.headers),
352 body=typing.cast(
353 typing.Any,
354 parse_obj_as(
355 type_=typing.Any, # type: ignore
356 object_=_response.json(),
357 ),
358 ),
359 )
360 _response_json = _response.json()
361 except JSONDecodeError:
362 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
363 except ValidationError as e:
364 raise ParsingError(
365 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
366 )
367 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
368
369 async def update_many(
370 self,
371 trigger_id: ActionTriggerTypeEnum,
372 *,
373 bindings: typing.Optional[typing.Sequence[ActionBindingWithRef]] = OMIT,
374 request_options: typing.Optional[RequestOptions] = None,
375 ) -> AsyncHttpResponse[UpdateActionBindingsResponseContent]:
376 """
377 Update the actions that are bound (i.e. attached) to a trigger. Once an action is created and deployed, it must be attached (i.e. bound) to a trigger so that it will be executed as part of a flow. The order in which the actions are provided will determine the order in which they are executed.
378
379 Parameters
380 ----------
381 trigger_id : ActionTriggerTypeEnum
382 An actions extensibility point.
383
384 bindings : typing.Optional[typing.Sequence[ActionBindingWithRef]]
385 The actions that will be bound to this trigger. The order in which they are included will be the order in which they are executed.
386
387 request_options : typing.Optional[RequestOptions]
388 Request-specific configuration.
389
390 Returns
391 -------
392 AsyncHttpResponse[UpdateActionBindingsResponseContent]
393 The bindings were updated.
394 """
395 _response = await self._client_wrapper.httpx_client.request(
396 f"actions/triggers/{encode_path_param(trigger_id)}/bindings",
397 method="PATCH",
398 json={
399 "bindings": convert_and_respect_annotation_metadata(
400 object_=bindings, annotation=typing.Sequence[ActionBindingWithRef], direction="write"
401 ),
402 },
403 headers={
404 "content-type": "application/json",
405 },
406 request_options=request_options,
407 omit=OMIT,
408 )
409 try:
410 if 200 <= _response.status_code < 300:
411 _data = typing.cast(
412 UpdateActionBindingsResponseContent,
413 parse_obj_as(
414 type_=UpdateActionBindingsResponseContent, # type: ignore
415 object_=_response.json(),
416 ),
417 )
418 return AsyncHttpResponse(response=_response, data=_data)
419 if _response.status_code == 400:
420 raise BadRequestError(
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 if _response.status_code == 401:
431 raise UnauthorizedError(
432 headers=dict(_response.headers),
433 body=typing.cast(
434 typing.Any,
435 parse_obj_as(
436 type_=typing.Any, # type: ignore
437 object_=_response.json(),
438 ),
439 ),
440 )
441 if _response.status_code == 403:
442 raise ForbiddenError(
443 headers=dict(_response.headers),
444 body=typing.cast(
445 typing.Any,
446 parse_obj_as(
447 type_=typing.Any, # type: ignore
448 object_=_response.json(),
449 ),
450 ),
451 )
452 if _response.status_code == 429:
453 raise TooManyRequestsError(
454 headers=dict(_response.headers),
455 body=typing.cast(
456 typing.Any,
457 parse_obj_as(
458 type_=typing.Any, # type: ignore
459 object_=_response.json(),
460 ),
461 ),
462 )
463 _response_json = _response.json()
464 except JSONDecodeError:
465 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
466 except ValidationError as e:
467 raise ParsingError(
468 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
469 )
470 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)