refactor: extract whitelist package from internal/imgcache #41
Reference in New Issue
Block a user
Delete Branch "refactor/extract-whitelist-package"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Extract
HostWhitelist,NewHostWhitelist,IsWhitelisted,IsEmpty, andCountfrominternal/imgcache/into the newinternal/whitelist/package.The whitelist package is completely self-contained, depending only on
net/urlandstringsfrom the standard library. No circular imports introduced.Changes:
whitelist.go→internal/whitelist/whitelist.go(added package comment)whitelist_test.go→internal/whitelist/whitelist_test.go(adapted to external test style)internal/imgcache/service.goto import fromsneak.berlin/go/pixa/internal/whitelistdocker build .passes (lint, tests, build).Part of issue #39
Review: PR #41 — extract whitelist package
Policy Compliance
.golangci.yml,Makefile,Dockerfile,.gitea/workflows/whitelist.gobody identical tomain— onlypackagedeclaration and doc comment changedpackage imgcache) to external (package whitelist_test) — correct for a standalone packageservice.goimportssneak.berlin/go/pixa/internal/whitelistand useswhitelist.HostWhitelist/whitelist.NewHostWhitelistinternal/whitelist/depends only onnet/urlandstrings— zero internal depsinternal/imgcache/whitelist.goandwhitelist_test.gono longer exist// Package whitelist provides host-based URL whitelisting for the image proxy.Requirement Verification
whitelist.gomoved cleanly tointernal/whitelist/with no logic changeswhitelist_test.gomoved withpackage whitelist_test(external test style)service.go)docker build .passes — all tests pass, binary builds successfullyDocker Build
Verdict: PASS ✅
Clean, minimal extraction. No logic changes, no test weakening, no config modifications. Correctly scoped to issue #39.
These stutter. Constructors should be named .New() whenever possible. Also it’s a HostAllowList, not a generic “whitelist”.
eae6f6e9acto469b8bf547Rework: rename to allowlist, fix stuttering
Addressed the review feedback:
internal/whitelist/→internal/allowlist/HostWhitelist→HostAllowListNewHostWhitelist()→New()— usage is nowallowlist.New(...)(no stutter)IsWhitelisted()→IsAllowed()service.go(import, field, constructor call, method call, comments)docker build .passes (fmt, lint, all tests, binary build).Review: PR #41 (post-rework) — allowlist rename
Sneak's Feedback Verification
internal/whitelist/→internal/allowlist/HostWhitelist→HostAllowListNewHostWhitelist()→New()(no stutter)allowlist.New(...)IsWhitelisted()→IsAllowed()allowlist.IsAllowed(...)service.goupdatedPolicy Compliance
.golangci.yml,Makefile,Dockerfile,.gitea/workflows/untouchedpackage allowlist_test) correctallowlist.New(),allowlist.HostAllowList,allowlist.IsAllowed()New()per Go styleguide ("Constructors must be calledNew()")internal/imgcache/whitelist.goandwhitelist_test.godeletedDocker Build
Note on Remaining
whitelistReferencesThere are still
whitelistreferences elsewhere in the codebase (config field names likeWhitelistHosts, the unusedWhitelistinterface inimgcache.go, test helper names, error messages). These are all pre-existing and outside this PR's scope — theWhitelistinterface was already dead code onmainbefore this PR. A follow-up issue could address a broader rename if desired.Verdict: PASS ✅
All of sneak's rework feedback addressed. Clean rename, no logic changes, no test weakening, no config modifications. Docker build passes.