Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prod #110

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions pkg/server/errorshandler/handler_sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const SentryQueueName = "external/sentry"
const CatcherType = "sentry"
const CatcherType = "external/sentry"

// HandleHTTP processes HTTP requests with JSON body
func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
Expand All @@ -20,32 +20,46 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
return
}

// check that X-Sentry-Auth header is available
auth := ctx.Request.Header.Peek("X-Sentry-Auth")
if auth == nil {
log.Warnf("Incoming request without X-Sentry-Auth header")
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "X-Sentry-Auth header is missing"})
return
}

hawkToken, err := getSentryKeyFromAuth(string(auth))
if err != nil {
log.Warnf("Incoming request with invalid X-Sentry-Auth header: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: err.Error()})
return
var hawkToken string
var err error

// parse incoming get request params
sentryKey := ctx.QueryArgs().Peek("sentry_key")
if sentryKey == nil {
log.Warnf("Incoming request with deprecated sentry_key parameter")

// check that X-Sentry-Auth header is available
auth := ctx.Request.Header.Peek("X-Sentry-Auth")
if auth == nil {
log.Warnf("Incoming request without X-Sentry-Auth header")
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "X-Sentry-Auth header is missing"})
return
}

hawkToken, err = getSentryKeyFromAuth(string(auth))
if err != nil {
log.Warnf("Incoming request with invalid X-Sentry-Auth header=%s: %s", auth, err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: err.Error()})
return
}
} else {
hawkToken = string(sentryKey)
}

log.Debugf("Incoming request with hawk integration token: %s", hawkToken)

body := ctx.PostBody()

sentryEnvelopeBody, err := decompressGzipString(body)
if err != nil {
log.Warnf("Failed to decompress gzip body: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress gzip body"})
return
sentryEnvelopeBody := ctx.PostBody()

// todo: add check of gzip header
if sentryKey == nil {
sentryEnvelopeBody, err = decompressGzipString(sentryEnvelopeBody)
if err != nil {
log.Warnf("Failed to decompress gzip body: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress gzip body"})
return
}
log.Debugf("Decompressed body: %s", sentryEnvelopeBody)
}
log.Debugf("Decompressed body: %s", sentryEnvelopeBody)

projectId, ok := handler.AccountsMongoDBClient.ValidTokens[hawkToken]
if !ok {
Expand Down
7 changes: 1 addition & 6 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ func (s *Server) handler(ctx *fasthttp.RequestCtx) {
case "/release":
s.ReleaseHandler.HandleHTTP(ctx)
case "/api/0/envelope/":
auth := ctx.Request.Header.Peek("X-Sentry-Auth")
if auth != nil {
s.ErrorsHandler.HandleSentry(ctx)
} else {
ctx.Error("X-Sentry-Auth not found", fasthttp.StatusBadRequest)
}
s.ErrorsHandler.HandleSentry(ctx)
default:
ctx.Error("Not found", fasthttp.StatusNotFound)
}
Expand Down
Loading