Give ban causes, limit kinds, alert events, actions and dispositions named types (closes #428)
check / check (push) Waiting to run
check / check (push) Waiting to run
Each fixed set of string constants becomes a named string type in the package that owns it, and the fields and parameters that carry it use the type: bans.Cause, ratelimit.LimitKind, alerts.Event, alerts.DestinationName, rules.Action, requestlog.Action, requestlog.Offence, requestlog.WAFLineKind and wafprotocol.Disposition. Every value keeps its string, so the logs, state files, alerts and metrics do not change. The switches exhaustive now checks list their missing cases. Model: opus-5-5
This commit is contained in:
1 parent
86bb33bf07
commit
de78a12801
43 files changed
+373
-255
No files matched your search
@@ -8,7 +8,7 @@ import "net/http"
|
||||
type Answer struct {
|
||||
// Disposition is what rproxy does with the request: DispositionAllow,
|
||||
// DispositionDeny or DispositionClose.
|
||||
Disposition string
|
||||
Disposition Disposition
|
||||
// ASN and Country are the client's AS number and country, each empty
|
||||
// when the answer does not give it.
|
||||
ASN, Country string
|
||||
@@ -17,7 +17,7 @@ type Answer struct {
|
||||
// SetAnswerHeaders sets the headers of waf's answer that tell rproxy answer,
|
||||
// leaving out an ASN or Country that is empty.
|
||||
func SetAnswerHeaders(header http.Header, answer Answer) {
|
||||
header.Set(DispositionHeader, answer.Disposition)
|
||||
header.Set(DispositionHeader, string(answer.Disposition))
|
||||
|
||||
if answer.ASN != "" {
|
||||
header.Set(ASNHeader, answer.ASN)
|
||||
@@ -31,7 +31,7 @@ func SetAnswerHeaders(header http.Header, answer Answer) {
|
||||
// ReadAnswer returns what the headers of waf's answer tell rproxy, and
|
||||
// whether they give a valid disposition.
|
||||
func ReadAnswer(header http.Header) (Answer, bool) {
|
||||
disposition := header.Get(DispositionHeader)
|
||||
disposition := Disposition(header.Get(DispositionHeader))
|
||||
|
||||
switch disposition {
|
||||
case DispositionAllow, DispositionDeny, DispositionClose:
|
||||
|
||||
@@ -27,18 +27,22 @@ const (
|
||||
CountryHeader = "X-Client-Country"
|
||||
)
|
||||
|
||||
// Disposition is what waf tells rproxy to do with a request, in
|
||||
// DispositionHeader.
|
||||
type Disposition string
|
||||
|
||||
// The values of DispositionHeader.
|
||||
const (
|
||||
// DispositionAllow tells rproxy to pass the request to the app.
|
||||
DispositionAllow = "allow"
|
||||
DispositionAllow Disposition = "allow"
|
||||
// DispositionDeny tells rproxy to give the visitor the answer's status,
|
||||
// headers and body.
|
||||
DispositionDeny = "deny"
|
||||
DispositionDeny Disposition = "deny"
|
||||
// DispositionClose tells rproxy to close the visitor's connection
|
||||
// without an answer, which SWW_WAF_BAN_RESPONSE asks for when it is close.
|
||||
// waf closing the question's connection instead would read as
|
||||
// waf being down, and rproxy would then let the request through.
|
||||
DispositionClose = "close"
|
||||
DispositionClose Disposition = "close"
|
||||
)
|
||||
|
||||
// OwnEndpointPrefix starts the path of every request for sww itself: waf's
|
||||
|
||||
Reference in new issue
Block a user