Skip to content

Commit

Permalink
feat: add webhook secret support for webhook alert channels [sc-22462] (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
sorccu authored Nov 28, 2024
1 parent 77a3ab0 commit 43bf5ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ export const webhookChannel = new WebhookAlertChannel('webhook-channel-1', {
}`,
...sendDefaults,
})

export const webhookChannelWithSecret = new WebhookAlertChannel('webhook-channel-with-secret', {
name: 'Pushover webhook w/ secret',
method: 'POST',
url: new URL('https://webhook.site/ddead495-8b15-4b0d-a25d-f6cda4144dc7'),
template: `{
"token":"FILL_IN_YOUR_SECRET_TOKEN_FROM_PUSHOVER",
"user":"FILL_IN_YOUR_USER_FROM_PUSHOVER",
"title":"{{ALERT_TITLE}}",
"html":1,
"priority":2,
"retry":30,
"expire":10800,
"message":"{{ALERT_TYPE}} {{STARTED_AT}} ({{RESPONSE_TIME}}ms) {{RESULT_LINK}}"
}`,
webhookSecret: 'hunter2',
...sendDefaults,
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { ApiCheck, AssertionBuilder } from 'checkly/constructs'
import { slackChannel, webhookChannel } from '../../alert-channels'
import { slackChannel, webhookChannel, webhookChannelWithSecret } from '../../alert-channels'

const apiCheck = new ApiCheck('homepage-api-check-1', {
name: 'Runtimes',
alertChannels: [slackChannel, webhookChannel],
alertChannels: [
slackChannel,
webhookChannel,
webhookChannelWithSecret,
],
degradedResponseTime: 10000,
maxResponseTime: 20000,
request: {
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/constructs/webhook-alert-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export interface WebhookAlertChannelProps extends AlertChannelProps {
* Key-value elements array with the query parameters to include in the URL for the webhook HTTP request.
*/
queryParameters?: Array<QueryParam>
/**
* An optional value to use as the
* {@link https://www.checklyhq.com/docs/alerting-and-retries/webhooks/#webhook-secrets secret for the webhook}.
*
* You may specify any value that meets your security criteria.
*/
webhookSecret?: string
}

/**
Expand All @@ -49,6 +56,7 @@ export class WebhookAlertChannel extends AlertChannel {
method?: HttpRequestMethod
headers?: Array<HttpHeader>
queryParameters?: Array<QueryParam>
webhookSecret?: string
/**
* Constructs the Webhook Alert Channel instance
*
Expand All @@ -66,6 +74,7 @@ export class WebhookAlertChannel extends AlertChannel {
this.method = props.method
this.headers = props.headers
this.queryParameters = props.queryParameters
this.webhookSecret = props.webhookSecret
Session.registerConstruct(this)
}

Expand All @@ -81,6 +90,7 @@ export class WebhookAlertChannel extends AlertChannel {
method: this.method,
headers: this.headers,
queryParameters: this.queryParameters,
webhookSecret: this.webhookSecret,
},
}
}
Expand Down

0 comments on commit 43bf5ac

Please sign in to comment.