Skip to content

Commit

Permalink
Handle Azure EventGrid webhook validation idiosyncracy (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcspragu authored Nov 1, 2023
1 parent 6a6dc1e commit b96907d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion azure/azevents/azevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"net/http"
"path"
"strings"
"time"

"github.com/RMI/pacta/task"
Expand Down Expand Up @@ -123,7 +124,10 @@ func (s *Server) verifyWebhook(next http.Handler) http.Handler {
return
}
fullTopic := path.Join("/subscriptions", s.subscription, "resourceGroups", s.resourceGroup, "providers/Microsoft.EventGrid/topics", topic)
if req.Topic != fullTopic {
// We lowercase these because *sometimes* the request comes from Azure with
// "microsoft.eventgrid" instead of "Microsoft.EventGrid". This is exceptionally
// annoying.
if strings.ToLower(req.Topic) != strings.ToLower(fullTopic) {
s.logger.Error("invalid topic given for path", zap.String("got_topic", req.Topic), zap.String("expected_topic", fullTopic))
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
Expand Down

0 comments on commit b96907d

Please sign in to comment.