Skip to content

Commit

Permalink
feat(tem): add support for webhook (#4004)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <[email protected]>
  • Loading branch information
scaleway-bot and remyleone authored Jul 25, 2024
1 parent c3cb877 commit ac08142
Show file tree
Hide file tree
Showing 11 changed files with 610 additions and 6 deletions.
23 changes: 23 additions & 0 deletions cmd/scw/testdata/test-all-usage-tem-webhook-create-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Create a new Webhook triggered by a list of event types and pushed to a Scaleway SNS ARN.

USAGE:
scw tem webhook create [arg=value ...]

ARGS:
[domain-id] ID of the Domain to watch for triggering events
[project-id] Project ID to use. If none is passed the default project ID will be used
[name] Name of the Webhook
[event-types.{index}] List of event types that will trigger an event (unknown_type | email_queued | email_dropped | email_deferred | email_delivered | email_spam | email_mailbox_not_found)
[sns-arn] Scaleway SNS ARN topic to push the events to
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for create

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
19 changes: 19 additions & 0 deletions cmd/scw/testdata/test-all-usage-tem-webhook-delete-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
You must specify the Webhook you want to delete by the `region` and `webhook_id`. Deleting a Webhook is permanent and cannot be undone.

USAGE:
scw tem webhook delete <webhook-id ...> [arg=value ...]

ARGS:
webhook-id ID of the Webhook to delete
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for delete

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
19 changes: 19 additions & 0 deletions cmd/scw/testdata/test-all-usage-tem-webhook-get-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve information about a specific Webhook using the `webhook_id` and `region` parameters.

USAGE:
scw tem webhook get <webhook-id ...> [arg=value ...]

ARGS:
webhook-id ID of the Webhook to check
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for get

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve the list of Webhook events triggered from a specific Webhook or for a specific Project or Organization. You must specify the `region`.

USAGE:
scw tem webhook list-events [arg=value ...]

ARGS:
[order-by] (Optional) List Webhook events corresponding to specific criteria (created_at_desc | created_at_asc)
webhook-id ID of the Webhook linked to the events
[email-id] ID of the email linked to the events
[event-types.{index}] List of event types linked to the events (unknown_type | email_queued | email_dropped | email_deferred | email_delivered | email_spam | email_mailbox_not_found)
[statuses.{index}] List of event statuses (unknown_status | sending | sent | failed)
[project-id] ID of the webhook Project
[domain-id] ID of the domain to watch for triggering events
[organization-id] ID of the webhook Organization
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | all)

FLAGS:
-h, --help help for list-events

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
22 changes: 22 additions & 0 deletions cmd/scw/testdata/test-all-usage-tem-webhook-list-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Retrieve Webhooks in a specific Project or in a specific Organization using the `region` parameter.

USAGE:
scw tem webhook list [arg=value ...]

ARGS:
[order-by] (Optional) List Webhooks corresponding to specific criteria (created_at_desc | created_at_asc)
[project-id] (Optional) ID of the Project for which to list the Webhooks
[domain-id] (Optional) ID of the Domain for which to list the Webhooks
[organization-id] (Optional) ID of the Organization for which to list the Webhooks
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | all)

FLAGS:
-h, --help help for list

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
22 changes: 22 additions & 0 deletions cmd/scw/testdata/test-all-usage-tem-webhook-update-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Update a Webhook events type, SNS ARN or name.

USAGE:
scw tem webhook update [arg=value ...]

ARGS:
webhook-id ID of the Webhook to update
[name] Name of the Webhook to update
[event-types.{index}] List of event types to update (unknown_type | email_queued | email_dropped | email_deferred | email_delivered | email_spam | email_mailbox_not_found)
[sns-arn] Scaleway SNS ARN topic to update
[region=fr-par] Region to target. If none is passed will use default region from the config (fr-par)

