refactor: modular local provider interfaces #52

Merged
benvin merged 1 commits from benvin/local-provider-interfaces into master 2026-06-23 22:56:25 +10:00
Owner

Summary

Move package-type-specific local repo logic out of centralized handlers into provider packages via optional Go interfaces.

New interfaces in provider package:

  • `LocalUploader`: `ValidateUpload(filePath) → (storagePath, contentType, error)` + `UploadResponse(...)`
  • `LocalIndexer`: `ServeLocalIndex(w, r, files, repoName, path) → bool` + `GenerateLocalIndex(ctx, files, repoName, path) → ([]byte, error)`
  • `FileStore`: `ListFilesByPrefix` + `ListPackages` (implemented by database.DB)

Providers implement these interfaces:

  • PyPI: upload validation (wheel/sdist naming), simple index serving + generation
  • Terraform: upload validation (provider zip naming), mirror protocol serving

Handlers simplified to generic dispatch:

  • `local.go`: type-asserts to `LocalUploader`, falls back to generic upload
  • `proxy.go`: type-asserts to `LocalIndexer`, falls back to raw file serving
  • `engine.go`: type-asserts to `LocalIndexer` for local virtual members

Adding a new local repo type (e.g. RPM) = implement the interfaces in its provider package. Zero handler changes.

Test plan

  • Build + unit tests pass
  • E2E: PyPI local upload → simple index → uv pip install (smoke test after refactor)
## Summary Move package-type-specific local repo logic out of centralized handlers into provider packages via optional Go interfaces. **New interfaces in `provider` package:** - \`LocalUploader\`: \`ValidateUpload(filePath) → (storagePath, contentType, error)\` + \`UploadResponse(...)\` - \`LocalIndexer\`: \`ServeLocalIndex(w, r, files, repoName, path) → bool\` + \`GenerateLocalIndex(ctx, files, repoName, path) → ([]byte, error)\` - \`FileStore\`: \`ListFilesByPrefix\` + \`ListPackages\` (implemented by database.DB) **Providers implement these interfaces:** - PyPI: upload validation (wheel/sdist naming), simple index serving + generation - Terraform: upload validation (provider zip naming), mirror protocol serving **Handlers simplified to generic dispatch:** - \`local.go\`: type-asserts to \`LocalUploader\`, falls back to generic upload - \`proxy.go\`: type-asserts to \`LocalIndexer\`, falls back to raw file serving - \`engine.go\`: type-asserts to \`LocalIndexer\` for local virtual members Adding a new local repo type (e.g. RPM) = implement the interfaces in its provider package. Zero handler changes. ## Test plan - [x] Build + unit tests pass - [x] E2E: PyPI local upload → simple index → uv pip install (smoke test after refactor)
unkinben added 1 commit 2026-06-23 22:41:46 +10:00
refactor: modular local provider interfaces
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
5b830fc3de
Move package-type-specific local repo logic into provider packages via
optional interfaces, eliminating switch statements from handlers.

- provider.LocalUploader: ValidateUpload + UploadResponse
- provider.LocalIndexer: ServeLocalIndex + GenerateLocalIndex
- provider.FileStore: interface for querying local files (implemented
  by database.DB)

PyPI and Terraform providers now implement both interfaces. The local
handler and v1 proxy use type assertions to dispatch — adding a new
local repo type only requires implementing the interfaces in its
provider package, no handler changes needed.

local.go: 468 → 163 lines (removed all PyPI/Terraform specifics)
proxy.go: 211 → 136 lines (removed switch + helper methods)
engine.go: removed LocalIndexGenerator, uses provider.LocalIndexer
benvin merged commit 3a6721c2a7 into master 2026-06-23 22:56:25 +10:00
benvin deleted branch benvin/local-provider-interfaces 2026-06-23 22:56:25 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#52