Add logging filter token

The token is used to filter out request logs when the user agent matches a randomly generated string.
This commit is contained in:
Maximilian Paß
2024-01-24 12:43:27 +01:00
committed by Sebastian Serth
parent 221a6ff1b2
commit 57590457a8
5 changed files with 52 additions and 3 deletions

View File

@ -9,6 +9,17 @@ import (
"strings"
)
var (
// UserAgentOut for outgoing requests (without libraries). The Git Hash will be replaced by main.go.
UserAgentOut = "Poseidon/" + UserAgentVCSPlaceholder + " Go-http-client/1.1"
UserAgentFiltered = "Poseidon/" + UserAgentVCSPlaceholder + " (" + UserAgentFilterTokenPlaceholder + ") Go-http-client/1.1"
)
const (
UserAgentVCSPlaceholder = "<7 Git Hash>"
UserAgentFilterTokenPlaceholder = "FilterToken"
)
// RunnerRequest is the expected json structure of the request body for the ProvideRunner function.
type RunnerRequest struct {
ExecutionEnvironmentID int `json:"executionEnvironmentId"`

View File

@ -93,7 +93,11 @@ func HTTPLoggingMiddleware(next http.Handler) http.Handler {
"duration": latency,
"user_agent": RemoveNewlineSymbol(r.UserAgent()),
})
logEntry.Debug()
if r.UserAgent() == dto.UserAgentFiltered {
logEntry.Trace()
} else {
logEntry.Debug()
}
})
}