hoverclient

package
v0.5.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 26 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hoverclient implements the Hover DNS provider client.

Hover ships no official API. This package mimics the browser-side authentication flow exposed by Hover's signin UI:

  1. POST https://www.hover.com/signin/auth.json (username, password).
  2. POST https://www.hover.com/signin/auth2.json (code) when MFA is required.
  3. Subsequent requests carry the session cookie jar.

TOTP codes are RFC 6238 (HMAC-SHA1, 30s window, 6 digits).

Index

Constants

This section is empty.

Variables

View Source
var ErrBotChallenge = errors.New("hover: Imperva/bot challenge blocked the browser session — check network or rotate browser profile")

ErrBotChallenge is returned when Imperva (or another bot-protection layer) blocks the browser session: clearance cookies never arrive, or the login endpoint returns a persistent access-denied response. Operators should check network egress rules or rotate the browser profile.

View Source
var ErrBrowserBackendUnavailable = errors.New("hover: browser backend not yet available for this operation (Task 4)")

ErrBrowserBackendUnavailable is returned by browserBackend write operations that are not yet implemented (Task 4). Callers should treat this as a "not yet implemented via browser" signal.

View Source
var ErrChromeUnavailable = errors.New("hover: no Chrome binary found; install Chrome or set HOVER_BROWSER_DOWNLOAD=true")

ErrChromeUnavailable is returned when no Chrome binary can be found and BrowserOptions.Download is false. Install Chrome or set HOVER_BROWSER_DOWNLOAD=true to enable automatic download.

View Source
var ErrEmail2FARequired = errors.New("hover: account uses email/non-TOTP 2FA — configure an authenticator app (TOTP) on the account and supply totp_secret, or pre-trust this browser profile")

ErrEmail2FARequired is returned when Hover reports need_2fa but no TOTP secret is configured on the Credentials. This means the account uses email-OTP or another non-TOTP second factor. Configure a TOTP authenticator app on the account and supply the base32 seed as totp_secret.

View Source
var ErrEmptyNameservers = errors.New("hover: delegation read returned 0 nameservers (verify field shape)")

ErrEmptyNameservers is returned by GetDomainDelegation when the parsed response has zero nameservers. Converts the silent-thrash failure mode (empty → Diff says NeedsUpdate forever → re-PUT loop) into a loud, single-iteration error visible at the first wfctl plan.

Functions

This section is empty.

Types

type BrowserOptions added in v0.5.0

type BrowserOptions struct {
	Path       string
	Download   bool
	Headless   bool
	ProfileDir string
	Timeout    time.Duration
}

BrowserOptions controls the local Chrome instance used for live Hover access.

func BrowserOptionsFromEnv added in v0.5.0

func BrowserOptionsFromEnv() (BrowserOptions, error)

BrowserOptionsFromEnv returns BrowserOptions using HOVER_BROWSER_* env aliases.

func DefaultBrowserOptions added in v0.5.0

func DefaultBrowserOptions() BrowserOptions

DefaultBrowserOptions returns conservative runtime defaults for Chrome.

type Client

type Client struct {
	UserAgent string
	// contains filtered or unexported fields
}

Client is a Hover account-portal client. Concurrency-safe; the underlying cookie jar serialises across goroutines via mu.

func NewClient

func NewClient(creds Credentials, httpClient *http.Client) (*Client, error)

NewClient returns a fresh Client. Pass httpClient=nil for the browser backend (production path — Chrome drives Imperva clearance + login). Pass a non-nil *http.Client to select the HTTP backend; tests inject a stub to redirect requests without launching Chrome.

func NewClientWithOptions added in v0.5.0

func NewClientWithOptions(creds Credentials, httpClient *http.Client, opts ClientOptions) (*Client, error)

NewClientWithOptions returns a Client with explicit runtime options. opts.Browser is used when httpClient is nil (browser backend); it is ignored when httpClient is non-nil (HTTP backend selected).

func (*Client) CreateRecord

func (c *Client) CreateRecord(ctx context.Context, domainID string, rec DNSRecord) (*DNSRecord, error)

CreateRecord adds a new DNS record for the domain.

func (*Client) DeleteRecord

func (c *Client) DeleteRecord(ctx context.Context, recordID string) error

DeleteRecord removes a record by ID.

func (*Client) GetDomain

func (c *Client) GetDomain(ctx context.Context, domain string) (*Domain, error)

GetDomain returns the full Domain struct (including the hover-assigned ID) for the named zone. The ID is required when creating new records via CreateRecord; the human-readable name is not accepted by the POST /api/dns endpoint.

func (*Client) GetDomainDelegation

func (c *Client) GetDomainDelegation(ctx context.Context, domainName string) (*DomainDelegation, error)

GetDomainDelegation fetches the registrar-level nameserver delegation for the named domain via the control-panel API (same endpoint family as the PUT used by SetNameservers — more likely to surface nameservers reliably than the DNS-records-oriented /api/domains/<name>/dns endpoint).

Returns ErrEmptyNameservers if the parsed response has zero nameservers. This loud-on-empty behavior is intentional: it converts the silent re-apply thrash failure mode (empty → Diff says NeedsUpdate forever) into a single-iteration error visible at first wfctl plan.

func (*Client) ListDomains added in v0.4.0

func (c *Client) ListDomains(ctx context.Context) ([]Domain, error)

