No part imports config #447

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

From the architecture review, "internal/config, and values with a fixed set of choices", under "config sits on both sides of the parts": #283 (comment). Approved for building, with the recommended option, "config above the parts": #283 (comment). The code was read at 809d266 on next. Line numbers are that commit's.

The review made this wait for the settings change through viper and for one settings file per daemon. Both are on next.

What is there

  • config imports four of the parts for their types and lists: alerts.Events, anomaly.Thresholds, anomaly.NamedNetblock, coreruleset.AppNames and the three remotelog.Scheme… constants.
  • Three parts import config for helpers:
    • reputation: the type TagList, and ParseNetblock, ParseASN, ParsePercent, MaskZoneKey;
    • rules: IsHeaderName (internal/rules/rules.go:381);
    • metrics: MaskZoneKey.
  • Every other part takes plain values in a Params struct and does not import config.

Why it matters

A reader cannot state which way the dependency goes. A part that config imports can never use a config helper, and a part that imports config can never give config a type. The next helper or type lands wherever it compiles.

What changes

No part imports config. Only sww, waf and rproxy read it.

  • TagList and MaskZoneKey move to reputation, which owns tag lists and DNSBL zones.
  • ParseNetblock, ParseASN and ParsePercent move to reputation, the lower of their two users. config imports them from there.
  • IsHeaderName: rules and config both call httpguts.ValidHeaderFieldName from golang.org/x/net, already an indirect dependency, and IsHeaderName goes.
    • The review compared the two by reading only. Before IsHeaderName is deleted, a test checks that both give the same answer for the empty name and for every single-byte name.
    • If they differ anywhere, IsHeaderName moves to rules instead, and config imports it from there.

What stays

  • config goes on importing the parts for their types.
  • The tag names (ASNTagPrefix, ExploitSignatureTag and the rest) stay in config: waf reads them, and waf is not a part.
  • No moved function changes what it accepts or returns, and no setting changes.

Done when

  • no non-test file of reputation, rules or metrics imports internal/config, and no other part does;
  • behaviour is unchanged: every existing test passes with no assertion changed, moved tests included;
  • make check passes;
  • the PR body says which way IsHeaderName went, and lists any name that changed with its move.

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

Model: fable-5-2

From the architecture review, "`internal/config`, and values with a fixed set of choices", under "`config` sits on both sides of the parts": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-173841. Approved for building, with the recommended option, "`config` above the parts": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-183550. The code was read at `809d266` on `next`. Line numbers are that commit's. The review made this wait for the settings change through viper and for one settings file per daemon. Both are on `next`. ### What is there - `config` imports four of the parts for their types and lists: `alerts.Events`, `anomaly.Thresholds`, `anomaly.NamedNetblock`, `coreruleset.AppNames` and the three `remotelog.Scheme…` constants. - Three parts import `config` for helpers: - `reputation`: the type `TagList`, and `ParseNetblock`, `ParseASN`, `ParsePercent`, `MaskZoneKey`; - `rules`: `IsHeaderName` (`internal/rules/rules.go:381`); - `metrics`: `MaskZoneKey`. - Every other part takes plain values in a `Params` struct and does not import `config`. ### Why it matters A reader cannot state which way the dependency goes. A part that `config` imports can never use a `config` helper, and a part that imports `config` can never give `config` a type. The next helper or type lands wherever it compiles. ### What changes No part imports `config`. Only `sww`, `waf` and `rproxy` read it. - `TagList` and `MaskZoneKey` move to `reputation`, which owns tag lists and DNSBL zones. - `ParseNetblock`, `ParseASN` and `ParsePercent` move to `reputation`, the lower of their two users. `config` imports them from there. - `IsHeaderName`: `rules` and `config` both call `httpguts.ValidHeaderFieldName` from `golang.org/x/net`, already an indirect dependency, and `IsHeaderName` goes. - The review compared the two by reading only. Before `IsHeaderName` is deleted, a test checks that both give the same answer for the empty name and for every single-byte name. - If they differ anywhere, `IsHeaderName` moves to `rules` instead, and `config` imports it from there. ### What stays - `config` goes on importing the parts for their types. - The tag names (`ASNTagPrefix`, `ExploitSignatureTag` and the rest) stay in `config`: `waf` reads them, and `waf` is not a part. - No moved function changes what it accepts or returns, and no setting changes. ### Done when - no non-test file of `reputation`, `rules` or `metrics` imports `internal/config`, and no other part does; - behaviour is unchanged: every existing test passes with no assertion changed, moved tests included; - `make check` passes; - the PR body says which way `IsHeaderName` went, and lists any name that changed with its move. 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:27 +01:00
Author
Collaborator

Built in #470 (branch issue-447-config-above-the-parts). No part imports config now. IsHeaderName went to httpguts.ValidHeaderFieldName, and a test pins that check to the characters IsHeaderName took.

Model: opus-5-5

Built in https://git.eeqj.de/sneak/smallwebwaf/pulls/470 (branch `issue-447-config-above-the-parts`). No part imports `config` now. `IsHeaderName` went to `httpguts.ValidHeaderFieldName`, and a test pins that check to the characters `IsHeaderName` took. 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#447