FLAGS:
-h, --help help for update

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use
12 changes: 11 additions & 1 deletion cmd/scw/testdata/test-all-usage-tem-webhook-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
Webhooks enable real-time communication and automation between systems by sending messages through all protocols supported by SNS, such as HTTP, HTTPS, and Serverless Functions, allowing for immediate updates and actions based on specific events. This feature is in beta. You can request quotas from the [Scaleway betas page](https://www.scaleway.com/fr/betas/#email-webhooks).

USAGE:
scw tem webhook
scw tem webhook <command>

AVAILABLE COMMANDS:
create Create a Webhook
delete Delete a Webhook
get Get information about a Webhook
list List Webhooks
list-events List Webhook triggered events
update Update a Webhook

FLAGS:
-h, --help help for webhook
Expand All @@ -13,3 +21,5 @@ GLOBAL FLAGS:
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw tem webhook [command] --help" for more information about a command.
138 changes: 136 additions & 2 deletions docs/commands/tem.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ This API allows you to manage your Transactional Email services.
- [Email statuses](#email-statuses)
- [List emails](#list-emails)
- [Webhook management commands](#webhook-management-commands)
- [Create a Webhook](#create-a-webhook)
- [Delete a Webhook](#delete-a-webhook)
- [Get information about a Webhook](#get-information-about-a-webhook)
- [List Webhooks](#list-webhooks)
- [List Webhook triggered events](#list-webhook-triggered-events)
- [Update a Webhook](#update-a-webhook)


## Domain management commands
Expand Down Expand Up @@ -290,13 +296,141 @@ scw tem email list [arg=value ...]

Webhooks enable real-time communication and automation between systems by sending messages through all protocols supported by SNS, such as HTTP, HTTPS, and Serverless Functions, allowing for immediate updates and actions based on specific events. This feature is in beta. You can request quotas from the [Scaleway betas page](https://www.scaleway.com/fr/betas/#email-webhooks).

Webhooks enable real-time communication and automation between systems by sending messages through all protocols supported by SNS, such as HTTP, HTTPS, and Serverless Functions, allowing for immediate updates and actions based on specific events. This feature is in beta. You can request quotas from the [Scaleway betas page](https://www.scaleway.com/fr/betas/#email-webhooks).

### Create a Webhook

Create a new Webhook triggered by a list of event types and pushed to a Scaleway SNS ARN.

**Usage:**

```
scw tem webhook create [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| domain-id | | ID of the Domain to watch for triggering events |
| project-id | | Project ID to use. If none is passed the default project ID will be used |
| name | | Name of the Webhook |
| event-types.{index} | One of: `unknown_type`, `email_queued`, `email_dropped`, `email_deferred`, `email_delivered`, `email_spam`, `email_mailbox_not_found` | List of event types that will trigger an event |
| sns-arn | | Scaleway SNS ARN topic to push the events to |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### Delete a Webhook

You must specify the Webhook you want to delete by the `region` and `webhook_id`. Deleting a Webhook is permanent and cannot be undone.

**Usage:**

```
scw tem webhook delete <webhook-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| webhook-id | Required | ID of the Webhook to delete |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### Get information about a Webhook

Retrieve information about a specific Webhook using the `webhook_id` and `region` parameters.

**Usage:**

```
scw tem webhook
scw tem webhook get <webhook-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| webhook-id | Required | ID of the Webhook to check |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



### List Webhooks

Retrieve Webhooks in a specific Project or in a specific Organization using the `region` parameter.

**Usage:**

```
scw tem webhook list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| order-by | One of: `created_at_desc`, `created_at_asc` | (Optional) List Webhooks corresponding to specific criteria |
| project-id | | (Optional) ID of the Project for which to list the Webhooks |
| domain-id | | (Optional) ID of the Domain for which to list the Webhooks |
| organization-id | | (Optional) ID of the Organization for which to list the Webhooks |
| region | Default: `fr-par`<br />One of: `fr-par`, `all` | Region to target. If none is passed will use default region from the config |



### List Webhook triggered events

Retrieve the list of Webhook events triggered from a specific Webhook or for a specific Project or Organization. You must specify the `region`.

**Usage:**

```
scw tem webhook list-events [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| order-by | One of: `created_at_desc`, `created_at_asc` | (Optional) List Webhook events corresponding to specific criteria |
| webhook-id | Required | ID of the Webhook linked to the events |
| email-id | | ID of the email linked to the events |
| event-types.{index} | One of: `unknown_type`, `email_queued`, `email_dropped`, `email_deferred`, `email_delivered`, `email_spam`, `email_mailbox_not_found` | List of event types linked to the events |
| statuses.{index} | One of: `unknown_status`, `sending`, `sent`, `failed` | List of event statuses |
| project-id | | ID of the webhook Project |
| domain-id | | ID of the domain to watch for triggering events |
| organization-id | | ID of the webhook Organization |
| region | Default: `fr-par`<br />One of: `fr-par`, `all` | Region to target. If none is passed will use default region from the config |



### Update a Webhook

Update a Webhook events type, SNS ARN or name.

**Usage:**

```
scw tem webhook update [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| webhook-id | Required | ID of the Webhook to update |
| name | | Name of the Webhook to update |
| event-types.{index} | One of: `unknown_type`, `email_queued`, `email_dropped`, `email_deferred`, `email_delivered`, `email_spam`, `email_mailbox_not_found` | List of event types to update |
| sns-arn | | Scaleway SNS ARN topic to update |
| region | Default: `fr-par`<br />One of: `fr-par` | Region to target. If none is passed will use default region from the config |



2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/moby/buildkit v0.13.2
github.com/opencontainers/go-digest v1.0.0
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240723092404-648ea2801f9f
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240725041911-1cd5fcfaf214
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240723092404-648ea2801f9f h1:xNv7pVCmf+8RmlAnALEeSNS6oGI4DFPAHt+19xY1oa8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240723092404-648ea2801f9f/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240725041911-1cd5fcfaf214 h1:OvbLG2G2BmPcxjarPKe/6dC17INl7SSr6q8f11tT0ho=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.29.0.20240725041911-1cd5fcfaf214/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=
Expand Down
Loading

0 comments on commit ac08142

Please sign in to comment.