internal/config/waf.go: each setting's code in one place #449

Open
opened 2026-11-19 17:14:41 +01:00 by clawbot · 1 comment
Collaborator

Start once these three are closed, since each adds to, or takes from, the file this issue rearranges:

  • named types for the settings with a fixed set of values: #427;
  • no part imports config: #447;
  • constants for the setting names written into log lines: #448.

Pick it up while no other open PR edits internal/config/waf.go: a PR that only moves code conflicts with every edit to what it moves. The settings audit (#202) removes settings from the same file.

From the architecture review, "internal/config, and values with a fixed set of choices", under "One setting's code is in six places": #283 (comment). Approved for building: #283 (comment). The code was read at 809d266 on next. Line numbers and setting names are that commit's.

The review made this wait for one settings file per daemon. That is on next: waf's settings are internal/config/waf.go.

What is there

  • internal/config/waf.go is 2,581 lines, ordered by kind of code: the struct, the constants, one block of errors, WAFFromEnvironment, about 60 reader methods, the checks across settings, about 60 parsers.
  • Example, SWW_WAF_DNSBL_ZONES:
    • the field DNSBLZones at line 152;
    • its errors errNotZone and errZoneTooLong at 477 and 480;
    • the line that reads it at 592;
    • the reader method zones at 1078;
    • the check against the tags, in requestCanGetTag, at 1250;
    • the parser parseZones at 2413.

Why it matters

Following or changing one setting means six jumps in one file. This is the file a newcomer opens first to learn what a setting does.

What changes

Moves only. No identifier is renamed and no line of code changes.

  • The struct WAF and WAFFromEnvironment stay whole and stay first, so the list of settings stays in one place.
  • Under them, the code is ordered by setting, in the order of SPEC's settings sections ("Core" to "Anomaly thresholds"). A setting's reader method, its parser, its errors and its check sit together.
  • The one var block of errors is split, each error beside the code that returns it.
  • A helper that several settings share sits before the first setting that uses it.

What stays

  • Every identifier, comment, error message and behaviour.
  • internal/config/config.go, which holds what both daemons' settings share, and internal/config/rproxy.go, which is short.

Done when

  • every setting's reader, parser, errors and check are next to one another, in SPEC's order of sections;
  • the diff is moves only: git diff --color-moved shows no changed line inside a moved block;
  • every existing test passes with no assertion changed;
  • make check passes.

If this is more than one PR can carry, say so on this issue instead of starting.

Model: fable-5-2

**Start once these three are closed**, since each adds to, or takes from, the file this issue rearranges: - named types for the settings with a fixed set of values: https://git.eeqj.de/sneak/smallwebwaf/issues/427; - no part imports `config`: https://git.eeqj.de/sneak/smallwebwaf/issues/447; - constants for the setting names written into log lines: https://git.eeqj.de/sneak/smallwebwaf/issues/448. Pick it up while no other open PR edits `internal/config/waf.go`: a PR that only moves code conflicts with every edit to what it moves. The settings audit (https://git.eeqj.de/sneak/smallwebwaf/issues/202) removes settings from the same file. From the architecture review, "`internal/config`, and values with a fixed set of choices", under "One setting's code is in six places": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-173841. Approved for building: https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-183550. The code was read at `809d266` on `next`. Line numbers and setting names are that commit's. The review made this wait for one settings file per daemon. That is on `next`: `waf`'s settings are `internal/config/waf.go`. ### What is there - `internal/config/waf.go` is 2,581 lines, ordered by kind of code: the struct, the constants, one block of errors, `WAFFromEnvironment`, about 60 reader methods, the checks across settings, about 60 parsers. - Example, `SWW_WAF_DNSBL_ZONES`: - the field `DNSBLZones` at line 152; - its errors `errNotZone` and `errZoneTooLong` at 477 and 480; - the line that reads it at 592; - the reader method `zones` at 1078; - the check against the tags, in `requestCanGetTag`, at 1250; - the parser `parseZones` at 2413. ### Why it matters Following or changing one setting means six jumps in one file. This is the file a newcomer opens first to learn what a setting does. ### What changes Moves only. No identifier is renamed and no line of code changes. - The struct `WAF` and `WAFFromEnvironment` stay whole and stay first, so the list of settings stays in one place. - Under them, the code is ordered by setting, in the order of SPEC's settings sections ("Core" to "Anomaly thresholds"). A setting's reader method, its parser, its errors and its check sit together. - The one `var` block of errors is split, each error beside the code that returns it. - A helper that several settings share sits before the first setting that uses it. ### What stays - Every identifier, comment, error message and behaviour. - `internal/config/config.go`, which holds what both daemons' settings share, and `internal/config/rproxy.go`, which is short. ### Done when - every setting's reader, parser, errors and check are next to one another, in SPEC's order of sections; - the diff is moves only: `git diff --color-moved` shows no changed line inside a moved block; - every existing test passes with no assertion changed; - `make check` passes. If this is more than one PR can carry, say so on this issue instead of starting. Model: fable-5-2
clawbot self-assigned this 2026-11-19 17:14:41 +01:00
clawbot added the needs-decision label 2026-11-19 18:23:54 +01:00
Author
Collaborator

Deferred, not started: its prerequisites (#427, #447, #448) are still open, and #466 edits internal/config/waf.go; dispatch again once all three close.

Model: opus-5-5

Deferred, not started: its prerequisites (https://git.eeqj.de/sneak/smallwebwaf/issues/427, https://git.eeqj.de/sneak/smallwebwaf/issues/447, https://git.eeqj.de/sneak/smallwebwaf/issues/448) are still open, and https://git.eeqj.de/sneak/smallwebwaf/pulls/466 edits `internal/config/waf.go`; dispatch again once all three close. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/smallwebwaf#449