Debian Codegraph @

src/auth0/management/keys/custom_signing/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.parse_error import ParsingError
10 from ...core.pydantic_utilities import parse_obj_as
11 from ...core.request_options import RequestOptions
12 from ...core.serialization import convert_and_respect_annotation_metadata
13 from ...errors.bad_request_error import BadRequestError
14 from ...errors.forbidden_error import ForbiddenError
15 from ...errors.not_found_error import NotFoundError
16 from ...errors.too_many_requests_error import TooManyRequestsError
17 from ...errors.unauthorized_error import UnauthorizedError
18 from ...types.custom_signing_key_jwk import CustomSigningKeyJwk
19 from ...types.get_custom_signing_keys_response_content import GetCustomSigningKeysResponseContent
20 from ...types.set_custom_signing_keys_response_content import SetCustomSigningKeysResponseContent
21 from pydantic import ValidationError
22
23 # this is used as the default value for optional parameters
24 OMIT = typing.cast(typing.Any, ...)
25
26
27 class RawCustomSigningClient:
28 def __init__(self, *, client_wrapper: SyncClientWrapper):
29 self._client_wrapper = client_wrapper
30
31 def get(
32 self, *, request_options: typing.Optional[RequestOptions] = None
33 ) -> HttpResponse[GetCustomSigningKeysResponseContent]:
34 """
35 Get entire jwks representation of custom signing keys.
36
37 Parameters
38 ----------
39 request_options : typing.Optional[RequestOptions]
40 Request-specific configuration.
41
42 Returns
43 -------
44 HttpResponse[GetCustomSigningKeysResponseContent]
45 Custom signing keys were successfully retrieved.
46 """
47 _response = self._client_wrapper.httpx_client.request(
48 "keys/custom-signing",
49 method="GET",
50 request_options=request_options,
51 )
52 try:
53 if 200 <= _response.status_code < 300:
54 _data = typing.cast(
55 GetCustomSigningKeysResponseContent,
56 parse_obj_as(
57 type_=GetCustomSigningKeysResponseContent, # type: ignore
58 object_=_response.json(),
59 ),
60 )
61 return HttpResponse(response=_response, data=_data)
62 if _response.status_code == 401:
63 raise UnauthorizedError(
64 headers=dict(_response.headers),
65 body=typing.cast(
66 typing.Any,
67 parse_obj_as(
68 type_=typing.Any, # type: ignore
69 object_=_response.json(),
70 ),
71 ),
72 )
73 if _response.status_code == 403:
74 raise ForbiddenError(
75 headers=dict(_response.headers),
76 body=typing.cast(
77 typing.Any,
78 parse_obj_as(
79 type_=typing.Any, # type: ignore
80 object_=_response.json(),
81 ),
82 ),
83 )
84 if _response.status_code == 404:
85 raise NotFoundError(
86 headers=dict(_response.headers),
87 body=typing.cast(
88 typing.Any,
89 parse_obj_as(
90 type_=typing.Any, # type: ignore
91 object_=_response.json(),
92 ),
93 ),
94 )
95 if _response.status_code == 429:
96 raise TooManyRequestsError(
97 headers=dict(_response.headers),
98 body=typing.cast(
99 typing.Any,
100 parse_obj_as(
101 type_=typing.Any, # type: ignore
102 object_=_response.json(),
103 ),
104 ),
105 )
106 _response_json = _response.json()
107 except JSONDecodeError:
108 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
109 except ValidationError as e:
110 raise ParsingError(
111 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
112 )
113 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
114
115 def set(
116 self, *, keys: typing.Sequence[CustomSigningKeyJwk], request_options: typing.Optional[RequestOptions] = None
117 ) -> HttpResponse[SetCustomSigningKeysResponseContent]:
118 """
119 Create or replace entire jwks representation of custom signing keys.
120
121 Parameters
122 ----------
123 keys : typing.Sequence[CustomSigningKeyJwk]
124 An array of custom public signing keys.
125
126 request_options : typing.Optional[RequestOptions]
127 Request-specific configuration.
128
129 Returns
130 -------
131 HttpResponse[SetCustomSigningKeysResponseContent]
132 Custom signing keys were successfully created or replaced.
133 """
134 _response = self._client_wrapper.httpx_client.request(
135 "keys/custom-signing",
136 method="PUT",
137 json={
138 "keys": convert_and_respect_annotation_metadata(
139 object_=keys, annotation=typing.Sequence[CustomSigningKeyJwk], direction="write"
140 ),
141 },
142 headers={
143 "content-type": "application/json",
144 },
145 request_options=request_options,
146 omit=OMIT,
147 )
148 try:
149 if 200 <= _response.status_code < 300:
150 _data = typing.cast(
151 SetCustomSigningKeysResponseContent,
152 parse_obj_as(
153 type_=SetCustomSigningKeysResponseContent, # type: ignore
154 object_=_response.json(),
155 ),
156 )
157 return HttpResponse(response=_response, data=_data)
158 if _response.status_code == 400:
159 raise BadRequestError(
160 headers=dict(_response.headers),
161 body=typing.cast(
162 typing.Any,
163 parse_obj_as(
164 type_=typing.Any, # type: ignore
165 object_=_response.json(),
166 ),
167 ),
168 )
169 if _response.status_code == 401:
170 raise UnauthorizedError(
171 headers=dict(_response.headers),
172 body=typing.cast(
173 typing.Any,
174 parse_obj_as(
175 type_=typing.Any, # type: ignore
176 object_=_response.json(),
177 ),
178 ),
179 )
180 if _response.status_code == 403:
181 raise ForbiddenError(
182 headers=dict(_response.headers),
183 body=typing.cast(
184 typing.Any,
185 parse_obj_as(
186 type_=typing.Any, # type: ignore
187 object_=_response.json(),
188 ),
189 ),
190 )
191 if _response.status_code == 429:
192 raise TooManyRequestsError(
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 _response_json = _response.json()
203 except JSONDecodeError:
204 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
205 except ValidationError as e:
206 raise ParsingError(
207 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
208 )
209 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
210
211 def delete(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
212 """
213 Delete entire jwks representation of custom signing keys.
214
215 Parameters
216 ----------
217 request_options : typing.Optional[RequestOptions]
218 Request-specific configuration.
219
220 Returns
221 -------
222 HttpResponse[None]
223 """
224 _response = self._client_wrapper.httpx_client.request(
225 "keys/custom-signing",
226 method="DELETE",
227 request_options=request_options,
228 )
229 try:
230 if 200 <= _response.status_code < 300:
231 return HttpResponse(response=_response, data=None)
232 if _response.status_code == 401:
233 raise UnauthorizedError(
234 headers=dict(_response.headers),
235 body=typing.cast(
236 typing.Any,
237 parse_obj_as(
238 type_=typing.Any, # type: ignore
239 object_=_response.json(),
240 ),
241 ),
242 )
243 if _response.status_code == 403:
244 raise ForbiddenError(
245 headers=dict(_response.headers),
246 body=typing.cast(
247 typing.Any,
248 parse_obj_as(
249 type_=typing.Any, # type: ignore
250 object_=_response.json(),
251 ),
252 ),
253 )
254 if _response.status_code == 429:
255 raise TooManyRequestsError(
256 headers=dict(_response.headers),
257 body=typing.cast(
258 typing.Any,
259 parse_obj_as(
260 type_=typing.Any, # type: ignore
261 object_=_response.json(),
262 ),
263 ),
264 )
265 _response_json = _response.json()
266 except JSONDecodeError:
267 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
268 except ValidationError as e:
269 raise ParsingError(
270 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
271 )
272 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
273
274
275 class AsyncRawCustomSigningClient:
276 def __init__(self, *, client_wrapper: AsyncClientWrapper):
277 self._client_wrapper = client_wrapper
278
279 async def get(
280 self, *, request_options: typing.Optional[RequestOptions] = None
281 ) -> AsyncHttpResponse[GetCustomSigningKeysResponseContent]:
282 """
283 Get entire jwks representation of custom signing keys.
284
285 Parameters
286 ----------
287 request_options : typing.Optional[RequestOptions]
288 Request-specific configuration.
289
290 Returns
291 -------
292 AsyncHttpResponse[GetCustomSigningKeysResponseContent]
293 Custom signing keys were successfully retrieved.
294 """
295 _response = await self._client_wrapper.httpx_client.request(
296 "keys/custom-signing",
297 method="GET",
298 request_options=request_options,
299 )
300 try:
301 if 200 <= _response.status_code < 300:
302 _data = typing.cast(
303 GetCustomSigningKeysResponseContent,
304 parse_obj_as(
305 type_=GetCustomSigningKeysResponseContent, # type: ignore
306 object_=_response.json(),
307 ),
308 )
309 return AsyncHttpResponse(response=_response, data=_data)
310 if _response.status_code == 401:
311 raise UnauthorizedError(
312 headers=dict(_response.headers),
313 body=typing.cast(
314 typing.Any,
315 parse_obj_as(
316 type_=typing.Any, # type: ignore
317 object_=_response.json(),
318 ),
319 ),
320 )
321 if _response.status_code == 403:
322 raise ForbiddenError(
323 headers=dict(_response.headers),
324 body=typing.cast(
325 typing.Any,
326 parse_obj_as(
327 type_=typing.Any, # type: ignore
328 object_=_response.json(),
329 ),
330 ),
331 )
332 if _response.status_code == 404:
333 raise NotFoundError(
334 headers=dict(_response.headers),
335 body=typing.cast(
336 typing.Any,
337 parse_obj_as(
338 type_=typing.Any, # type: ignore
339 object_=_response.json(),
340 ),
341 ),
342 )
343 if _response.status_code == 429:
344 raise TooManyRequestsError(
345 headers=dict(_response.headers),
346 body=typing.cast(
347 typing.Any,
348 parse_obj_as(
349 type_=typing.Any, # type: ignore
350 object_=_response.json(),
351 ),
352 ),
353 )
354 _response_json = _response.json()
355 except JSONDecodeError:
356 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
357 except ValidationError as e:
358 raise ParsingError(
359 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
360 )
361 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
362
363 async def set(
364 self, *, keys: typing.Sequence[CustomSigningKeyJwk], request_options: typing.Optional[RequestOptions] = None
365 ) -> AsyncHttpResponse[SetCustomSigningKeysResponseContent]:
366 """
367 Create or replace entire jwks representation of custom signing keys.
368
369 Parameters
370 ----------
371 keys : typing.Sequence[CustomSigningKeyJwk]
372 An array of custom public signing keys.
373
374 request_options : typing.Optional[RequestOptions]
375 Request-specific configuration.
376
377 Returns
378 -------
379 AsyncHttpResponse[SetCustomSigningKeysResponseContent]
380 Custom signing keys were successfully created or replaced.
381 """
382 _response = await self._client_wrapper.httpx_client.request(
383 "keys/custom-signing",
384 method="PUT",
385 json={
386 "keys": convert_and_respect_annotation_metadata(
387 object_=keys, annotation=typing.Sequence[CustomSigningKeyJwk], direction="write"
388 ),
389 },
390 headers={
391 "content-type": "application/json",
392 },
393 request_options=request_options,
394 omit=OMIT,
395 )
396 try:
397 if 200 <= _response.status_code < 300:
398 _data = typing.cast(
399 SetCustomSigningKeysResponseContent,
400 parse_obj_as(
401 type_=SetCustomSigningKeysResponseContent, # type: ignore
402 object_=_response.json(),
403 ),
404 )
405 return AsyncHttpResponse(response=_response, data=_data)
406 if _response.status_code == 400:
407 raise BadRequestError(
408 headers=dict(_response.headers),
409 body=typing.cast(
410 typing.Any,
411 parse_obj_as(
412 type_=typing.Any, # type: ignore
413 object_=_response.json(),
414 ),
415 ),
416 )
417 if _response.status_code == 401:
418 raise UnauthorizedError(
419 headers=dict(_response.headers),
420 body=typing.cast(
421 typing.Any,
422 parse_obj_as(
423 type_=typing.Any, # type: ignore
424 object_=_response.json(),
425 ),
426 ),
427 )
428 if _response.status_code == 403:
429 raise ForbiddenError(
430 headers=dict(_response.headers),
431 body=typing.cast(
432 typing.Any,
433 parse_obj_as(
434 type_=typing.Any, # type: ignore
435 object_=_response.json(),
436 ),
437 ),
438 )
439 if _response.status_code == 429:
440 raise TooManyRequestsError(
441 headers=dict(_response.headers),
442 body=typing.cast(
443 typing.Any,
444 parse_obj_as(
445 type_=typing.Any, # type: ignore
446 object_=_response.json(),
447 ),
448 ),
449 )
450 _response_json = _response.json()
451 except JSONDecodeError:
452 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
453 except ValidationError as e:
454 raise ParsingError(
455 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
456 )
457 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
458
459 async def delete(self, *, request_options: typing.Optional[RequestOptions] = None) -> AsyncHttpResponse[None]:
460 """
461 Delete entire jwks representation of custom signing keys.
462
463 Parameters
464 ----------
465 request_options : typing.Optional[RequestOptions]
466 Request-specific configuration.
467
468 Returns
469 -------
470 AsyncHttpResponse[None]
471 """
472 _response = await self._client_wrapper.httpx_client.request(
473 "keys/custom-signing",
474 method="DELETE",
475 request_options=request_options,
476 )
477 try:
478 if 200 <= _response.status_code < 300:
479 return AsyncHttpResponse(response=_response, data=None)
480 if _response.status_code == 401:
481 raise UnauthorizedError(
482 headers=dict(_response.headers),
483 body=typing.cast(
484 typing.Any,
485 parse_obj_as(
486 type_=typing.Any, # type: ignore
487 object_=_response.json(),
488 ),
489 ),
490 )
491 if _response.status_code == 403:
492 raise ForbiddenError(
493 headers=dict(_response.headers),
494 body=typing.cast(
495 typing.Any,
496 parse_obj_as(
497 type_=typing.Any, # type: ignore
498 object_=_response.json(),
499 ),
500 ),
501 )
502 if _response.status_code == 429:
503 raise TooManyRequestsError(
504 headers=dict(_response.headers),
505 body=typing.cast(
506 typing.Any,
507 parse_obj_as(
508 type_=typing.Any, # type: ignore
509 object_=_response.json(),
510 ),
511 ),
512 )
513 _response_json = _response.json()
514 except JSONDecodeError:
515 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
516 except ValidationError as e:
517 raise ParsingError(
518 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
519 )
520 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)