Skip to content

feat(tem): read update delete webhook(s) #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scaleway-async/scaleway_async/tem/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from .types import EmailStatus
from .content import EMAIL_TRANSIENT_STATUSES
from .types import ListEmailsRequestOrderBy
from .types import ListWebhookEventsRequestOrderBy
from .types import ListWebhooksRequestOrderBy
from .types import WebhookEventStatus
from .types import WebhookEventType
from .types import DomainRecordsDMARC
from .types import EmailTry
from .types import DomainRecords
Expand All @@ -22,11 +26,14 @@
from .types import DomainLastStatusDmarcRecord
from .types import DomainLastStatusSpfRecord
from .types import Domain
from .types import WebhookEvent
from .types import Webhook
from .types import CancelEmailRequest
from .types import CheckDomainRequest
from .types import CreateDomainRequest
from .types import CreateEmailRequest
from .types import CreateEmailResponse
from .types import DeleteWebhookRequest
from .types import DomainLastStatus
from .types import GetDomainLastStatusRequest
from .types import GetDomainRequest
Expand All @@ -36,8 +43,13 @@
from .types import ListDomainsResponse
from .types import ListEmailsRequest
from .types import ListEmailsResponse
from .types import ListWebhookEventsRequest
from .types import ListWebhookEventsResponse
from .types import ListWebhooksRequest
from .types import ListWebhooksResponse
from .types import RevokeDomainRequest
from .types import Statistics
from .types import UpdateWebhookRequest
from .api import TemV1Alpha1API

