Skip to content

Commit 776b666

Browse files
jbelientlimoncellisignalwerk
authored
NEW PROVIDER: INFOMANIAK (#3574)
This is a provider for @Infomaniak (https://www.infomaniak.com/). --------- Co-authored-by: Tom Limoncelli <[email protected]> Co-authored-by: signalwerk <[email protected]>
1 parent e5e7934 commit 776b666

File tree

10 files changed

+640
-0
lines changed

10 files changed

+640
-0
lines changed

OWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ providers/hetznerv2 @das7pad
3131
providers/hexonet @KaiSchwarz-cnic
3232
providers/hostingde @juliusrickert
3333
providers/huaweicloud @huihuimoe
34+
providers/infomaniak @jbelien
3435
providers/internetbs @pragmaton
3536
providers/inwx @patschi
3637
providers/joker @atrull

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Currently supported DNS providers:
4545
- hosting.de
4646
- Huawei Cloud DNS
4747
- Hurricane Electric DNS
48+
- Infomaniak
4849
- INWX
4950
- Joker
5051
- Linode

documentation/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
* [hosting.de](provider/hostingde.md)
148148
* [Huawei Cloud DNS](provider/huaweicloud.md)
149149
* [Hurricane Electric DNS](provider/hedns.md)
150+
* [Infomaniak](provider/infomaniak.md)
150151
* [Internet.bs](provider/internetbs.md)
151152
* [INWX](provider/inwx.md)
152153
* [Joker](provider/joker.md)

documentation/provider/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Jump to a table:
5858
| [`HEXONET`](hexonet.md) ||||
5959
| [`HOSTINGDE`](hostingde.md) ||||
6060
| [`HUAWEICLOUD`](huaweicloud.md) ||||
61+
| [`INFOMANIAK`](infomaniak.md) ||||
6162
| [`INTERNETBS`](internetbs.md) ||||
6263
| [`INWX`](inwx.md) ||||
6364
| [`JOKER`](joker.md) ||||
@@ -122,6 +123,7 @@ Jump to a table:
122123
| [`HEXONET`](hexonet.md) |||||
123124
| [`HOSTINGDE`](hostingde.md) |||||
124125
| [`HUAWEICLOUD`](huaweicloud.md) |||||
126+
| [`INFOMANIAK`](infomaniak.md) |||||
125127
| [`INTERNETBS`](internetbs.md) |||||
126128
| [`INWX`](inwx.md) |||||
127129
| [`JOKER`](joker.md) |||||
@@ -183,6 +185,7 @@ Jump to a table:
183185
| [`HEXONET`](hexonet.md) ||||||
184186
| [`HOSTINGDE`](hostingde.md) ||||||
185187
| [`HUAWEICLOUD`](huaweicloud.md) ||||||
188+
| [`INFOMANIAK`](infomaniak.md) ||||||
186189
| [`INWX`](inwx.md) ||||||
187190
| [`JOKER`](joker.md) ||||||
188191
| [`LINODE`](linode.md) ||||||
@@ -241,6 +244,7 @@ Jump to a table:
241244
| [`HEXONET`](hexonet.md) |||||
242245
| [`HOSTINGDE`](hostingde.md) |||||
243246
| [`HUAWEICLOUD`](huaweicloud.md) |||||
247+
| [`INFOMANIAK`](infomaniak.md) |||||
244248
| [`INWX`](inwx.md) |||||
245249
| [`JOKER`](joker.md) |||||
246250
| [`LOOPIA`](loopia.md) |||||
@@ -298,6 +302,7 @@ Jump to a table:
298302
| [`HEXONET`](hexonet.md) ||||||
299303
| [`HOSTINGDE`](hostingde.md) ||||||
300304
| [`HUAWEICLOUD`](huaweicloud.md) ||||||
305+
| [`INFOMANIAK`](infomaniak.md) ||||||
301306
| [`INWX`](inwx.md) ||||||
302307
| [`JOKER`](joker.md) ||||||
303308
| [`LINODE`](linode.md) ||||||
@@ -345,6 +350,7 @@ Jump to a table:
345350
| [`HETZNER_V2`](hetznerv2.md) ||||
346351
| [`HOSTINGDE`](hostingde.md) ||||
347352
| [`HUAWEICLOUD`](huaweicloud.md) ||||
353+
| [`INFOMANIAK`](infomaniak.md) ||||
348354
| [`INWX`](inwx.md) ||||
349355
| [`JOKER`](joker.md) ||||
350356
| [`LOOPIA`](loopia.md) ||||
@@ -428,6 +434,7 @@ Providers in this category and their maintainers are:
428434
|[`HEXONET`](hexonet.md)|@KaiSchwarz-cnic|
429435
|[`HOSTINGDE`](hostingde.md)|@membero|
430436
|[`HUAWEICLOUD`](huaweicloud.md)|@huihuimoe|
437+
|[`INFOMANIAK`](infomaniak.md)|@jbelien|
431438
|[`INTERNETBS`](internetbs.md)|@pragmaton|
432439
|[`INWX`](inwx.md)|@patschi|
433440
|[`LINODE`](linode.md)|@koesie10|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
This is the provider for [Infomaniak](https://www.infomaniak.com/).
2+
3+
## Configuration
4+
5+
To use this provider, add an entry to `creds.json` with `TYPE` set to `INFOMANIAK` along with a Infomaniak account personal access token.
6+
7+
Examples:
8+
9+
{% code title="creds.json" %}
10+
```json
11+
{
12+
"infomaniak": {
13+
"TYPE": "INFOMANIAK",
14+
"token": "your-infomaniak-account-access-token",
15+
}
16+
}
17+
```
18+
{% endcode %}
19+
20+
## Metadata
21+
This provider does not recognize any special metadata fields unique to Infomaniak.
22+
23+
## Usage
24+
An example configuration:
25+
26+
{% code title="dnsconfig.js" %}
27+
```javascript
28+
var REG_NONE = NewRegistrar("none");
29+
var DSP_INFOMANIAK = NewDnsProvider("infomaniak");
30+
31+
D("example.com", REG_NONE, DnsProvider(DSP_INFOMANIAK),
32+
A("test", "1.2.3.4"),
33+
);
34+
```
35+
{% endcode %}
36+
37+
## Activation
38+
DNSControl depends on a Infomaniak account personal access token.

integrationTest/profiles.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@
213213
"TYPE": "HUAWEICLOUD",
214214
"domain": "$HUAWEICLOUD_DOMAIN"
215215
},
216+
"INFOMANIAK": {
217+
"TYPE": "INFOMANIAK",
218+
"domain": "$INFOMANIAK_DOMAIN",
219+
"token": "$INFOMANIAK_TOKEN"
220+
},
216221
"INWX": {
217222
"TYPE": "INWX",
218223
"domain": "$INWX_DOMAIN",

pkg/providers/_all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
_ "github.com/StackExchange/dnscontrol/v4/providers/hexonet"
3737
_ "github.com/StackExchange/dnscontrol/v4/providers/hostingde"
3838
_ "github.com/StackExchange/dnscontrol/v4/providers/huaweicloud"
39+
_ "github.com/StackExchange/dnscontrol/v4/providers/infomaniak"
3940
_ "github.com/StackExchange/dnscontrol/v4/providers/internetbs"
4041
_ "github.com/StackExchange/dnscontrol/v4/providers/inwx"
4142
_ "github.com/StackExchange/dnscontrol/v4/providers/joker"

providers/infomaniak/api.go

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
package infomaniak
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
)
9+
10+
const baseURL = "https://api.infomaniak.com/2"
11+
12+
type dnssecRecord struct {
13+
IsEnabled bool `json:"is_enabled"`
14+
}
15+
16+
type errorRecord struct {
17+
Code string `json:"code"`
18+
Description string `json:"description"`
19+
}
20+
21+
type dnsZoneResponse struct {
22+
Result string `json:"result"`
23+
Data dnsZone `json:"data,omitempty"`
24+
Error errorRecord `json:"error,omitempty"`
25+
}
26+
27+
type dnsRecordsResponse struct {
28+
Result string `json:"result"`
29+
Data []dnsRecord `json:"data,omitempty"`
30+
Error errorRecord `json:"error,omitempty"`
31+
}
32+
33+
type dnsRecordResponse struct {
34+
Result string `json:"result"`
35+
Data dnsRecord `json:"data,omitempty"`
36+
Error errorRecord `json:"error,omitempty"`
37+
}
38+
39+
type boolResponse struct {
40+
Result string `json:"result"`
41+
Data bool `json:"data,omitempty"`
42+
Error errorRecord `json:"error,omitempty"`
43+
}
44+
type dnsZone struct {
45+
ID int64 `json:"id,omitempty"`
46+
FQDN string `json:"fqdn,omitempty"`
47+
DNSSEC dnssecRecord `json:"dnssec,omitempty"`
48+
Nameservers []string `json:"nameservers,omitempty"`
49+
}
50+
51+
type dnsRecord struct {
52+
ID int64 `json:"id,omitempty"`
53+
Source string `json:"source,omitempty"`
54+
Type string `json:"type,omitempty"`
55+
TTL int64 `json:"ttl,omitempty"`
56+
Target string `json:"target,omitempty"`
57+
UpdatedAt int64 `json:"updated_at,omitempty"`
58+
}
59+
60+
type dnsRecordCreate struct {
61+
Source string `json:"source,omitempty"`
62+
Type string `json:"type,omitempty"`
63+
TTL int64 `json:"ttl,omitempty"`
64+
Target string `json:"target,omitempty"`
65+
}
66+
67+
type dnsRecordUpdate struct {
68+
Target string `json:"target,omitempty"`
69+
TTL int64 `json:"ttl,omitempty"`
70+
}
71+
72+
// Get zone information
73+
// See https://developer.infomaniak.com/docs/api/get/2/zones/%7Bzone%7D
74+
func (p *infomaniakProvider) getDNSZone(zone string) (*dnsZone, error) {
75+
reqURL := fmt.Sprintf("%s/zones/%s", baseURL, zone)
76+
77+
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
78+
if err != nil {
79+
return nil, err
80+
}
81+
req.Header.Add("Authorization", "Bearer "+p.apiToken)
82+
req.Header.Add("Content-Type", "application/json")
83+
84+
res, err := http.DefaultClient.Do(req)
85+
if err != nil {
86+
return nil, err
87+
}
88+
defer res.Body.Close()
89+
90+
response := &dnsZoneResponse{}
91+
err = json.NewDecoder(res.Body).Decode(response)
92+
if err != nil {
93+
return nil, err
94+
}
95+
96+
return &response.Data, nil
97+
}
98+
99+
// Retrieve all dns record for a given zone
100+
// See https://developer.infomaniak.com/docs/api/get/2/zones/%7Bzone%7D/records
101+
func (p *infomaniakProvider) getDNSRecords(zone string) ([]dnsRecord, error) {
102+
reqURL := fmt.Sprintf("%s/zones/%s/records", baseURL, zone)
103+
104+
req, err := http.NewRequest(http.MethodGet, reqURL, nil)
105+
if err != nil {
106+
return nil, err
107+
}
108+
req.Header.Add("Authorization", "Bearer "+p.apiToken)
109+
req.Header.Add("Content-Type", "application/json")
110+
111+
res, err := http.DefaultClient.Do(req)
112+
if err != nil {
113+
return nil, err
114+
}
115+
defer res.Body.Close()
116+
117+
response := &dnsRecordsResponse{}
118+
err = json.NewDecoder(res.Body).Decode(response)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
return response.Data, nil
124+
}
125+
126+
// Delete a dns record
127+
// See https://developer.infomaniak.com/docs/api/delete/2/zones/%7Bzone%7D/records/%7Brecord%7D
128+
func (p *infomaniakProvider) deleteDNSRecord(zone string, recordID string) error {
129+
reqURL := fmt.Sprintf("%s/zones/%s/records/%s", baseURL, zone, recordID)
130+
131+
req, err := http.NewRequest(http.MethodDelete, reqURL, nil)
132+
if err != nil {
133+
return err
134+
}
135+
req.Header.Add("Authorization", "Bearer "+p.apiToken)
136+
req.Header.Add("Content-Type", "application/json")
137+
138+
res, err := http.DefaultClient.Do(req)
139+
if err != nil {
140+
return err
141+
}
142+
defer res.Body.Close()
143+
144+
response := &boolResponse{}
145+
err = json.NewDecoder(res.Body).Decode(response)
146+
if err != nil {
147+
return err
148+
}
149+
150+
if response.Result == "error" {
151+
return fmt.Errorf("failed to delete record %s in zone %s: %s", recordID, zone, response.Error.Description)
152+
}
153+
154+
return nil
155+
}
156+
157+
// Create a dns record in a given zone
158+
// See https://developer.infomaniak.com/docs/api/post/2/zones/%7Bzone%7D/records
159+
func (p *infomaniakProvider) createDNSRecord(zone string, rec *dnsRecordCreate) (*dnsRecord, error) {
160+
reqURL := fmt.Sprintf("%s/zones/%s/records", baseURL, zone)
161+
162+
data, err := json.Marshal(rec)
163+
if err != nil {
164+
return nil, err
165+
}
166+
167+
req, err := http.NewRequest(http.MethodPost, reqURL, bytes.NewReader(data))
168+
if err != nil {
169+
return nil, err
170+
}
171+
req.Header.Add("Authorization", "Bearer "+p.apiToken)
172+
req.Header.Add("Content-Type", "application/json")
173+
174+
res, err := http.DefaultClient.Do(req)
175+
if err != nil {
176+
return nil, err
177+
}
178+
defer res.Body.Close()
179+
180+
response := &dnsRecordResponse{}
181+
err = json.NewDecoder(res.Body).Decode(response)
182+
if err != nil {
183+
return nil, err
184+
}
185+
186+
if response.Result == "error" {
187+
return nil, fmt.Errorf("failed to create %s record in zone %s: %s", rec.Type, zone, response.Error.Description)
188+
}
189+
190+
return &response.Data, nil
191+
}
192+
193+
// Update a dns record in a given zone
194+
// See https://developer.infomaniak.com/docs/api/put/2/zones/%7Bzone%7D/records/%7Brecord%7D
195+
func (p *infomaniakProvider) updateDNSRecord(zone string, recordID string, rec *dnsRecordUpdate) (*dnsRecord, error) {
196+
reqURL := fmt.Sprintf("%s/zones/%s/records/%s", baseURL, zone, recordID)
197+
198+
data, err := json.Marshal(rec)
199+
if err != nil {
200+
return nil, err
201+
}
202+
203+
req, err := http.NewRequest(http.MethodPut, reqURL, bytes.NewReader(data))
204+
if err != nil {
205+
return nil, err
206+
}
207+
req.Header.Add("Authorization", "Bearer "+p.apiToken)
208+
req.Header.Add("Content-Type", "application/json")
209+
210+
res, err := http.DefaultClient.Do(req)
211+
if err != nil {
212+
return nil, err
213+
}
214+
defer res.Body.Close()
215+
216+
response := &dnsRecordResponse{}
217+
err = json.NewDecoder(res.Body).Decode(response)
218+
if err != nil {
219+
return nil, err
220+
}
221+
222+
if response.Result == "error" {
223+
return nil, fmt.Errorf("failed to update record %s in zone %s: %s", recordID, zone, response.Error.Description)
224+
}
225+
226+
return &response.Data, nil
227+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package infomaniak
2+
3+
import (
4+
"github.com/StackExchange/dnscontrol/v4/models"
5+
"github.com/StackExchange/dnscontrol/v4/pkg/rejectif"
6+
)
7+
8+
// AuditRecords returns a list of errors corresponding to the records
9+
// that aren't supported by this provider. If all records are
10+
// supported, an empty list is returned.
11+
func AuditRecords(records []*models.RecordConfig) []error {
12+
a := rejectif.Auditor{}
13+
14+
return a.Audit(records)
15+
}

0 commit comments

Comments
 (0)