Give ban causes, limit kinds, alert events, actions and dispositions named types (closes #428) #464

Open
clawbot wants to merge 1 commits from issue-428-named-value-types into next
pull from: issue-428-named-value-types
Collaborator

Closes #428.

Each fixed set of string constants is now a named string type in the package that owns it. Fields, parameters and comparisons use it. Every value keeps its string, so the logs, state files, alerts and metrics are unchanged.

New types:

  • bans.Cause: why a ban was made.
  • ratelimit.LimitKind: what a limit counts (requests, bytes or refusals). bans.Notes.Kind uses it, so bans now imports ratelimit.
  • alerts.Event: what an alert is for. config.WAF.AlertEvents is []alerts.Event.
  • alerts.Destination: where alerts are sent.
  • rules.Action: what a rule does when it matches.
  • requestlog.Action: what waf did with a request, as its log line names it.
  • requestlog.Offence: what a request was held as.
  • requestlog.WAFLine: which of waf's two lines a request line is.
  • waf.Disposition: what waf tells rproxy to do with a request.

What the diff does not show:

  • WAFBackendNoAnswerDisposition and requestlog.Line.Disposition stay string. waf imports config and requestlog, so neither can import waf.Disposition. They can take the type once #425 moves the dispositions to a package below both.
  • Alert details hold string(cause) and string(kind), so a detail in memory equals one read back from alerts.json.
  • An any holding a named type never equals a plain string. Tests that compare decoded JSON with a constant therefore convert it with string(...).
  • exhaustive asked for cases in seven switches. Where a default returned a value, the listed cases now fall through to that same return after the switch.
  • Test changes are helper parameter and table field types only; no expected value changed.

Model: opus-5-5

Closes https://git.eeqj.de/sneak/smallwebwaf/issues/428. Each fixed set of string constants is now a named string type in the package that owns it. Fields, parameters and comparisons use it. Every value keeps its string, so the logs, state files, alerts and metrics are unchanged. New types: - `bans.Cause`: why a ban was made. - `ratelimit.LimitKind`: what a limit counts (requests, bytes or refusals). `bans.Notes.Kind` uses it, so `bans` now imports `ratelimit`. - `alerts.Event`: what an alert is for. `config.WAF.AlertEvents` is `[]alerts.Event`. - `alerts.Destination`: where alerts are sent. - `rules.Action`: what a rule does when it matches. - `requestlog.Action`: what waf did with a request, as its log line names it. - `requestlog.Offence`: what a request was held as. - `requestlog.WAFLine`: which of waf's two lines a request line is. - `waf.Disposition`: what waf tells rproxy to do with a request. What the diff does not show: - `WAFBackendNoAnswerDisposition` and `requestlog.Line.Disposition` stay `string`. `waf` imports `config` and `requestlog`, so neither can import `waf.Disposition`. They can take the type once https://git.eeqj.de/sneak/smallwebwaf/issues/425 moves the dispositions to a package below both. - Alert details hold `string(cause)` and `string(kind)`, so a detail in memory equals one read back from `alerts.json`. - An `any` holding a named type never equals a plain string. Tests that compare decoded JSON with a constant therefore convert it with `string(...)`. - `exhaustive` asked for cases in seven switches. Where a `default` returned a value, the listed cases now fall through to that same return after the switch. - Test changes are helper parameter and table field types only; no expected value changed. Model: opus-5-5
clawbot added 1 commit 2026-11-19 17:48:45 +01:00
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.Destination, rules.Action, requestlog.Action, requestlog.Offence,
requestlog.WAFLine and waf.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
clawbot self-assigned this 2026-11-19 17:48:47 +01:00
clawbot added the needs-review label 2026-11-19 17:48:47 +01:00
Author
Collaborator

Verdict: FAIL
Head: 58dafa1876

  1. Two fields that carry a disposition are still string: WAFBackendNoAnswerDisposition in internal/config/rproxy.go and Disposition on requestlog.Line in internal/requestlog/requestlog.go.
    • The issue's definition of done says every field that carries one of these sets uses its type, and the issue names WAFBackendNoAnswerDisposition explicitly.
    • As it stands, env.disposition still checks the literals "allow" and "deny", and internal/rproxy converts with waf.Disposition(...) and string(...).
    • waf imports both config and requestlog, so neither field can use waf.Disposition. The type belongs in a package below both, and the wafprotocol package from #461 is that package.
    • The deferral is recorded only in a comment on #425. That PR was opened before the comment and does not do the work, so the item would be lost once this PR closes its issue.
    • Acceptable: once #461 is merged into next, rebase onto it and declare Disposition with its three constants in internal/wafprotocol. Give both fields, and wafprotocol.Answer.Disposition, that type. Have env.disposition compare against the constants and return the type. Remove the conversions in internal/rproxy.

Sequencing: this finding can only be acted on after #461 is merged.

Model: opus-5-5

Verdict: FAIL Head: 58dafa1876413e619507c768736ef6489508222b 1. Two fields that carry a disposition are still `string`: `WAFBackendNoAnswerDisposition` in `internal/config/rproxy.go` and `Disposition` on `requestlog.Line` in `internal/requestlog/requestlog.go`. - The issue's definition of done says every field that carries one of these sets uses its type, and the issue names `WAFBackendNoAnswerDisposition` explicitly. - As it stands, `env.disposition` still checks the literals `"allow"` and `"deny"`, and `internal/rproxy` converts with `waf.Disposition(...)` and `string(...)`. - `waf` imports both `config` and `requestlog`, so neither field can use `waf.Disposition`. The type belongs in a package below both, and the `wafprotocol` package from https://git.eeqj.de/sneak/smallwebwaf/pulls/461 is that package. - The deferral is recorded only in a comment on https://git.eeqj.de/sneak/smallwebwaf/issues/425. That PR was opened before the comment and does not do the work, so the item would be lost once this PR closes its issue. - Acceptable: once https://git.eeqj.de/sneak/smallwebwaf/pulls/461 is merged into `next`, rebase onto it and declare `Disposition` with its three constants in `internal/wafprotocol`. Give both fields, and `wafprotocol.Answer.Disposition`, that type. Have `env.disposition` compare against the constants and return the type. Remove the conversions in `internal/rproxy`. Sequencing: this finding can only be acted on after https://git.eeqj.de/sneak/smallwebwaf/pulls/461 is merged. Model: opus-5-5
Some checks are pending
check / check (push) Waiting to run
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-428-named-value-types:issue-428-named-value-types
git checkout issue-428-named-value-types
Sign in to join this conversation.