ListDomains fetches every domain in the authenticated account via the account-level GET /api/domains endpoint. The returned slice is the inverse-key of the SetNameservers / GetDomainDelegation / GetDomain surface (which all operate on a single named zone) — callers iterate the list to drive cross-zone operations like IaCProviderEnumerator.EnumerateAll("infra.dns").

CSRF is not required for GET requests under Hover's API; ensureLogin is still called so the session cookie is fresh.

func (*Client) ListRecords

func (c *Client) ListRecords(ctx context.Context, domain string) ([]DNSRecord, error)

ListRecords returns records for the named zone. Caller MUST pass the apex domain (e.g. "example.com").

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login performs a full authentication cycle against Hover's control panel. It is safe to call when already authenticated — it re-authenticates only when the session is older than sessionStaleAfter (1 hour). Safe for concurrent use; the internal mutex serialises calls.

On the HTTP backend the underlying auth flow follows Hover's current React signin UI:

  1. POST https://www.hover.com/signin/auth.json with username + password.
  2. If the response status is "need_2fa", POST /signin/auth2.json with the current TOTP code.
  3. Session cookies are stored in the jar for subsequent API calls.

func (*Client) SetNameservers

func (c *Client) SetNameservers(ctx context.Context, domainName string, ns []string) error

SetNameservers updates the registrar-level nameservers for a domain via Hover's control-panel API.

Lock discipline: holds c.mu for the entire auth → CSRF fetch → PUT sequence. This eliminates the TOCTOU window between auth-check and PUT (another goroutine cannot re-auth and invalidate the CSRF token between the two requests).

Trade-off: any concurrent caller using the same *Client blocks for the full duration of the held-lock sequence. Worst case (session is stale and re-auth fires inside ensureLoginLocked):

  • POST /signin/auth.json (credentials)
  • POST /signin/auth2.json (TOTP code, only if MFA enabled)
  • GET /control_panel/domain/<name> (CSRF for the API write)
  • PUT /api/control_panel/domains/domain-<name>

Up to ~180s at the 30s default per-request timeout when re-auth is needed; ~60s on the warm-session path (CSRF GET + PUT). Acceptable for the field-test scope (single goroutine, one delegation resource). Future: cache CSRF at session granularity if mixed-resource throughput becomes a concern.

func (*Client) UpdateRecord

func (c *Client) UpdateRecord(ctx context.Context, recordID string, rec DNSRecord) error

UpdateRecord PATCHes an existing record's content (and TTL when > 0).

type ClientOptions added in v0.5.0

type ClientOptions struct {
	Browser BrowserOptions
}

ClientOptions configures a Client beyond credentials. Zero value is valid; individual fields fall back to defaults.

type Credentials

type Credentials struct {
	Username   string
	Password   string
	TOTPSecret TOTPSecret
}

Credentials carries the operator-provided login material.

type DNSRecord

type DNSRecord struct {
	ID      string `json:"id,omitempty"`
	Type    string `json:"type"`
	Name    string `json:"name"`
	Content string `json:"content"`
	TTL     int    `json:"ttl,omitempty"`
}

DNSRecord mirrors Hover's internal API record shape.

type Domain

type Domain struct {
	ID          string      `json:"id"`
	Name        string      `json:"domain_name"`
	Records     []DNSRecord `json:"entries"`
	Nameservers []string    `json:"nameservers"`
}

Domain is the API shape returned by GET /api/domains.

type DomainDelegation

type DomainDelegation struct {
	ID          string   `json:"id"`
	Name        string   `json:"domain_name"`
	Nameservers []string `json:"nameservers"`
}

DomainDelegation is the response shape of GET /api/control_panel/domains/domain-<name>. Distinct from Domain (which represents the /api/domains/<name>/dns shape with Records) to avoid ambiguity over which fields are populated by which endpoint.

Tentative envelope per design A6: flat object, not wrapped in {"domains":[...]}. First field-test call must confirm this shape; if Hover returns a different envelope the implementer pauses and amends the design before proceeding.

type LiveAuthProbeResult added in v0.5.0

type LiveAuthProbeResult struct {
	LoginSucceeded    bool
	ClearanceCookies  []string
	GoHTTPReuseViable bool
	DomainCount       int
}

LiveAuthProbeResult captures the live Hover browser-auth viability signal.

func ProbeLiveBrowserAuth added in v0.5.0

func ProbeLiveBrowserAuth(ctx context.Context, creds Credentials, opts BrowserOptions) (LiveAuthProbeResult, error)

ProbeLiveBrowserAuth exercises real Chrome against Hover. It is intended for opt-in live tests only; it never logs credentials or TOTP material.

func (LiveAuthProbeResult) ClearanceCookieNames added in v0.5.0

func (r LiveAuthProbeResult) ClearanceCookieNames() []string

type TOTPSecret

type TOTPSecret struct {
	// contains filtered or unexported fields
}

TOTPSecret holds a decoded HOTP key. Construct via ParseBase32.

func ParseBase32

func ParseBase32(seed string) (TOTPSecret, error)

ParseBase32 parses a Google-Authenticator-style base32 seed (case- insensitive, padding optional) into a TOTPSecret. Spaces are stripped so users can paste from the Hover 2FA setup dialog.

func (TOTPSecret) Code

func (s TOTPSecret) Code() string

Code returns the 6-digit code for the current wall-clock time.

func (TOTPSecret) CodeAt

func (s TOTPSecret) CodeAt(t int64) string

CodeAt returns the 6-digit code for the given Unix time t (seconds). 30-second step per RFC 6238 §4. Pure HMAC-SHA1 — no external deps.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL