Skip to content

Commit 43bf5ac

Browse files
authored
feat: add webhook secret support for webhook alert channels [sc-22462] (#985)
* feat: add webhook secret support for webhook alert channels * feat: use webhook secret in e2e tests Hardly a true test for whether the secret really gets set or not, but it's in line with the current tests.
1 parent 77a3ab0 commit 43bf5ac

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

packages/cli/e2e/__tests__/fixtures/test-project/src/alert-channels.ts

+18
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,21 @@ export const webhookChannel = new WebhookAlertChannel('webhook-channel-1', {
4646
}`,
4747
...sendDefaults,
4848
})
49+
50+
export const webhookChannelWithSecret = new WebhookAlertChannel('webhook-channel-with-secret', {
51+
name: 'Pushover webhook w/ secret',
52+
method: 'POST',
53+
url: new URL('https://webhook.site/ddead495-8b15-4b0d-a25d-f6cda4144dc7'),
54+
template: `{
55+
"token":"FILL_IN_YOUR_SECRET_TOKEN_FROM_PUSHOVER",
56+
"user":"FILL_IN_YOUR_USER_FROM_PUSHOVER",
57+
"title":"{{ALERT_TITLE}}",
58+
"html":1,
59+
"priority":2,
60+
"retry":30,
61+
"expire":10800,
62+
"message":"{{ALERT_TYPE}} {{STARTED_AT}} ({{RESPONSE_TIME}}ms) {{RESULT_LINK}}"
63+
}`,
64+
webhookSecret: 'hunter2',
65+
...sendDefaults,
66+
})

packages/cli/e2e/__tests__/fixtures/test-project/src/services/api/api.check.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { ApiCheck, AssertionBuilder } from 'checkly/constructs'
2-
import { slackChannel, webhookChannel } from '../../alert-channels'
2+
import { slackChannel, webhookChannel, webhookChannelWithSecret } from '../../alert-channels'
33

44
const apiCheck = new ApiCheck('homepage-api-check-1', {
55
name: 'Runtimes',
6-
alertChannels: [slackChannel, webhookChannel],
6+
alertChannels: [
7+
slackChannel,
8+
webhookChannel,
9+
webhookChannelWithSecret,
10+
],
711
degradedResponseTime: 10000,
812
maxResponseTime: 20000,
913
request: {

packages/cli/src/constructs/webhook-alert-channel.ts

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ export interface WebhookAlertChannelProps extends AlertChannelProps {
3232
* Key-value elements array with the query parameters to include in the URL for the webhook HTTP request.
3333
*/
3434
queryParameters?: Array<QueryParam>
35+
/**
36+
* An optional value to use as the
37+
* {@link https://www.checklyhq.com/docs/alerting-and-retries/webhooks/#webhook-secrets secret for the webhook}.
38+
*
39+
* You may specify any value that meets your security criteria.
40+
*/
41+
webhookSecret?: string
3542
}
3643

3744
/**
@@ -49,6 +56,7 @@ export class WebhookAlertChannel extends AlertChannel {
4956
method?: HttpRequestMethod
5057
headers?: Array<HttpHeader>
5158
queryParameters?: Array<QueryParam>
59+
webhookSecret?: string
5260
/**
5361
* Constructs the Webhook Alert Channel instance
5462
*
@@ -66,6 +74,7 @@ export class WebhookAlertChannel extends AlertChannel {
6674
this.method = props.method
6775
this.headers = props.headers
6876
this.queryParameters = props.queryParameters
77+
this.webhookSecret = props.webhookSecret
6978
Session.registerConstruct(this)
7079
}
7180

@@ -81,6 +90,7 @@ export class WebhookAlertChannel extends AlertChannel {
8190
method: this.method,
8291
headers: this.headers,
8392
queryParameters: this.queryParameters,
93+
webhookSecret: this.webhookSecret,
8494
},
8595
}
8696
}

0 commit comments

Comments
 (0)