This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
zone.go
66 lines (57 loc) · 2.2 KB
/
zone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gandi
import "strings"
// Zone represents a DNS Zone
type Zone struct {
Retry int `json:"retry,omitempty"`
UUID string `json:"uuid,omitempty"`
ZoneHref string `json:"zone_href,omitempty"`
Minimum int `json:"minimum,omitempty"`
DomainsHref string `json:"domains_href,omitempty"`
Refresh int `json:"refresh,omitempty"`
ZoneRecordsHref string `json:"zone_records_href,omitempty"`
Expire int `json:"expire,omitempty"`
SharingID string `json:"sharing_id,omitempty"`
Serial int `json:"serial,omitempty"`
Email string `json:"email,omitempty"`
PrimaryNS string `json:"primary_ns,omitempty"`
Name string `json:"name,omitempty"`
}
// ListZones lists all zones
func (g *Gandi) ListZones() (zones []Zone, err error) {
_, err = g.askGandi(mGET, "zones", nil, &zones)
return
}
// CreateZone creates a zone
func (g *Gandi) CreateZone(name string) (response StandardResponse, err error) {
headers, err := g.askGandi(mPOST, "zones", Zone{Name: name}, &response)
spLoc := strings.Split(headers.Get("Location"), "/")
response.UUID = spLoc[len(spLoc)-1]
return
}
// GetZone returns a zone
func (g *Gandi) GetZone(uuid string) (zone Zone, err error) {
_, err = g.askGandi(mGET, "zones/"+uuid, nil, &zone)
return
}
// UpdateZone updates a zone (only its name, actually...)
func (g *Gandi) UpdateZone(uuid, name string) (response StandardResponse, err error) {
headers, err := g.askGandi(mPATCH, "zones/"+uuid, Zone{Name: name}, &response)
spLoc := strings.Split(headers.Get("Location"), "/")
response.UUID = spLoc[len(spLoc)-1]
return
}
// DeleteZone deletes a zone
func (g *Gandi) DeleteZone(uuid string) (err error) {
_, err = g.askGandi(mDELETE, "zones/"+uuid, nil, nil)
return
}
// GetZoneDomains returns domains attached to a zone
func (g *Gandi) GetZoneDomains(uuid string) (domains []Domain, err error) {
_, err = g.askGandi(mGET, "zones/"+uuid+"/domains", nil, &domains)
return
}
// AttachDomainToZone attaches a domain to a zone
func (g *Gandi) AttachDomainToZone(uuid, fqdn string) (response StandardResponse, err error) {
_, err = g.askGandi(mPOST, "zones/"+uuid+"/domains/"+fqdn, nil, &response)
return
}