Skip to content

Commit

Permalink
fix: webhooks processor deserialize into an interface (#580)
Browse files Browse the repository at this point in the history
**Describe the pull request**

Fix an issue on the webhooks processor, where the payload are
unserialized into an interface.

**Checklist**

- [x] I have made the modifications or added tests related to my PR
- [x] I have run the tests and linters locally and they pass
- [x] I have added/updated the documentation for my RP
  • Loading branch information
42atomys authored Feb 20, 2024
1 parent beccd5e commit 2343d81
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/webhooks/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,23 @@ func (p *processor) githubHandler(data []byte) error {

// duoHandler is the processor for the duo webhooks.
func (p *processor) duoHandler(data []byte) error {
webhook, err := unmarshalWebhook[*duoapi.WebhookMetadata, duoapi.IWebhookPayload](data)
webhook, err := unmarshalWebhook[*duoapi.WebhookMetadata, any](data)
if err != nil {
return err
}

payload, ok := webhook.Payload.(duoapi.IWebhookPayload)
if !ok {
return errors.New("invalid duo webhook payload. Cannot cast to IWebhookPayload interface")
}

switch webhook.Metadata.Model {
case "campus_user":
err = webhook.Payload.ProcessWebhook(p.ctx, webhook.Metadata, &campusUserProcessor{processor: p})
err = payload.ProcessWebhook(p.ctx, webhook.Metadata, &campusUserProcessor{processor: p})
case "location":
err = webhook.Payload.ProcessWebhook(p.ctx, webhook.Metadata, &locationProcessor{processor: p})
err = payload.ProcessWebhook(p.ctx, webhook.Metadata, &locationProcessor{processor: p})
case "user":
err = webhook.Payload.ProcessWebhook(p.ctx, webhook.Metadata, &userProcessor{processor: p})
err = payload.ProcessWebhook(p.ctx, webhook.Metadata, &userProcessor{processor: p})
}
if err != nil {
log.Error().Err(err).Str("model", webhook.Metadata.Model).Str("event", webhook.Metadata.Event).Msg("Failed to process webhook")
Expand Down

0 comments on commit 2343d81

Please sign in to comment.