forked from TrueCloudLab/lego
hetzner: improve zone ID detection (#1815)
This commit is contained in:
parent
5ff9695c09
commit
9b0b4cbbd6
2 changed files with 25 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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:"-"`
|
||||
}
|
Loading…
Reference in a new issue