Preserve repo_type on remote update #179

Merged
benvin merged 3 commits from benvin/fix-update-repo-type into master 2026-11-01 21:18:37 +11:00
Member

PUT /api/v2/remotes/{name} decodes into a fresh struct without seeding repo_type, so terraform updates wipe it to "" on every non-local remote. Virtual repos then redirect member downloads to /api/v1//<remote>/..., which 404s.

  • keep the existing repo_type when the PUT omits it or sends "", default to remote only for a new row, reject invalid values
  • require base_url on update when repo_type is remote, matching create
  • add migration 0011 to repair empty repo_type rows as local (no base_url) or remote
  • add TestRepoTypeKeptOnUpdate
PUT /api/v2/remotes/{name} decodes into a fresh struct without seeding repo_type, so terraform updates wipe it to "" on every non-local remote. Virtual repos then redirect member downloads to `/api/v1//<remote>/...`, which 404s. - keep the existing repo_type when the PUT omits it or sends "", default to `remote` only for a new row, reject invalid values - require base_url on update when repo_type is `remote`, matching create - add migration 0011 to repair empty repo_type rows as `local` (no base_url) or `remote` - add TestRepoTypeKeptOnUpdate
unkin-agent added 1 commit 2026-11-01 15:17:39 +11:00
Preserve repo_type on remote update
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
98bee14385
Author
Member
  • internal/api/v2/remotes.go:145 — an explicit "repo_type":"" in the PUT body overwrites the seeded value, then defaults to remote, so a local repo can still be flipped to remote → default empty to existing.RepoType (when oldKnown) instead of RepoTypeRemote, or reject empty on update.
  • migrations/0011_remote_repo_type_repair.sql:1 — blanket remote also mislabels any local repo that was wiped (locals have empty base_url) → set repo_type = CASE WHEN base_url = '' THEN 'local' ELSE 'remote' END, or confirm no local was ever wiped.
  • internal/api/v2/remotes_ttl_test.go:~200 — no case for PUT with explicit "repo_type":"" on a local; add one alongside the fix above.
- internal/api/v2/remotes.go:145 — an explicit `"repo_type":""` in the PUT body overwrites the seeded value, then defaults to `remote`, so a local repo can still be flipped to remote → default empty to `existing.RepoType` (when oldKnown) instead of `RepoTypeRemote`, or reject empty on update. - migrations/0011_remote_repo_type_repair.sql:1 — blanket `remote` also mislabels any local repo that was wiped (locals have empty `base_url`) → set `repo_type = CASE WHEN base_url = '' THEN 'local' ELSE 'remote' END`, or confirm no local was ever wiped. - internal/api/v2/remotes_ttl_test.go:~200 — no case for PUT with explicit `"repo_type":""` on a local; add one alongside the fix above.
unkin-agent added 1 commit 2026-11-01 15:21:04 +11:00
keep existing repo_type on explicit empty PUT; repair wiped locals as local
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
f28fb21705
Author
Member
  • internal/api/v2/remotes.go:152 — update accepts repo_type: remote with empty base_url (e.g. PUT flipping a local to remote, or a new-row fallback to remote); create rejects this → apply the same RepoTypeRemote && BaseURL == "" check to update after defaulting.
  • nit: internal/api/v2/remotes_ttl_test.go — no step flips type on PUT (local→remote / remote→local), and migration 0011 has no test → add a PUT with explicit repo_type change; optionally seed an empty-repo_type row and assert the SQL.
- internal/api/v2/remotes.go:152 — update accepts `repo_type: remote` with empty `base_url` (e.g. PUT flipping a local to remote, or a new-row fallback to remote); create rejects this → apply the same `RepoTypeRemote && BaseURL == ""` check to update after defaulting. - nit: internal/api/v2/remotes_ttl_test.go — no step flips type on PUT (local→remote / remote→local), and migration 0011 has no test → add a PUT with explicit `repo_type` change; optionally seed an empty-repo_type row and assert the SQL.
unkin-agent added 1 commit 2026-11-01 15:24:13 +11:00
require base_url when an update sets repo_type remote
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
771bb13333
Author
Member

No findings.

No findings.
benvin merged commit f8d6db3bd2 into master 2026-11-01 21:18:37 +11:00
benvin deleted branch benvin/fix-update-repo-type 2026-11-01 21:18:38 +11: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#179