Skip to content

Commit

Permalink
Merge pull request #15 from uploadcare/feat/webhook-signing-secret
Browse files Browse the repository at this point in the history
Webhook signing secret
  • Loading branch information
zaa authored Dec 4, 2021
2 parents 3970610 + 8935dd5 commit 8bc80c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/testenv/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Artifacts struct {
Files []*file.Info
GroupIDs []string
ConversionJobs []conversion.Job
WebhookID int64
Webhook webhook.Info
}

// NewRunner returns new Runner instance
Expand Down
19 changes: 12 additions & 7 deletions test/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

var (
webhookURL string
webhookURLSuffix int
webhookURL string
webhookSignSecret string
webhookURLSuffix int
)

func init() {
Expand All @@ -26,6 +27,7 @@ func init() {
"https://google.com/webhook_endpoint%d",
webhookURLSuffix,
)
webhookSignSecret = "new_signing_secret"
}

func webhookCreate(t *testing.T, r *testenv.Runner) {
Expand All @@ -34,25 +36,28 @@ func webhookCreate(t *testing.T, r *testenv.Runner) {
"https://duckduckgo.com/webhook_endpoint%d",
webhookURLSuffix,
)),
IsActive: ucare.Bool(true),
Event: ucare.String(webhook.EventFileUploaded),
SigningSecret: ucare.String("test_signing_secret"),
IsActive: ucare.Bool(true),
Event: ucare.String(webhook.EventFileUploaded),
}
info, err := r.Webhook.Create(context.Background(), params)
assert.Equal(t, nil, err)

r.Artifacts.WebhookID = info.ID
r.Artifacts.Webhook = info
}

func webhookUpdate(t *testing.T, r *testenv.Runner) {
params := webhook.Params{
ID: ucare.Int64(r.Artifacts.WebhookID),
TargetURL: ucare.String(webhookURL),
ID: ucare.Int64(r.Artifacts.Webhook.ID),
TargetURL: ucare.String(webhookURL),
SigningSecret: ucare.String(webhookSignSecret),
}
info, err := r.Webhook.Update(context.Background(), params)

assert.Equal(t, nil, err)

assert.Equal(t, webhookURL, info.TargetURL)
assert.Equal(t, webhookSignSecret, *info.SigningSecret)
}

func webhookList(t *testing.T, r *testenv.Runner) {
Expand Down
5 changes: 5 additions & 0 deletions webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ type Info struct {
// Where webhook data will be posted.
TargetURL string `json:"target_url"`

// Signing secret (optional)
SigningSecret *string `json:"signing_secret,omitempty"`

// Webhook project ID.
Project int64 `json:"project"`

Expand All @@ -114,6 +117,8 @@ type Params struct {
// A target URL MUST be unique for each project — event type combination.
// Will not be changed if set to nil.
TargetURL *string `json:"target_url,omitempty"`
// Signing secret can be added when creating or updating a webhook
SigningSecret *string `json:"signing_secret"`
// An event you subscribe to. Presently, we only support the EventFileUploaded event.
// Will not be changed if set to nil.
Event *string `json:"event,omitempty"`
Expand Down

0 comments on commit 8bc80c6

Please sign in to comment.