Debian Codegraph @

src/auth0/management/connections/clients/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.connection_enabled_client import ConnectionEnabledClient
21 from ...types.get_connection_enabled_clients_response_content import GetConnectionEnabledClientsResponseContent
22 from ...types.update_enabled_client_connections_request_content import UpdateEnabledClientConnectionsRequestContent
23 from pydantic import ValidationError
24
25 # this is used as the default value for optional parameters
26 OMIT = typing.cast(typing.Any, ...)
27
28
29 class RawClientsClient:
30 def __init__(self, *, client_wrapper: SyncClientWrapper):
31 self._client_wrapper = client_wrapper
32
33 def get(
34 self,
35 id: str,
36 *,
37 take: typing.Optional[int] = 50,
38 from_: typing.Optional[str] = None,
39 request_options: typing.Optional[RequestOptions] = None,
40 ) -> SyncPager[ConnectionEnabledClient, GetConnectionEnabledClientsResponseContent]:
41 """
42 Retrieve all clients that have the specified [connection](https://auth0.com/docs/authenticate/identity-providers) enabled.
43
44 **Note**: The first time you call this endpoint, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no further results are remaining.
45
46 Parameters
47 ----------
48 id : str
49 The id of the connection for which enabled clients are to be retrieved
50
51 take : typing.Optional[int]
52 Number of results per page. Defaults to 50.
53
54 from_ : typing.Optional[str]
55 Optional Id from which to start selection.
56
57 request_options : typing.Optional[RequestOptions]
58 Request-specific configuration.
59
60 Returns
61 -------
62 SyncPager[ConnectionEnabledClient, GetConnectionEnabledClientsResponseContent]
63 Success
64 """
65 _response = self._client_wrapper.httpx_client.request(
66 f"connections/{encode_path_param(id)}/clients",
67 method="GET",
68 params={
69 "take": take,
70 "from": from_,
71 },
72 request_options=request_options,
73 )
74 try:
75 if 200 <= _response.status_code < 300:
76 _parsed_response = typing.cast(
77 GetConnectionEnabledClientsResponseContent,
78 parse_obj_as(
79 type_=GetConnectionEnabledClientsResponseContent, # type: ignore
80 object_=_response.json(),
81 ),
82 )
83 _items = _parsed_response.clients
84 _parsed_next = _parsed_response.next
85 _has_next = _parsed_next is not None and _parsed_next != ""
86 _get_next = lambda: self.get(
87 id,
88 take=take,
89 from_=_parsed_next,
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 == 404:
127 raise NotFoundError(
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 if _response.status_code == 429:
138 raise TooManyRequestsError(
139 headers=dict(_response.headers),
140 body=typing.cast(
141 typing.Any,
142 parse_obj_as(
143 type_=typing.Any, # type: ignore
144 object_=_response.json(),
145 ),
146 ),
147 )
148 _response_json = _response.json()
149 except JSONDecodeError:
150 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
151 except ValidationError as e:
152 raise ParsingError(
153 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
154 )
155 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
156
157 def update(
158 self,
159 id: str,
160 *,
161 request: UpdateEnabledClientConnectionsRequestContent,
162 request_options: typing.Optional[RequestOptions] = None,
163 ) -> HttpResponse[None]:
164 """
165 Parameters
166 ----------
167 id : str
168 The id of the connection to modify
169
170 request : UpdateEnabledClientConnectionsRequestContent
171
172 request_options : typing.Optional[RequestOptions]
173 Request-specific configuration.
174
175 Returns
176 -------
177 HttpResponse[None]
178 """
179 _response = self._client_wrapper.httpx_client.request(
180 f"connections/{encode_path_param(id)}/clients",
181 method="PATCH",
182 json=convert_and_respect_annotation_metadata(
183 object_=request, annotation=UpdateEnabledClientConnectionsRequestContent, direction="write"
184 ),
185 request_options=request_options,
186 omit=OMIT,
187 )
188 try:
189 if 200 <= _response.status_code < 300:
190 return HttpResponse(response=_response, data=None)
191 if _response.status_code == 400:
192 raise BadRequestError(
193 headers=dict(_response.headers),
194 body=typing.cast(
195 typing.Any,
196 parse_obj_as(
197 type_=typing.Any, # type: ignore
198 object_=_response.json(),
199 ),
200 ),
201 )
202 if _response.status_code == 401:
203 raise UnauthorizedError(
204 headers=dict(_response.headers),
205 body=typing.cast(
206 typing.Any,
207 parse_obj_as(
208 type_=typing.Any, # type: ignore
209 object_=_response.json(),
210 ),
211 ),
212 )
213 if _response.status_code == 403:
214 raise ForbiddenError(
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 == 404:
225 raise NotFoundError(
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 == 429:
236 raise TooManyRequestsError(
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 _response_json = _response.json()
247 except JSONDecodeError:
248 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
249 except ValidationError as e:
250 raise ParsingError(
251 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
252 )
253 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
254
255
256 class AsyncRawClientsClient:
257 def __init__(self, *, client_wrapper: AsyncClientWrapper):
258 self._client_wrapper = client_wrapper
259
260 async def get(
261 self,
262 id: str,
263 *,
264 take: typing.Optional[int] = 50,
265 from_: typing.Optional[str] = None,
266 request_options: typing.Optional[RequestOptions] = None,
267 ) -> AsyncPager[ConnectionEnabledClient, GetConnectionEnabledClientsResponseContent]:
268 """
269 Retrieve all clients that have the specified [connection](https://auth0.com/docs/authenticate/identity-providers) enabled.
270
271 **Note**: The first time you call this endpoint, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no further results are remaining.
272
273 Parameters
274 ----------
275 id : str
276 The id of the connection for which enabled clients are to be retrieved
277
278 take : typing.Optional[int]
279 Number of results per page. Defaults to 50.
280
281 from_ : typing.Optional[str]
282 Optional Id from which to start selection.
283
284 request_options : typing.Optional[RequestOptions]
285 Request-specific configuration.
286
287 Returns
288 -------
289 AsyncPager[ConnectionEnabledClient, GetConnectionEnabledClientsResponseContent]
290 Success
291 """
292 _response = await self._client_wrapper.httpx_client.request(
293 f"connections/{encode_path_param(id)}/clients",
294 method="GET",
295 params={
296 "take": take,
297 "from": from_,
298 },
299 request_options=request_options,
300 )
301 try:
302 if 200 <= _response.status_code < 300:
303 _parsed_response = typing.cast(
304 GetConnectionEnabledClientsResponseContent,
305 parse_obj_as(
306 type_=GetConnectionEnabledClientsResponseContent, # type: ignore
307 object_=_response.json(),
308 ),
309 )
310 _items = _parsed_response.clients
311 _parsed_next = _parsed_response.next
312 _has_next = _parsed_next is not None and _parsed_next != ""
313
314 async def _get_next():
315 return await self.get(
316 id,
317 take=take,
318 from_=_parsed_next,
319 request_options=request_options,
320 )
321
322 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
323 if _response.status_code == 400:
324 raise BadRequestError(
325 headers=dict(_response.headers),
326 body=typing.cast(
327 typing.Any,
328 parse_obj_as(
329 type_=typing.Any, # type: ignore
330 object_=_response.json(),
331 ),
332 ),
333 )
334 if _response.status_code == 401:
335 raise UnauthorizedError(
336 headers=dict(_response.headers),
337 body=typing.cast(
338 typing.Any,
339 parse_obj_as(
340 type_=typing.Any, # type: ignore
341 object_=_response.json(),
342 ),
343 ),
344 )
345 if _response.status_code == 403:
346 raise ForbiddenError(
347 headers=dict(_response.headers),
348 body=typing.cast(
349 typing.Any,
350 parse_obj_as(
351 type_=typing.Any, # type: ignore
352 object_=_response.json(),
353 ),
354 ),
355 )
356 if _response.status_code == 404:
357 raise NotFoundError(
358 headers=dict(_response.headers),
359 body=typing.cast(
360 typing.Any,
361 parse_obj_as(
362 type_=typing.Any, # type: ignore
363 object_=_response.json(),
364 ),
365 ),
366 )
367 if _response.status_code == 429:
368 raise TooManyRequestsError(
369 headers=dict(_response.headers),
370 body=typing.cast(
371 typing.Any,
372 parse_obj_as(
373 type_=typing.Any, # type: ignore
374 object_=_response.json(),
375 ),
376 ),
377 )
378 _response_json = _response.json()
379 except JSONDecodeError:
380 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
381 except ValidationError as e:
382 raise ParsingError(
383 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
384 )
385 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
386
387 async def update(
388 self,
389 id: str,
390 *,
391 request: UpdateEnabledClientConnectionsRequestContent,
392 request_options: typing.Optional[RequestOptions] = None,
393 ) -> AsyncHttpResponse[None]:
394 """
395 Parameters
396 ----------
397 id : str
398 The id of the connection to modify
399
400 request : UpdateEnabledClientConnectionsRequestContent
401
402 request_options : typing.Optional[RequestOptions]
403 Request-specific configuration.
404
405 Returns
406 -------
407 AsyncHttpResponse[None]
408 """
409 _response = await self._client_wrapper.httpx_client.request(
410 f"connections/{encode_path_param(id)}/clients",
411 method="PATCH",
412 json=convert_and_respect_annotation_metadata(
413 object_=request, annotation=UpdateEnabledClientConnectionsRequestContent, direction="write"
414 ),
415 request_options=request_options,
416 omit=OMIT,
417 )
418 try:
419 if 200 <= _response.status_code < 300:
420 return AsyncHttpResponse(response=_response, data=None)
421 if _response.status_code == 400:
422 raise BadRequestError(
423 headers=dict(_response.headers),
424 body=typing.cast(
425 typing.Any,
426 parse_obj_as(
427 type_=typing.Any, # type: ignore
428 object_=_response.json(),
429 ),
430 ),
431 )
432 if _response.status_code == 401:
433 raise UnauthorizedError(
434 headers=dict(_response.headers),
435 body=typing.cast(
436 typing.Any,
437 parse_obj_as(
438 type_=typing.Any, # type: ignore
439 object_=_response.json(),
440 ),
441 ),
442 )
443 if _response.status_code == 403:
444 raise ForbiddenError(
445 headers=dict(_response.headers),
446 body=typing.cast(
447 typing.Any,
448 parse_obj_as(
449 type_=typing.Any, # type: ignore
450 object_=_response.json(),
451 ),
452 ),
453 )
454 if _response.status_code == 404:
455 raise NotFoundError(
456 headers=dict(_response.headers),
457 body=typing.cast(
458 typing.Any,
459 parse_obj_as(
460 type_=typing.Any, # type: ignore
461 object_=_response.json(),
462 ),
463 ),
464 )
465 if _response.status_code == 429:
466 raise TooManyRequestsError(
467 headers=dict(_response.headers),
468 body=typing.cast(
469 typing.Any,
470 parse_obj_as(
471 type_=typing.Any, # type: ignore
472 object_=_response.json(),
473 ),
474 ),
475 )
476 _response_json = _response.json()
477 except JSONDecodeError:
478 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
479 except ValidationError as e:
480 raise ParsingError(
481 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
482 )
483 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)