diff --git a/scaleway-async/scaleway_async/tem/v1alpha1/__init__.py b/scaleway-async/scaleway_async/tem/v1alpha1/__init__.py index 59ca17f59..805d56c4a 100644 --- a/scaleway-async/scaleway_async/tem/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/tem/v1alpha1/__init__.py @@ -1,5 +1,6 @@ # This file was automatically generated. DO NOT EDIT. # If you have any remark or suggestion do not hesitate to open an issue. +from .types import BlocklistType from .types import DomainLastStatusAutoconfigStateReason from .types import DomainLastStatusRecordStatus from .types import DomainReputationStatus @@ -9,6 +10,7 @@ from .types import EmailRcptType from .types import EmailStatus from .content import EMAIL_TRANSIENT_STATUSES +from .types import ListBlocklistsRequestOrderBy from .types import ListEmailsRequestOrderBy from .types import ListWebhookEventsRequestOrderBy from .types import ListWebhooksRequestOrderBy @@ -20,6 +22,7 @@ from .types import DomainRecords from .types import DomainReputation from .types import DomainStatistics +from .types import Blocklist from .types import CreateEmailRequestAddress from .types import CreateEmailRequestAttachment from .types import CreateEmailRequestHeader @@ -33,12 +36,15 @@ from .types import Webhook from .types import ProjectSettingsPeriodicReport from .types import UpdateProjectSettingsRequestUpdatePeriodicReport +from .types import BulkCreateBlocklistsRequest +from .types import BulkCreateBlocklistsResponse from .types import CancelEmailRequest from .types import CheckDomainRequest from .types import CreateDomainRequest from .types import CreateEmailRequest from .types import CreateEmailResponse from .types import CreateWebhookRequest +from .types import DeleteBlocklistRequest from .types import DeleteWebhookRequest from .types import DomainLastStatus from .types import GetDomainLastStatusRequest @@ -47,6 +53,8 @@ from .types import GetProjectSettingsRequest from .types import GetStatisticsRequest from .types import GetWebhookRequest +from .types import ListBlocklistsRequest +from .types import ListBlocklistsResponse from .types import ListDomainsRequest from .types import ListDomainsResponse from .types import ListEmailsRequest @@ -64,6 +72,7 @@ from .api import TemV1Alpha1API __all__ = [ + "BlocklistType", "DomainLastStatusAutoconfigStateReason", "DomainLastStatusRecordStatus", "DomainReputationStatus", @@ -73,6 +82,7 @@ "EmailRcptType", "EmailStatus", "EMAIL_TRANSIENT_STATUSES", + "ListBlocklistsRequestOrderBy", "ListEmailsRequestOrderBy", "ListWebhookEventsRequestOrderBy", "ListWebhooksRequestOrderBy", @@ -84,6 +94,7 @@ "DomainRecords", "DomainReputation", "DomainStatistics", + "Blocklist", "CreateEmailRequestAddress", "CreateEmailRequestAttachment", "CreateEmailRequestHeader", @@ -97,12 +108,15 @@ "Webhook", "ProjectSettingsPeriodicReport", "UpdateProjectSettingsRequestUpdatePeriodicReport", + "BulkCreateBlocklistsRequest", + "BulkCreateBlocklistsResponse", "CancelEmailRequest", "CheckDomainRequest", "CreateDomainRequest", "CreateEmailRequest", "CreateEmailResponse", "CreateWebhookRequest", + "DeleteBlocklistRequest", "DeleteWebhookRequest", "DomainLastStatus", "GetDomainLastStatusRequest", @@ -111,6 +125,8 @@ "GetProjectSettingsRequest", "GetStatisticsRequest", "GetWebhookRequest", + "ListBlocklistsRequest", + "ListBlocklistsResponse", "ListDomainsRequest", "ListDomainsResponse", "ListEmailsRequest", diff --git a/scaleway-async/scaleway_async/tem/v1alpha1/api.py b/scaleway-async/scaleway_async/tem/v1alpha1/api.py index 17da57b48..223d9e6d9 100644 --- a/scaleway-async/scaleway_async/tem/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/tem/v1alpha1/api.py @@ -15,14 +15,19 @@ wait_for_resource_async, ) from .types import ( + BlocklistType, DomainStatus, EmailFlag, EmailStatus, + ListBlocklistsRequestOrderBy, ListEmailsRequestOrderBy, ListWebhookEventsRequestOrderBy, ListWebhooksRequestOrderBy, WebhookEventStatus, WebhookEventType, + Blocklist, + BulkCreateBlocklistsRequest, + BulkCreateBlocklistsResponse, CreateDomainRequest, CreateEmailRequest, CreateEmailRequestAddress, @@ -33,6 +38,7 @@ Domain, DomainLastStatus, Email, + ListBlocklistsResponse, ListDomainsResponse, ListEmailsResponse, ListWebhookEventsResponse, @@ -54,14 +60,17 @@ unmarshal_Email, unmarshal_Domain, unmarshal_Webhook, + unmarshal_BulkCreateBlocklistsResponse, unmarshal_CreateEmailResponse, unmarshal_DomainLastStatus, + unmarshal_ListBlocklistsResponse, unmarshal_ListDomainsResponse, unmarshal_ListEmailsResponse, unmarshal_ListWebhookEventsResponse, unmarshal_ListWebhooksResponse, unmarshal_ProjectSettings, unmarshal_Statistics, + marshal_BulkCreateBlocklistsRequest, marshal_CreateDomainRequest, marshal_CreateEmailRequest, marshal_CreateWebhookRequest, @@ -1277,3 +1286,187 @@ async def update_project_settings( self._throw_on_error(res) return unmarshal_ProjectSettings(res.json()) + + async def list_blocklists( + self, + *, + domain_id: str, + region: Optional[Region] = None, + order_by: Optional[ListBlocklistsRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + email: Optional[str] = None, + type_: Optional[BlocklistType] = None, + custom: Optional[bool] = None, + ) -> ListBlocklistsResponse: + """ + List blocklists. + Retrieve the list of blocklists. + :param domain_id: (Optional) Filter by a domain ID. + :param region: Region to target. If none is passed will use default region from the config. + :param order_by: (Optional) List blocklist corresponding to specific criteria. + :param page: (Optional) Requested page number. Value must be greater or equal to 1. + :param page_size: (Optional) Requested page size. Value must be between 1 and 100. + :param email: (Optional) Filter by an email address. + :param type_: (Optional) Filter by a blocklist type. + :param custom: (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false). + :return: :class:`ListBlocklistsResponse ` + + Usage: + :: + + result = await api.list_blocklists( + domain_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/transactional-email/v1alpha1/regions/{param_region}/blocklists", + params={ + "custom": custom, + "domain_id": domain_id, + "email": email, + "order_by": order_by, + "page": page, + "page_size": page_size or self.client.default_page_size, + "type": type_, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListBlocklistsResponse(res.json()) + + async def list_blocklists_all( + self, + *, + domain_id: str, + region: Optional[Region] = None, + order_by: Optional[ListBlocklistsRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + email: Optional[str] = None, + type_: Optional[BlocklistType] = None, + custom: Optional[bool] = None, + ) -> List[Blocklist]: + """ + List blocklists. + Retrieve the list of blocklists. + :param domain_id: (Optional) Filter by a domain ID. + :param region: Region to target. If none is passed will use default region from the config. + :param order_by: (Optional) List blocklist corresponding to specific criteria. + :param page: (Optional) Requested page number. Value must be greater or equal to 1. + :param page_size: (Optional) Requested page size. Value must be between 1 and 100. + :param email: (Optional) Filter by an email address. + :param type_: (Optional) Filter by a blocklist type. + :param custom: (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false). + :return: :class:`List[Blocklist] ` + + Usage: + :: + + result = await api.list_blocklists_all( + domain_id="example", + ) + """ + + return await fetch_all_pages_async( + type=ListBlocklistsResponse, + key="blocklists", + fetcher=self.list_blocklists, + args={ + "domain_id": domain_id, + "region": region, + "order_by": order_by, + "page": page, + "page_size": page_size, + "email": email, + "type_": type_, + "custom": custom, + }, + ) + + async def bulk_create_blocklists( + self, + *, + domain_id: str, + region: Optional[Region] = None, + emails: Optional[List[str]] = None, + type_: Optional[BlocklistType] = None, + reason: Optional[str] = None, + ) -> BulkCreateBlocklistsResponse: + """ + Bulk create blocklists. + Create multiple blocklists in a specific Project or Organization using the `region` parameter. + :param domain_id: Domain ID linked to the blocklist. + :param region: Region to target. If none is passed will use default region from the config. + :param emails: Email blocked by the blocklist. + :param type_: Type of blocklist. + :param reason: Reason to block the email. + :return: :class:`BulkCreateBlocklistsResponse ` + + Usage: + :: + + result = await api.bulk_create_blocklists( + domain_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/transactional-email/v1alpha1/regions/{param_region}/blocklists", + body=marshal_BulkCreateBlocklistsRequest( + BulkCreateBlocklistsRequest( + domain_id=domain_id, + region=region, + emails=emails, + type_=type_, + reason=reason, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_BulkCreateBlocklistsResponse(res.json()) + + async def delete_blocklist( + self, + *, + blocklist_id: str, + region: Optional[Region] = None, + ) -> None: + """ + Delete a blocklist. + You must specify the blocklist you want to delete by the `region` and `blocklist_id`. + :param blocklist_id: ID of the blocklist to delete. + :param region: Region to target. If none is passed will use default region from the config. + + Usage: + :: + + result = await api.delete_blocklist( + blocklist_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_blocklist_id = validate_path_param("blocklist_id", blocklist_id) + + res = self._request( + "DELETE", + f"/transactional-email/v1alpha1/regions/{param_region}/blocklists/{param_blocklist_id}", + ) + + self._throw_on_error(res) diff --git a/scaleway-async/scaleway_async/tem/v1alpha1/marshalling.py b/scaleway-async/scaleway_async/tem/v1alpha1/marshalling.py index 4d225341a..9d454d9d4 100644 --- a/scaleway-async/scaleway_async/tem/v1alpha1/marshalling.py +++ b/scaleway-async/scaleway_async/tem/v1alpha1/marshalling.py @@ -16,12 +16,15 @@ DomainStatistics, Domain, Webhook, + Blocklist, + BulkCreateBlocklistsResponse, CreateEmailResponse, DomainLastStatusAutoconfigState, DomainLastStatusDkimRecord, DomainLastStatusDmarcRecord, DomainLastStatusSpfRecord, DomainLastStatus, + ListBlocklistsResponse, ListDomainsResponse, ListEmailsResponse, WebhookEvent, @@ -30,6 +33,7 @@ ProjectSettingsPeriodicReport, ProjectSettings, Statistics, + BulkCreateBlocklistsRequest, CreateDomainRequest, CreateEmailRequestAddress, CreateEmailRequestAttachment, @@ -407,6 +411,76 @@ def unmarshal_Webhook(data: Any) -> Webhook: return Webhook(**args) +def unmarshal_Blocklist(data: Any) -> Blocklist: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Blocklist' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("domain_id", None) + if field is not None: + args["domain_id"] = field + + field = data.get("email", None) + if field is not None: + args["email"] = field + + field = data.get("type", None) + if field is not None: + args["type_"] = field + + field = data.get("reason", None) + if field is not None: + args["reason"] = field + + field = data.get("custom", None) + if field is not None: + args["custom"] = field + + field = data.get("created_at", None) + if field is not None: + args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["created_at"] = None + + field = data.get("updated_at", None) + if field is not None: + args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["updated_at"] = None + + field = data.get("ends_at", None) + if field is not None: + args["ends_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["ends_at"] = None + + return Blocklist(**args) + + +def unmarshal_BulkCreateBlocklistsResponse(data: Any) -> BulkCreateBlocklistsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'BulkCreateBlocklistsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("blocklists", None) + if field is not None: + args["blocklists"] = ( + [unmarshal_Blocklist(v) for v in field] if field is not None else None + ) + + return BulkCreateBlocklistsResponse(**args) + + def unmarshal_CreateEmailResponse(data: Any) -> CreateEmailResponse: if not isinstance(data, dict): raise TypeError( @@ -581,6 +655,27 @@ def unmarshal_DomainLastStatus(data: Any) -> DomainLastStatus: return DomainLastStatus(**args) +def unmarshal_ListBlocklistsResponse(data: Any) -> ListBlocklistsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListBlocklistsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + field = data.get("blocklists", None) + if field is not None: + args["blocklists"] = ( + [unmarshal_Blocklist(v) for v in field] if field is not None else None + ) + + return ListBlocklistsResponse(**args) + + def unmarshal_ListDomainsResponse(data: Any) -> ListDomainsResponse: if not isinstance(data, dict): raise TypeError( @@ -805,6 +900,27 @@ def unmarshal_Statistics(data: Any) -> Statistics: return Statistics(**args) +def marshal_BulkCreateBlocklistsRequest( + request: BulkCreateBlocklistsRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.domain_id is not None: + output["domain_id"] = request.domain_id + + if request.emails is not None: + output["emails"] = request.emails + + if request.type_ is not None: + output["type"] = str(request.type_) + + if request.reason is not None: + output["reason"] = request.reason + + return output + + def marshal_CreateDomainRequest( request: CreateDomainRequest, defaults: ProfileDefaults, diff --git a/scaleway-async/scaleway_async/tem/v1alpha1/types.py b/scaleway-async/scaleway_async/tem/v1alpha1/types.py index e0c63211b..be59f2052 100644 --- a/scaleway-async/scaleway_async/tem/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/tem/v1alpha1/types.py @@ -15,6 +15,15 @@ ) +class BlocklistType(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_TYPE = "unknown_type" + MAILBOX_FULL = "mailbox_full" + MAILBOX_NOT_FOUND = "mailbox_not_found" + + def __str__(self) -> str: + return str(self.value) + + class DomainLastStatusAutoconfigStateReason(str, Enum, metaclass=StrEnumMeta): UNKNOWN_REASON = "unknown_reason" PERMISSION_DENIED = "permission_denied" @@ -95,6 +104,16 @@ def __str__(self) -> str: return str(self.value) +class ListBlocklistsRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + CREATED_AT_DESC = "created_at_desc" + CREATED_AT_ASC = "created_at_asc" + ENDS_AT_DESC = "ends_at_desc" + ENDS_AT_ASC = "ends_at_asc" + + def __str__(self) -> str: + return str(self.value) + + class ListEmailsRequestOrderBy(str, Enum, metaclass=StrEnumMeta): CREATED_AT_DESC = "created_at_desc" CREATED_AT_ASC = "created_at_asc" @@ -247,6 +266,54 @@ class DomainStatistics: canceled_count: int +@dataclass +class Blocklist: + id: str + """ + ID of the blocklist. + """ + + domain_id: str + """ + Domain ID linked to the blocklist. + """ + + email: str + """ + Email blocked by the blocklist. + """ + + type_: BlocklistType + """ + Type of block for this email. + """ + + reason: str + """ + Reason to block this email. + """ + + custom: bool + """ + True if this blocklist was created manually. False for an automatic Transactional Email blocklist. + """ + + created_at: Optional[datetime] + """ + Date and time of the blocklist creation. + """ + + updated_at: Optional[datetime] + """ + Date and time of the blocklist's last update. + """ + + ends_at: Optional[datetime] + """ + Date and time when the blocklist ends. Empty if the blocklist has no end. + """ + + @dataclass class CreateEmailRequestAddress: email: str @@ -681,6 +748,42 @@ class UpdateProjectSettingsRequestUpdatePeriodicReport: """ +@dataclass +class BulkCreateBlocklistsRequest: + domain_id: str + """ + Domain ID linked to the blocklist. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + emails: Optional[List[str]] + """ + Email blocked by the blocklist. + """ + + type_: Optional[BlocklistType] + """ + Type of blocklist. + """ + + reason: Optional[str] + """ + Reason to block the email. + """ + + +@dataclass +class BulkCreateBlocklistsResponse: + blocklists: List[Blocklist] + """ + List of blocklist created. + """ + + @dataclass class CancelEmailRequest: email_id: str @@ -839,6 +942,19 @@ class CreateWebhookRequest: """ +@dataclass +class DeleteBlocklistRequest: + blocklist_id: str + """ + ID of the blocklist to delete. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + @dataclass class DeleteWebhookRequest: webhook_id: str @@ -983,6 +1099,62 @@ class GetWebhookRequest: """ +@dataclass +class ListBlocklistsRequest: + domain_id: str + """ + (Optional) Filter by a domain ID. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + order_by: Optional[ListBlocklistsRequestOrderBy] + """ + (Optional) List blocklist corresponding to specific criteria. + """ + + page: Optional[int] + """ + (Optional) Requested page number. Value must be greater or equal to 1. + """ + + page_size: Optional[int] + """ + (Optional) Requested page size. Value must be between 1 and 100. + """ + + email: Optional[str] + """ + (Optional) Filter by an email address. + """ + + type_: Optional[BlocklistType] + """ + (Optional) Filter by a blocklist type. + """ + + custom: Optional[bool] + """ + (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false). + """ + + +@dataclass +class ListBlocklistsResponse: + total_count: int + """ + Number of blocklists matching the requested criteria. + """ + + blocklists: List[Blocklist] + """ + Single page of blocklists matching the requested criteria. + """ + + @dataclass class ListDomainsRequest: region: Optional[Region] diff --git a/scaleway/scaleway/tem/v1alpha1/__init__.py b/scaleway/scaleway/tem/v1alpha1/__init__.py index 59ca17f59..805d56c4a 100644 --- a/scaleway/scaleway/tem/v1alpha1/__init__.py +++ b/scaleway/scaleway/tem/v1alpha1/__init__.py @@ -1,5 +1,6 @@ # This file was automatically generated. DO NOT EDIT. # If you have any remark or suggestion do not hesitate to open an issue. +from .types import BlocklistType from .types import DomainLastStatusAutoconfigStateReason from .types import DomainLastStatusRecordStatus from .types import DomainReputationStatus @@ -9,6 +10,7 @@ from .types import EmailRcptType from .types import EmailStatus from .content import EMAIL_TRANSIENT_STATUSES +from .types import ListBlocklistsRequestOrderBy from .types import ListEmailsRequestOrderBy from .types import ListWebhookEventsRequestOrderBy from .types import ListWebhooksRequestOrderBy @@ -20,6 +22,7 @@ from .types import DomainRecords from .types import DomainReputation from .types import DomainStatistics +from .types import Blocklist from .types import CreateEmailRequestAddress from .types import CreateEmailRequestAttachment from .types import CreateEmailRequestHeader @@ -33,12 +36,15 @@ from .types import Webhook from .types import ProjectSettingsPeriodicReport from .types import UpdateProjectSettingsRequestUpdatePeriodicReport +from .types import BulkCreateBlocklistsRequest +from .types import BulkCreateBlocklistsResponse from .types import CancelEmailRequest from .types import CheckDomainRequest from .types import CreateDomainRequest from .types import CreateEmailRequest from .types import CreateEmailResponse from .types import CreateWebhookRequest +from .types import DeleteBlocklistRequest from .types import DeleteWebhookRequest from .types import DomainLastStatus from .types import GetDomainLastStatusRequest @@ -47,6 +53,8 @@ from .types import GetProjectSettingsRequest from .types import GetStatisticsRequest from .types import GetWebhookRequest +from .types import ListBlocklistsRequest +from .types import ListBlocklistsResponse from .types import ListDomainsRequest from .types import ListDomainsResponse from .types import ListEmailsRequest @@ -64,6 +72,7 @@ from .api import TemV1Alpha1API __all__ = [ + "BlocklistType", "DomainLastStatusAutoconfigStateReason", "DomainLastStatusRecordStatus", "DomainReputationStatus", @@ -73,6 +82,7 @@ "EmailRcptType", "EmailStatus", "EMAIL_TRANSIENT_STATUSES", + "ListBlocklistsRequestOrderBy", "ListEmailsRequestOrderBy", "ListWebhookEventsRequestOrderBy", "ListWebhooksRequestOrderBy", @@ -84,6 +94,7 @@ "DomainRecords", "DomainReputation", "DomainStatistics", + "Blocklist", "CreateEmailRequestAddress", "CreateEmailRequestAttachment", "CreateEmailRequestHeader", @@ -97,12 +108,15 @@ "Webhook", "ProjectSettingsPeriodicReport", "UpdateProjectSettingsRequestUpdatePeriodicReport", + "BulkCreateBlocklistsRequest", + "BulkCreateBlocklistsResponse", "CancelEmailRequest", "CheckDomainRequest", "CreateDomainRequest", "CreateEmailRequest", "CreateEmailResponse", "CreateWebhookRequest", + "DeleteBlocklistRequest", "DeleteWebhookRequest", "DomainLastStatus", "GetDomainLastStatusRequest", @@ -111,6 +125,8 @@ "GetProjectSettingsRequest", "GetStatisticsRequest", "GetWebhookRequest", + "ListBlocklistsRequest", + "ListBlocklistsResponse", "ListDomainsRequest", "ListDomainsResponse", "ListEmailsRequest", diff --git a/scaleway/scaleway/tem/v1alpha1/api.py b/scaleway/scaleway/tem/v1alpha1/api.py index f48e915e9..764fc23f2 100644 --- a/scaleway/scaleway/tem/v1alpha1/api.py +++ b/scaleway/scaleway/tem/v1alpha1/api.py @@ -15,14 +15,19 @@ wait_for_resource, ) from .types import ( + BlocklistType, DomainStatus, EmailFlag, EmailStatus, + ListBlocklistsRequestOrderBy, ListEmailsRequestOrderBy, ListWebhookEventsRequestOrderBy, ListWebhooksRequestOrderBy, WebhookEventStatus, WebhookEventType, + Blocklist, + BulkCreateBlocklistsRequest, + BulkCreateBlocklistsResponse, CreateDomainRequest, CreateEmailRequest, CreateEmailRequestAddress, @@ -33,6 +38,7 @@ Domain, DomainLastStatus, Email, + ListBlocklistsResponse, ListDomainsResponse, ListEmailsResponse, ListWebhookEventsResponse, @@ -54,14 +60,17 @@ unmarshal_Email, unmarshal_Domain, unmarshal_Webhook, + unmarshal_BulkCreateBlocklistsResponse, unmarshal_CreateEmailResponse, unmarshal_DomainLastStatus, + unmarshal_ListBlocklistsResponse, unmarshal_ListDomainsResponse, unmarshal_ListEmailsResponse, unmarshal_ListWebhookEventsResponse, unmarshal_ListWebhooksResponse, unmarshal_ProjectSettings, unmarshal_Statistics, + marshal_BulkCreateBlocklistsRequest, marshal_CreateDomainRequest, marshal_CreateEmailRequest, marshal_CreateWebhookRequest, @@ -1277,3 +1286,187 @@ def update_project_settings( self._throw_on_error(res) return unmarshal_ProjectSettings(res.json()) + + def list_blocklists( + self, + *, + domain_id: str, + region: Optional[Region] = None, + order_by: Optional[ListBlocklistsRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + email: Optional[str] = None, + type_: Optional[BlocklistType] = None, + custom: Optional[bool] = None, + ) -> ListBlocklistsResponse: + """ + List blocklists. + Retrieve the list of blocklists. + :param domain_id: (Optional) Filter by a domain ID. + :param region: Region to target. If none is passed will use default region from the config. + :param order_by: (Optional) List blocklist corresponding to specific criteria. + :param page: (Optional) Requested page number. Value must be greater or equal to 1. + :param page_size: (Optional) Requested page size. Value must be between 1 and 100. + :param email: (Optional) Filter by an email address. + :param type_: (Optional) Filter by a blocklist type. + :param custom: (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false). + :return: :class:`ListBlocklistsResponse ` + + Usage: + :: + + result = api.list_blocklists( + domain_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/transactional-email/v1alpha1/regions/{param_region}/blocklists", + params={ + "custom": custom, + "domain_id": domain_id, + "email": email, + "order_by": order_by, + "page": page, + "page_size": page_size or self.client.default_page_size, + "type": type_, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListBlocklistsResponse(res.json()) + + def list_blocklists_all( + self, + *, + domain_id: str, + region: Optional[Region] = None, + order_by: Optional[ListBlocklistsRequestOrderBy] = None, + page: Optional[int] = None, + page_size: Optional[int] = None, + email: Optional[str] = None, + type_: Optional[BlocklistType] = None, + custom: Optional[bool] = None, + ) -> List[Blocklist]: + """ + List blocklists. + Retrieve the list of blocklists. + :param domain_id: (Optional) Filter by a domain ID. + :param region: Region to target. If none is passed will use default region from the config. + :param order_by: (Optional) List blocklist corresponding to specific criteria. + :param page: (Optional) Requested page number. Value must be greater or equal to 1. + :param page_size: (Optional) Requested page size. Value must be between 1 and 100. + :param email: (Optional) Filter by an email address. + :param type_: (Optional) Filter by a blocklist type. + :param custom: (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false). + :return: :class:`List[Blocklist] ` + + Usage: + :: + + result = api.list_blocklists_all( + domain_id="example", + ) + """ + + return fetch_all_pages( + type=ListBlocklistsResponse, + key="blocklists", + fetcher=self.list_blocklists, + args={ + "domain_id": domain_id, + "region": region, + "order_by": order_by, + "page": page, + "page_size": page_size, + "email": email, + "type_": type_, + "custom": custom, + }, + ) + + def bulk_create_blocklists( + self, + *, + domain_id: str, + region: Optional[Region] = None, + emails: Optional[List[str]] = None, + type_: Optional[BlocklistType] = None, + reason: Optional[str] = None, + ) -> BulkCreateBlocklistsResponse: + """ + Bulk create blocklists. + Create multiple blocklists in a specific Project or Organization using the `region` parameter. + :param domain_id: Domain ID linked to the blocklist. + :param region: Region to target. If none is passed will use default region from the config. + :param emails: Email blocked by the blocklist. + :param type_: Type of blocklist. + :param reason: Reason to block the email. + :return: :class:`BulkCreateBlocklistsResponse ` + + Usage: + :: + + result = api.bulk_create_blocklists( + domain_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "POST", + f"/transactional-email/v1alpha1/regions/{param_region}/blocklists", + body=marshal_BulkCreateBlocklistsRequest( + BulkCreateBlocklistsRequest( + domain_id=domain_id, + region=region, + emails=emails, + type_=type_, + reason=reason, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_BulkCreateBlocklistsResponse(res.json()) + + def delete_blocklist( + self, + *, + blocklist_id: str, + region: Optional[Region] = None, + ) -> None: + """ + Delete a blocklist. + You must specify the blocklist you want to delete by the `region` and `blocklist_id`. + :param blocklist_id: ID of the blocklist to delete. + :param region: Region to target. If none is passed will use default region from the config. + + Usage: + :: + + result = api.delete_blocklist( + blocklist_id="example", + ) + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + param_blocklist_id = validate_path_param("blocklist_id", blocklist_id) + + res = self._request( + "DELETE", + f"/transactional-email/v1alpha1/regions/{param_region}/blocklists/{param_blocklist_id}", + ) + + self._throw_on_error(res) diff --git a/scaleway/scaleway/tem/v1alpha1/marshalling.py b/scaleway/scaleway/tem/v1alpha1/marshalling.py index 4d225341a..9d454d9d4 100644 --- a/scaleway/scaleway/tem/v1alpha1/marshalling.py +++ b/scaleway/scaleway/tem/v1alpha1/marshalling.py @@ -16,12 +16,15 @@ DomainStatistics, Domain, Webhook, + Blocklist, + BulkCreateBlocklistsResponse, CreateEmailResponse, DomainLastStatusAutoconfigState, DomainLastStatusDkimRecord, DomainLastStatusDmarcRecord, DomainLastStatusSpfRecord, DomainLastStatus, + ListBlocklistsResponse, ListDomainsResponse, ListEmailsResponse, WebhookEvent, @@ -30,6 +33,7 @@ ProjectSettingsPeriodicReport, ProjectSettings, Statistics, + BulkCreateBlocklistsRequest, CreateDomainRequest, CreateEmailRequestAddress, CreateEmailRequestAttachment, @@ -407,6 +411,76 @@ def unmarshal_Webhook(data: Any) -> Webhook: return Webhook(**args) +def unmarshal_Blocklist(data: Any) -> Blocklist: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Blocklist' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("domain_id", None) + if field is not None: + args["domain_id"] = field + + field = data.get("email", None) + if field is not None: + args["email"] = field + + field = data.get("type", None) + if field is not None: + args["type_"] = field + + field = data.get("reason", None) + if field is not None: + args["reason"] = field + + field = data.get("custom", None) + if field is not None: + args["custom"] = field + + field = data.get("created_at", None) + if field is not None: + args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["created_at"] = None + + field = data.get("updated_at", None) + if field is not None: + args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["updated_at"] = None + + field = data.get("ends_at", None) + if field is not None: + args["ends_at"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["ends_at"] = None + + return Blocklist(**args) + + +def unmarshal_BulkCreateBlocklistsResponse(data: Any) -> BulkCreateBlocklistsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'BulkCreateBlocklistsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("blocklists", None) + if field is not None: + args["blocklists"] = ( + [unmarshal_Blocklist(v) for v in field] if field is not None else None + ) + + return BulkCreateBlocklistsResponse(**args) + + def unmarshal_CreateEmailResponse(data: Any) -> CreateEmailResponse: if not isinstance(data, dict): raise TypeError( @@ -581,6 +655,27 @@ def unmarshal_DomainLastStatus(data: Any) -> DomainLastStatus: return DomainLastStatus(**args) +def unmarshal_ListBlocklistsResponse(data: Any) -> ListBlocklistsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListBlocklistsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("total_count", None) + if field is not None: + args["total_count"] = field + + field = data.get("blocklists", None) + if field is not None: + args["blocklists"] = ( + [unmarshal_Blocklist(v) for v in field] if field is not None else None + ) + + return ListBlocklistsResponse(**args) + + def unmarshal_ListDomainsResponse(data: Any) -> ListDomainsResponse: if not isinstance(data, dict): raise TypeError( @@ -805,6 +900,27 @@ def unmarshal_Statistics(data: Any) -> Statistics: return Statistics(**args) +def marshal_BulkCreateBlocklistsRequest( + request: BulkCreateBlocklistsRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.domain_id is not None: + output["domain_id"] = request.domain_id + + if request.emails is not None: + output["emails"] = request.emails + + if request.type_ is not None: + output["type"] = str(request.type_) + + if request.reason is not None: + output["reason"] = request.reason + + return output + + def marshal_CreateDomainRequest( request: CreateDomainRequest, defaults: ProfileDefaults, diff --git a/scaleway/scaleway/tem/v1alpha1/types.py b/scaleway/scaleway/tem/v1alpha1/types.py index e0c63211b..be59f2052 100644 --- a/scaleway/scaleway/tem/v1alpha1/types.py +++ b/scaleway/scaleway/tem/v1alpha1/types.py @@ -15,6 +15,15 @@ ) +class BlocklistType(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_TYPE = "unknown_type" + MAILBOX_FULL = "mailbox_full" + MAILBOX_NOT_FOUND = "mailbox_not_found" + + def __str__(self) -> str: + return str(self.value) + + class DomainLastStatusAutoconfigStateReason(str, Enum, metaclass=StrEnumMeta): UNKNOWN_REASON = "unknown_reason" PERMISSION_DENIED = "permission_denied" @@ -95,6 +104,16 @@ def __str__(self) -> str: return str(self.value) +class ListBlocklistsRequestOrderBy(str, Enum, metaclass=StrEnumMeta): + CREATED_AT_DESC = "created_at_desc" + CREATED_AT_ASC = "created_at_asc" + ENDS_AT_DESC = "ends_at_desc" + ENDS_AT_ASC = "ends_at_asc" + + def __str__(self) -> str: + return str(self.value) + + class ListEmailsRequestOrderBy(str, Enum, metaclass=StrEnumMeta): CREATED_AT_DESC = "created_at_desc" CREATED_AT_ASC = "created_at_asc" @@ -247,6 +266,54 @@ class DomainStatistics: canceled_count: int +@dataclass +class Blocklist: + id: str + """ + ID of the blocklist. + """ + + domain_id: str + """ + Domain ID linked to the blocklist. + """ + + email: str + """ + Email blocked by the blocklist. + """ + + type_: BlocklistType + """ + Type of block for this email. + """ + + reason: str + """ + Reason to block this email. + """ + + custom: bool + """ + True if this blocklist was created manually. False for an automatic Transactional Email blocklist. + """ + + created_at: Optional[datetime] + """ + Date and time of the blocklist creation. + """ + + updated_at: Optional[datetime] + """ + Date and time of the blocklist's last update. + """ + + ends_at: Optional[datetime] + """ + Date and time when the blocklist ends. Empty if the blocklist has no end. + """ + + @dataclass class CreateEmailRequestAddress: email: str @@ -681,6 +748,42 @@ class UpdateProjectSettingsRequestUpdatePeriodicReport: """ +@dataclass +class BulkCreateBlocklistsRequest: + domain_id: str + """ + Domain ID linked to the blocklist. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + emails: Optional[List[str]] + """ + Email blocked by the blocklist. + """ + + type_: Optional[BlocklistType] + """ + Type of blocklist. + """ + + reason: Optional[str] + """ + Reason to block the email. + """ + + +@dataclass +class BulkCreateBlocklistsResponse: + blocklists: List[Blocklist] + """ + List of blocklist created. + """ + + @dataclass class CancelEmailRequest: email_id: str @@ -839,6 +942,19 @@ class CreateWebhookRequest: """ +@dataclass +class DeleteBlocklistRequest: + blocklist_id: str + """ + ID of the blocklist to delete. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + @dataclass class DeleteWebhookRequest: webhook_id: str @@ -983,6 +1099,62 @@ class GetWebhookRequest: """ +@dataclass +class ListBlocklistsRequest: + domain_id: str + """ + (Optional) Filter by a domain ID. + """ + + region: Optional[Region] + """ + Region to target. If none is passed will use default region from the config. + """ + + order_by: Optional[ListBlocklistsRequestOrderBy] + """ + (Optional) List blocklist corresponding to specific criteria. + """ + + page: Optional[int] + """ + (Optional) Requested page number. Value must be greater or equal to 1. + """ + + page_size: Optional[int] + """ + (Optional) Requested page size. Value must be between 1 and 100. + """ + + email: Optional[str] + """ + (Optional) Filter by an email address. + """ + + type_: Optional[BlocklistType] + """ + (Optional) Filter by a blocklist type. + """ + + custom: Optional[bool] + """ + (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false). + """ + + +@dataclass +class ListBlocklistsResponse: + total_count: int + """ + Number of blocklists matching the requested criteria. + """ + + blocklists: List[Blocklist] + """ + Single page of blocklists matching the requested criteria. + """ + + @dataclass class ListDomainsRequest: region: Optional[Region]