Debian Codegraph @

src/auth0/management/keys/encryption/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.conflict_error import ConflictError
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.create_encryption_key_public_wrapping_response_content import (
21 CreateEncryptionKeyPublicWrappingResponseContent,
22 )
23 from ...types.create_encryption_key_response_content import CreateEncryptionKeyResponseContent
24 from ...types.create_encryption_key_type import CreateEncryptionKeyType
25 from ...types.encryption_key import EncryptionKey
26 from ...types.get_encryption_key_response_content import GetEncryptionKeyResponseContent
27 from ...types.import_encryption_key_response_content import ImportEncryptionKeyResponseContent
28 from ...types.list_encryption_key_offset_paginated_response_content import (
29 ListEncryptionKeyOffsetPaginatedResponseContent,
30 )
31 from pydantic import ValidationError
32
33 # this is used as the default value for optional parameters
34 OMIT = typing.cast(typing.Any, ...)
35
36
37 class RawEncryptionClient:
38 def __init__(self, *, client_wrapper: SyncClientWrapper):
39 self._client_wrapper = client_wrapper
40
41 def list(
42 self,
43 *,
44 page: typing.Optional[int] = 0,
45 per_page: typing.Optional[int] = 50,
46 include_totals: typing.Optional[bool] = True,
47 request_options: typing.Optional[RequestOptions] = None,
48 ) -> SyncPager[EncryptionKey, ListEncryptionKeyOffsetPaginatedResponseContent]:
49 """
50 Retrieve details of all the encryption keys associated with your tenant.
51
52 Parameters
53 ----------
54 page : typing.Optional[int]
55 Page index of the results to return. First page is 0.
56
57 per_page : typing.Optional[int]
58 Number of results per page. Default value is 50, maximum value is 100.
59
60 include_totals : typing.Optional[bool]
61 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
62
63 request_options : typing.Optional[RequestOptions]
64 Request-specific configuration.
65
66 Returns
67 -------
68 SyncPager[EncryptionKey, ListEncryptionKeyOffsetPaginatedResponseContent]
69 The keys were successfully retrieved.
70 """
71 page = page if page is not None else 0
72
73 _response = self._client_wrapper.httpx_client.request(
74 "keys/encryption",
75 method="GET",
76 params={
77 "page": page,
78 "per_page": per_page,
79 "include_totals": include_totals,
80 },
81 request_options=request_options,
82 )
83 try:
84 if 200 <= _response.status_code < 300:
85 _parsed_response = typing.cast(
86 ListEncryptionKeyOffsetPaginatedResponseContent,
87 parse_obj_as(
88 type_=ListEncryptionKeyOffsetPaginatedResponseContent, # type: ignore
89 object_=_response.json(),
90 ),
91 )
92 _items = _parsed_response.keys
93 _has_next = len(_items or []) > 0
94 _get_next = lambda: self.list(
95 page=page + 1,
96 per_page=per_page,
97 include_totals=include_totals,
98 request_options=request_options,
99 )
100 return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
101 if _response.status_code == 400:
102 raise BadRequestError(
103 headers=dict(_response.headers),
104 body=typing.cast(
105 typing.Any,
106 parse_obj_as(
107 type_=typing.Any, # type: ignore
108 object_=_response.json(),
109 ),
110 ),
111 )
112 if _response.status_code == 401:
113 raise UnauthorizedError(
114 headers=dict(_response.headers),
115 body=typing.cast(
116 typing.Any,
117 parse_obj_as(
118 type_=typing.Any, # type: ignore
119 object_=_response.json(),
120 ),
121 ),
122 )
123 if _response.status_code == 403:
124 raise ForbiddenError(
125 headers=dict(_response.headers),
126 body=typing.cast(
127 typing.Any,
128 parse_obj_as(
129 type_=typing.Any, # type: ignore
130 object_=_response.json(),
131 ),
132 ),
133 )
134 if _response.status_code == 429:
135 raise TooManyRequestsError(
136 headers=dict(_response.headers),
137 body=typing.cast(
138 typing.Any,
139 parse_obj_as(
140 type_=typing.Any, # type: ignore
141 object_=_response.json(),
142 ),
143 ),
144 )
145 _response_json = _response.json()
146 except JSONDecodeError:
147 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
148 except ValidationError as e:
149 raise ParsingError(
150 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
151 )
152 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
153
154 def create(
155 self, *, type: CreateEncryptionKeyType, request_options: typing.Optional[RequestOptions] = None
156 ) -> HttpResponse[CreateEncryptionKeyResponseContent]:
157 """
158 Create the new, pre-activated encryption key, without the key material.
159
160 Parameters
161 ----------
162 type : CreateEncryptionKeyType
163
164 request_options : typing.Optional[RequestOptions]
165 Request-specific configuration.
166
167 Returns
168 -------
169 HttpResponse[CreateEncryptionKeyResponseContent]
170 The key was successfully created.
171 """
172 _response = self._client_wrapper.httpx_client.request(
173 "keys/encryption",
174 method="POST",
175 json={
176 "type": type,
177 },
178 headers={
179 "content-type": "application/json",
180 },
181 request_options=request_options,
182 omit=OMIT,
183 )
184 try:
185 if 200 <= _response.status_code < 300:
186 _data = typing.cast(
187 CreateEncryptionKeyResponseContent,
188 parse_obj_as(
189 type_=CreateEncryptionKeyResponseContent, # type: ignore
190 object_=_response.json(),
191 ),
192 )
193 return HttpResponse(response=_response, data=_data)
194 if _response.status_code == 400:
195 raise BadRequestError(
196 headers=dict(_response.headers),
197 body=typing.cast(
198 typing.Any,
199 parse_obj_as(
200 type_=typing.Any, # type: ignore
201 object_=_response.json(),
202 ),
203 ),
204 )
205 if _response.status_code == 401:
206 raise UnauthorizedError(
207 headers=dict(_response.headers),
208 body=typing.cast(
209 typing.Any,
210 parse_obj_as(
211 type_=typing.Any, # type: ignore
212 object_=_response.json(),
213 ),
214 ),
215 )
216 if _response.status_code == 403:
217 raise ForbiddenError(
218 headers=dict(_response.headers),
219 body=typing.cast(
220 typing.Any,
221 parse_obj_as(
222 type_=typing.Any, # type: ignore
223 object_=_response.json(),
224 ),
225 ),
226 )
227 if _response.status_code == 409:
228 raise ConflictError(
229 headers=dict(_response.headers),
230 body=typing.cast(
231 typing.Any,
232 parse_obj_as(
233 type_=typing.Any, # type: ignore
234 object_=_response.json(),
235 ),
236 ),
237 )
238 if _response.status_code == 429:
239 raise TooManyRequestsError(
240 headers=dict(_response.headers),
241 body=typing.cast(
242 typing.Any,
243 parse_obj_as(
244 type_=typing.Any, # type: ignore
245 object_=_response.json(),
246 ),
247 ),
248 )
249 _response_json = _response.json()
250 except JSONDecodeError:
251 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
252 except ValidationError as e:
253 raise ParsingError(
254 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
255 )
256 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
257
258 def rekey(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
259 """
260 Perform rekeying operation on the key hierarchy.
261
262 Parameters
263 ----------
264 request_options : typing.Optional[RequestOptions]
265 Request-specific configuration.
266
267 Returns
268 -------
269 HttpResponse[None]
270 """
271 _response = self._client_wrapper.httpx_client.request(
272 "keys/encryption/rekey",
273 method="POST",
274 request_options=request_options,
275 )
276 try:
277 if 200 <= _response.status_code < 300:
278 return HttpResponse(response=_response, data=None)
279 if _response.status_code == 401:
280 raise UnauthorizedError(
281 headers=dict(_response.headers),
282 body=typing.cast(
283 typing.Any,
284 parse_obj_as(
285 type_=typing.Any, # type: ignore
286 object_=_response.json(),
287 ),
288 ),
289 )
290 if _response.status_code == 403:
291 raise ForbiddenError(
292 headers=dict(_response.headers),
293 body=typing.cast(
294 typing.Any,
295 parse_obj_as(
296 type_=typing.Any, # type: ignore
297 object_=_response.json(),
298 ),
299 ),
300 )
301 if _response.status_code == 429:
302 raise TooManyRequestsError(
303 headers=dict(_response.headers),
304 body=typing.cast(
305 typing.Any,
306 parse_obj_as(
307 type_=typing.Any, # type: ignore
308 object_=_response.json(),
309 ),
310 ),
311 )
312 _response_json = _response.json()
313 except JSONDecodeError:
314 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
315 except ValidationError as e:
316 raise ParsingError(
317 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
318 )
319 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
320
321 def get(
322 self, kid: str, *, request_options: typing.Optional[RequestOptions] = None
323 ) -> HttpResponse[GetEncryptionKeyResponseContent]:
324 """
325 Retrieve details of the encryption key with the given ID.
326
327 Parameters
328 ----------
329 kid : str
330 Encryption key ID
331
332 request_options : typing.Optional[RequestOptions]
333 Request-specific configuration.
334
335 Returns
336 -------
337 HttpResponse[GetEncryptionKeyResponseContent]
338 The key was successfully retrieved.
339 """
340 _response = self._client_wrapper.httpx_client.request(
341 f"keys/encryption/{encode_path_param(kid)}",
342 method="GET",
343 request_options=request_options,
344 )
345 try:
346 if 200 <= _response.status_code < 300:
347 _data = typing.cast(
348 GetEncryptionKeyResponseContent,
349 parse_obj_as(
350 type_=GetEncryptionKeyResponseContent, # type: ignore
351 object_=_response.json(),
352 ),
353 )
354 return HttpResponse(response=_response, data=_data)
355 if _response.status_code == 400:
356 raise BadRequestError(
357 headers=dict(_response.headers),
358 body=typing.cast(
359 typing.Any,
360 parse_obj_as(
361 type_=typing.Any, # type: ignore
362 object_=_response.json(),
363 ),
364 ),
365 )
366 if _response.status_code == 401:
367 raise UnauthorizedError(
368 headers=dict(_response.headers),
369 body=typing.cast(
370 typing.Any,
371 parse_obj_as(
372 type_=typing.Any, # type: ignore
373 object_=_response.json(),
374 ),
375 ),
376 )
377 if _response.status_code == 403:
378 raise ForbiddenError(
379 headers=dict(_response.headers),
380 body=typing.cast(
381 typing.Any,
382 parse_obj_as(
383 type_=typing.Any, # type: ignore
384 object_=_response.json(),
385 ),
386 ),
387 )
388 if _response.status_code == 404:
389 raise NotFoundError(
390 headers=dict(_response.headers),
391 body=typing.cast(
392 typing.Any,
393 parse_obj_as(
394 type_=typing.Any, # type: ignore
395 object_=_response.json(),
396 ),
397 ),
398 )
399 if _response.status_code == 429:
400 raise TooManyRequestsError(
401 headers=dict(_response.headers),
402 body=typing.cast(
403 typing.Any,
404 parse_obj_as(
405 type_=typing.Any, # type: ignore
406 object_=_response.json(),
407 ),
408 ),
409 )
410 _response_json = _response.json()
411 except JSONDecodeError:
412 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
413 except ValidationError as e:
414 raise ParsingError(
415 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
416 )
417 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
418
419 def import_(
420 self, kid: str, *, wrapped_key: str, request_options: typing.Optional[RequestOptions] = None
421 ) -> HttpResponse[ImportEncryptionKeyResponseContent]:
422 """
423 Import wrapped key material and activate encryption key.
424
425 Parameters
426 ----------
427 kid : str
428 Encryption key ID
429
430 wrapped_key : str
431 Base64 encoded ciphertext of key material wrapped by public wrapping key.
432
433 request_options : typing.Optional[RequestOptions]
434 Request-specific configuration.
435
436 Returns
437 -------
438 HttpResponse[ImportEncryptionKeyResponseContent]
439 The key was successfully imported.
440 """
441 _response = self._client_wrapper.httpx_client.request(
442 f"keys/encryption/{encode_path_param(kid)}",
443 method="POST",
444 json={
445 "wrapped_key": wrapped_key,
446 },
447 headers={
448 "content-type": "application/json",
449 },
450 request_options=request_options,
451 omit=OMIT,
452 )
453 try:
454 if 200 <= _response.status_code < 300:
455 _data = typing.cast(
456 ImportEncryptionKeyResponseContent,
457 parse_obj_as(
458 type_=ImportEncryptionKeyResponseContent, # type: ignore
459 object_=_response.json(),
460 ),
461 )
462 return HttpResponse(response=_response, data=_data)
463 if _response.status_code == 400:
464 raise BadRequestError(
465 headers=dict(_response.headers),
466 body=typing.cast(
467 typing.Any,
468 parse_obj_as(
469 type_=typing.Any, # type: ignore
470 object_=_response.json(),
471 ),
472 ),
473 )
474 if _response.status_code == 401:
475 raise UnauthorizedError(
476 headers=dict(_response.headers),
477 body=typing.cast(
478 typing.Any,
479 parse_obj_as(
480 type_=typing.Any, # type: ignore
481 object_=_response.json(),
482 ),
483 ),
484 )
485 if _response.status_code == 403:
486 raise ForbiddenError(
487 headers=dict(_response.headers),
488 body=typing.cast(
489 typing.Any,
490 parse_obj_as(
491 type_=typing.Any, # type: ignore
492 object_=_response.json(),
493 ),
494 ),
495 )
496 if _response.status_code == 409:
497 raise ConflictError(
498 headers=dict(_response.headers),
499 body=typing.cast(
500 typing.Any,
501 parse_obj_as(
502 type_=typing.Any, # type: ignore
503 object_=_response.json(),
504 ),
505 ),
506 )
507 if _response.status_code == 429:
508 raise TooManyRequestsError(
509 headers=dict(_response.headers),
510 body=typing.cast(
511 typing.Any,
512 parse_obj_as(
513 type_=typing.Any, # type: ignore
514 object_=_response.json(),
515 ),
516 ),
517 )
518 _response_json = _response.json()
519 except JSONDecodeError:
520 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
521 except ValidationError as e:
522 raise ParsingError(
523 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
524 )
525 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
526
527 def delete(self, kid: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
528 """
529 Delete the custom provided encryption key with the given ID and move back to using native encryption key.
530
531 Parameters
532 ----------
533 kid : str
534 Encryption key ID
535
536 request_options : typing.Optional[RequestOptions]
537 Request-specific configuration.
538
539 Returns
540 -------
541 HttpResponse[None]
542 """
543 _response = self._client_wrapper.httpx_client.request(
544 f"keys/encryption/{encode_path_param(kid)}",
545 method="DELETE",
546 request_options=request_options,
547 )
548 try:
549 if 200 <= _response.status_code < 300:
550 return HttpResponse(response=_response, data=None)
551 if _response.status_code == 400:
552 raise BadRequestError(
553 headers=dict(_response.headers),
554 body=typing.cast(
555 typing.Any,
556 parse_obj_as(
557 type_=typing.Any, # type: ignore
558 object_=_response.json(),
559 ),
560 ),
561 )
562 if _response.status_code == 401:
563 raise UnauthorizedError(
564 headers=dict(_response.headers),
565 body=typing.cast(
566 typing.Any,
567 parse_obj_as(
568 type_=typing.Any, # type: ignore
569 object_=_response.json(),
570 ),
571 ),
572 )
573 if _response.status_code == 403:
574 raise ForbiddenError(
575 headers=dict(_response.headers),
576 body=typing.cast(
577 typing.Any,
578 parse_obj_as(
579 type_=typing.Any, # type: ignore
580 object_=_response.json(),
581 ),
582 ),
583 )
584 if _response.status_code == 429:
585 raise TooManyRequestsError(
586 headers=dict(_response.headers),
587 body=typing.cast(
588 typing.Any,
589 parse_obj_as(
590 type_=typing.Any, # type: ignore
591 object_=_response.json(),
592 ),
593 ),
594 )
595 _response_json = _response.json()
596 except JSONDecodeError:
597 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
598 except ValidationError as e:
599 raise ParsingError(
600 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
601 )
602 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
603
604 def create_public_wrapping_key(
605 self, kid: str, *, request_options: typing.Optional[RequestOptions] = None
606 ) -> HttpResponse[CreateEncryptionKeyPublicWrappingResponseContent]:
607 """
608 Create the public wrapping key to wrap your own encryption key material.
609
610 Parameters
611 ----------
612 kid : str
613 Encryption key ID
614
615 request_options : typing.Optional[RequestOptions]
616 Request-specific configuration.
617
618 Returns
619 -------
620 HttpResponse[CreateEncryptionKeyPublicWrappingResponseContent]
621 The public wrapping key was successfully created.
622 """
623 _response = self._client_wrapper.httpx_client.request(
624 f"keys/encryption/{encode_path_param(kid)}/wrapping-key",
625 method="POST",
626 request_options=request_options,
627 )
628 try:
629 if 200 <= _response.status_code < 300:
630 _data = typing.cast(
631 CreateEncryptionKeyPublicWrappingResponseContent,
632 parse_obj_as(
633 type_=CreateEncryptionKeyPublicWrappingResponseContent, # type: ignore
634 object_=_response.json(),
635 ),
636 )
637 return HttpResponse(response=_response, data=_data)
638 if _response.status_code == 400:
639 raise BadRequestError(
640 headers=dict(_response.headers),
641 body=typing.cast(
642 typing.Any,
643 parse_obj_as(
644 type_=typing.Any, # type: ignore
645 object_=_response.json(),
646 ),
647 ),
648 )
649 if _response.status_code == 401:
650 raise UnauthorizedError(
651 headers=dict(_response.headers),
652 body=typing.cast(
653 typing.Any,
654 parse_obj_as(
655 type_=typing.Any, # type: ignore
656 object_=_response.json(),
657 ),
658 ),
659 )
660 if _response.status_code == 403:
661 raise ForbiddenError(
662 headers=dict(_response.headers),
663 body=typing.cast(
664 typing.Any,
665 parse_obj_as(
666 type_=typing.Any, # type: ignore
667 object_=_response.json(),
668 ),
669 ),
670 )
671 if _response.status_code == 409:
672 raise ConflictError(
673 headers=dict(_response.headers),
674 body=typing.cast(
675 typing.Any,
676 parse_obj_as(
677 type_=typing.Any, # type: ignore
678 object_=_response.json(),
679 ),
680 ),
681 )
682 if _response.status_code == 429:
683 raise TooManyRequestsError(
684 headers=dict(_response.headers),
685 body=typing.cast(
686 typing.Any,
687 parse_obj_as(
688 type_=typing.Any, # type: ignore
689 object_=_response.json(),
690 ),
691 ),
692 )
693 _response_json = _response.json()
694 except JSONDecodeError:
695 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
696 except ValidationError as e:
697 raise ParsingError(
698 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
699 )
700 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
701
702
703 class AsyncRawEncryptionClient:
704 def __init__(self, *, client_wrapper: AsyncClientWrapper):
705 self._client_wrapper = client_wrapper
706
707 async def list(
708 self,
709 *,
710 page: typing.Optional[int] = 0,
711 per_page: typing.Optional[int] = 50,
712 include_totals: typing.Optional[bool] = True,
713 request_options: typing.Optional[RequestOptions] = None,
714 ) -> AsyncPager[EncryptionKey, ListEncryptionKeyOffsetPaginatedResponseContent]:
715 """
716 Retrieve details of all the encryption keys associated with your tenant.
717
718 Parameters
719 ----------
720 page : typing.Optional[int]
721 Page index of the results to return. First page is 0.
722
723 per_page : typing.Optional[int]
724 Number of results per page. Default value is 50, maximum value is 100.
725
726 include_totals : typing.Optional[bool]
727 Return results inside an object that contains the total result count (true) or as a direct array of results (false, default).
728
729 request_options : typing.Optional[RequestOptions]
730 Request-specific configuration.
731
732 Returns
733 -------
734 AsyncPager[EncryptionKey, ListEncryptionKeyOffsetPaginatedResponseContent]
735 The keys were successfully retrieved.
736 """
737 page = page if page is not None else 0
738
739 _response = await self._client_wrapper.httpx_client.request(
740 "keys/encryption",
741 method="GET",
742 params={
743 "page": page,
744 "per_page": per_page,
745 "include_totals": include_totals,
746 },
747 request_options=request_options,
748 )
749 try:
750 if 200 <= _response.status_code < 300:
751 _parsed_response = typing.cast(
752 ListEncryptionKeyOffsetPaginatedResponseContent,
753 parse_obj_as(
754 type_=ListEncryptionKeyOffsetPaginatedResponseContent, # type: ignore
755 object_=_response.json(),
756 ),
757 )
758 _items = _parsed_response.keys
759 _has_next = len(_items or []) > 0
760
761 async def _get_next():
762 return await self.list(
763 page=page + 1,
764 per_page=per_page,
765 include_totals=include_totals,
766 request_options=request_options,
767 )
768
769 return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
770 if _response.status_code == 400:
771 raise BadRequestError(
772 headers=dict(_response.headers),
773 body=typing.cast(
774 typing.Any,
775 parse_obj_as(
776 type_=typing.Any, # type: ignore
777 object_=_response.json(),
778 ),
779 ),
780 )
781 if _response.status_code == 401:
782 raise UnauthorizedError(
783 headers=dict(_response.headers),
784 body=typing.cast(
785 typing.Any,
786 parse_obj_as(
787 type_=typing.Any, # type: ignore
788 object_=_response.json(),
789 ),
790 ),
791 )
792 if _response.status_code == 403:
793 raise ForbiddenError(
794 headers=dict(_response.headers),
795 body=typing.cast(
796 typing.Any,
797 parse_obj_as(
798 type_=typing.Any, # type: ignore
799 object_=_response.json(),
800 ),
801 ),
802 )
803 if _response.status_code == 429:
804 raise TooManyRequestsError(
805 headers=dict(_response.headers),
806 body=typing.cast(
807 typing.Any,
808 parse_obj_as(
809 type_=typing.Any, # type: ignore
810 object_=_response.json(),
811 ),
812 ),
813 )
814 _response_json = _response.json()
815 except JSONDecodeError:
816 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
817 except ValidationError as e:
818 raise ParsingError(
819 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
820 )
821 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
822
823 async def create(
824 self, *, type: CreateEncryptionKeyType, request_options: typing.Optional[RequestOptions] = None
825 ) -> AsyncHttpResponse[CreateEncryptionKeyResponseContent]:
826 """
827 Create the new, pre-activated encryption key, without the key material.
828
829 Parameters
830 ----------
831 type : CreateEncryptionKeyType
832
833 request_options : typing.Optional[RequestOptions]
834 Request-specific configuration.
835
836 Returns
837 -------
838 AsyncHttpResponse[CreateEncryptionKeyResponseContent]
839 The key was successfully created.
840 """
841 _response = await self._client_wrapper.httpx_client.request(
842 "keys/encryption",
843 method="POST",
844 json={
845 "type": type,
846 },
847 headers={
848 "content-type": "application/json",
849 },
850 request_options=request_options,
851 omit=OMIT,
852 )
853 try:
854 if 200 <= _response.status_code < 300:
855 _data = typing.cast(
856 CreateEncryptionKeyResponseContent,
857 parse_obj_as(
858 type_=CreateEncryptionKeyResponseContent, # type: ignore
859 object_=_response.json(),
860 ),
861 )
862 return AsyncHttpResponse(response=_response, data=_data)
863 if _response.status_code == 400:
864 raise BadRequestError(
865 headers=dict(_response.headers),
866 body=typing.cast(
867 typing.Any,
868 parse_obj_as(
869 type_=typing.Any, # type: ignore
870 object_=_response.json(),
871 ),
872 ),
873 )
874 if _response.status_code == 401:
875 raise UnauthorizedError(
876 headers=dict(_response.headers),
877 body=typing.cast(
878 typing.Any,
879 parse_obj_as(
880 type_=typing.Any, # type: ignore
881 object_=_response.json(),
882 ),
883 ),
884 )
885 if _response.status_code == 403:
886 raise ForbiddenError(
887 headers=dict(_response.headers),
888 body=typing.cast(
889 typing.Any,
890 parse_obj_as(
891 type_=typing.Any, # type: ignore
892 object_=_response.json(),
893 ),
894 ),
895 )
896 if _response.status_code == 409:
897 raise ConflictError(
898 headers=dict(_response.headers),
899 body=typing.cast(
900 typing.Any,
901 parse_obj_as(
902 type_=typing.Any, # type: ignore
903 object_=_response.json(),
904 ),
905 ),
906 )
907 if _response.status_code == 429:
908 raise TooManyRequestsError(
909 headers=dict(_response.headers),
910 body=typing.cast(
911 typing.Any,
912 parse_obj_as(
913 type_=typing.Any, # type: ignore
914 object_=_response.json(),
915 ),
916 ),
917 )
918 _response_json = _response.json()
919 except JSONDecodeError:
920 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
921 except ValidationError as e:
922 raise ParsingError(
923 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
924 )
925 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
926
927 async def rekey(self, *, request_options: typing.Optional[RequestOptions] = None) -> AsyncHttpResponse[None]:
928 """
929 Perform rekeying operation on the key hierarchy.
930
931 Parameters
932 ----------
933 request_options : typing.Optional[RequestOptions]
934 Request-specific configuration.
935
936 Returns
937 -------
938 AsyncHttpResponse[None]
939 """
940 _response = await self._client_wrapper.httpx_client.request(
941 "keys/encryption/rekey",
942 method="POST",
943 request_options=request_options,
944 )
945 try:
946 if 200 <= _response.status_code < 300:
947 return AsyncHttpResponse(response=_response, data=None)
948 if _response.status_code == 401:
949 raise UnauthorizedError(
950 headers=dict(_response.headers),
951 body=typing.cast(
952 typing.Any,
953 parse_obj_as(
954 type_=typing.Any, # type: ignore
955 object_=_response.json(),
956 ),
957 ),
958 )
959 if _response.status_code == 403:
960 raise ForbiddenError(
961 headers=dict(_response.headers),
962 body=typing.cast(
963 typing.Any,
964 parse_obj_as(
965 type_=typing.Any, # type: ignore
966 object_=_response.json(),
967 ),
968 ),
969 )
970 if _response.status_code == 429:
971 raise TooManyRequestsError(
972 headers=dict(_response.headers),
973 body=typing.cast(
974 typing.Any,
975 parse_obj_as(
976 type_=typing.Any, # type: ignore
977 object_=_response.json(),
978 ),
979 ),
980 )
981 _response_json = _response.json()
982 except JSONDecodeError:
983 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
984 except ValidationError as e:
985 raise ParsingError(
986 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
987 )
988 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
989
990 async def get(
991 self, kid: str, *, request_options: typing.Optional[RequestOptions] = None
992 ) -> AsyncHttpResponse[GetEncryptionKeyResponseContent]:
993 """
994 Retrieve details of the encryption key with the given ID.
995
996 Parameters
997 ----------
998 kid : str
999 Encryption key ID
1000
1001 request_options : typing.Optional[RequestOptions]
1002 Request-specific configuration.
1003
1004 Returns
1005 -------
1006 AsyncHttpResponse[GetEncryptionKeyResponseContent]
1007 The key was successfully retrieved.
1008 """
1009 _response = await self._client_wrapper.httpx_client.request(
1010 f"keys/encryption/{encode_path_param(kid)}",
1011 method="GET",
1012 request_options=request_options,
1013 )
1014 try:
1015 if 200 <= _response.status_code < 300:
1016 _data = typing.cast(
1017 GetEncryptionKeyResponseContent,
1018 parse_obj_as(
1019 type_=GetEncryptionKeyResponseContent, # type: ignore
1020 object_=_response.json(),
1021 ),
1022 )
1023 return AsyncHttpResponse(response=_response, data=_data)
1024 if _response.status_code == 400:
1025 raise BadRequestError(
1026 headers=dict(_response.headers),
1027 body=typing.cast(
1028 typing.Any,
1029 parse_obj_as(
1030 type_=typing.Any, # type: ignore
1031 object_=_response.json(),
1032 ),
1033 ),
1034 )
1035 if _response.status_code == 401:
1036 raise UnauthorizedError(
1037 headers=dict(_response.headers),
1038 body=typing.cast(
1039 typing.Any,
1040 parse_obj_as(
1041 type_=typing.Any, # type: ignore
1042 object_=_response.json(),
1043 ),
1044 ),
1045 )
1046 if _response.status_code == 403:
1047 raise ForbiddenError(
1048 headers=dict(_response.headers),
1049 body=typing.cast(
1050 typing.Any,
1051 parse_obj_as(
1052 type_=typing.Any, # type: ignore
1053 object_=_response.json(),
1054 ),
1055 ),
1056 )
1057 if _response.status_code == 404:
1058 raise NotFoundError(
1059 headers=dict(_response.headers),
1060 body=typing.cast(
1061 typing.Any,
1062 parse_obj_as(
1063 type_=typing.Any, # type: ignore
1064 object_=_response.json(),
1065 ),
1066 ),
1067 )
1068 if _response.status_code == 429:
1069 raise TooManyRequestsError(
1070 headers=dict(_response.headers),
1071 body=typing.cast(
1072 typing.Any,
1073 parse_obj_as(
1074 type_=typing.Any, # type: ignore
1075 object_=_response.json(),
1076 ),
1077 ),
1078 )
1079 _response_json = _response.json()
1080 except JSONDecodeError:
1081 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1082 except ValidationError as e:
1083 raise ParsingError(
1084 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1085 )
1086 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1087
1088 async def import_(
1089 self, kid: str, *, wrapped_key: str, request_options: typing.Optional[RequestOptions] = None
1090 ) -> AsyncHttpResponse[ImportEncryptionKeyResponseContent]:
1091 """
1092 Import wrapped key material and activate encryption key.
1093
1094 Parameters
1095 ----------
1096 kid : str
1097 Encryption key ID
1098
1099 wrapped_key : str
1100 Base64 encoded ciphertext of key material wrapped by public wrapping key.
1101
1102 request_options : typing.Optional[RequestOptions]
1103 Request-specific configuration.
1104
1105 Returns
1106 -------
1107 AsyncHttpResponse[ImportEncryptionKeyResponseContent]
1108 The key was successfully imported.
1109 """
1110 _response = await self._client_wrapper.httpx_client.request(
1111 f"keys/encryption/{encode_path_param(kid)}",
1112 method="POST",
1113 json={
1114 "wrapped_key": wrapped_key,
1115 },
1116 headers={
1117 "content-type": "application/json",
1118 },
1119 request_options=request_options,
1120 omit=OMIT,
1121 )
1122 try:
1123 if 200 <= _response.status_code < 300:
1124 _data = typing.cast(
1125 ImportEncryptionKeyResponseContent,
1126 parse_obj_as(
1127 type_=ImportEncryptionKeyResponseContent, # type: ignore
1128 object_=_response.json(),
1129 ),
1130 )
1131 return AsyncHttpResponse(response=_response, data=_data)
1132 if _response.status_code == 400:
1133 raise BadRequestError(
1134 headers=dict(_response.headers),
1135 body=typing.cast(
1136 typing.Any,
1137 parse_obj_as(
1138 type_=typing.Any, # type: ignore
1139 object_=_response.json(),
1140 ),
1141 ),
1142 )
1143 if _response.status_code == 401:
1144 raise UnauthorizedError(
1145 headers=dict(_response.headers),
1146 body=typing.cast(
1147 typing.Any,
1148 parse_obj_as(
1149 type_=typing.Any, # type: ignore
1150 object_=_response.json(),
1151 ),
1152 ),
1153 )
1154 if _response.status_code == 403:
1155 raise ForbiddenError(
1156 headers=dict(_response.headers),
1157 body=typing.cast(
1158 typing.Any,
1159 parse_obj_as(
1160 type_=typing.Any, # type: ignore
1161 object_=_response.json(),
1162 ),
1163 ),
1164 )
1165 if _response.status_code == 409:
1166 raise ConflictError(
1167 headers=dict(_response.headers),
1168 body=typing.cast(
1169 typing.Any,
1170 parse_obj_as(
1171 type_=typing.Any, # type: ignore
1172 object_=_response.json(),
1173 ),
1174 ),
1175 )
1176 if _response.status_code == 429:
1177 raise TooManyRequestsError(
1178 headers=dict(_response.headers),
1179 body=typing.cast(
1180 typing.Any,
1181 parse_obj_as(
1182 type_=typing.Any, # type: ignore
1183 object_=_response.json(),
1184 ),
1185 ),
1186 )
1187 _response_json = _response.json()
1188 except JSONDecodeError:
1189 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1190 except ValidationError as e:
1191 raise ParsingError(
1192 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1193 )
1194 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1195
1196 async def delete(
1197 self, kid: str, *, request_options: typing.Optional[RequestOptions] = None
1198 ) -> AsyncHttpResponse[None]:
1199 """
1200 Delete the custom provided encryption key with the given ID and move back to using native encryption key.
1201
1202 Parameters
1203 ----------
1204 kid : str
1205 Encryption key ID
1206
1207 request_options : typing.Optional[RequestOptions]
1208 Request-specific configuration.
1209
1210 Returns
1211 -------
1212 AsyncHttpResponse[None]
1213 """
1214 _response = await self._client_wrapper.httpx_client.request(
1215 f"keys/encryption/{encode_path_param(kid)}",
1216 method="DELETE",
1217 request_options=request_options,
1218 )
1219 try:
1220 if 200 <= _response.status_code < 300:
1221 return AsyncHttpResponse(response=_response, data=None)
1222 if _response.status_code == 400:
1223 raise BadRequestError(
1224 headers=dict(_response.headers),
1225 body=typing.cast(
1226 typing.Any,
1227 parse_obj_as(
1228 type_=typing.Any, # type: ignore
1229 object_=_response.json(),
1230 ),
1231 ),
1232 )
1233 if _response.status_code == 401:
1234 raise UnauthorizedError(
1235 headers=dict(_response.headers),
1236 body=typing.cast(
1237 typing.Any,
1238 parse_obj_as(
1239 type_=typing.Any, # type: ignore
1240 object_=_response.json(),
1241 ),
1242 ),
1243 )
1244 if _response.status_code == 403:
1245 raise ForbiddenError(
1246 headers=dict(_response.headers),
1247 body=typing.cast(
1248 typing.Any,
1249 parse_obj_as(
1250 type_=typing.Any, # type: ignore
1251 object_=_response.json(),
1252 ),
1253 ),
1254 )
1255 if _response.status_code == 429:
1256 raise TooManyRequestsError(
1257 headers=dict(_response.headers),
1258 body=typing.cast(
1259 typing.Any,
1260 parse_obj_as(
1261 type_=typing.Any, # type: ignore
1262 object_=_response.json(),
1263 ),
1264 ),
1265 )
1266 _response_json = _response.json()
1267 except JSONDecodeError:
1268 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1269 except ValidationError as e:
1270 raise ParsingError(
1271 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1272 )
1273 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1274
1275 async def create_public_wrapping_key(
1276 self, kid: str, *, request_options: typing.Optional[RequestOptions] = None
1277 ) -> AsyncHttpResponse[CreateEncryptionKeyPublicWrappingResponseContent]:
1278 """
1279 Create the public wrapping key to wrap your own encryption key material.
1280
1281 Parameters
1282 ----------
1283 kid : str
1284 Encryption key ID
1285
1286 request_options : typing.Optional[RequestOptions]
1287 Request-specific configuration.
1288
1289 Returns
1290 -------
1291 AsyncHttpResponse[CreateEncryptionKeyPublicWrappingResponseContent]
1292 The public wrapping key was successfully created.
1293 """
1294 _response = await self._client_wrapper.httpx_client.request(
1295 f"keys/encryption/{encode_path_param(kid)}/wrapping-key",
1296 method="POST",
1297 request_options=request_options,
1298 )
1299 try:
1300 if 200 <= _response.status_code < 300:
1301 _data = typing.cast(
1302 CreateEncryptionKeyPublicWrappingResponseContent,
1303 parse_obj_as(
1304 type_=CreateEncryptionKeyPublicWrappingResponseContent, # type: ignore
1305 object_=_response.json(),
1306 ),
1307 )
1308 return AsyncHttpResponse(response=_response, data=_data)
1309 if _response.status_code == 400:
1310 raise BadRequestError(
1311 headers=dict(_response.headers),
1312 body=typing.cast(
1313 typing.Any,
1314 parse_obj_as(
1315 type_=typing.Any, # type: ignore
1316 object_=_response.json(),
1317 ),
1318 ),
1319 )
1320 if _response.status_code == 401:
1321 raise UnauthorizedError(
1322 headers=dict(_response.headers),
1323 body=typing.cast(
1324 typing.Any,
1325 parse_obj_as(
1326 type_=typing.Any, # type: ignore
1327 object_=_response.json(),
1328 ),
1329 ),
1330 )
1331 if _response.status_code == 403:
1332 raise ForbiddenError(
1333 headers=dict(_response.headers),
1334 body=typing.cast(
1335 typing.Any,
1336 parse_obj_as(
1337 type_=typing.Any, # type: ignore
1338 object_=_response.json(),
1339 ),
1340 ),
1341 )
1342 if _response.status_code == 409:
1343 raise ConflictError(
1344 headers=dict(_response.headers),
1345 body=typing.cast(
1346 typing.Any,
1347 parse_obj_as(
1348 type_=typing.Any, # type: ignore
1349 object_=_response.json(),
1350 ),
1351 ),
1352 )
1353 if _response.status_code == 429:
1354 raise TooManyRequestsError(
1355 headers=dict(_response.headers),
1356 body=typing.cast(
1357 typing.Any,
1358 parse_obj_as(
1359 type_=typing.Any, # type: ignore
1360 object_=_response.json(),
1361 ),
1362 ),
1363 )
1364 _response_json = _response.json()
1365 except JSONDecodeError:
1366 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1367 except ValidationError as e:
1368 raise ParsingError(
1369 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1370 )
1371 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)