diff --git a/providers/dns/hetzner/internal/client.go b/providers/dns/hetzner/internal/client.go index f90439b2..efe8f48f 100644 --- a/providers/dns/hetzner/internal/client.go +++ b/providers/dns/hetzner/internal/client.go @@ -129,7 +129,7 @@ func (c *Client) DeleteRecord(recordID string) error { // GetZoneID gets the zone ID for a domain. func (c *Client) GetZoneID(domain string) (string, error) { - zones, err := c.getZones() + zones, err := c.getZones(domain) if err != nil { return "", err } @@ -144,17 +144,26 @@ func (c *Client) GetZoneID(domain string) (string, error) { } // https://dns.hetzner.com/api-docs#operation/GetZones -func (c *Client) getZones() (*Zones, error) { +func (c *Client) getZones(name string) (*Zones, error) { endpoint, err := c.createEndpoint("api", "v1", "zones") if err != nil { return nil, fmt.Errorf("failed to create endpoint: %w", err) } + query := endpoint.Query() + query.Set("name", name) + endpoint.RawQuery = query.Encode() + resp, err := c.do(http.MethodGet, endpoint, nil) if err != nil { return nil, fmt.Errorf("could not get zones: %w", err) } + // EOF fallback + if resp.StatusCode == http.StatusNotFound { + return &Zones{}, nil + } + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("could not get zones: %s", resp.Status) } diff --git a/providers/dns/hetzner/internal/model.go b/providers/dns/hetzner/internal/types.go similarity index 58% rename from providers/dns/hetzner/internal/model.go rename to providers/dns/hetzner/internal/types.go index 1771b1a7..d0e28451 100644 --- a/providers/dns/hetzner/internal/model.go +++ b/providers/dns/hetzner/internal/types.go @@ -25,4 +25,18 @@ type Zone struct { // Zones a set of DNS zones. type Zones struct { Zones []Zone `json:"zones"` + Meta Meta `json:"meta,omitempty"` +} + +// Meta response metadata. +type Meta struct { + Pagination Pagination `json:"pagination,omitempty"` +} + +// Pagination information about pagination. +type Pagination struct { + Page int `json:"page,omitempty" url:"page"` + PerPage int `json:"per_page,omitempty" url:"per_page"` + LastPage int `json:"last_page,omitempty" url:"-"` + TotalEntries int `json:"total_entries,omitempty" url:"-"` }