-
Notifications
You must be signed in to change notification settings - Fork 0
/
domains.go
166 lines (153 loc) · 7.26 KB
/
domains.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package gandiapi
import "time"
// DomainResponse struct stores response from zones endpoint.
type DomainResponse struct {
Autorenew bool `json:"autorenew"`
Dates struct {
RegistryCreatedAt time.Time `json:"registry_created_at"`
UpdatedAt time.Time `json:"updated_at"`
AuthinfoExpiresAt time.Time `json:"authinfo_expires_at,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
DeletesAt time.Time `json:"deletes_at,omitempty"`
HoldBeginsAt time.Time `json:"hold_begins_at,omitempty"`
HoldEndsAt time.Time `json:"hold_ends_at,omitempty"`
PendingDeleteEndsAt time.Time `json:"pending_delete_ends_at,omitempty"`
RegistryEndsAt time.Time `json:"registry_ends_at,omitempty"`
RenewBeginsAt time.Time `json:"renew_begins_at,omitempty"`
RestoreEndsAt time.Time `json:"restore_ends_at,omitempty"`
} `json:"dates"`
DomainOwner string `json:"domain_owner"`
Fqdn string `json:"fqdn"`
FqdnUnicode string `json:"fqdn_unicode"`
Href string `json:"href"`
ID string `json:"id"`
Nameserver struct {
Current string `json:"current"`
Hosts []string `json:"hosts,omitempty"`
} `json:"nameserver"`
OrgaOwner string `json:"orga_owner"`
Owner string `json:"owner"`
SharingID string `json:"sharing_id,omitempty"`
Status []string `json:"status"`
Tags []string `json:"tags,omitempty"`
Tld string `json:"tld"`
}
// DomainContact represents the contact details of a domain contact or owner.
type DomainContact struct {
// A country code. See https://api.gandi.net/docs/domains/#appendix-Country-Codes
// for possible values.
Country string `json:"country"`
Email string `json:"email"`
Family string `json:"family"`
Given string `json:"given"`
Streetaddr string `json:"streetaddr"`
// One of: "individual", "company", "association", "publicbody"
Type string `json:"type"`
BrandNumber string `json:"brand_number,omitempty"`
City string `json:"city,omitempty"`
// More info available at https://docs.gandi.net/en/domain_names/common_operations/whois_privacy.html
Data_obfuscated bool `json:"data_obfuscated,omitempty"`
// TODO: add support for this field
// Extra parameters needed for some extensions. See https://api.gandi.net/docs/domains/#appendix-Contact-Extra-Parameters
// for possible values
// ExtraParameters struct {} `json:"extra_parameters,omitempty"`
Fax string `json:"fax,omitempty"`
JoAnnounceNumber string `json:"jo_announce_number,omitempty"`
JoAnnouncePage string `json:"jo_announce_page,omitempty"`
JoDeclarationDate string `json:"jo_declaration_date,omitempty"`
JoPublicationDate string `json:"jo_publication_date,omitempty"`
// One of: "en", "es", "fr", "ja", "zh-hans", "zh-hant"
Lang string `json:"lang,omitempty"`
MailObfuscated bool `json:"mail_obfuscated,omitempty"`
Mobile string `json:"mobile,omitempty"`
// Legal name of the company, association, or public body if the contact type is not "individual"
Orgname string `json:"orgname,omitempty"`
Phone string `json:"phone,omitempty"`
Siren string `json:"siren,omitempty"`
// See https://docs.gandi.net/en/rest_api/domain_api/contacts_api.html for more information on state codes.
State string `json:"state,omitempty"`
// One of: "pending", "done", "failed", "deleted", "none"
Validation string `json:"validation,omitempty"`
Zip string `json:"zip,omitempty"`
}
type DomainContacts struct {
Admin *DomainContact `json:"admin,omitempty"`
Billing *DomainContact `json:"billing,omitempty"`
Owner *DomainContact `json:"owner,omitempty"`
Tech *DomainContact `json:"tech,omitempty"`
}
// DomainCreateRequest is the data sent with a CreateDomain request
type DomainCreateRequest struct {
Fqdn string `json:"fqdn"`
Owner DomainContact `json:"owner"`
Admin DomainContact `json:"admin,omitempty"`
Bill DomainContact `json:"bill,omitempty"`
Claims string `json:"claims,omitempty"`
// One of: "EUR", "USD", "GBP", "TWD", "CNY"
Currency string `json:"currency,omitempty"`
// Between 1 and 10
Duration int `json:"duration,omitempty"`
// Must be set to true if the domain is a premium domain
EnforcePremium bool `json:"enforce_premium,omitempty"`
// TODO: add support for this field
// Extra parameters needed for some extensions. See https://api.gandi.net/docs/domains/#appendix-Contact-Extra-Parameters
// for possible values
// ExtraParameters struct {} `json:"extra_parameters,omitempty"`
// ISO-639-2 language code of the domain. Required for some IDN domains.
Lang string `json:"lang,omitempty"`
// For glue records only. Dictionary associating a nameserver to a list of IP addresses.
NameserverIPs map[string][]string `json:"nameserver_ips,omitempty"`
// List of name servers. Gandi's LiveDNS nameservers are used if omitted.
Nameservers []string `json:"nameservers,omitempty"`
Price int `json:"price,omitempty"`
ReselleeID string `json:"resellee_id,omitempty"`
// Contents of a Signed Mark Data file (used for newgtld sunrises, `tld_period` must be sunrise).
SMD string `json:"smd,omitempty"`
Tech DomainContact `json:"tech,omitempty"`
// Template applied when the process is done. It must be a template ID as you can retrieve it using the Template API:
// https://api.gandi.net/docs/template/#get-v5-template-templates
TemplateID string `json:"template_id,omitempty"`
// One of: "sunrise", "landrush", "eap1", "eap2", "eap3", "eap4", "eap5", "eap6", "eap7", "eap8", "eap9", "golive"
TLD_Period string `json:"tld_period,omitempty"`
}
// GetDomains returns a list of domains owned by the current user, as defined by the client API Key.
func (c *Client) GetDomains() (resp []DomainResponse, err error) {
_, err = c.get("domain/domains", nil, &resp)
return
}
// CreateDomain registers a new domain name. Note that this is *NOT* a free operation!
// Ensure your Gandi prepaid account has sufficient credit before performing this action.
func (c *Client) CreateDomain(data DomainCreateRequest) (err error) {
_, err = c.post("domain/domains", data, nil)
return
}
// GetDomainContacts returns all contacts for the specified domain.
func (c *Client) GetDomainContacts(fqdn string) (resp DomainContacts, err error) {
_, err = c.get("domain/domains/"+fqdn+"/contacts", nil, &resp)
return
}
// SetDomainContacts updates contacts for the specified domain. Note that only the admin, tech and billing contact
// information can be changed.
func (c *Client) SetDomainContacts(fqdn string, contacts DomainContacts) (err error) {
_, err = c.patch("domain/domains/"+fqdn+"/contacts", contacts, nil)
return
}
// SetDomainOwner sets the owner information for the specified domain.
// Information that would trigger a full change of ownership cannot be changed, such as names.
func (c *Client) SetDomainOwner(fqdn string, contact DomainContact) (err error) {
_, err = c.put("domain/domains/"+fqdn+"/contacts/owner", contact, nil)
return
}
// SetDomainAutoRenew sets the automatic renewal configuration for the specified domain
func (c *Client) SetDomainAutoRenew(fqdn, org_id string, enabled bool, duration int) (err error) {
_, err = c.patch("domain/domains/"+fqdn+"/autorenew", struct {
enabled bool
duration int
org_id string
}{
enabled: enabled,
duration: duration,
org_id: org_id,
}, nil)
return
}