feat(cli): validate --location against vendored zone list (#94)#95
Draft
LukasWodka wants to merge 1 commit into
Draft
feat(cli): validate --location against vendored zone list (#94)#95LukasWodka wants to merge 1 commit into
LukasWodka wants to merge 1 commit into
Conversation
EdgeDevice.location is CharField(choices=ZONE_CHOICES) (electricityMaps zones),
so the backend rejects any zone not in the list. The CLI didn't validate, so a
bad --location (or a prompt typo) only failed as an opaque 400 at create time.
- internal/zones: the backend's ZONE_CHOICES vendored as zones.json (352 zones)
and go:embed-ed; Valid / Name / Suggest. scripts/sync-zones.sh regenerates it
from the backend's metaApi/models/zone_choices.py (the source of truth — a
private repo, so a local sibling read rather than a curl), with a --check
drift mode for CI, mirroring sync-schema.sh.
- client create: --location and the location prompt validate against the list
and fail fast with close-match suggestions ("germany" → did you mean DE?). The
cli#93 auto-detect only pre-fills a detected zone if it's valid.
Tests: zones Valid/Name/Suggest; cli rejects an invalid --location before any
API call. go build/vet/test green.
Closes #94.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #94.
EdgeDevice.locationisCharField(choices=ZONE_CHOICES)(electricityMaps zones), so the backend'sChoiceFieldrejects any zone not in the list. The CLI didn't validate--location/ the prompt, so a bad value (Germany,eu-central-1, a typo) only failed as an opaque 400 at create time. This validates against a vendored copy of the list and fails fast with suggestions.Stacked on #93 (
feat/84-location-autodetect, itself on #92) — retarget down the chain as each merges.What's here
internal/zones— the backend'sZONE_CHOICESvendored aszones.json(352 zones: countries + sub-zones likeUS-CAL-CISO), embedded viago:embed.Valid/Name/Suggest.scripts/sync-zones.sh— regenerateszones.jsonfrom the backend'smetaApi/models/zone_choices.py(the source of truth — it's what the API validates against), with a--checkdrift mode for CI.client create—--locationand the location prompt validate against the list, failing fast with close-match suggestions ("germany"→ did you mean: DE?;"de"→ DE). The feat(cli): location auto-detect for client create (#84) #93 auto-detect only pre-fills a detected zone if it's actually valid.Why a local-file sync (not a URL like sync-schema.sh)
sync-schema.shcurls data-ingestors (a public repo).backendis private, so an anonymouscurlofzone_choices.pywon't work — and the backend file is the authoritative validation source, so the script reads it from a sibling checkout (ZONES_SOURCEto override). The committedzones.jsonis what the binary uses; the script is the maintenance / CI-drift tool.Tests
internal/zones:Valid/Name(case-sensitivity + sub-zones),Suggest(name match, wrong-case, prefix, garbage → none).internal/cli: an invalid--locationerrors with aDEsuggestion before any API call; the existing flow/interactive tests still pass (DE/US/detectedFRare valid). Fullgo build/vet/test ./...green.🤖 Generated with Claude Code