__all__ = [
Expand All @@ -50,6 +62,10 @@
"EmailStatus",
"EMAIL_TRANSIENT_STATUSES",
"ListEmailsRequestOrderBy",
"ListWebhookEventsRequestOrderBy",
"ListWebhooksRequestOrderBy",
"WebhookEventStatus",
"WebhookEventType",
"DomainRecordsDMARC",
"EmailTry",
"DomainRecords",
Expand All @@ -63,11 +79,14 @@
"DomainLastStatusDmarcRecord",
"DomainLastStatusSpfRecord",
"Domain",
"WebhookEvent",
"Webhook",
"CancelEmailRequest",
"CheckDomainRequest",
"CreateDomainRequest",
"CreateEmailRequest",
"CreateEmailResponse",
"DeleteWebhookRequest",
"DomainLastStatus",
"GetDomainLastStatusRequest",
"GetDomainRequest",
Expand All @@ -77,7 +96,12 @@
"ListDomainsResponse",
"ListEmailsRequest",
"ListEmailsResponse",
"ListWebhookEventsRequest",
"ListWebhookEventsResponse",
"ListWebhooksRequest",
"ListWebhooksResponse",
"RevokeDomainRequest",
"Statistics",
"UpdateWebhookRequest",
"TemV1Alpha1API",
]
255 changes: 255 additions & 0 deletions scaleway-async/scaleway_async/tem/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
EmailFlag,
EmailStatus,
ListEmailsRequestOrderBy,
ListWebhookEventsRequestOrderBy,
ListWebhooksRequestOrderBy,
WebhookEventType,
CreateDomainRequest,
CreateEmailRequest,
CreateEmailRequestAddress,
Expand All @@ -30,7 +33,12 @@
Email,
ListDomainsResponse,
ListEmailsResponse,
ListWebhookEventsResponse,
ListWebhooksResponse,
Statistics,
UpdateWebhookRequest,
Webhook,
WebhookEvent,
)
from .content import (
DOMAIN_TRANSIENT_STATUSES,
Expand All @@ -39,13 +47,17 @@
from .marshalling import (
unmarshal_Email,
unmarshal_Domain,
unmarshal_Webhook,
unmarshal_CreateEmailResponse,
unmarshal_DomainLastStatus,
unmarshal_ListDomainsResponse,
unmarshal_ListEmailsResponse,
unmarshal_ListWebhookEventsResponse,
unmarshal_ListWebhooksResponse,
unmarshal_Statistics,
marshal_CreateDomainRequest,
marshal_CreateEmailRequest,
marshal_UpdateWebhookRequest,
)


Expand Down Expand Up @@ -740,3 +752,246 @@ async def get_domain_last_status(

self._throw_on_error(res)
return unmarshal_DomainLastStatus(res.json())

async def list_webhooks(
self,
*,
region: Optional[Region] = None,
order_by: Optional[ListWebhooksRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
) -> ListWebhooksResponse:
"""
:param region: Region to target. If none is passed will use default region from the config.
:param order_by: (Optional) List Webhooks 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 project_id: (Optional) ID of the Project for which to list the Webhooks.
:param organization_id: (Optional) ID of the Organization for which to list the Webhooks.
:return: :class:`ListWebhooksResponse <ListWebhooksResponse>`

Usage:
::

result = await api.list_webhooks()
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)

res = self._request(
"GET",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks",
params={
"order_by": order_by,
"organization_id": organization_id
or self.client.default_organization_id,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
},
)

self._throw_on_error(res)
return unmarshal_ListWebhooksResponse(res.json())

async def list_webhooks_all(
self,
*,
region: Optional[Region] = None,
order_by: Optional[ListWebhooksRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
project_id: Optional[str] = None,
organization_id: Optional[str] = None,
) -> List[Webhook]:
"""
:param region: Region to target. If none is passed will use default region from the config.
:param order_by: (Optional) List Webhooks 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 project_id: (Optional) ID of the Project for which to list the Webhooks.
:param organization_id: (Optional) ID of the Organization for which to list the Webhooks.
:return: :class:`List[Webhook] <List[Webhook]>`

Usage:
::

result = await api.list_webhooks_all()
"""

return await fetch_all_pages_async(
type=ListWebhooksResponse,
key="webhooks",
fetcher=self.list_webhooks,
args={
"region": region,
"order_by": order_by,
"page": page,
"page_size": page_size,
"project_id": project_id,
"organization_id": organization_id,
},
)

async def update_webhook(
self,
*,
webhook_id: str,
region: Optional[Region] = None,
name: Optional[str] = None,
event_types: Optional[List[WebhookEventType]] = None,
sns_arn: Optional[str] = None,
) -> Webhook:
"""
:param webhook_id: ID of the Webhook to update.
:param region: Region to target. If none is passed will use default region from the config.
:param name: Name of the Webhook to update.
:param event_types: List of event types to update.
:param sns_arn: Scaleway SNS ARN topic to update.
:return: :class:`Webhook <Webhook>`

Usage:
::

result = await api.update_webhook(
webhook_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_webhook_id = validate_path_param("webhook_id", webhook_id)

res = self._request(
"PATCH",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
body=marshal_UpdateWebhookRequest(
UpdateWebhookRequest(
webhook_id=webhook_id,
region=region,
name=name,
event_types=event_types,
sns_arn=sns_arn,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Webhook(res.json())

async def delete_webhook(
self,
*,
webhook_id: str,
region: Optional[Region] = None,
) -> None:
"""
:param webhook_id: ID of the Webhook to delete.
:param region: Region to target. If none is passed will use default region from the config.

Usage:
::

result = await api.delete_webhook(
webhook_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_webhook_id = validate_path_param("webhook_id", webhook_id)

res = self._request(
"DELETE",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}",
)

self._throw_on_error(res)

async def list_webhook_events(
self,
*,
webhook_id: str,
region: Optional[Region] = None,
order_by: Optional[ListWebhookEventsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> ListWebhookEventsResponse:
"""
:param webhook_id: ID of the Webhook linked to the events.
:param region: Region to target. If none is passed will use default region from the config.
:param order_by: (Optional) List Webhook events corresponding to specific criteria.
:param page: Requested page number. Value must be greater or equal to 1.
:param page_size: Requested page size. Value must be between 1 and 100.
:return: :class:`ListWebhookEventsResponse <ListWebhookEventsResponse>`

Usage:
::

result = await api.list_webhook_events(
webhook_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_webhook_id = validate_path_param("webhook_id", webhook_id)

res = self._request(
"GET",
f"/transactional-email/v1alpha1/regions/{param_region}/webhooks/{param_webhook_id}/events",
params={
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
},
)

self._throw_on_error(res)
return unmarshal_ListWebhookEventsResponse(res.json())

async def list_webhook_events_all(
self,
*,
webhook_id: str,
region: Optional[Region] = None,
order_by: Optional[ListWebhookEventsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
) -> List[WebhookEvent]:
"""
:param webhook_id: ID of the Webhook linked to the events.
:param region: Region to target. If none is passed will use default region from the config.
:param order_by: (Optional) List Webhook events corresponding to specific criteria.
:param page: Requested page number. Value must be greater or equal to 1.
:param page_size: Requested page size. Value must be between 1 and 100.
:return: :class:`List[WebhookEvent] <List[WebhookEvent]>`

Usage:
::

result = await api.list_webhook_events_all(
webhook_id="example",
)
"""

return await fetch_all_pages_async(
type=ListWebhookEventsResponse,
key="webhook_events",
fetcher=self.list_webhook_events,
args={
"webhook_id": webhook_id,
"region": region,
"order_by": order_by,
"page": page,
"page_size": page_size,
},
)
Loading