fix(hoverclient): read NS from /api/domains (not PUT-only control_panel GET) — v0.5.4#36
Merged
Merged
Conversation
…y control_panel GET + v0.5.4 getDomainDelegationHTTP was hitting GET /api/control_panel/domains/domain-<name> which is PUT-only on live Hover (returns 404). Fix: populate a domainNS cache in listDomainsHTTP from the nameservers field already present in GET /api/domains; getDomainDelegationHTTP checks the cache first, falls back to GET /api/domains/<name> (wrapped envelope). Eliminates per-domain fan-out and the 429s it caused. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes Hover delegation reads by sourcing nameservers from the correct read endpoints and reducing API fan-out, addressing 404s (PUT-only control_panel path) and helping avoid rate limiting during imports.
Changes:
- Add nameservers parsing to
GET /api/domains, cache them, and haveGetDomainDelegationread from the cache first. - Add per-domain fallback read via
GET /api/domains/<name>and update JSON decoding accordingly. - Bump plugin version to
v0.5.4and extend tests to cover parsing/caching/fallback behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| plugin.json | Bumps plugin version to 0.5.4. |
| cmd/workflow-plugin-hover/plugin.json | Bumps embedded plugin version to 0.5.4. |
| pkg/hoverclient/client.go | Implements NS caching from /api/domains and updates delegation reads to use cache + per-domain fallback. |
| pkg/hoverclient/client_test.go | Updates existing delegation tests and adds coverage for NS parsing + cache behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+436
to
+447
| c.mu.Lock() | ||
| cached, ok := c.domainNS[domainName] | ||
| if ok { | ||
| ns := make([]string, len(cached)) | ||
| copy(ns, cached) | ||
| c.mu.Unlock() | ||
| if len(ns) == 0 { | ||
| return nil, fmt.Errorf("hover: GetDomainDelegation %q: %w", domainName, ErrEmptyNameservers) | ||
| } | ||
| return &DomainDelegation{Name: domainName, Nameservers: ns}, nil | ||
| } | ||
| c.mu.Unlock() |
Comment on lines
+463
to
472
| // The per-domain endpoint wraps the domain in {"succeeded":...,"domain":{...}}. | ||
| var wrap struct { | ||
| Succeeded bool `json:"succeeded"` | ||
| Domain Domain `json:"domain"` | ||
| } | ||
| if err := json.NewDecoder(resp.Body).Decode(&wrap); err != nil { | ||
| return nil, fmt.Errorf("hover: GetDomainDelegation %q: decode: %w", domainName, err) | ||
| } | ||
| if len(d.Nameservers) == 0 { | ||
| if len(wrap.Domain.Nameservers) == 0 { | ||
| return nil, fmt.Errorf("hover: GetDomainDelegation %q: %w", domainName, ErrEmptyNameservers) |
Comment on lines
+597
to
+609
| c.mu.Lock() | ||
| if c.domainNS == nil { | ||
| c.domainNS = make(map[string][]string, len(body.Domains)) | ||
| } | ||
| for _, d := range body.Domains { | ||
| if d.Name == "" { | ||
| continue | ||
| } | ||
| ns := make([]string, len(d.Nameservers)) | ||
| copy(ns, d.Nameservers) | ||
| c.domainNS[d.Name] = ns | ||
| } | ||
| c.mu.Unlock() |
Comment on lines
+878
to
+893
| mux := http.NewServeMux() | ||
| mux.HandleFunc("/signin/auth.json", func(w http.ResponseWriter, _ *http.Request) { | ||
| _ = json.NewEncoder(w).Encode(map[string]any{"status": "completed"}) | ||
| }) | ||
| mux.HandleFunc("/api/domains", func(w http.ResponseWriter, r *http.Request) { | ||
| // Return a.com with ns1.x — only exact /api/domains (not /api/domains/*) | ||
| if r.URL.Path != "/api/domains" { | ||
| // This is a per-domain fallback hit — count it. | ||
| perDomainHits++ | ||
| http.Error(w, "should not be called", http.StatusInternalServerError) | ||
| return | ||
| } | ||
| w.Header().Set("Content-Type", "application/json") | ||
| _, _ = io.WriteString(w, `{"succeeded":true,"domains":[{"id":"dom1","domain_name":"a.com","nameservers":["ns1.x"]}]}`) | ||
| }) | ||
|
|
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.
The delegation import 404'd on every domain:
GetDomainDelegationdidGET /api/control_panel/domains/domain-<name>, but that path is PUT-only (field updates). Root-caused live against Hover's API.Fix: nameservers are already in the
GET /api/domainslist response (one call, all domains).ListDomainsnow parses + caches them;GetDomainDelegationreads from the cache (so the delegation import is ~1 Hover call, not 30 — which also avoids the Imperva 429 fan-out), withGET /api/domains/<name>as the per-domain fallback.SetNameservers(PUT to control_panel) unchanged — it was correct. plugin.json → 0.5.4. go test green.Last piece for the both-layers catalog: release v0.5.4 → re-pin → re-import.
🤖 Generated with Claude Code