Skip to content

Commit

Permalink
feat: add DNS provider for Variomedia
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 6, 2022
1 parent 9a95c86 commit 8311464
Show file tree
Hide file tree
Showing 16 changed files with 937 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns).
| [reg.ru](https://go-acme.github.io/lego/dns/regru/) | [RFC2136](https://go-acme.github.io/lego/dns/rfc2136/) | [RimuHosting](https://go-acme.github.io/lego/dns/rimuhosting/) | [Sakura Cloud](https://go-acme.github.io/lego/dns/sakuracloud/) |
| [Scaleway](https://go-acme.github.io/lego/dns/scaleway/) | [Selectel](https://go-acme.github.io/lego/dns/selectel/) | [Servercow](https://go-acme.github.io/lego/dns/servercow/) | [Simply.com](https://go-acme.github.io/lego/dns/simply/) |
| [Sonic](https://go-acme.github.io/lego/dns/sonic/) | [Stackpath](https://go-acme.github.io/lego/dns/stackpath/) | [Tencent Cloud DNS](https://go-acme.github.io/lego/dns/tencentcloud/) | [TransIP](https://go-acme.github.io/lego/dns/transip/) |
| [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) | [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) | [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) |
| [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) | [Vultr](https://go-acme.github.io/lego/dns/vultr/) | [WEDOS](https://go-acme.github.io/lego/dns/wedos/) |
| [Yandex](https://go-acme.github.io/lego/dns/yandex/) | [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) | [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) | |
| [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) | [Variomedia](https://go-acme.github.io/lego/dns/variomedia/) | [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) |
| [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) | [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) | [Vultr](https://go-acme.github.io/lego/dns/vultr/) |
| [WEDOS](https://go-acme.github.io/lego/dns/wedos/) | [Yandex](https://go-acme.github.io/lego/dns/yandex/) | [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) | [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) |

<!-- END DNS PROVIDERS LIST -->

Expand Down
22 changes: 22 additions & 0 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func allDNSCodes() string {
"stackpath",
"tencentcloud",
"transip",
"variomedia",
"vegadns",
"vercel",
"versio",
Expand Down Expand Up @@ -2087,6 +2088,27 @@ func displayDNSHelp(name string) error {
ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/transip`)

case "variomedia":
// generated from: providers/dns/variomedia/variomedia.toml
ew.writeln(`Configuration for Variomedia.`)
ew.writeln(`Code: 'variomedia'`)
ew.writeln(`Since: 'v4.8.0'`)
ew.writeln()

ew.writeln(`Credentials:`)
ew.writeln(` - "API_TOKEN": API token`)
ew.writeln()

ew.writeln(`Additional Configuration:`)
ew.writeln(` - "DODE_SEQUENCE_INTERVAL": Time between sequential requests`)
ew.writeln(` - "VARIOMEDIA_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "VARIOMEDIA_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "VARIOMEDIA_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "VARIOMEDIA_TTL": The TTL of the TXT record used for the DNS challenge`)

ew.writeln()
ew.writeln(`More information: https://go-acme.github.io/lego/dns/variomedia`)

case "vegadns":
// generated from: providers/dns/vegadns/vegadns.toml
ew.writeln(`Configuration for VegaDNS.`)
Expand Down
63 changes: 63 additions & 0 deletions docs/content/dns/zz_gen_variomedia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: "Variomedia"
date: 2019-03-03T16:39:46+01:00
draft: false
slug: variomedia
---

<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/variomedia/variomedia.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->

Since: v4.8.0

Configuration for [Variomedia](https://www.variomedia.de/).


<!--more-->

- Code: `variomedia`

Here is an example bash command using the Variomedia provider:

```bash
API_TOKEN=xxxx \
lego --email [email protected] --dns variomedia --domains my.example.org run
```




## Credentials

| Environment Variable Name | Description |
|-----------------------|-------------|
| `API_TOKEN` | API token |

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 |
|--------------------------------|-------------|
| `DODE_SEQUENCE_INTERVAL` | Time between sequential requests |
| `VARIOMEDIA_HTTP_TIMEOUT` | API request timeout |
| `VARIOMEDIA_POLLING_INTERVAL` | Time between DNS propagation check |
| `VARIOMEDIA_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `VARIOMEDIA_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://api.variomedia.de/docs/dns-records.html)

<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
<!-- providers/dns/variomedia/variomedia.toml -->
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
3 changes: 3 additions & 0 deletions providers/dns/dns_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/stackpath"
"github.com/go-acme/lego/v4/providers/dns/tencentcloud"
"github.com/go-acme/lego/v4/providers/dns/transip"
"github.com/go-acme/lego/v4/providers/dns/variomedia"
"github.com/go-acme/lego/v4/providers/dns/vegadns"
"github.com/go-acme/lego/v4/providers/dns/vercel"
"github.com/go-acme/lego/v4/providers/dns/versio"
Expand Down Expand Up @@ -298,6 +299,8 @@ func NewDNSChallengeProviderByName(name string) (challenge.Provider, error) {
return tencentcloud.NewDNSProvider()
case "transip":
return transip.NewDNSProvider()
case "variomedia":
return variomedia.NewDNSProvider()
case "vegadns":
return vegadns.NewDNSProvider()
case "vercel":
Expand Down
137 changes: 137 additions & 0 deletions providers/dns/variomedia/internal/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package internal

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"path"
"time"
)

const defaultBaseURL = "https://api.variomedia.de"

type Client struct {
apiToken string
baseURL *url.URL
HTTPClient *http.Client
}

func NewClient(apiToken string) *Client {
baseURL, _ := url.Parse(defaultBaseURL)

return &Client{
apiToken: apiToken,
baseURL: baseURL,
HTTPClient: &http.Client{Timeout: 10 * time.Second},
}
}

func (c Client) CreateDNSRecord(record DNSRecord) (*CreateDNSRecordResponse, error) {
endpoint, err := c.baseURL.Parse(path.Join(c.baseURL.Path, "dns-records"))
if err != nil {
return nil, err
}

data := CreateDNSRecordRequest{Data: Data{
Type: "dns-record",
Attributes: record,
}}

body, err := json.Marshal(data)
if err != nil {
return nil, err
}

req, err := http.NewRequest(http.MethodPost, endpoint.String(), bytes.NewReader(body))
if err != nil {
return nil, err
}

var result CreateDNSRecordResponse
err = c.do(req, &result)
if err != nil {
return nil, err
}

return &result, nil
}

func (c Client) DeleteDNSRecord(id string) (*DeleteRecordResponse, error) {
endpoint, err := c.baseURL.Parse(path.Join(c.baseURL.Path, "dns-records", id))
if err != nil {
return nil, err
}

req, err := http.NewRequest(http.MethodDelete, endpoint.String(), nil)
if err != nil {
return nil, err
}

var result DeleteRecordResponse
err = c.do(req, &result)
if err != nil {
return nil, err
}

return &result, nil
}

func (c Client) GetJob(id string) (*GetJobResponse, error) {
endpoint, err := c.baseURL.Parse(path.Join(c.baseURL.Path, "queue-jobs", id))
if err != nil {
return nil, err
}

req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}

var result GetJobResponse
err = c.do(req, &result)
if err != nil {
return nil, err
}

return &result, nil
}

func (c Client) do(req *http.Request, data interface{}) error {
req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Accept", "application/vnd.variomedia.v1+json")
req.Header.Set("Authorization", "token "+c.apiToken)

resp, err := c.HTTPClient.Do(req)
if err != nil {
return err
}

defer func() { _ = resp.Body.Close() }()

if resp.StatusCode/100 != 2 {
all, _ := io.ReadAll(resp.Body)

var e APIError
err = json.Unmarshal(all, &e)
if err != nil {
return fmt.Errorf("%d: %s", resp.StatusCode, string(all))
}

return e
}

content, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

err = json.Unmarshal(content, data)
if err != nil {
return fmt.Errorf("%w: %s", err, string(content))
}

return nil
}
Loading

0 comments on commit 8311464

Please sign in to comment.