Debian Codegraph @

src/auth0/management/emails/provider/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.conflict_error import ConflictError
15 from ...errors.forbidden_error import ForbiddenError
16 from ...errors.not_found_error import NotFoundError
17 from ...errors.too_many_requests_error import TooManyRequestsError
18 from ...errors.unauthorized_error import UnauthorizedError
19 from ...types.create_email_provider_response_content import CreateEmailProviderResponseContent
20 from ...types.email_provider_credentials_schema import EmailProviderCredentialsSchema
21 from ...types.email_provider_name_enum import EmailProviderNameEnum
22 from ...types.email_specific_provider_settings_with_additional_properties import (
23 EmailSpecificProviderSettingsWithAdditionalProperties,
24 )
25 from ...types.get_email_provider_response_content import GetEmailProviderResponseContent
26 from ...types.update_email_provider_response_content import UpdateEmailProviderResponseContent
27 from pydantic import ValidationError
28
29 # this is used as the default value for optional parameters
30 OMIT = typing.cast(typing.Any, ...)
31
32
33 class RawProviderClient:
34 def __init__(self, *, client_wrapper: SyncClientWrapper):
35 self._client_wrapper = client_wrapper
36
37 def get(
38 self,
39 *,
40 fields: typing.Optional[str] = None,
41 include_fields: typing.Optional[bool] = None,
42 request_options: typing.Optional[RequestOptions] = None,
43 ) -> HttpResponse[GetEmailProviderResponseContent]:
44 """
45 Retrieve details of the [email provider configuration](https://auth0.com/docs/customize/email/smtp-email-providers) in your tenant. A list of fields to include or exclude may also be specified.
46
47 Parameters
48 ----------
49 fields : typing.Optional[str]
50 Comma-separated list of fields to include or exclude (dependent upon include_fields) from the result. Leave empty to retrieve `name` and `enabled`. Additional fields available include `credentials`, `default_from_address`, and `settings`.
51
52 include_fields : typing.Optional[bool]
53 Whether specified fields are to be included (true) or excluded (false).
54
55 request_options : typing.Optional[RequestOptions]
56 Request-specific configuration.
57
58 Returns
59 -------
60 HttpResponse[GetEmailProviderResponseContent]
61 Email provider successfully retrieved.
62 """
63 _response = self._client_wrapper.httpx_client.request(
64 "emails/provider",
65 method="GET",
66 params={
67 "fields": fields,
68 "include_fields": include_fields,
69 },
70 request_options=request_options,
71 )
72 try:
73 if 200 <= _response.status_code < 300:
74 _data = typing.cast(
75 GetEmailProviderResponseContent,
76 parse_obj_as(
77 type_=GetEmailProviderResponseContent, # type: ignore
78 object_=_response.json(),
79 ),
80 )
81 return HttpResponse(response=_response, data=_data)
82 if _response.status_code == 400:
83 raise BadRequestError(
84 headers=dict(_response.headers),
85 body=typing.cast(
86 typing.Any,
87 parse_obj_as(
88 type_=typing.Any, # type: ignore
89 object_=_response.json(),
90 ),
91 ),
92 )
93 if _response.status_code == 401:
94 raise UnauthorizedError(
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 == 403:
105 raise ForbiddenError(
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 == 404:
116 raise NotFoundError(
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 create(
147 self,
148 *,
149 name: EmailProviderNameEnum,
150 credentials: EmailProviderCredentialsSchema,
151 enabled: typing.Optional[bool] = OMIT,
152 default_from_address: typing.Optional[str] = OMIT,
153 settings: typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties] = OMIT,
154 request_options: typing.Optional[RequestOptions] = None,
155 ) -> HttpResponse[CreateEmailProviderResponseContent]:
156 """
157 Create an [email provider](https://auth0.com/docs/email/providers). The `credentials` object
158 requires different properties depending on the email provider (which is specified using the `name` property):
159
160 - `mandrill` requires `api_key`
161 - `sendgrid` requires `api_key`
162 - `sparkpost` requires `api_key`. Optionally, set `region` to `eu` to use
163 the SparkPost service hosted in Western Europe; set to `null` to use the SparkPost service hosted in
164 North America. `eu` or `null` are the only valid values for `region`.
165 - `mailgun` requires `api_key` and `domain`. Optionally, set `region` to
166 `eu` to use the Mailgun service hosted in Europe; set to `null` otherwise. `eu` or
167 `null` are the only valid values for `region`.
168 - `ses` requires `accessKeyId`, `secretAccessKey`, and `region`
169 - `smtp` requires `smtp_host`, `smtp_port`, `smtp_user`, and
170 `smtp_pass`
171
172 Depending on the type of provider it is possible to specify `settings` object with different configuration
173 options, which will be used when sending an email:
174
175 - `smtp` provider, `settings` may contain `headers` object.
176 - When using AWS SES SMTP host, you may provide a name of configuration set in
177 `X-SES-Configuration-Set` header. Value must be a string.
178 - When using Sparkpost host, you may provide value for
179 `X-MSYS_API` header. Value must be an object.
180 - For `ses` provider, `settings` may contain `message` object, where you can provide
181 a name of configuration set in `configuration_set_name` property. Value must be a string.
182
183 Parameters
184 ----------
185 name : EmailProviderNameEnum
186
187 credentials : EmailProviderCredentialsSchema
188
189 enabled : typing.Optional[bool]
190 Whether the provider is enabled (true) or disabled (false).
191
192 default_from_address : typing.Optional[str]
193 Email address to use as "from" when no other address specified.
194
195 settings : typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties]
196
197 request_options : typing.Optional[RequestOptions]
198 Request-specific configuration.
199
200 Returns
201 -------
202 HttpResponse[CreateEmailProviderResponseContent]
203 Email provider successfully created.
204 """
205 _response = self._client_wrapper.httpx_client.request(
206 "emails/provider",
207 method="POST",
208 json={
209 "name": name,
210 "enabled": enabled,
211 "default_from_address": default_from_address,
212 "credentials": convert_and_respect_annotation_metadata(
213 object_=credentials, annotation=EmailProviderCredentialsSchema, direction="write"
214 ),
215 "settings": settings,
216 },
217 headers={
218 "content-type": "application/json",
219 },
220 request_options=request_options,
221 omit=OMIT,
222 )
223 try:
224 if 200 <= _response.status_code < 300:
225 _data = typing.cast(
226 CreateEmailProviderResponseContent,
227 parse_obj_as(
228 type_=CreateEmailProviderResponseContent, # type: ignore
229 object_=_response.json(),
230 ),
231 )
232 return HttpResponse(response=_response, data=_data)
233 if _response.status_code == 400:
234 raise BadRequestError(
235 headers=dict(_response.headers),
236 body=typing.cast(
237 typing.Any,
238 parse_obj_as(
239 type_=typing.Any, # type: ignore
240 object_=_response.json(),
241 ),
242 ),
243 )
244 if _response.status_code == 401:
245 raise UnauthorizedError(
246 headers=dict(_response.headers),
247 body=typing.cast(
248 typing.Any,
249 parse_obj_as(
250 type_=typing.Any, # type: ignore
251 object_=_response.json(),
252 ),
253 ),
254 )
255 if _response.status_code == 403:
256 raise ForbiddenError(
257 headers=dict(_response.headers),
258 body=typing.cast(
259 typing.Any,
260 parse_obj_as(
261 type_=typing.Any, # type: ignore
262 object_=_response.json(),
263 ),
264 ),
265 )
266 if _response.status_code == 409:
267 raise ConflictError(
268 headers=dict(_response.headers),
269 body=typing.cast(
270 typing.Any,
271 parse_obj_as(
272 type_=typing.Any, # type: ignore
273 object_=_response.json(),
274 ),
275 ),
276 )
277 if _response.status_code == 429:
278 raise TooManyRequestsError(
279 headers=dict(_response.headers),
280 body=typing.cast(
281 typing.Any,
282 parse_obj_as(
283 type_=typing.Any, # type: ignore
284 object_=_response.json(),
285 ),
286 ),
287 )
288 _response_json = _response.json()
289 except JSONDecodeError:
290 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
291 except ValidationError as e:
292 raise ParsingError(
293 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
294 )
295 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
296
297 def delete(self, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
298 """
299 Delete the email provider.
300
301 Parameters
302 ----------
303 request_options : typing.Optional[RequestOptions]
304 Request-specific configuration.
305
306 Returns
307 -------
308 HttpResponse[None]
309 """
310 _response = self._client_wrapper.httpx_client.request(
311 "emails/provider",
312 method="DELETE",
313 request_options=request_options,
314 )
315 try:
316 if 200 <= _response.status_code < 300:
317 return HttpResponse(response=_response, data=None)
318 if _response.status_code == 400:
319 raise BadRequestError(
320 headers=dict(_response.headers),
321 body=typing.cast(
322 typing.Any,
323 parse_obj_as(
324 type_=typing.Any, # type: ignore
325 object_=_response.json(),
326 ),
327 ),
328 )
329 if _response.status_code == 401:
330 raise UnauthorizedError(
331 headers=dict(_response.headers),
332 body=typing.cast(
333 typing.Any,
334 parse_obj_as(
335 type_=typing.Any, # type: ignore
336 object_=_response.json(),
337 ),
338 ),
339 )
340 if _response.status_code == 403:
341 raise ForbiddenError(
342 headers=dict(_response.headers),
343 body=typing.cast(
344 typing.Any,
345 parse_obj_as(
346 type_=typing.Any, # type: ignore
347 object_=_response.json(),
348 ),
349 ),
350 )
351 if _response.status_code == 404:
352 raise NotFoundError(
353 headers=dict(_response.headers),
354 body=typing.cast(
355 typing.Any,
356 parse_obj_as(
357 type_=typing.Any, # type: ignore
358 object_=_response.json(),
359 ),
360 ),
361 )
362 if _response.status_code == 429:
363 raise TooManyRequestsError(
364 headers=dict(_response.headers),
365 body=typing.cast(
366 typing.Any,
367 parse_obj_as(
368 type_=typing.Any, # type: ignore
369 object_=_response.json(),
370 ),
371 ),
372 )
373 _response_json = _response.json()
374 except JSONDecodeError:
375 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
376 except ValidationError as e:
377 raise ParsingError(
378 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
379 )
380 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
381
382 def update(
383 self,
384 *,
385 name: typing.Optional[EmailProviderNameEnum] = OMIT,
386 enabled: typing.Optional[bool] = OMIT,
387 default_from_address: typing.Optional[str] = OMIT,
388 credentials: typing.Optional[EmailProviderCredentialsSchema] = OMIT,
389 settings: typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties] = OMIT,
390 request_options: typing.Optional[RequestOptions] = None,
391 ) -> HttpResponse[UpdateEmailProviderResponseContent]:
392 """
393 Update an [email provider](https://auth0.com/docs/email/providers). The `credentials` object
394 requires different properties depending on the email provider (which is specified using the `name` property):
395
396 - `mandrill` requires `api_key`
397 - `sendgrid` requires `api_key`
398 - `sparkpost` requires `api_key`. Optionally, set `region` to `eu` to use
399 the SparkPost service hosted in Western Europe; set to `null` to use the SparkPost service hosted in
400 North America. `eu` or `null` are the only valid values for `region`.
401 - `mailgun` requires `api_key` and `domain`. Optionally, set `region` to
402 `eu` to use the Mailgun service hosted in Europe; set to `null` otherwise. `eu` or
403 `null` are the only valid values for `region`.
404 - `ses` requires `accessKeyId`, `secretAccessKey`, and `region`
405 - `smtp` requires `smtp_host`, `smtp_port`, `smtp_user`, and
406 `smtp_pass`
407
408 Depending on the type of provider it is possible to specify `settings` object with different configuration
409 options, which will be used when sending an email:
410
411 - `smtp` provider, `settings` may contain `headers` object.
412 - When using AWS SES SMTP host, you may provide a name of configuration set in
413 `X-SES-Configuration-Set` header. Value must be a string.
414 - When using Sparkpost host, you may provide value for
415 `X-MSYS_API` header. Value must be an object.
416
417 For `ses` provider, `settings` may contain `message` object, where you can provide
418 a name of configuration set in `configuration_set_name` property. Value must be a string.
419
420 Parameters
421 ----------
422 name : typing.Optional[EmailProviderNameEnum]
423
424 enabled : typing.Optional[bool]
425 Whether the provider is enabled (true) or disabled (false).
426
427 default_from_address : typing.Optional[str]
428 Email address to use as "from" when no other address specified.
429
430 credentials : typing.Optional[EmailProviderCredentialsSchema]
431
432 settings : typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties]
433
434 request_options : typing.Optional[RequestOptions]
435 Request-specific configuration.
436
437 Returns
438 -------
439 HttpResponse[UpdateEmailProviderResponseContent]
440 Email provider successfully updated.
441 """
442 _response = self._client_wrapper.httpx_client.request(
443 "emails/provider",
444 method="PATCH",
445 json={
446 "name": name,
447 "enabled": enabled,
448 "default_from_address": default_from_address,
449 "credentials": convert_and_respect_annotation_metadata(
450 object_=credentials, annotation=EmailProviderCredentialsSchema, direction="write"
451 ),
452 "settings": settings,
453 },
454 headers={
455 "content-type": "application/json",
456 },
457 request_options=request_options,
458 omit=OMIT,
459 )
460 try:
461 if 200 <= _response.status_code < 300:
462 _data = typing.cast(
463 UpdateEmailProviderResponseContent,
464 parse_obj_as(
465 type_=UpdateEmailProviderResponseContent, # type: ignore
466 object_=_response.json(),
467 ),
468 )
469 return HttpResponse(response=_response, data=_data)
470 if _response.status_code == 400:
471 raise BadRequestError(
472 headers=dict(_response.headers),
473 body=typing.cast(
474 typing.Any,
475 parse_obj_as(
476 type_=typing.Any, # type: ignore
477 object_=_response.json(),
478 ),
479 ),
480 )
481 if _response.status_code == 401:
482 raise UnauthorizedError(
483 headers=dict(_response.headers),
484 body=typing.cast(
485 typing.Any,
486 parse_obj_as(
487 type_=typing.Any, # type: ignore
488 object_=_response.json(),
489 ),
490 ),
491 )
492 if _response.status_code == 403:
493 raise ForbiddenError(
494 headers=dict(_response.headers),
495 body=typing.cast(
496 typing.Any,
497 parse_obj_as(
498 type_=typing.Any, # type: ignore
499 object_=_response.json(),
500 ),
501 ),
502 )
503 if _response.status_code == 404:
504 raise NotFoundError(
505 headers=dict(_response.headers),
506 body=typing.cast(
507 typing.Any,
508 parse_obj_as(
509 type_=typing.Any, # type: ignore
510 object_=_response.json(),
511 ),
512 ),
513 )
514 if _response.status_code == 409:
515 raise ConflictError(
516 headers=dict(_response.headers),
517 body=typing.cast(
518 typing.Any,
519 parse_obj_as(
520 type_=typing.Any, # type: ignore
521 object_=_response.json(),
522 ),
523 ),
524 )
525 if _response.status_code == 429:
526 raise TooManyRequestsError(
527 headers=dict(_response.headers),
528 body=typing.cast(
529 typing.Any,
530 parse_obj_as(
531 type_=typing.Any, # type: ignore
532 object_=_response.json(),
533 ),
534 ),
535 )
536 _response_json = _response.json()
537 except JSONDecodeError:
538 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
539 except ValidationError as e:
540 raise ParsingError(
541 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
542 )
543 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
544
545
546 class AsyncRawProviderClient:
547 def __init__(self, *, client_wrapper: AsyncClientWrapper):
548 self._client_wrapper = client_wrapper
549
550 async def get(
551 self,
552 *,
553 fields: typing.Optional[str] = None,
554 include_fields: typing.Optional[bool] = None,
555 request_options: typing.Optional[RequestOptions] = None,
556 ) -> AsyncHttpResponse[GetEmailProviderResponseContent]:
557 """
558 Retrieve details of the [email provider configuration](https://auth0.com/docs/customize/email/smtp-email-providers) in your tenant. A list of fields to include or exclude may also be specified.
559
560 Parameters
561 ----------
562 fields : typing.Optional[str]
563 Comma-separated list of fields to include or exclude (dependent upon include_fields) from the result. Leave empty to retrieve `name` and `enabled`. Additional fields available include `credentials`, `default_from_address`, and `settings`.
564
565 include_fields : typing.Optional[bool]
566 Whether specified fields are to be included (true) or excluded (false).
567
568 request_options : typing.Optional[RequestOptions]
569 Request-specific configuration.
570
571 Returns
572 -------
573 AsyncHttpResponse[GetEmailProviderResponseContent]
574 Email provider successfully retrieved.
575 """
576 _response = await self._client_wrapper.httpx_client.request(
577 "emails/provider",
578 method="GET",
579 params={
580 "fields": fields,
581 "include_fields": include_fields,
582 },
583 request_options=request_options,
584 )
585 try:
586 if 200 <= _response.status_code < 300:
587 _data = typing.cast(
588 GetEmailProviderResponseContent,
589 parse_obj_as(
590 type_=GetEmailProviderResponseContent, # type: ignore
591 object_=_response.json(),
592 ),
593 )
594 return AsyncHttpResponse(response=_response, data=_data)
595 if _response.status_code == 400:
596 raise BadRequestError(
597 headers=dict(_response.headers),
598 body=typing.cast(
599 typing.Any,
600 parse_obj_as(
601 type_=typing.Any, # type: ignore
602 object_=_response.json(),
603 ),
604 ),
605 )
606 if _response.status_code == 401:
607 raise UnauthorizedError(
608 headers=dict(_response.headers),
609 body=typing.cast(
610 typing.Any,
611 parse_obj_as(
612 type_=typing.Any, # type: ignore
613 object_=_response.json(),
614 ),
615 ),
616 )
617 if _response.status_code == 403:
618 raise ForbiddenError(
619 headers=dict(_response.headers),
620 body=typing.cast(
621 typing.Any,
622 parse_obj_as(
623 type_=typing.Any, # type: ignore
624 object_=_response.json(),
625 ),
626 ),
627 )
628 if _response.status_code == 404:
629 raise NotFoundError(
630 headers=dict(_response.headers),
631 body=typing.cast(
632 typing.Any,
633 parse_obj_as(
634 type_=typing.Any, # type: ignore
635 object_=_response.json(),
636 ),
637 ),
638 )
639 if _response.status_code == 429:
640 raise TooManyRequestsError(
641 headers=dict(_response.headers),
642 body=typing.cast(
643 typing.Any,
644 parse_obj_as(
645 type_=typing.Any, # type: ignore
646 object_=_response.json(),
647 ),
648 ),
649 )
650 _response_json = _response.json()
651 except JSONDecodeError:
652 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
653 except ValidationError as e:
654 raise ParsingError(
655 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
656 )
657 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
658
659 async def create(
660 self,
661 *,
662 name: EmailProviderNameEnum,
663 credentials: EmailProviderCredentialsSchema,
664 enabled: typing.Optional[bool] = OMIT,
665 default_from_address: typing.Optional[str] = OMIT,
666 settings: typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties] = OMIT,
667 request_options: typing.Optional[RequestOptions] = None,
668 ) -> AsyncHttpResponse[CreateEmailProviderResponseContent]:
669 """
670 Create an [email provider](https://auth0.com/docs/email/providers). The `credentials` object
671 requires different properties depending on the email provider (which is specified using the `name` property):
672
673 - `mandrill` requires `api_key`
674 - `sendgrid` requires `api_key`
675 - `sparkpost` requires `api_key`. Optionally, set `region` to `eu` to use
676 the SparkPost service hosted in Western Europe; set to `null` to use the SparkPost service hosted in
677 North America. `eu` or `null` are the only valid values for `region`.
678 - `mailgun` requires `api_key` and `domain`. Optionally, set `region` to
679 `eu` to use the Mailgun service hosted in Europe; set to `null` otherwise. `eu` or
680 `null` are the only valid values for `region`.
681 - `ses` requires `accessKeyId`, `secretAccessKey`, and `region`
682 - `smtp` requires `smtp_host`, `smtp_port`, `smtp_user`, and
683 `smtp_pass`
684
685 Depending on the type of provider it is possible to specify `settings` object with different configuration
686 options, which will be used when sending an email:
687
688 - `smtp` provider, `settings` may contain `headers` object.
689 - When using AWS SES SMTP host, you may provide a name of configuration set in
690 `X-SES-Configuration-Set` header. Value must be a string.
691 - When using Sparkpost host, you may provide value for
692 `X-MSYS_API` header. Value must be an object.
693 - For `ses` provider, `settings` may contain `message` object, where you can provide
694 a name of configuration set in `configuration_set_name` property. Value must be a string.
695
696 Parameters
697 ----------
698 name : EmailProviderNameEnum
699
700 credentials : EmailProviderCredentialsSchema
701
702 enabled : typing.Optional[bool]
703 Whether the provider is enabled (true) or disabled (false).
704
705 default_from_address : typing.Optional[str]
706 Email address to use as "from" when no other address specified.
707
708 settings : typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties]
709
710 request_options : typing.Optional[RequestOptions]
711 Request-specific configuration.
712
713 Returns
714 -------
715 AsyncHttpResponse[CreateEmailProviderResponseContent]
716 Email provider successfully created.
717 """
718 _response = await self._client_wrapper.httpx_client.request(
719 "emails/provider",
720 method="POST",
721 json={
722 "name": name,
723 "enabled": enabled,
724 "default_from_address": default_from_address,
725 "credentials": convert_and_respect_annotation_metadata(
726 object_=credentials, annotation=EmailProviderCredentialsSchema, direction="write"
727 ),
728 "settings": settings,
729 },
730 headers={
731 "content-type": "application/json",
732 },
733 request_options=request_options,
734 omit=OMIT,
735 )
736 try:
737 if 200 <= _response.status_code < 300:
738 _data = typing.cast(
739 CreateEmailProviderResponseContent,
740 parse_obj_as(
741 type_=CreateEmailProviderResponseContent, # type: ignore
742 object_=_response.json(),
743 ),
744 )
745 return AsyncHttpResponse(response=_response, data=_data)
746 if _response.status_code == 400:
747 raise BadRequestError(
748 headers=dict(_response.headers),
749 body=typing.cast(
750 typing.Any,
751 parse_obj_as(
752 type_=typing.Any, # type: ignore
753 object_=_response.json(),
754 ),
755 ),
756 )
757 if _response.status_code == 401:
758 raise UnauthorizedError(
759 headers=dict(_response.headers),
760 body=typing.cast(
761 typing.Any,
762 parse_obj_as(
763 type_=typing.Any, # type: ignore
764 object_=_response.json(),
765 ),
766 ),
767 )
768 if _response.status_code == 403:
769 raise ForbiddenError(
770 headers=dict(_response.headers),
771 body=typing.cast(
772 typing.Any,
773 parse_obj_as(
774 type_=typing.Any, # type: ignore
775 object_=_response.json(),
776 ),
777 ),
778 )
779 if _response.status_code == 409:
780 raise ConflictError(
781 headers=dict(_response.headers),
782 body=typing.cast(
783 typing.Any,
784 parse_obj_as(
785 type_=typing.Any, # type: ignore
786 object_=_response.json(),
787 ),
788 ),
789 )
790 if _response.status_code == 429:
791 raise TooManyRequestsError(
792 headers=dict(_response.headers),
793 body=typing.cast(
794 typing.Any,
795 parse_obj_as(
796 type_=typing.Any, # type: ignore
797 object_=_response.json(),
798 ),
799 ),
800 )
801 _response_json = _response.json()
802 except JSONDecodeError:
803 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
804 except ValidationError as e:
805 raise ParsingError(
806 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
807 )
808 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
809
810 async def delete(self, *, request_options: typing.Optional[RequestOptions] = None) -> AsyncHttpResponse[None]:
811 """
812 Delete the email provider.
813
814 Parameters
815 ----------
816 request_options : typing.Optional[RequestOptions]
817 Request-specific configuration.
818
819 Returns
820 -------
821 AsyncHttpResponse[None]
822 """
823 _response = await self._client_wrapper.httpx_client.request(
824 "emails/provider",
825 method="DELETE",
826 request_options=request_options,
827 )
828 try:
829 if 200 <= _response.status_code < 300:
830 return AsyncHttpResponse(response=_response, data=None)
831 if _response.status_code == 400:
832 raise BadRequestError(
833 headers=dict(_response.headers),
834 body=typing.cast(
835 typing.Any,
836 parse_obj_as(
837 type_=typing.Any, # type: ignore
838 object_=_response.json(),
839 ),
840 ),
841 )
842 if _response.status_code == 401:
843 raise UnauthorizedError(
844 headers=dict(_response.headers),
845 body=typing.cast(
846 typing.Any,
847 parse_obj_as(
848 type_=typing.Any, # type: ignore
849 object_=_response.json(),
850 ),
851 ),
852 )
853 if _response.status_code == 403:
854 raise ForbiddenError(
855 headers=dict(_response.headers),
856 body=typing.cast(
857 typing.Any,
858 parse_obj_as(
859 type_=typing.Any, # type: ignore
860 object_=_response.json(),
861 ),
862 ),
863 )
864 if _response.status_code == 404:
865 raise NotFoundError(
866 headers=dict(_response.headers),
867 body=typing.cast(
868 typing.Any,
869 parse_obj_as(
870 type_=typing.Any, # type: ignore
871 object_=_response.json(),
872 ),
873 ),
874 )
875 if _response.status_code == 429:
876 raise TooManyRequestsError(
877 headers=dict(_response.headers),
878 body=typing.cast(
879 typing.Any,
880 parse_obj_as(
881 type_=typing.Any, # type: ignore
882 object_=_response.json(),
883 ),
884 ),
885 )
886 _response_json = _response.json()
887 except JSONDecodeError:
888 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
889 except ValidationError as e:
890 raise ParsingError(
891 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
892 )
893 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
894
895 async def update(
896 self,
897 *,
898 name: typing.Optional[EmailProviderNameEnum] = OMIT,
899 enabled: typing.Optional[bool] = OMIT,
900 default_from_address: typing.Optional[str] = OMIT,
901 credentials: typing.Optional[EmailProviderCredentialsSchema] = OMIT,
902 settings: typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties] = OMIT,
903 request_options: typing.Optional[RequestOptions] = None,
904 ) -> AsyncHttpResponse[UpdateEmailProviderResponseContent]:
905 """
906 Update an [email provider](https://auth0.com/docs/email/providers). The `credentials` object
907 requires different properties depending on the email provider (which is specified using the `name` property):
908
909 - `mandrill` requires `api_key`
910 - `sendgrid` requires `api_key`
911 - `sparkpost` requires `api_key`. Optionally, set `region` to `eu` to use
912 the SparkPost service hosted in Western Europe; set to `null` to use the SparkPost service hosted in
913 North America. `eu` or `null` are the only valid values for `region`.
914 - `mailgun` requires `api_key` and `domain`. Optionally, set `region` to
915 `eu` to use the Mailgun service hosted in Europe; set to `null` otherwise. `eu` or
916 `null` are the only valid values for `region`.
917 - `ses` requires `accessKeyId`, `secretAccessKey`, and `region`
918 - `smtp` requires `smtp_host`, `smtp_port`, `smtp_user`, and
919 `smtp_pass`
920
921 Depending on the type of provider it is possible to specify `settings` object with different configuration
922 options, which will be used when sending an email:
923
924 - `smtp` provider, `settings` may contain `headers` object.
925 - When using AWS SES SMTP host, you may provide a name of configuration set in
926 `X-SES-Configuration-Set` header. Value must be a string.
927 - When using Sparkpost host, you may provide value for
928 `X-MSYS_API` header. Value must be an object.
929
930 For `ses` provider, `settings` may contain `message` object, where you can provide
931 a name of configuration set in `configuration_set_name` property. Value must be a string.
932
933 Parameters
934 ----------
935 name : typing.Optional[EmailProviderNameEnum]
936
937 enabled : typing.Optional[bool]
938 Whether the provider is enabled (true) or disabled (false).
939
940 default_from_address : typing.Optional[str]
941 Email address to use as "from" when no other address specified.
942
943 credentials : typing.Optional[EmailProviderCredentialsSchema]
944
945 settings : typing.Optional[EmailSpecificProviderSettingsWithAdditionalProperties]
946
947 request_options : typing.Optional[RequestOptions]
948 Request-specific configuration.
949
950 Returns
951 -------
952 AsyncHttpResponse[UpdateEmailProviderResponseContent]
953 Email provider successfully updated.
954 """
955 _response = await self._client_wrapper.httpx_client.request(
956 "emails/provider",
957 method="PATCH",
958 json={
959 "name": name,
960 "enabled": enabled,
961 "default_from_address": default_from_address,
962 "credentials": convert_and_respect_annotation_metadata(
963 object_=credentials, annotation=EmailProviderCredentialsSchema, direction="write"
964 ),
965 "settings": settings,
966 },
967 headers={
968 "content-type": "application/json",
969 },
970 request_options=request_options,
971 omit=OMIT,
972 )
973 try:
974 if 200 <= _response.status_code < 300:
975 _data = typing.cast(
976 UpdateEmailProviderResponseContent,
977 parse_obj_as(
978 type_=UpdateEmailProviderResponseContent, # type: ignore
979 object_=_response.json(),
980 ),
981 )
982 return AsyncHttpResponse(response=_response, data=_data)
983 if _response.status_code == 400:
984 raise BadRequestError(
985 headers=dict(_response.headers),
986 body=typing.cast(
987 typing.Any,
988 parse_obj_as(
989 type_=typing.Any, # type: ignore
990 object_=_response.json(),
991 ),
992 ),
993 )
994 if _response.status_code == 401:
995 raise UnauthorizedError(
996 headers=dict(_response.headers),
997 body=typing.cast(
998 typing.Any,
999 parse_obj_as(
1000 type_=typing.Any, # type: ignore
1001 object_=_response.json(),
1002 ),
1003 ),
1004 )
1005 if _response.status_code == 403:
1006 raise ForbiddenError(
1007 headers=dict(_response.headers),
1008 body=typing.cast(
1009 typing.Any,
1010 parse_obj_as(
1011 type_=typing.Any, # type: ignore
1012 object_=_response.json(),
1013 ),
1014 ),
1015 )
1016 if _response.status_code == 404:
1017 raise NotFoundError(
1018 headers=dict(_response.headers),
1019 body=typing.cast(
1020 typing.Any,
1021 parse_obj_as(
1022 type_=typing.Any, # type: ignore
1023 object_=_response.json(),
1024 ),
1025 ),
1026 )
1027 if _response.status_code == 409:
1028 raise ConflictError(
1029 headers=dict(_response.headers),
1030 body=typing.cast(
1031 typing.Any,
1032 parse_obj_as(
1033 type_=typing.Any, # type: ignore
1034 object_=_response.json(),
1035 ),
1036 ),
1037 )
1038 if _response.status_code == 429:
1039 raise TooManyRequestsError(
1040 headers=dict(_response.headers),
1041 body=typing.cast(
1042 typing.Any,
1043 parse_obj_as(
1044 type_=typing.Any, # type: ignore
1045 object_=_response.json(),
1046 ),
1047 ),
1048 )
1049 _response_json = _response.json()
1050 except JSONDecodeError:
1051 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1052 except ValidationError as e:
1053 raise ParsingError(
1054 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1055 )
1056 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)