-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
964 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: "WEDOS" | ||
date: 2019-03-03T16:39:46+01:00 | ||
draft: false | ||
slug: wedos | ||
--- | ||
|
||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. --> | ||
<!-- providers/dns/wedos/wedos.toml --> | ||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. --> | ||
|
||
Since: v4.4.0 | ||
|
||
Configuration for [WEDOS](https://www.wedos.com). | ||
|
||
|
||
<!--more--> | ||
|
||
- Code: `wedos` | ||
|
||
Here is an example bash command using the WEDOS provider: | ||
|
||
```bash | ||
WEDOS_USERNAME=xxxxxxxx \ | ||
WEDOS_WAPI_PASSWORD=xxxxxxxx \ | ||
lego -email myemail@example.com --dns wedos --domains my.example.org -run | ||
``` | ||
|
||
|
||
|
||
|
||
## Credentials | ||
|
||
| Environment Variable Name | Description | | ||
|-----------------------|-------------| | ||
| `WEDOS_USERNAME` | Username is the same as for the admin account | | ||
| `WEDOS_WAPI_PASSWORD` | Password needs to be generated and IP allowed in the admin interface | | ||
|
||
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. | ||
More information [here](/lego/dns/#configuration-and-credentials). | ||
|
||
|
||
## Additional Configuration | ||
|
||
| Environment Variable Name | Description | | ||
|--------------------------------|-------------| | ||
| `WEDOS_HTTP_TIMEOUT` | API request timeout | | ||
| `WEDOS_POLLING_INTERVAL` | Time between DNS propagation check | | ||
| `WEDOS_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | ||
| `WEDOS_TTL` | The TTL of the TXT record used for the DNS challenge | | ||
|
||
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. | ||
More information [here](/lego/dns/#configuration-and-credentials). | ||
|
||
|
||
|
||
|
||
## More information | ||
|
||
- [API documentation](https://kb.wedos.com/en/kategorie/wapi-api-interface/wdns-en/) | ||
|
||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. --> | ||
<!-- providers/dns/wedos/wedos.toml --> | ||
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package internal | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
"time" | ||
|
||
"github.com/go-acme/lego/v4/challenge/dns01" | ||
) | ||
|
||
const baseURL = "https://api.wedos.com/wapi/json" | ||
|
||
const codeOk = 1000 | ||
|
||
const ( | ||
commandPing = "ping" | ||
commandDNSDomainCommit = "dns-domain-commit" | ||
commandDNSRowsList = "dns-rows-list" | ||
commandDNSRowDelete = "dns-row-delete" | ||
commandDNSRowAdd = "dns-row-add" | ||
commandDNSRowUpdate = "dns-row-update" | ||
) | ||
|
||
type ResponsePayload struct { | ||
Code int `json:"code,omitempty"` | ||
Result string `json:"result,omitempty"` | ||
Timestamp int `json:"timestamp,omitempty"` | ||
SvTRID string `json:"svTRID,omitempty"` | ||
Command string `json:"command,omitempty"` | ||
Data json.RawMessage `json:"data"` | ||
DNSRowsList []DNSRow | ||
} | ||
|
||
type DNSRow struct { | ||
ID string `json:"ID,omitempty"` | ||
Domain string `json:"domain,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
TTL json.Number `json:"ttl,omitempty" type:"integer"` | ||
Type string `json:"rdtype,omitempty"` | ||
Data string `json:"rdata"` | ||
} | ||
|
||
type APIRequest struct { | ||
User string `json:"user,omitempty"` | ||
Auth string `json:"auth,omitempty"` | ||
Command string `json:"command,omitempty"` | ||
Data interface{} `json:"data,omitempty"` | ||
} | ||
|
||
type Client struct { | ||
username string | ||
password string | ||
baseURL string | ||
HTTPClient *http.Client | ||
} | ||
|
||
func NewClient(username string, password string) *Client { | ||
return &Client{ | ||
username: username, | ||
password: password, | ||
baseURL: baseURL, | ||
HTTPClient: &http.Client{Timeout: 10 * time.Second}, | ||
} | ||
} | ||
|
||
// GetRecords lists all the records in the zone. | ||
// https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-rows-list/ | ||
func (c *Client) GetRecords(ctx context.Context, zone string) ([]DNSRow, error) { | ||
payload := map[string]interface{}{ | ||
"domain": dns01.UnFqdn(zone), | ||
} | ||
|
||
resp, err := c.do(ctx, commandDNSRowsList, payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
arrayWrapper := struct { | ||
Rows []DNSRow `json:"row"` | ||
}{} | ||
|
||
err = json.Unmarshal(resp.Data, &arrayWrapper) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return arrayWrapper.Rows, err | ||
} | ||
|
||
// AddRecord adds a record in the zone, either by updating existing records or creating new ones. | ||
// https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-add-row/ | ||
// https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-row-update/ | ||
func (c *Client) AddRecord(ctx context.Context, zone string, record DNSRow) error { | ||
payload := DNSRow{ | ||
Domain: dns01.UnFqdn(zone), | ||
TTL: record.TTL, | ||
Type: record.Type, | ||
Data: record.Data, | ||
} | ||
|
||
cmd := commandDNSRowAdd | ||
if record.ID == "" { | ||
payload.Name = record.Name | ||
} else { | ||
cmd = commandDNSRowUpdate | ||
payload.ID = record.ID | ||
} | ||
|
||
_, err := c.do(ctx, cmd, payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// DeleteRecord deletes a record from the zone. | ||
// If a record does not have an ID, it will be looked up. | ||
// https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-row-delete/ | ||
func (c *Client) DeleteRecord(ctx context.Context, zone string, recordID string) error { | ||
payload := DNSRow{ | ||
Domain: dns01.UnFqdn(zone), | ||
ID: recordID, | ||
} | ||
|
||
_, err := c.do(ctx, commandDNSRowDelete, payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Commit not really required, all changes will be auto-committed after 5 minutes. | ||
// https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-domain-commit/ | ||
func (c *Client) Commit(ctx context.Context, zone string) error { | ||
payload := map[string]interface{}{ | ||
"name": dns01.UnFqdn(zone), | ||
} | ||
|
||
_, err := c.do(ctx, commandDNSDomainCommit, payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Client) Ping(ctx context.Context) error { | ||
_, err := c.do(ctx, commandPing, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Client) do(ctx context.Context, command string, payload interface{}) (*ResponsePayload, error) { | ||
requestObject := map[string]interface{}{ | ||
"request": APIRequest{ | ||
User: c.username, | ||
Auth: authToken(c.username, c.password), | ||
Command: command, | ||
Data: payload, | ||
}, | ||
} | ||
|
||
jsonBytes, err := json.Marshal(requestObject) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
form := url.Values{} | ||
form.Add("request", string(jsonBytes)) | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL, strings.NewReader(form.Encode())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||
|
||
resp, err := c.HTTPClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if resp.StatusCode/100 != 2 { | ||
return nil, fmt.Errorf("API error, status code: %d", resp.StatusCode) | ||
} | ||
|
||
responseWrapper := struct { | ||
Response ResponsePayload `json:"response"` | ||
}{} | ||
|
||
err = json.Unmarshal(body, &responseWrapper) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if responseWrapper.Response.Code != codeOk { | ||
return nil, fmt.Errorf("wedos responded with error code %d = %s", responseWrapper.Response.Code, responseWrapper.Response.Result) | ||
} | ||
|
||
return &responseWrapper.Response, err | ||
} |
Oops, something went wrong.