mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
chore: update to go1.24 (#2566)
This commit is contained in:
parent
40baed291c
commit
713acefd7f
198 changed files with 968 additions and 881 deletions
|
|
@ -6,6 +6,13 @@ formatters:
|
||||||
- gofmt
|
- gofmt
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goimports
|
- goimports
|
||||||
|
settings:
|
||||||
|
gofumpt:
|
||||||
|
extra-rules: true
|
||||||
|
gofmt:
|
||||||
|
rewrite-rules:
|
||||||
|
- pattern: 'interface{}'
|
||||||
|
replacement: 'any'
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
default: all
|
default: all
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func New(httpClient *http.Client, userAgent, caDirURL, kid string, privateKey cr
|
||||||
|
|
||||||
// post performs an HTTP POST request and parses the response body as JSON,
|
// post performs an HTTP POST request and parses the response body as JSON,
|
||||||
// into the provided respBody object.
|
// into the provided respBody object.
|
||||||
func (a *Core) post(uri string, reqBody, response interface{}) (*http.Response, error) {
|
func (a *Core) post(uri string, reqBody, response any) (*http.Response, error) {
|
||||||
content, err := json.Marshal(reqBody)
|
content, err := json.Marshal(reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("failed to marshal message")
|
return nil, errors.New("failed to marshal message")
|
||||||
|
|
@ -71,11 +71,11 @@ func (a *Core) post(uri string, reqBody, response interface{}) (*http.Response,
|
||||||
|
|
||||||
// postAsGet performs an HTTP POST ("POST-as-GET") request.
|
// postAsGet performs an HTTP POST ("POST-as-GET") request.
|
||||||
// https://www.rfc-editor.org/rfc/rfc8555.html#section-6.3
|
// https://www.rfc-editor.org/rfc/rfc8555.html#section-6.3
|
||||||
func (a *Core) postAsGet(uri string, response interface{}) (*http.Response, error) {
|
func (a *Core) postAsGet(uri string, response any) (*http.Response, error) {
|
||||||
return a.retrievablePost(uri, []byte{}, response)
|
return a.retrievablePost(uri, []byte{}, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Core) retrievablePost(uri string, content []byte, response interface{}) (*http.Response, error) {
|
func (a *Core) retrievablePost(uri string, content []byte, response any) (*http.Response, error) {
|
||||||
// during tests, allow to support ~90% of bad nonce with a minimum of attempts.
|
// during tests, allow to support ~90% of bad nonce with a minimum of attempts.
|
||||||
bo := backoff.NewExponentialBackOff()
|
bo := backoff.NewExponentialBackOff()
|
||||||
bo.InitialInterval = 200 * time.Millisecond
|
bo.InitialInterval = 200 * time.Millisecond
|
||||||
|
|
@ -111,7 +111,7 @@ func (a *Core) retrievablePost(uri string, content []byte, response interface{})
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Core) signedPost(uri string, content []byte, response interface{}) (*http.Response, error) {
|
func (a *Core) signedPost(uri string, content []byte, response any) (*http.Response, error) {
|
||||||
signedContent, err := a.jws.SignContent(uri, content)
|
signedContent, err := a.jws.SignContent(uri, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to post JWS message: failed to sign content: %w", err)
|
return nil, fmt.Errorf("failed to post JWS message: failed to sign content: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ func (j *JWS) SignContent(url string, content []byte) (*jose.JSONWebSignature, e
|
||||||
|
|
||||||
options := jose.SignerOptions{
|
options := jose.SignerOptions{
|
||||||
NonceSource: j.nonces,
|
NonceSource: j.nonces,
|
||||||
ExtraHeaders: map[jose.HeaderKey]interface{}{
|
ExtraHeaders: map[jose.HeaderKey]any{
|
||||||
"url": url,
|
"url": url,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +87,7 @@ func (j *JWS) SignEABContent(url, kid string, hmac []byte) (*jose.JSONWebSignatu
|
||||||
jose.SigningKey{Algorithm: jose.HS256, Key: hmac},
|
jose.SigningKey{Algorithm: jose.HS256, Key: hmac},
|
||||||
&jose.SignerOptions{
|
&jose.SignerOptions{
|
||||||
EmbedJWK: false,
|
EmbedJWK: false,
|
||||||
ExtraHeaders: map[jose.HeaderKey]interface{}{
|
ExtraHeaders: map[jose.HeaderKey]any{
|
||||||
"kid": kid,
|
"kid": kid,
|
||||||
"url": url,
|
"url": url,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func NewDoer(client *http.Client, userAgent string) *Doer {
|
||||||
|
|
||||||
// Get performs a GET request with a proper User-Agent string.
|
// Get performs a GET request with a proper User-Agent string.
|
||||||
// If "response" is not provided, callers should close resp.Body when done reading from it.
|
// If "response" is not provided, callers should close resp.Body when done reading from it.
|
||||||
func (d *Doer) Get(url string, response interface{}) (*http.Response, error) {
|
func (d *Doer) Get(url string, response any) (*http.Response, error) {
|
||||||
req, err := d.newRequest(http.MethodGet, url, nil)
|
req, err := d.newRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -57,7 +57,7 @@ func (d *Doer) Head(url string) (*http.Response, error) {
|
||||||
|
|
||||||
// Post performs a POST request with a proper User-Agent string.
|
// Post performs a POST request with a proper User-Agent string.
|
||||||
// If "response" is not provided, callers should close resp.Body when done reading from it.
|
// If "response" is not provided, callers should close resp.Body when done reading from it.
|
||||||
func (d *Doer) Post(url string, body io.Reader, bodyType string, response interface{}) (*http.Response, error) {
|
func (d *Doer) Post(url string, body io.Reader, bodyType string, response any) (*http.Response, error) {
|
||||||
req, err := d.newRequest(http.MethodPost, url, body, contentType(bodyType))
|
req, err := d.newRequest(http.MethodPost, url, body, contentType(bodyType))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -84,7 +84,7 @@ func (d *Doer) newRequest(method, uri string, body io.Reader, opts ...RequestOpt
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Doer) do(req *http.Request, response interface{}) (*http.Response, error) {
|
func (d *Doer) do(req *http.Request, response any) (*http.Response, error) {
|
||||||
resp, err := d.httpClient.Do(req)
|
resp, err := d.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -179,11 +179,11 @@ func CreateCSR(privateKey crypto.PrivateKey, opts CSROptions) ([]byte, error) {
|
||||||
return x509.CreateCertificateRequest(rand.Reader, &template, privateKey)
|
return x509.CreateCertificateRequest(rand.Reader, &template, privateKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PEMEncode(data interface{}) []byte {
|
func PEMEncode(data any) []byte {
|
||||||
return pem.EncodeToMemory(PEMBlock(data))
|
return pem.EncodeToMemory(PEMBlock(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func PEMBlock(data interface{}) *pem.Block {
|
func PEMBlock(data any) *pem.Block {
|
||||||
var pemBlock *pem.Block
|
var pemBlock *pem.Block
|
||||||
switch key := data.(type) {
|
switch key := data.(type) {
|
||||||
case *ecdsa.PrivateKey:
|
case *ecdsa.PrivateKey:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
package dns01
|
package dns01
|
||||||
|
|
||||||
|
import (
|
||||||
|
"iter"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
// ToFqdn converts the name into a fqdn appending a trailing dot.
|
// ToFqdn converts the name into a fqdn appending a trailing dot.
|
||||||
func ToFqdn(name string) string {
|
func ToFqdn(name string) string {
|
||||||
n := len(name)
|
n := len(name)
|
||||||
|
|
@ -17,3 +23,33 @@ func UnFqdn(name string) string {
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnFqdnDomainsSeq generates a sequence of "unFQDNed" domain names derived from a domain (FQDN or not) in descending order.
|
||||||
|
func UnFqdnDomainsSeq(fqdn string) iter.Seq[string] {
|
||||||
|
return func(yield func(string) bool) {
|
||||||
|
if fqdn == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, index := range dns.Split(fqdn) {
|
||||||
|
if !yield(UnFqdn(fqdn[index:])) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainsSeq generates a sequence of domain names derived from a domain (FQDN or not) in descending order.
|
||||||
|
func DomainsSeq(fqdn string) iter.Seq[string] {
|
||||||
|
return func(yield func(string) bool) {
|
||||||
|
if fqdn == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, index := range dns.Split(fqdn) {
|
||||||
|
if !yield(fqdn[index:]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package dns01
|
package dns01
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
@ -62,3 +63,103 @@ func TestUnFqdn(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnFqdnDomainsSeq(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
fqdn string
|
||||||
|
expected []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "empty",
|
||||||
|
fqdn: "",
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "TLD",
|
||||||
|
fqdn: "com",
|
||||||
|
expected: []string{"com"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "2 levels",
|
||||||
|
fqdn: "example.com",
|
||||||
|
expected: []string{"example.com", "com"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "3 levels",
|
||||||
|
fqdn: "foo.example.com",
|
||||||
|
expected: []string{"foo.example.com", "example.com", "com"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
for name, suffix := range map[string]string{"": "", " FQDN": "."} { //nolint:gocritic
|
||||||
|
t.Run(test.desc+name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
actual := slices.Collect(UnFqdnDomainsSeq(test.fqdn + suffix))
|
||||||
|
|
||||||
|
assert.Equal(t, test.expected, actual)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDomainsSeq(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
fqdn string
|
||||||
|
expected []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "empty",
|
||||||
|
fqdn: "",
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "empty FQDN",
|
||||||
|
fqdn: ".",
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "TLD FQDN",
|
||||||
|
fqdn: "com",
|
||||||
|
expected: []string{"com"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "TLD",
|
||||||
|
fqdn: "com.",
|
||||||
|
expected: []string{"com."},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "2 levels",
|
||||||
|
fqdn: "example.com",
|
||||||
|
expected: []string{"example.com", "com"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "2 levels FQDN",
|
||||||
|
fqdn: "example.com.",
|
||||||
|
expected: []string{"example.com.", "com."},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "3 levels",
|
||||||
|
fqdn: "foo.example.com",
|
||||||
|
expected: []string{"foo.example.com", "example.com", "com"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "3 levels FQDN",
|
||||||
|
fqdn: "foo.example.com.",
|
||||||
|
expected: []string{"foo.example.com.", "example.com.", "com."},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
actual := slices.Collect(DomainsSeq(test.fqdn))
|
||||||
|
|
||||||
|
assert.Equal(t, test.expected, actual)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,10 +175,7 @@ func fetchSoaByFqdn(fqdn string, nameservers []string) (*soaCacheEntry, error) {
|
||||||
var err error
|
var err error
|
||||||
var r *dns.Msg
|
var r *dns.Msg
|
||||||
|
|
||||||
labelIndexes := dns.Split(fqdn)
|
for domain := range DomainsSeq(fqdn) {
|
||||||
for _, index := range labelIndexes {
|
|
||||||
domain := fqdn[index:]
|
|
||||||
|
|
||||||
r, err = dnsQuery(domain, dns.TypeSOA, nameservers, true)
|
r, err = dnsQuery(domain, dns.TypeSOA, nameservers, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ type errWriter struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ew *errWriter) writeln(a ...interface{}) {
|
func (ew *errWriter) writeln(a ...any) {
|
||||||
if ew.err != nil {
|
if ew.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ func (ew *errWriter) writeln(a ...interface{}) {
|
||||||
_, ew.err = fmt.Fprintln(ew.w, a...)
|
_, ew.err = fmt.Fprintln(ew.w, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ew *errWriter) writef(format string, a ...interface{}) {
|
func (ew *errWriter) writef(format string, a ...any) {
|
||||||
if ew.err != nil {
|
if ew.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package loader
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -16,6 +17,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/platform/wait"
|
"github.com/go-acme/lego/v4/platform/wait"
|
||||||
|
"github.com/ldez/grignotin/goenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -311,8 +313,13 @@ func goTool() (string, error) {
|
||||||
exeSuffix = ".exe"
|
exeSuffix = ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
|
goRoot, err := goenv.GetOne(context.Background(), goenv.GOROOT)
|
||||||
if _, err := os.Stat(path); err == nil {
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("cannot find go root: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(goRoot, "bin", "go"+exeSuffix)
|
||||||
|
if _, err = os.Stat(path); err == nil {
|
||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
3
go.mod
3
go.mod
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/go-acme/lego/v4
|
module github.com/go-acme/lego/v4
|
||||||
|
|
||||||
go 1.23.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go/compute/metadata v0.6.0
|
cloud.google.com/go/compute/metadata v0.6.0
|
||||||
|
|
@ -44,6 +44,7 @@ require (
|
||||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df
|
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df
|
||||||
github.com/infobloxopen/infoblox-go-client/v2 v2.9.0
|
github.com/infobloxopen/infoblox-go-client/v2 v2.9.0
|
||||||
github.com/labbsr0x/bindman-dns-webhook v1.0.2
|
github.com/labbsr0x/bindman-dns-webhook v1.0.2
|
||||||
|
github.com/ldez/grignotin v0.9.0
|
||||||
github.com/linode/linodego v1.48.1
|
github.com/linode/linodego v1.48.1
|
||||||
github.com/liquidweb/liquidweb-go v1.6.4
|
github.com/liquidweb/liquidweb-go v1.6.4
|
||||||
github.com/mattn/go-isatty v0.0.20
|
github.com/mattn/go-isatty v0.0.20
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -597,6 +597,8 @@ github.com/labbsr0x/bindman-dns-webhook v1.0.2 h1:I7ITbmQPAVwrDdhd6dHKi+MYJTJqPC
|
||||||
github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA=
|
github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA=
|
||||||
github.com/labbsr0x/goh v1.0.1 h1:97aBJkDjpyBZGPbQuOK5/gHcSFbcr5aRsq3RSRJFpPk=
|
github.com/labbsr0x/goh v1.0.1 h1:97aBJkDjpyBZGPbQuOK5/gHcSFbcr5aRsq3RSRJFpPk=
|
||||||
github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w=
|
github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w=
|
||||||
|
github.com/ldez/grignotin v0.9.0 h1:MgOEmjZIVNn6p5wPaGp/0OKWyvq42KnzAt/DAb8O4Ow=
|
||||||
|
github.com/ldez/grignotin v0.9.0/go.mod h1:uaVTr0SoZ1KBii33c47O1M8Jp3OP3YDwhZCmzT9GHEk=
|
||||||
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||||
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
github.com/linode/linodego v1.48.1 h1:Ojw1S+K5jJr1dggO8/H6r4FINxXnJbOU5GkbpaTfmhU=
|
github.com/linode/linodego v1.48.1 h1:Ojw1S+K5jJr1dggO8/H6r4FINxXnJbOU5GkbpaTfmhU=
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ func generateCLIHelp(models *descriptors.Providers) error {
|
||||||
|
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
err = template.Must(
|
err = template.Must(
|
||||||
template.New(filepath.Base(cliTemplate)).Funcs(map[string]interface{}{
|
template.New(filepath.Base(cliTemplate)).Funcs(map[string]any{
|
||||||
"safe": func(src string) string {
|
"safe": func(src string) string {
|
||||||
return strings.ReplaceAll(src, "`", "'")
|
return strings.ReplaceAll(src, "`", "'")
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func generate() error {
|
||||||
|
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
err = template.Must(
|
err = template.Must(
|
||||||
template.New("").Funcs(map[string]interface{}{
|
template.New("").Funcs(map[string]any{
|
||||||
"cleanName": func(src string) string {
|
"cleanName": func(src string) string {
|
||||||
return strings.ReplaceAll(src, "-", "")
|
return strings.ReplaceAll(src, "-", "")
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ type Generator struct {
|
||||||
targetFile string
|
targetFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGenerator(templatePath string, targetFile string) *Generator {
|
func NewGenerator(templatePath, targetFile string) *Generator {
|
||||||
return &Generator{templatePath: templatePath, targetFile: targetFile}
|
return &Generator{templatePath: templatePath, targetFile: targetFile}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,50 +10,50 @@ var Logger StdLogger = log.New(os.Stderr, "", log.LstdFlags)
|
||||||
|
|
||||||
// StdLogger interface for Standard Logger.
|
// StdLogger interface for Standard Logger.
|
||||||
type StdLogger interface {
|
type StdLogger interface {
|
||||||
Fatal(args ...interface{})
|
Fatal(args ...any)
|
||||||
Fatalln(args ...interface{})
|
Fatalln(args ...any)
|
||||||
Fatalf(format string, args ...interface{})
|
Fatalf(format string, args ...any)
|
||||||
Print(args ...interface{})
|
Print(args ...any)
|
||||||
Println(args ...interface{})
|
Println(args ...any)
|
||||||
Printf(format string, args ...interface{})
|
Printf(format string, args ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatal writes a log entry.
|
// Fatal writes a log entry.
|
||||||
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
||||||
func Fatal(args ...interface{}) {
|
func Fatal(args ...any) {
|
||||||
Logger.Fatal(args...)
|
Logger.Fatal(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf writes a log entry.
|
// Fatalf writes a log entry.
|
||||||
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
||||||
func Fatalf(format string, args ...interface{}) {
|
func Fatalf(format string, args ...any) {
|
||||||
Logger.Fatalf(format, args...)
|
Logger.Fatalf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print writes a log entry.
|
// Print writes a log entry.
|
||||||
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
||||||
func Print(args ...interface{}) {
|
func Print(args ...any) {
|
||||||
Logger.Print(args...)
|
Logger.Print(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Println writes a log entry.
|
// Println writes a log entry.
|
||||||
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
||||||
func Println(args ...interface{}) {
|
func Println(args ...any) {
|
||||||
Logger.Println(args...)
|
Logger.Println(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printf writes a log entry.
|
// Printf writes a log entry.
|
||||||
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
// It uses Logger if not nil, otherwise it uses the default log.Logger.
|
||||||
func Printf(format string, args ...interface{}) {
|
func Printf(format string, args ...any) {
|
||||||
Logger.Printf(format, args...)
|
Logger.Printf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnf writes a log entry.
|
// Warnf writes a log entry.
|
||||||
func Warnf(format string, args ...interface{}) {
|
func Warnf(format string, args ...any) {
|
||||||
Printf("[WARN] "+format, args...)
|
Printf("[WARN] "+format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof writes a log entry.
|
// Infof writes a log entry.
|
||||||
func Infof(format string, args ...interface{}) {
|
func Infof(format string, args ...any) {
|
||||||
Printf("[INFO] "+format, args...)
|
Printf("[INFO] "+format, args...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
platform/config/env/env.go
vendored
19
platform/config/env/env.go
vendored
|
|
@ -107,7 +107,7 @@ func getOneWithFallback(main string, names ...string) (string, string) {
|
||||||
|
|
||||||
// GetOrDefaultString returns the given environment variable value as a string.
|
// GetOrDefaultString returns the given environment variable value as a string.
|
||||||
// Returns the default if the env var cannot be found.
|
// Returns the default if the env var cannot be found.
|
||||||
func GetOrDefaultString(envVar string, defaultValue string) string {
|
func GetOrDefaultString(envVar, defaultValue string) string {
|
||||||
return getOrDefault(envVar, defaultValue, ParseString)
|
return getOrDefault(envVar, defaultValue, ParseString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,3 +184,20 @@ func ParseString(s string) (string, error) {
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParsePairs parses a raw string of comma-separated key-value pairs into a map.
|
||||||
|
// Keys and values are separated by a colon and are trimmed of whitespace.
|
||||||
|
func ParsePairs(raw string) (map[string]string, error) {
|
||||||
|
result := make(map[string]string)
|
||||||
|
|
||||||
|
for pair := range strings.SplitSeq(strings.TrimSuffix(raw, ","), ",") {
|
||||||
|
data := strings.Split(pair, ":")
|
||||||
|
if len(data) != 2 {
|
||||||
|
return nil, fmt.Errorf("incorrect pair: %s", pair)
|
||||||
|
}
|
||||||
|
|
||||||
|
result[strings.TrimSpace(data[0])] = strings.TrimSpace(data[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
74
platform/config/env/env_test.go
vendored
74
platform/config/env/env_test.go
vendored
|
|
@ -408,3 +408,77 @@ func TestGetOrFile_PrefersEnvVars(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, "lego_env", value)
|
assert.Equal(t, "lego_env", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParsePairs(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
value string
|
||||||
|
expected map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "one pair",
|
||||||
|
value: "foo:bar",
|
||||||
|
expected: map[string]string{"foo": "bar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "multiple pairs",
|
||||||
|
value: "foo:bar,a:b,c:d",
|
||||||
|
expected: map[string]string{"a": "b", "c": "d", "foo": "bar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "multiple pairs with spaces",
|
||||||
|
value: "foo:bar, a:b , c: d",
|
||||||
|
expected: map[string]string{"a": "b", "c": "d", "foo": "bar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "empty value pair",
|
||||||
|
value: "foo:",
|
||||||
|
expected: map[string]string{"foo": ""},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "empty key pair",
|
||||||
|
value: ":bar",
|
||||||
|
expected: map[string]string{"": "bar"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
pairs, err := ParsePairs(test.value)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, test.expected, pairs)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParsePairs_error(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
value string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "empty value",
|
||||||
|
value: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "multiple colons",
|
||||||
|
value: "foo:bar:bir",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "valid pair and multiple colons",
|
||||||
|
value: "a:b,foo:bar:bir",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
_, err := ParsePairs(test.value)
|
||||||
|
require.Error(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func SetupFakeAPI(t *testing.T) (*http.ServeMux, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteJSONResponse marshals the body as JSON and writes it to the response.
|
// WriteJSONResponse marshals the body as JSON and writes it to the response.
|
||||||
func WriteJSONResponse(w http.ResponseWriter, body interface{}) error {
|
func WriteJSONResponse(w http.ResponseWriter, body any) error {
|
||||||
bs, err := json.Marshal(body)
|
bs, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package acmedns
|
package acmedns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -133,7 +132,7 @@ func TestRegister(t *testing.T) {
|
||||||
p.storage = test.Storage
|
p.storage = test.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
acc, err := p.register(context.Background(), egDomain, egFQDN)
|
acc, err := p.register(t.Context(), egDomain, egFQDN)
|
||||||
if test.ExpectedError != nil {
|
if test.ExpectedError != nil {
|
||||||
assert.Equal(t, test.ExpectedError, err)
|
assert.Equal(t, test.ExpectedError, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -242,7 +241,7 @@ func TestRegister_httpStorage(t *testing.T) {
|
||||||
w.WriteHeader(test.StatusCode)
|
w.WriteHeader(test.StatusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
acc, err := p.register(context.Background(), egDomain, egFQDN)
|
acc, err := p.register(t.Context(), egDomain, egFQDN)
|
||||||
if test.ExpectedError != nil {
|
if test.ExpectedError != nil {
|
||||||
assert.Equal(t, test.ExpectedError, err)
|
assert.Equal(t, test.ExpectedError, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -54,7 +53,7 @@ func setupTest(t *testing.T, pattern, filename string, statusCode int) *HTTPStor
|
||||||
func TestHTTPStorage_Fetch(t *testing.T) {
|
func TestHTTPStorage_Fetch(t *testing.T) {
|
||||||
storage := setupTest(t, "GET /example.com", "fetch.json", http.StatusOK)
|
storage := setupTest(t, "GET /example.com", "fetch.json", http.StatusOK)
|
||||||
|
|
||||||
account, err := storage.Fetch(context.Background(), "example.com")
|
account, err := storage.Fetch(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := goacmedns.Account{
|
expected := goacmedns.Account{
|
||||||
|
|
@ -71,14 +70,14 @@ func TestHTTPStorage_Fetch(t *testing.T) {
|
||||||
func TestHTTPStorage_Fetch_error(t *testing.T) {
|
func TestHTTPStorage_Fetch_error(t *testing.T) {
|
||||||
storage := setupTest(t, "GET /example.com", "error.json", http.StatusInternalServerError)
|
storage := setupTest(t, "GET /example.com", "error.json", http.StatusInternalServerError)
|
||||||
|
|
||||||
_, err := storage.Fetch(context.Background(), "example.com")
|
_, err := storage.Fetch(t.Context(), "example.com")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPStorage_FetchAll(t *testing.T) {
|
func TestHTTPStorage_FetchAll(t *testing.T) {
|
||||||
storage := setupTest(t, "GET /", "fetch-all.json", http.StatusOK)
|
storage := setupTest(t, "GET /", "fetch-all.json", http.StatusOK)
|
||||||
|
|
||||||
account, err := storage.FetchAll(context.Background())
|
account, err := storage.FetchAll(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := map[string]goacmedns.Account{
|
expected := map[string]goacmedns.Account{
|
||||||
|
|
@ -104,7 +103,7 @@ func TestHTTPStorage_FetchAll(t *testing.T) {
|
||||||
func TestHTTPStorage_FetchAll_error(t *testing.T) {
|
func TestHTTPStorage_FetchAll_error(t *testing.T) {
|
||||||
storage := setupTest(t, "GET /", "error.json", http.StatusInternalServerError)
|
storage := setupTest(t, "GET /", "error.json", http.StatusInternalServerError)
|
||||||
|
|
||||||
_, err := storage.FetchAll(context.Background())
|
_, err := storage.FetchAll(t.Context())
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +118,7 @@ func TestHTTPStorage_Put(t *testing.T) {
|
||||||
ServerURL: "https://example.com",
|
ServerURL: "https://example.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := storage.Put(context.Background(), "example.com", account)
|
err := storage.Put(t.Context(), "example.com", account)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +133,7 @@ func TestHTTPStorage_Put_error(t *testing.T) {
|
||||||
ServerURL: "https://example.com",
|
ServerURL: "https://example.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := storage.Put(context.Background(), "example.com", account)
|
err := storage.Put(t.Context(), "example.com", account)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,6 +148,6 @@ func TestHTTPStorage_Put_CNAME_created(t *testing.T) {
|
||||||
ServerURL: "https://example.com",
|
ServerURL: "https://example.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := storage.Put(context.Background(), "example.com", account)
|
err := storage.Put(t.Context(), "example.com", account)
|
||||||
require.ErrorIs(t, err, ErrCNAMEAlreadyCreated)
|
require.ErrorIs(t, err, ErrCNAMEAlreadyCreated)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func TestClient_GetDNSSettings(t *testing.T) {
|
||||||
client := NewClient("user")
|
client := NewClient("user")
|
||||||
client.baseURL = server.URL
|
client.baseURL = server.URL
|
||||||
|
|
||||||
records, err := client.GetDNSSettings(mockContext(), "example.com", "")
|
records, err := client.GetDNSSettings(mockContext(t), "example.com", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []ReturnInfo{
|
expected := []ReturnInfo{
|
||||||
|
|
@ -112,7 +112,7 @@ func TestClient_AddDNSSettings(t *testing.T) {
|
||||||
RecordData: "abcdefgh",
|
RecordData: "abcdefgh",
|
||||||
}
|
}
|
||||||
|
|
||||||
recordID, err := client.AddDNSSettings(mockContext(), record)
|
recordID, err := client.AddDNSSettings(mockContext(t), record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "57347444", recordID)
|
assert.Equal(t, "57347444", recordID)
|
||||||
|
|
@ -128,7 +128,7 @@ func TestClient_DeleteDNSSettings(t *testing.T) {
|
||||||
client := NewClient("user")
|
client := NewClient("user")
|
||||||
client.baseURL = server.URL
|
client.baseURL = server.URL
|
||||||
|
|
||||||
r, err := client.DeleteDNSSettings(mockContext(), "57347450")
|
r, err := client.DeleteDNSSettings(mockContext(t), "57347450")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "TRUE", r)
|
assert.Equal(t, "TRUE", r)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ type Identifier struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIdentifier creates a new Identifier.
|
// NewIdentifier creates a new Identifier.
|
||||||
func NewIdentifier(login string, password string) *Identifier {
|
func NewIdentifier(login, password string) *Identifier {
|
||||||
return &Identifier{
|
return &Identifier{
|
||||||
login: login,
|
login: login,
|
||||||
password: password,
|
password: password,
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,10 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mockContext() context.Context {
|
func mockContext(t *testing.T) context.Context {
|
||||||
return context.WithValue(context.Background(), tokenKey, "593959ca04f0de9689b586c6a647d15d")
|
t.Helper()
|
||||||
|
|
||||||
|
return context.WithValue(t.Context(), tokenKey, "593959ca04f0de9689b586c6a647d15d")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIdentifier_Authentication(t *testing.T) {
|
func TestIdentifier_Authentication(t *testing.T) {
|
||||||
|
|
@ -24,7 +26,7 @@ func TestIdentifier_Authentication(t *testing.T) {
|
||||||
client := NewIdentifier("user", "secret")
|
client := NewIdentifier("user", "secret")
|
||||||
client.authEndpoint = server.URL
|
client.authEndpoint = server.URL
|
||||||
|
|
||||||
credentialToken, err := client.Authentication(context.Background(), 60, false)
|
credentialToken, err := client.Authentication(t.Context(), 60, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "593959ca04f0de9689b586c6a647d15d", credentialToken)
|
assert.Equal(t, "593959ca04f0de9689b586c6a647d15d", credentialToken)
|
||||||
|
|
@ -40,6 +42,6 @@ func TestIdentifier_Authentication_error(t *testing.T) {
|
||||||
client := NewIdentifier("user", "secret")
|
client := NewIdentifier("user", "secret")
|
||||||
client.authEndpoint = server.URL
|
client.authEndpoint = server.URL
|
||||||
|
|
||||||
_, err := client.Authentication(context.Background(), 60, false)
|
_, err := client.Authentication(t.Context(), 60, false)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -61,7 +60,7 @@ func TestClient_GetTxtRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := client.GetTxtRecord(context.Background(), domain, "_acme-challenge", "txtxtxt")
|
_, err := client.GetTxtRecord(t.Context(), domain, "_acme-challenge", "txtxtxt")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,13 +105,13 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
TTL: 600,
|
TTL: 600,
|
||||||
}
|
}
|
||||||
|
|
||||||
newRecord, err := client.CreateRecord(context.Background(), domain, record)
|
newRecord, err := client.CreateRecord(t.Context(), domain, record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &DNSRecord{
|
expected := &DNSRecord{
|
||||||
ID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
ID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
||||||
Type: "txt",
|
Type: "txt",
|
||||||
Value: map[string]interface{}{"text": "txtxtxt"},
|
Value: map[string]any{"text": "txtxtxt"},
|
||||||
Name: "_acme-challenge",
|
Name: "_acme-challenge",
|
||||||
TTL: 120,
|
TTL: 120,
|
||||||
UpstreamHTTPS: "default",
|
UpstreamHTTPS: "default",
|
||||||
|
|
@ -147,6 +146,6 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), domain, recordID)
|
err := client.DeleteRecord(t.Context(), domain, recordID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new Client.
|
// NewClient creates a new Client.
|
||||||
func NewClient(username string, password string, clientContext int) *Client {
|
func NewClient(username, password string, clientContext int) *Client {
|
||||||
baseURL, _ := url.Parse(DefaultEndpoint)
|
baseURL, _ := url.Parse(DefaultEndpoint)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -67,7 +66,7 @@ func TestClient_AddTxtRecords(t *testing.T) {
|
||||||
|
|
||||||
records := []*ResourceRecord{{}}
|
records := []*ResourceRecord{{}}
|
||||||
|
|
||||||
zone, err := client.AddTxtRecords(context.Background(), "example.com", records)
|
zone, err := client.AddTxtRecords(t.Context(), "example.com", records)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Zone{
|
expected := &Zone{
|
||||||
|
|
@ -91,6 +90,6 @@ func TestClient_RemoveTXTRecords(t *testing.T) {
|
||||||
|
|
||||||
records := []*ResourceRecord{{}}
|
records := []*ResourceRecord{{}}
|
||||||
|
|
||||||
err := client.RemoveTXTRecords(context.Background(), "example.com", records)
|
err := client.RemoveTXTRecords(t.Context(), "example.com", records)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -55,7 +54,7 @@ func setupTest(t *testing.T, pattern string, status int, filename string) *Clien
|
||||||
func TestClient_ListRecords(t *testing.T) {
|
func TestClient_ListRecords(t *testing.T) {
|
||||||
client := setupTest(t, "GET /dns_list", http.StatusOK, "dns_list.json")
|
client := setupTest(t, "GET /dns_list", http.StatusOK, "dns_list.json")
|
||||||
|
|
||||||
records, err := client.ListRecords(context.Background(), "example.com")
|
records, err := client.ListRecords(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Record{
|
expected := []Record{
|
||||||
|
|
@ -71,7 +70,7 @@ func TestClient_ListRecords(t *testing.T) {
|
||||||
func TestClient_ListRecords_error(t *testing.T) {
|
func TestClient_ListRecords_error(t *testing.T) {
|
||||||
client := setupTest(t, "GET /dns_list", http.StatusNotFound, "dns_list_error.json")
|
client := setupTest(t, "GET /dns_list", http.StatusNotFound, "dns_list_error.json")
|
||||||
|
|
||||||
_, err := client.ListRecords(context.Background(), "example.com")
|
_, err := client.ListRecords(t.Context(), "example.com")
|
||||||
require.EqualError(t, err, "error: Domain not found (1)")
|
require.EqualError(t, err, "error: Domain not found (1)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,7 +79,7 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
|
|
||||||
record := Record{ID: "74749"}
|
record := Record{ID: "74749"}
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", record)
|
err := client.DeleteRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +88,7 @@ func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
|
|
||||||
record := Record{ID: "74749"}
|
record := Record{ID: "74749"}
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", record)
|
err := client.DeleteRecord(t.Context(), "example.com", record)
|
||||||
require.EqualError(t, err, "error: Domain not found (1)")
|
require.EqualError(t, err, "error: Domain not found (1)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +97,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
|
|
||||||
record := Record{ID: "74749"}
|
record := Record{ID: "74749"}
|
||||||
|
|
||||||
err := client.AddRecord(context.Background(), "example.com", record)
|
err := client.AddRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,6 +106,6 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
|
|
||||||
record := Record{ID: "74749"}
|
record := Record{ID: "74749"}
|
||||||
|
|
||||||
err := client.AddRecord(context.Background(), "example.com", record)
|
err := client.AddRecord(t.Context(), "example.com", record)
|
||||||
require.EqualError(t, err, "error: Domain not found (1)")
|
require.EqualError(t, err, "error: Domain not found (1)")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/aziontech/azionapi-go-sdk/idns"
|
"github.com/aziontech/azionapi-go-sdk/idns"
|
||||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
"github.com/go-acme/lego/v4/platform/config/env"
|
"github.com/go-acme/lego/v4/platform/config/env"
|
||||||
"github.com/miekg/dns"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Environment variables names.
|
// Environment variables names.
|
||||||
|
|
@ -247,11 +246,7 @@ func (d *DNSProvider) findZone(ctx context.Context, fqdn string) (*idns.Zone, er
|
||||||
return nil, errors.New("get zones: no results")
|
return nil, errors.New("get zones: no results")
|
||||||
}
|
}
|
||||||
|
|
||||||
labelIndexes := dns.Split(fqdn)
|
for domain := range dns01.UnFqdnDomainsSeq(fqdn) {
|
||||||
|
|
||||||
for _, index := range labelIndexes {
|
|
||||||
domain := dns01.UnFqdn(fqdn[index:])
|
|
||||||
|
|
||||||
for _, zone := range resp.GetResults() {
|
for _, zone := range resp.GetResults() {
|
||||||
if zone.GetDomain() == domain {
|
if zone.GetDomain() == domain {
|
||||||
return &zone, nil
|
return &zone, nil
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ type Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(baseURL string, username, password string) *Client {
|
func NewClient(baseURL, username, password string) *Client {
|
||||||
bu, _ := url.Parse(baseURL)
|
bu, _ := url.Parse(baseURL)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -35,7 +34,7 @@ func TestClient_LookupParentZoneID(t *testing.T) {
|
||||||
http.Error(rw, "{}", http.StatusOK)
|
http.Error(rw, "{}", http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
parentID, name, err := client.LookupParentZoneID(context.Background(), 2, "foo.example.com")
|
parentID, name, err := client.LookupParentZoneID(t.Context(), 2, "foo.example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.EqualValues(t, 2, parentID)
|
assert.EqualValues(t, 2, parentID)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -48,7 +47,7 @@ func TestClient_CreateAuthenticatedContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx, err := client.CreateAuthenticatedContext(context.Background())
|
ctx, err := client.CreateAuthenticatedContext(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
at := getToken(ctx)
|
at := getToken(ctx)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -62,7 +61,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
Value: "test",
|
Value: "test",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.AddRecord(context.Background(), record)
|
err := client.AddRecord(t.Context(), record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +75,7 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
Value: "test",
|
Value: "test",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.AddRecord(context.Background(), record)
|
err := client.AddRecord(t.Context(), record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
require.EqualError(t, err, "unexpected response: notfqdn: Host _acme-challenge.sub.example.com. malformed / vhn")
|
require.EqualError(t, err, "unexpected response: notfqdn: Host _acme-challenge.sub.example.com. malformed / vhn")
|
||||||
|
|
@ -92,7 +91,7 @@ func TestClient_RemoveRecord(t *testing.T) {
|
||||||
Value: "test",
|
Value: "test",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.RemoveRecord(context.Background(), record)
|
err := client.RemoveRecord(t.Context(), record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +105,7 @@ func TestClient_RemoveRecord_error(t *testing.T) {
|
||||||
Value: "test",
|
Value: "test",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.RemoveRecord(context.Background(), record)
|
err := client.RemoveRecord(t.Context(), record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
require.EqualError(t, err, "unexpected response: notfqdn: Host _acme-challenge.sub.example.com. malformed / vhn")
|
require.EqualError(t, err, "unexpected response: notfqdn: Host _acme-challenge.sub.example.com. malformed / vhn")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -46,7 +45,7 @@ func setupTest(t *testing.T, filename string) *Client {
|
||||||
func TestClient_StatusDomain(t *testing.T) {
|
func TestClient_StatusDomain(t *testing.T) {
|
||||||
client := setupTest(t, "status-domain.json")
|
client := setupTest(t, "status-domain.json")
|
||||||
|
|
||||||
domain, err := client.StatusDomain(context.Background(), "example.com")
|
domain, err := client.StatusDomain(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &StatusResponse{
|
expected := &StatusResponse{
|
||||||
|
|
@ -82,14 +81,14 @@ func TestClient_StatusDomain(t *testing.T) {
|
||||||
func TestClient_StatusDomain_error(t *testing.T) {
|
func TestClient_StatusDomain_error(t *testing.T) {
|
||||||
client := setupTest(t, "error.json")
|
client := setupTest(t, "error.json")
|
||||||
|
|
||||||
_, err := client.StatusDomain(context.Background(), "example.com")
|
_, err := client.StatusDomain(t.Context(), "example.com")
|
||||||
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_ListRecords(t *testing.T) {
|
func TestClient_ListRecords(t *testing.T) {
|
||||||
client := setupTest(t, "list-records.json")
|
client := setupTest(t, "list-records.json")
|
||||||
|
|
||||||
resp, err := client.ListRecords(context.Background(), "example", "example.com")
|
resp, err := client.ListRecords(t.Context(), "example", "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &ListRecordsResponse{
|
expected := &ListRecordsResponse{
|
||||||
|
|
@ -108,7 +107,7 @@ func TestClient_ListRecords(t *testing.T) {
|
||||||
func TestClient_ListRecords_error(t *testing.T) {
|
func TestClient_ListRecords_error(t *testing.T) {
|
||||||
client := setupTest(t, "error.json")
|
client := setupTest(t, "error.json")
|
||||||
|
|
||||||
_, err := client.ListRecords(context.Background(), "example", "example.com")
|
_, err := client.ListRecords(t.Context(), "example", "example.com")
|
||||||
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +121,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
Content: "txttxttxt",
|
Content: "txttxttxt",
|
||||||
TTL: 600,
|
TTL: 600,
|
||||||
}
|
}
|
||||||
resp, err := client.AddRecord(context.Background(), "example.com", "test", "2565", testRecord)
|
resp, err := client.AddRecord(t.Context(), "example.com", "test", "2565", testRecord)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &AddRecord{
|
expected := &AddRecord{
|
||||||
|
|
@ -150,20 +149,20 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
TTL: 600,
|
TTL: 600,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.AddRecord(context.Background(), "example.com", "test", "2565", testRecord)
|
_, err := client.AddRecord(t.Context(), "example.com", "test", "2565", testRecord)
|
||||||
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, "delete-record.json")
|
client := setupTest(t, "delete-record.json")
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", "test", "example.com 600 IN TXT txttxttxt", "2374")
|
err := client.DeleteRecord(t.Context(), "example.com", "test", "example.com 600 IN TXT txttxttxt", "2374")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord_error(t *testing.T) {
|
func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, "error.json")
|
client := setupTest(t, "error.json")
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", "test", "example.com 600 IN TXT txttxttxt", "2374")
|
err := client.DeleteRecord(t.Context(), "example.com", "test", "example.com 600 IN TXT txttxttxt", "2374")
|
||||||
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
require.ErrorIs(t, err, APIError{Code: 402, Status: "error", Message: "Invalid user."})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
"github.com/go-acme/lego/v4/platform/config/env"
|
"github.com/go-acme/lego/v4/platform/config/env"
|
||||||
"github.com/go-acme/lego/v4/providers/dns/internal/ptr"
|
"github.com/go-acme/lego/v4/providers/dns/internal/ptr"
|
||||||
"github.com/miekg/dns"
|
|
||||||
"github.com/nrdcg/bunny-go"
|
"github.com/nrdcg/bunny-go"
|
||||||
"golang.org/x/net/publicsuffix"
|
"golang.org/x/net/publicsuffix"
|
||||||
)
|
)
|
||||||
|
|
@ -200,16 +199,14 @@ func findZone(zones *bunny.DNSZones, domain string) *bunny.DNSZone {
|
||||||
func possibleDomains(domain string) []string {
|
func possibleDomains(domain string) []string {
|
||||||
var domains []string
|
var domains []string
|
||||||
|
|
||||||
labelIndexes := dns.Split(domain)
|
tld, _ := publicsuffix.PublicSuffix(domain)
|
||||||
|
for d := range dns01.DomainsSeq(domain) {
|
||||||
for _, index := range labelIndexes {
|
if tld == d {
|
||||||
tld, _ := publicsuffix.PublicSuffix(domain)
|
|
||||||
if tld == domain[index:] {
|
|
||||||
// skip the TLD
|
// skip the TLD
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
domains = append(domains, dns01.UnFqdn(domain[index:]))
|
domains = append(domains, dns01.UnFqdn(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
return domains
|
return domains
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -67,7 +66,7 @@ func TestClient_GetDomainIDByName(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
id, err := client.GetDomainIDByName(context.Background(), "test.com")
|
id, err := client.GetDomainIDByName(t.Context(), "test.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, 1, id)
|
assert.Equal(t, 1, id)
|
||||||
|
|
@ -103,7 +102,7 @@ func TestClient_CheckNameservers(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.CheckNameservers(context.Background(), 1)
|
err := client.CheckNameservers(t.Context(), 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +140,7 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
Value: "value",
|
Value: "value",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.CreateRecord(context.Background(), 1, record)
|
err := client.CreateRecord(t.Context(), 1, record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,6 +255,6 @@ func TestClient_DeleteTXTRecord(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
info := dns01.GetChallengeInfo(domainName, "abc")
|
info := dns01.GetChallengeInfo(domainName, "abc")
|
||||||
err := client.DeleteTXTRecord(context.Background(), 1, info.EffectiveFQDN, recordValue)
|
err := client.DeleteTXTRecord(t.Context(), 1, info.EffectiveFQDN, recordValue)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -62,7 +61,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.AddRecord(context.Background(), "example.com", "_acme-challenge.example.com", "txt")
|
err := client.AddRecord(t.Context(), "example.com", "_acme-challenge.example.com", "txt")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +123,7 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx, err := client.CreateAuthenticatedContext(context.Background())
|
ctx, err := client.CreateAuthenticatedContext(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
err = client.DeleteRecord(ctx, "example.com", "_acme-challenge.example.com")
|
err = client.DeleteRecord(ctx, "example.com", "_acme-challenge.example.com")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -35,7 +34,7 @@ func TestClient_CreateAuthenticatedContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx, err := client.CreateAuthenticatedContext(context.Background())
|
ctx, err := client.CreateAuthenticatedContext(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
at := getAccessToken(ctx)
|
at := getAccessToken(ctx)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -134,7 +133,7 @@ func TestClient_GetZone(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
client := setupTest(t, "", handlerMock(http.MethodGet, []byte(test.apiResponse)))
|
client := setupTest(t, "", handlerMock(http.MethodGet, []byte(test.apiResponse)))
|
||||||
|
|
||||||
zone, err := client.GetZone(context.Background(), test.authFQDN)
|
zone, err := client.GetZone(t.Context(), test.authFQDN)
|
||||||
|
|
||||||
if test.expected.errorMsg != "" {
|
if test.expected.errorMsg != "" {
|
||||||
require.EqualError(t, err, test.expected.errorMsg)
|
require.EqualError(t, err, test.expected.errorMsg)
|
||||||
|
|
@ -241,7 +240,7 @@ func TestClient_FindTxtRecord(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
client := setupTest(t, "", handlerMock(http.MethodGet, []byte(test.apiResponse)))
|
client := setupTest(t, "", handlerMock(http.MethodGet, []byte(test.apiResponse)))
|
||||||
|
|
||||||
txtRecord, err := client.FindTxtRecord(context.Background(), test.zoneName, test.authFQDN)
|
txtRecord, err := client.FindTxtRecord(t.Context(), test.zoneName, test.authFQDN)
|
||||||
|
|
||||||
if test.expected.errorMsg != "" {
|
if test.expected.errorMsg != "" {
|
||||||
require.EqualError(t, err, test.expected.errorMsg)
|
require.EqualError(t, err, test.expected.errorMsg)
|
||||||
|
|
@ -350,7 +349,7 @@ func TestClient_ListTxtRecord(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
client := setupTest(t, "", handlerMock(http.MethodGet, []byte(test.apiResponse)))
|
client := setupTest(t, "", handlerMock(http.MethodGet, []byte(test.apiResponse)))
|
||||||
|
|
||||||
txtRecords, err := client.ListTxtRecords(context.Background(), test.zoneName, test.authFQDN)
|
txtRecords, err := client.ListTxtRecords(t.Context(), test.zoneName, test.authFQDN)
|
||||||
|
|
||||||
if test.expected.errorMsg != "" {
|
if test.expected.errorMsg != "" {
|
||||||
require.EqualError(t, err, test.expected.errorMsg)
|
require.EqualError(t, err, test.expected.errorMsg)
|
||||||
|
|
@ -455,7 +454,7 @@ func TestClient_AddTxtRecord(t *testing.T) {
|
||||||
handlerMock(http.MethodPost, []byte(test.apiResponse))(rw, req)
|
handlerMock(http.MethodPost, []byte(test.apiResponse))(rw, req)
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.AddTxtRecord(context.Background(), test.zoneName, test.authFQDN, test.value, test.ttl)
|
err := client.AddTxtRecord(t.Context(), test.zoneName, test.authFQDN, test.value, test.ttl)
|
||||||
|
|
||||||
if test.expected.errorMsg != "" {
|
if test.expected.errorMsg != "" {
|
||||||
require.EqualError(t, err, test.expected.errorMsg)
|
require.EqualError(t, err, test.expected.errorMsg)
|
||||||
|
|
@ -528,7 +527,7 @@ func TestClient_RemoveTxtRecord(t *testing.T) {
|
||||||
|
|
||||||
client.BaseURL, _ = url.Parse(server.URL)
|
client.BaseURL, _ = url.Parse(server.URL)
|
||||||
|
|
||||||
err = client.RemoveTxtRecord(context.Background(), test.id, test.zoneName)
|
err = client.RemoveTxtRecord(t.Context(), test.id, test.zoneName)
|
||||||
|
|
||||||
if test.expected.errorMsg != "" {
|
if test.expected.errorMsg != "" {
|
||||||
require.EqualError(t, err, test.expected.errorMsg)
|
require.EqualError(t, err, test.expected.errorMsg)
|
||||||
|
|
@ -598,7 +597,7 @@ func TestClient_GetUpdateStatus(t *testing.T) {
|
||||||
|
|
||||||
client.BaseURL, _ = url.Parse(server.URL)
|
client.BaseURL, _ = url.Parse(server.URL)
|
||||||
|
|
||||||
syncProgress, err := client.GetUpdateStatus(context.Background(), test.zoneName)
|
syncProgress, err := client.GetUpdateStatus(t.Context(), test.zoneName)
|
||||||
|
|
||||||
if test.expected.errorMsg != "" {
|
if test.expected.errorMsg != "" {
|
||||||
require.EqualError(t, err, test.expected.errorMsg)
|
require.EqualError(t, err, test.expected.errorMsg)
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func writeFixtureHandler(method, filename string) http.HandlerFunc {
|
||||||
func TestClient_GetZones(t *testing.T) {
|
func TestClient_GetZones(t *testing.T) {
|
||||||
client := setupTest(t, "/zones", writeFixtureHandler(http.MethodGet, "zones.json"))
|
client := setupTest(t, "/zones", writeFixtureHandler(http.MethodGet, "zones.json"))
|
||||||
|
|
||||||
ctx := mockContext()
|
ctx := mockContext(t)
|
||||||
|
|
||||||
zones, err := client.GetZones(ctx, "xxx")
|
zones, err := client.GetZones(ctx, "xxx")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -80,7 +80,7 @@ func TestClient_GetZones(t *testing.T) {
|
||||||
func TestClient_GetRecords(t *testing.T) {
|
func TestClient_GetRecords(t *testing.T) {
|
||||||
client := setupTest(t, "/zones/zzz/records", writeFixtureHandler(http.MethodGet, "records.json"))
|
client := setupTest(t, "/zones/zzz/records", writeFixtureHandler(http.MethodGet, "records.json"))
|
||||||
|
|
||||||
ctx := mockContext()
|
ctx := mockContext(t)
|
||||||
|
|
||||||
records, err := client.GetRecords(ctx, "zzz")
|
records, err := client.GetRecords(ctx, "zzz")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -124,7 +124,7 @@ func TestClient_GetRecords(t *testing.T) {
|
||||||
func TestClient_CreateRecord(t *testing.T) {
|
func TestClient_CreateRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/zones/zzz/records", writeFixtureHandler(http.MethodPost, "record.json"))
|
client := setupTest(t, "/zones/zzz/records", writeFixtureHandler(http.MethodPost, "record.json"))
|
||||||
|
|
||||||
ctx := mockContext()
|
ctx := mockContext(t)
|
||||||
|
|
||||||
recordReq := Record{
|
recordReq := Record{
|
||||||
Name: "www.example.com.",
|
Name: "www.example.com.",
|
||||||
|
|
@ -152,7 +152,7 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/zones/zzz/records/example.com/TXT", writeFixtureHandler(http.MethodDelete, "record.json"))
|
client := setupTest(t, "/zones/zzz/records/example.com/TXT", writeFixtureHandler(http.MethodDelete, "record.json"))
|
||||||
|
|
||||||
ctx := mockContext()
|
ctx := mockContext(t)
|
||||||
|
|
||||||
err := client.DeleteRecord(ctx, "zzz", "example.com", "TXT")
|
err := client.DeleteRecord(ctx, "zzz", "example.com", "TXT")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mockContext() context.Context {
|
func mockContext(t *testing.T) context.Context {
|
||||||
return context.WithValue(context.Background(), tokenKey, &Token{AccessToken: "xxx"})
|
t.Helper()
|
||||||
|
|
||||||
|
return context.WithValue(t.Context(), tokenKey, &Token{AccessToken: "xxx"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func tokenHandler(rw http.ResponseWriter, req *http.Request) {
|
func tokenHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
@ -60,7 +62,7 @@ func TestClient_obtainToken(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, client.token)
|
assert.Nil(t, client.token)
|
||||||
|
|
||||||
tok, err := client.obtainToken(context.Background())
|
tok, err := client.obtainToken(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.NotNil(t, tok)
|
assert.NotNil(t, tok)
|
||||||
|
|
@ -81,7 +83,7 @@ func TestClient_CreateAuthenticatedContext(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, client.token)
|
assert.Nil(t, client.token)
|
||||||
|
|
||||||
ctx, err := client.CreateAuthenticatedContext(context.Background())
|
ctx, err := client.CreateAuthenticatedContext(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tok := getToken(ctx)
|
tok := getToken(ctx)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a client instance logged into the ConoHa service.
|
// NewClient returns a client instance logged into the ConoHa service.
|
||||||
func NewClient(region string, token string) (*Client, error) {
|
func NewClient(region, token string) (*Client, error) {
|
||||||
baseURL, err := url.Parse(fmt.Sprintf(dnsServiceBaseURL, region))
|
baseURL, err := url.Parse(fmt.Sprintf(dnsServiceBaseURL, region))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -106,7 +105,7 @@ func TestClient_GetDomainID(t *testing.T) {
|
||||||
|
|
||||||
mux.Handle("/v1/domains", test.handler)
|
mux.Handle("/v1/domains", test.handler)
|
||||||
|
|
||||||
domainID, err := client.GetDomainID(context.Background(), test.domainName)
|
domainID, err := client.GetDomainID(t.Context(), test.domainName)
|
||||||
|
|
||||||
if test.expected.error {
|
if test.expected.error {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
@ -177,7 +176,7 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
TTL: 300,
|
TTL: 300,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.CreateRecord(context.Background(), domainID, record)
|
err := client.CreateRecord(t.Context(), domainID, record)
|
||||||
test.assert(t, err)
|
test.assert(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +188,7 @@ func TestClient_GetRecordID(t *testing.T) {
|
||||||
mux.HandleFunc("/v1/domains/89acac79-38e7-497d-807c-a011e1310438/records",
|
mux.HandleFunc("/v1/domains/89acac79-38e7-497d-807c-a011e1310438/records",
|
||||||
writeFixtureHandler(http.MethodGet, "domains-records_GET.json"))
|
writeFixtureHandler(http.MethodGet, "domains-records_GET.json"))
|
||||||
|
|
||||||
recordID, err := client.GetRecordID(context.Background(), "89acac79-38e7-497d-807c-a011e1310438", "www.example.com.", "A", "15.185.172.153")
|
recordID, err := client.GetRecordID(t.Context(), "89acac79-38e7-497d-807c-a011e1310438", "www.example.com.", "A", "15.185.172.153")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "2e32e609-3a4f-45ba-bdef-e50eacd345ad", recordID)
|
assert.Equal(t, "2e32e609-3a4f-45ba-bdef-e50eacd345ad", recordID)
|
||||||
|
|
@ -207,6 +206,6 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "89acac79-38e7-497d-807c-a011e1310438", "2e32e609-3a4f-45ba-bdef-e50eacd345ad")
|
err := client.DeleteRecord(t.Context(), "89acac79-38e7-497d-807c-a011e1310438", "2e32e609-3a4f-45ba-bdef-e50eacd345ad")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -32,7 +31,7 @@ func TestNewClient(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := identifier.GetToken(context.Background(), auth)
|
token, err := identifier.GetToken(t.Context(), auth)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &IdentityResponse{Access: Access{Token: Token{ID: "sample00d88246078f2bexample788f7"}}}
|
expected := &IdentityResponse{Access: Access{Token: Token{ID: "sample00d88246078f2bexample788f7"}}}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a client instance logged into the ConoHa service.
|
// NewClient returns a client instance logged into the ConoHa service.
|
||||||
func NewClient(region string, token string) (*Client, error) {
|
func NewClient(region, token string) (*Client, error) {
|
||||||
baseURL, err := url.Parse(fmt.Sprintf(dnsServiceBaseURL, region))
|
baseURL, err := url.Parse(fmt.Sprintf(dnsServiceBaseURL, region))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -106,7 +105,7 @@ func TestClient_GetDomainID(t *testing.T) {
|
||||||
|
|
||||||
mux.Handle("/v1/domains", test.handler)
|
mux.Handle("/v1/domains", test.handler)
|
||||||
|
|
||||||
domainID, err := client.GetDomainID(context.Background(), test.domainName)
|
domainID, err := client.GetDomainID(t.Context(), test.domainName)
|
||||||
|
|
||||||
if test.expected.error {
|
if test.expected.error {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
@ -177,7 +176,7 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
TTL: 300,
|
TTL: 300,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.CreateRecord(context.Background(), domainID, record)
|
err := client.CreateRecord(t.Context(), domainID, record)
|
||||||
test.assert(t, err)
|
test.assert(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +188,7 @@ func TestClient_GetRecordID(t *testing.T) {
|
||||||
mux.HandleFunc("/v1/domains/89acac79-38e7-497d-807c-a011e1310438/records",
|
mux.HandleFunc("/v1/domains/89acac79-38e7-497d-807c-a011e1310438/records",
|
||||||
writeFixtureHandler(http.MethodGet, "domains-records_GET.json"))
|
writeFixtureHandler(http.MethodGet, "domains-records_GET.json"))
|
||||||
|
|
||||||
recordID, err := client.GetRecordID(context.Background(), "89acac79-38e7-497d-807c-a011e1310438", "www.example.com.", "A", "15.185.172.153")
|
recordID, err := client.GetRecordID(t.Context(), "89acac79-38e7-497d-807c-a011e1310438", "www.example.com.", "A", "15.185.172.153")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "2e32e609-3a4f-45ba-bdef-e50eacd345ad", recordID)
|
assert.Equal(t, "2e32e609-3a4f-45ba-bdef-e50eacd345ad", recordID)
|
||||||
|
|
@ -207,6 +206,6 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
rw.WriteHeader(http.StatusOK)
|
rw.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "89acac79-38e7-497d-807c-a011e1310438", "2e32e609-3a4f-45ba-bdef-e50eacd345ad")
|
err := client.DeleteRecord(t.Context(), "89acac79-38e7-497d-807c-a011e1310438", "2e32e609-3a4f-45ba-bdef-e50eacd345ad")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -45,7 +44,7 @@ func TestGetToken_HeaderToken(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := identifier.GetToken(context.Background(), auth)
|
token, err := identifier.GetToken(t.Context(), auth)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "sample-header-token-123", token)
|
assert.Equal(t, "sample-header-token-123", token)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -48,7 +47,7 @@ func TestDomainService_GetAll(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
data, err := client.Domains.GetAll(context.Background(), nil)
|
data, err := client.Domains.GetAll(t.Context(), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Domain{
|
expected := []Domain{
|
||||||
|
|
@ -84,7 +83,7 @@ func TestDomainService_Search(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
data, err := client.Domains.Search(context.Background(), Exact, "lego.wtf")
|
data, err := client.Domains.Search(t.Context(), Exact, "lego.wtf")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Domain{
|
expected := []Domain{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -35,7 +34,7 @@ func TestTxtRecordService_Create(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
records, err := client.TxtRecords.Create(context.Background(), 12345, RecordRequest{})
|
records, err := client.TxtRecords.Create(t.Context(), 12345, RecordRequest{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
recordsJSON, err := json.Marshal(records)
|
recordsJSON, err := json.Marshal(records)
|
||||||
|
|
@ -70,7 +69,7 @@ func TestTxtRecordService_GetAll(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
records, err := client.TxtRecords.GetAll(context.Background(), 12345)
|
records, err := client.TxtRecords.GetAll(t.Context(), 12345)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
recordsJSON, err := json.Marshal(records)
|
recordsJSON, err := json.Marshal(records)
|
||||||
|
|
@ -105,7 +104,7 @@ func TestTxtRecordService_Get(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
record, err := client.TxtRecords.Get(context.Background(), 12345, 6789)
|
record, err := client.TxtRecords.Get(t.Context(), 12345, 6789)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Record{
|
expected := &Record{
|
||||||
|
|
@ -146,7 +145,7 @@ func TestTxtRecordService_Update(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
msg, err := client.TxtRecords.Update(context.Background(), 12345, 6789, RecordRequest{})
|
msg, err := client.TxtRecords.Update(t.Context(), 12345, 6789, RecordRequest{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &SuccessMessage{Success: "Record updated successfully"}
|
expected := &SuccessMessage{Success: "Record updated successfully"}
|
||||||
|
|
@ -169,7 +168,7 @@ func TestTxtRecordService_Delete(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
msg, err := client.TxtRecords.Delete(context.Background(), 12345, 6789)
|
msg, err := client.TxtRecords.Delete(t.Context(), 12345, 6789)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &SuccessMessage{Success: "Record deleted successfully"}
|
expected := &SuccessMessage{Success: "Record deleted successfully"}
|
||||||
|
|
@ -199,7 +198,7 @@ func TestTxtRecordService_Search(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
records, err := client.TxtRecords.Search(context.Background(), 12345, Exact, "test")
|
records, err := client.TxtRecords.Search(t.Context(), 12345, Exact, "test")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
recordsJSON, err := json.Marshal(records)
|
recordsJSON, err := json.Marshal(records)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -92,7 +91,7 @@ func TestClient_CreateAuthenticationToken(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/auth/token", testHandlerAuth(http.MethodPost, http.StatusOK, "auth.json"))
|
mux.HandleFunc("/auth/token", testHandlerAuth(http.MethodPost, http.StatusOK, "auth.json"))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
token, err := client.CreateAuthenticationToken(ctx)
|
token, err := client.CreateAuthenticationToken(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -109,7 +108,7 @@ func TestClient_ListZone(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/dnszones/", testHandler(http.MethodGet, http.StatusOK, "ListZone.json"))
|
mux.HandleFunc("/dnszones/", testHandler(http.MethodGet, http.StatusOK, "ListZone.json"))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
zones, err := client.ListZone(ctx)
|
zones, err := client.ListZone(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -127,7 +126,7 @@ func TestClient_GetZoneDetails(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/dnszones/example.com", testHandler(http.MethodGet, http.StatusOK, "GetZoneDetails.json"))
|
mux.HandleFunc("/dnszones/example.com", testHandler(http.MethodGet, http.StatusOK, "GetZoneDetails.json"))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
zone, err := client.GetZoneDetails(ctx, "example.com")
|
zone, err := client.GetZoneDetails(ctx, "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -147,7 +146,7 @@ func TestClient_ListRecords(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/dnszones/example.com/records/", testHandler(http.MethodGet, http.StatusOK, "ListRecords.json"))
|
mux.HandleFunc("/dnszones/example.com/records/", testHandler(http.MethodGet, http.StatusOK, "ListRecords.json"))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
records, err := client.ListRecords(ctx, "example.com")
|
records, err := client.ListRecords(ctx, "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -181,7 +180,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/dnszones/example.com/records/", testHandler(http.MethodPost, http.StatusNoContent, ""))
|
mux.HandleFunc("/dnszones/example.com/records/", testHandler(http.MethodPost, http.StatusNoContent, ""))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
record := Record{Name: "www", TTL: 3600, Type: "A", Data: "127.0.0.1"}
|
record := Record{Name: "www", TTL: 3600, Type: "A", Data: "127.0.0.1"}
|
||||||
|
|
||||||
|
|
@ -194,7 +193,7 @@ func TestClient_DeleteRecords(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/dnszones/example.com/records/delete", testHandler(http.MethodPost, http.StatusNoContent, ""))
|
mux.HandleFunc("/dnszones/example.com/records/delete", testHandler(http.MethodPost, http.StatusNoContent, ""))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
record := Record{Name: "www", Type: "A", Data: "127.0.0.1"}
|
record := Record{Name: "www", Type: "A", Data: "127.0.0.1"}
|
||||||
|
|
||||||
|
|
@ -207,7 +206,7 @@ func TestClient_CommitRecords(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/dnszones/example.com/records/commit", testHandler(http.MethodPost, http.StatusNoContent, ""))
|
mux.HandleFunc("/dnszones/example.com/records/commit", testHandler(http.MethodPost, http.StatusNoContent, ""))
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
err := client.CommitRecords(ctx, "example.com")
|
err := client.CommitRecords(ctx, "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ type Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(baseURL string, username string, token string) (*Client, error) {
|
func NewClient(baseURL, username, token string) (*Client, error) {
|
||||||
apiEndpoint, err := url.Parse(baseURL)
|
apiEndpoint, err := url.Parse(baseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package cpanel
|
package cpanel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -15,7 +14,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupTest(t *testing.T, pattern string, filename string) *Client {
|
func setupTest(t *testing.T, pattern, filename string) *Client {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
@ -55,7 +54,7 @@ func setupTest(t *testing.T, pattern string, filename string) *Client {
|
||||||
func TestClient_FetchZoneInformation(t *testing.T) {
|
func TestClient_FetchZoneInformation(t *testing.T) {
|
||||||
client := setupTest(t, "/execute/DNS/parse_zone", "zone-info.json")
|
client := setupTest(t, "/execute/DNS/parse_zone", "zone-info.json")
|
||||||
|
|
||||||
zoneInfo, err := client.FetchZoneInformation(context.Background(), "example.com")
|
zoneInfo, err := client.FetchZoneInformation(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []shared.ZoneRecord{{
|
expected := []shared.ZoneRecord{{
|
||||||
|
|
@ -73,7 +72,7 @@ func TestClient_FetchZoneInformation(t *testing.T) {
|
||||||
func TestClient_FetchZoneInformation_error(t *testing.T) {
|
func TestClient_FetchZoneInformation_error(t *testing.T) {
|
||||||
client := setupTest(t, "/execute/DNS/parse_zone", "zone-info_error.json")
|
client := setupTest(t, "/execute/DNS/parse_zone", "zone-info_error.json")
|
||||||
|
|
||||||
zoneInfo, err := client.FetchZoneInformation(context.Background(), "example.com")
|
zoneInfo, err := client.FetchZoneInformation(t.Context(), "example.com")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneInfo)
|
assert.Nil(t, zoneInfo)
|
||||||
|
|
@ -89,7 +88,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.AddRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.AddRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
||||||
|
|
@ -107,7 +106,7 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.AddRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.AddRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneSerial)
|
assert.Nil(t, zoneSerial)
|
||||||
|
|
@ -124,7 +123,7 @@ func TestClient_EditRecord(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.EditRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.EditRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
||||||
|
|
@ -143,7 +142,7 @@ func TestClient_EditRecord_error(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.EditRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.EditRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneSerial)
|
assert.Nil(t, zoneSerial)
|
||||||
|
|
@ -152,7 +151,7 @@ func TestClient_EditRecord_error(t *testing.T) {
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/execute/DNS/mass_edit_zone", "update-zone.json")
|
client := setupTest(t, "/execute/DNS/mass_edit_zone", "update-zone.json")
|
||||||
|
|
||||||
zoneSerial, err := client.DeleteRecord(context.Background(), 123456, "example.com", 0)
|
zoneSerial, err := client.DeleteRecord(t.Context(), 123456, "example.com", 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
||||||
|
|
@ -163,7 +162,7 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
func TestClient_DeleteRecord_error(t *testing.T) {
|
func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, "/execute/DNS/mass_edit_zone", "update-zone_error.json")
|
client := setupTest(t, "/execute/DNS/mass_edit_zone", "update-zone_error.json")
|
||||||
|
|
||||||
zoneSerial, err := client.DeleteRecord(context.Background(), 123456, "example.com", 0)
|
zoneSerial, err := client.DeleteRecord(t.Context(), 123456, "example.com", 0)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneSerial)
|
assert.Nil(t, zoneSerial)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ type Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(baseURL string, username string, token string) (*Client, error) {
|
func NewClient(baseURL, username, token string) (*Client, error) {
|
||||||
apiEndpoint, err := url.Parse(baseURL)
|
apiEndpoint, err := url.Parse(baseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package whm
|
package whm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -15,7 +14,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupTest(t *testing.T, pattern string, filename string) *Client {
|
func setupTest(t *testing.T, pattern, filename string) *Client {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
@ -55,7 +54,7 @@ func setupTest(t *testing.T, pattern string, filename string) *Client {
|
||||||
func TestClient_FetchZoneInformation(t *testing.T) {
|
func TestClient_FetchZoneInformation(t *testing.T) {
|
||||||
client := setupTest(t, "/json-api/parse_dns_zone", "zone-info.json")
|
client := setupTest(t, "/json-api/parse_dns_zone", "zone-info.json")
|
||||||
|
|
||||||
zoneInfo, err := client.FetchZoneInformation(context.Background(), "example.com")
|
zoneInfo, err := client.FetchZoneInformation(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []shared.ZoneRecord{{
|
expected := []shared.ZoneRecord{{
|
||||||
|
|
@ -73,7 +72,7 @@ func TestClient_FetchZoneInformation(t *testing.T) {
|
||||||
func TestClient_FetchZoneInformation_error(t *testing.T) {
|
func TestClient_FetchZoneInformation_error(t *testing.T) {
|
||||||
client := setupTest(t, "/json-api/parse_dns_zone", "zone-info_error.json")
|
client := setupTest(t, "/json-api/parse_dns_zone", "zone-info_error.json")
|
||||||
|
|
||||||
zoneInfo, err := client.FetchZoneInformation(context.Background(), "example.com")
|
zoneInfo, err := client.FetchZoneInformation(t.Context(), "example.com")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneInfo)
|
assert.Nil(t, zoneInfo)
|
||||||
|
|
@ -89,7 +88,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.AddRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.AddRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
||||||
|
|
@ -107,7 +106,7 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.AddRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.AddRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneSerial)
|
assert.Nil(t, zoneSerial)
|
||||||
|
|
@ -124,7 +123,7 @@ func TestClient_EditRecord(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.EditRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.EditRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
||||||
|
|
@ -143,7 +142,7 @@ func TestClient_EditRecord_error(t *testing.T) {
|
||||||
Data: []string{"string1", "string2"},
|
Data: []string{"string1", "string2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneSerial, err := client.EditRecord(context.Background(), 123456, "example.com", record)
|
zoneSerial, err := client.EditRecord(t.Context(), 123456, "example.com", record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneSerial)
|
assert.Nil(t, zoneSerial)
|
||||||
|
|
@ -152,7 +151,7 @@ func TestClient_EditRecord_error(t *testing.T) {
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/json-api/mass_edit_dns_zone", "update-zone.json")
|
client := setupTest(t, "/json-api/mass_edit_dns_zone", "update-zone.json")
|
||||||
|
|
||||||
zoneSerial, err := client.DeleteRecord(context.Background(), 123456, "example.com", 0)
|
zoneSerial, err := client.DeleteRecord(t.Context(), 123456, "example.com", 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
expected := &shared.ZoneSerial{NewSerial: "2021031903"}
|
||||||
|
|
@ -163,7 +162,7 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
func TestClient_DeleteRecord_error(t *testing.T) {
|
func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, "/json-api/mass_edit_dns_zone", "update-zone_error.json")
|
client := setupTest(t, "/json-api/mass_edit_dns_zone", "update-zone_error.json")
|
||||||
|
|
||||||
zoneSerial, err := client.DeleteRecord(context.Background(), 123456, "example.com", 0)
|
zoneSerial, err := client.DeleteRecord(t.Context(), 123456, "example.com", 0)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Nil(t, zoneSerial)
|
assert.Nil(t, zoneSerial)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ func (c Client) GetRecords(ctx context.Context, zoneID string, params *GetRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRecord gets a record by ID.
|
// GetRecord gets a record by ID.
|
||||||
func (c Client) GetRecord(ctx context.Context, zoneID string, recordID string) (*Record, error) {
|
func (c Client) GetRecord(ctx context.Context, zoneID, recordID string) (*Record, error) {
|
||||||
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
|
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
|
||||||
|
|
||||||
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
||||||
|
|
@ -97,7 +97,7 @@ func (c Client) CreateRecord(ctx context.Context, zoneID string, record Record)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditRecord edits an existing record.
|
// EditRecord edits an existing record.
|
||||||
func (c Client) EditRecord(ctx context.Context, zoneID string, recordID string, record Record) (*Record, error) {
|
func (c Client) EditRecord(ctx context.Context, zoneID, recordID string, record Record) (*Record, error) {
|
||||||
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
|
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
|
||||||
|
|
||||||
req, err := newJSONRequest(ctx, http.MethodPatch, endpoint, record)
|
req, err := newJSONRequest(ctx, http.MethodPatch, endpoint, record)
|
||||||
|
|
@ -115,7 +115,7 @@ func (c Client) EditRecord(ctx context.Context, zoneID string, recordID string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRecord deletes an existing record.
|
// DeleteRecord deletes an existing record.
|
||||||
func (c Client) DeleteRecord(ctx context.Context, zoneID string, recordID string) error {
|
func (c Client) DeleteRecord(ctx context.Context, zoneID, recordID string) error {
|
||||||
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
|
endpoint := c.baseURL.JoinPath("zones", zoneID, "dnsrecords", recordID)
|
||||||
|
|
||||||
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
|
req, err := newJSONRequest(ctx, http.MethodDelete, endpoint, nil)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -77,7 +76,7 @@ func TestGetRecords(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
|
||||||
testHandler(http.MethodGet, http.StatusOK, "records-GET.json"))
|
testHandler(http.MethodGet, http.StatusOK, "records-GET.json"))
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", &GetRecordsParameters{DNSType: "TXT", Content: `"test"'`})
|
records, err := client.GetRecords(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", &GetRecordsParameters{DNSType: "TXT", Content: `"test"'`})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
excepted := &GetRecordsResponse{Data: []Record{
|
excepted := &GetRecordsResponse{Data: []Record{
|
||||||
|
|
@ -140,7 +139,7 @@ func TestGetRecords_error(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords",
|
||||||
testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetRecords(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", &GetRecordsParameters{DNSType: "TXT", Content: `"test"'`})
|
_, err := client.GetRecords(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", &GetRecordsParameters{DNSType: "TXT", Content: `"test"'`})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +149,7 @@ func TestGetRecord(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/812bee17a0b440b0bd5ee099a78b839c",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/812bee17a0b440b0bd5ee099a78b839c",
|
||||||
testHandler(http.MethodGet, http.StatusOK, "record-GET.json"))
|
testHandler(http.MethodGet, http.StatusOK, "record-GET.json"))
|
||||||
|
|
||||||
record, err := client.GetRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "812bee17a0b440b0bd5ee099a78b839c")
|
record, err := client.GetRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", "812bee17a0b440b0bd5ee099a78b839c")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
excepted := &Record{
|
excepted := &Record{
|
||||||
|
|
@ -169,7 +168,7 @@ func TestGetRecord_error(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/812bee17a0b440b0bd5ee099a78b839c",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/812bee17a0b440b0bd5ee099a78b839c",
|
||||||
testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "812bee17a0b440b0bd5ee099a78b839c")
|
_, err := client.GetRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", "812bee17a0b440b0bd5ee099a78b839c")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,7 +185,7 @@ func TestCreateRecord(t *testing.T) {
|
||||||
TTL: 120,
|
TTL: 120,
|
||||||
}
|
}
|
||||||
|
|
||||||
record, err := client.CreateRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", r)
|
record, err := client.CreateRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", r)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
excepted := &Record{
|
excepted := &Record{
|
||||||
|
|
@ -212,7 +211,7 @@ func TestCreateRecord_error(t *testing.T) {
|
||||||
TTL: 120,
|
TTL: 120,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.CreateRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", r)
|
_, err := client.CreateRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", r)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -222,7 +221,7 @@ func TestEditRecord(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/eebc813de2f94d67b09d91e10e2d65c2",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/eebc813de2f94d67b09d91e10e2d65c2",
|
||||||
testHandler(http.MethodPatch, http.StatusOK, "record-PATCH.json"))
|
testHandler(http.MethodPatch, http.StatusOK, "record-PATCH.json"))
|
||||||
|
|
||||||
record, err := client.EditRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "eebc813de2f94d67b09d91e10e2d65c2", Record{
|
record, err := client.EditRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", "eebc813de2f94d67b09d91e10e2d65c2", Record{
|
||||||
Content: "foo",
|
Content: "foo",
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -243,7 +242,7 @@ func TestEditRecord_error(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/eebc813de2f94d67b09d91e10e2d65c2",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/eebc813de2f94d67b09d91e10e2d65c2",
|
||||||
testHandler(http.MethodPatch, http.StatusUnauthorized, "error.json"))
|
testHandler(http.MethodPatch, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.EditRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "eebc813de2f94d67b09d91e10e2d65c2", Record{
|
_, err := client.EditRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", "eebc813de2f94d67b09d91e10e2d65c2", Record{
|
||||||
Content: "foo",
|
Content: "foo",
|
||||||
})
|
})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
@ -255,7 +254,7 @@ func TestDeleteRecord(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/653464211b7447a1bee6b8fcb9fb86df",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/653464211b7447a1bee6b8fcb9fb86df",
|
||||||
testHandler(http.MethodDelete, http.StatusOK, "record-DELETE.json"))
|
testHandler(http.MethodDelete, http.StatusOK, "record-DELETE.json"))
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "653464211b7447a1bee6b8fcb9fb86df")
|
err := client.DeleteRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", "653464211b7447a1bee6b8fcb9fb86df")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,7 +264,7 @@ func TestDeleteRecord_error(t *testing.T) {
|
||||||
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/653464211b7447a1bee6b8fcb9fb86df",
|
mux.HandleFunc("/zones/47c0ecf6c91243308c649ad1d2d618dd/dnsrecords/653464211b7447a1bee6b8fcb9fb86df",
|
||||||
testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
|
testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "47c0ecf6c91243308c649ad1d2d618dd", "653464211b7447a1bee6b8fcb9fb86df")
|
err := client.DeleteRecord(t.Context(), "47c0ecf6c91243308c649ad1d2d618dd", "653464211b7447a1bee6b8fcb9fb86df")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,7 +273,7 @@ func TestGetZones(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/", testHandler(http.MethodGet, http.StatusOK, "service-cdn-zones.json"))
|
mux.HandleFunc("/", testHandler(http.MethodGet, http.StatusOK, "service-cdn-zones.json"))
|
||||||
|
|
||||||
zones, err := client.GetZones(context.Background())
|
zones, err := client.GetZones(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
excepted := []Zone{{
|
excepted := []Zone{{
|
||||||
|
|
@ -307,6 +306,6 @@ func TestGetZones_error(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
mux.HandleFunc("/", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetZones(context.Background())
|
_, err := client.GetZones(t.Context())
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -98,7 +97,7 @@ func TestClient_AddTxtRecord(t *testing.T) {
|
||||||
TTL: 30,
|
TTL: 30,
|
||||||
}
|
}
|
||||||
|
|
||||||
newRecord, err := client.AddTxtRecord(context.Background(), "example.com", record)
|
newRecord, err := client.AddTxtRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &TxtRecordResponse{DomainRecord: Record{
|
expected := &TxtRecordResponse{DomainRecord: Record{
|
||||||
|
|
@ -134,6 +133,6 @@ func TestClient_RemoveTxtRecord(t *testing.T) {
|
||||||
rw.WriteHeader(http.StatusNoContent)
|
rw.WriteHeader(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.RemoveTxtRecord(context.Background(), "example.com", 1234567)
|
err := client.RemoveTxtRecord(t.Context(), "example.com", 1234567)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -92,7 +91,7 @@ func TestClient_SetRecord(t *testing.T) {
|
||||||
TTL: 123,
|
TTL: 123,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.SetRecord(context.Background(), "example.com", record)
|
err := client.SetRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +109,7 @@ func TestClient_SetRecord_error(t *testing.T) {
|
||||||
TTL: 123,
|
TTL: 123,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.SetRecord(context.Background(), "example.com", record)
|
err := client.SetRecord(t.Context(), "example.com", record)
|
||||||
require.EqualError(t, err, "[status code 500] Cannot View Dns Record: OOPS")
|
require.EqualError(t, err, "[status code 500] Cannot View Dns Record: OOPS")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,7 +132,7 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
Value: "txtTXTtxt",
|
Value: "txtTXTtxt",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", record)
|
err := client.DeleteRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,6 +149,6 @@ func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
Value: "txtTXTtxt",
|
Value: "txtTXTtxt",
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", record)
|
err := client.DeleteRecord(t.Context(), "example.com", record)
|
||||||
require.EqualError(t, err, "[status code 500] Cannot View Dns Record: OOPS")
|
require.EqualError(t, err, "[status code 500] Cannot View Dns Record: OOPS")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
|
|
@ -62,9 +61,9 @@ func NewDNSProvider() (*DNSProvider, error) {
|
||||||
return nil, fmt.Errorf("dnshomede: %w", err)
|
return nil, fmt.Errorf("dnshomede: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
credentials, err := parseCredentials(values[EnvCredentials])
|
credentials, err := env.ParsePairs(values[EnvCredentials])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("dnshomede: %w", err)
|
return nil, fmt.Errorf("dnshomede: credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Credentials = credentials
|
config.Credentials = credentials
|
||||||
|
|
@ -131,19 +130,3 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
||||||
func (d *DNSProvider) Sequential() time.Duration {
|
func (d *DNSProvider) Sequential() time.Duration {
|
||||||
return d.config.SequenceInterval
|
return d.config.SequenceInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCredentials(raw string) (map[string]string, error) {
|
|
||||||
credentials := make(map[string]string)
|
|
||||||
|
|
||||||
credStrings := strings.Split(strings.TrimSuffix(raw, ","), ",")
|
|
||||||
for _, credPair := range credStrings {
|
|
||||||
data := strings.Split(credPair, ":")
|
|
||||||
if len(data) != 2 {
|
|
||||||
return nil, fmt.Errorf("invalid credential pair: %q", credPair)
|
|
||||||
}
|
|
||||||
|
|
||||||
credentials[strings.TrimSpace(data[0])] = strings.TrimSpace(data[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
return credentials, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func TestNewDNSProvider(t *testing.T) {
|
||||||
envVars: map[string]string{
|
envVars: map[string]string{
|
||||||
EnvCredentials: ",",
|
EnvCredentials: ",",
|
||||||
},
|
},
|
||||||
expected: `dnshomede: invalid credential pair: ""`,
|
expected: `dnshomede: credentials: incorrect pair: `,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "missing password",
|
desc: "missing password",
|
||||||
|
|
@ -55,7 +55,7 @@ func TestNewDNSProvider(t *testing.T) {
|
||||||
envVars: map[string]string{
|
envVars: map[string]string{
|
||||||
EnvCredentials: "example.org:123,example.net",
|
EnvCredentials: "example.org:123,example.net",
|
||||||
},
|
},
|
||||||
expected: `dnshomede: invalid credential pair: "example.net"`,
|
expected: "dnshomede: credentials: incorrect pair: example.net",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "missing credentials",
|
desc: "missing credentials",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -31,7 +30,7 @@ func TestClient_Add(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, map[string]string{"example.org": "secret"}, handlerMock(addAction, txtValue))
|
client := setupTest(t, map[string]string{"example.org": "secret"}, handlerMock(addAction, txtValue))
|
||||||
|
|
||||||
err := client.Add(context.Background(), "example.org", txtValue)
|
err := client.Add(t.Context(), "example.org", txtValue)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +39,7 @@ func TestClient_Add_error(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, map[string]string{"example.com": "secret"}, handlerMock(addAction, txtValue))
|
client := setupTest(t, map[string]string{"example.com": "secret"}, handlerMock(addAction, txtValue))
|
||||||
|
|
||||||
err := client.Add(context.Background(), "example.org", txtValue)
|
err := client.Add(t.Context(), "example.org", txtValue)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +48,7 @@ func TestClient_Remove(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, map[string]string{"example.org": "secret"}, handlerMock(removeAction, txtValue))
|
client := setupTest(t, map[string]string{"example.org": "secret"}, handlerMock(removeAction, txtValue))
|
||||||
|
|
||||||
err := client.Remove(context.Background(), "example.org", txtValue)
|
err := client.Remove(t.Context(), "example.org", txtValue)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +57,7 @@ func TestClient_Remove_error(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, map[string]string{"example.com": "secret"}, handlerMock(removeAction, txtValue))
|
client := setupTest(t, map[string]string{"example.com": "secret"}, handlerMock(removeAction, txtValue))
|
||||||
|
|
||||||
err := client.Remove(context.Background(), "example.org", txtValue)
|
err := client.Remove(t.Context(), "example.org", txtValue)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -81,13 +80,13 @@ func setupTest(t *testing.T, method, pattern string, status int, file string) *C
|
||||||
func TestClient_UpdateTxtRecord(t *testing.T) {
|
func TestClient_UpdateTxtRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/letsencrypt", http.StatusOK, "success.json")
|
client := setupTest(t, http.MethodGet, "/letsencrypt", http.StatusOK, "success.json")
|
||||||
|
|
||||||
err := client.UpdateTxtRecord(context.Background(), "example.com.", "value", false)
|
err := client.UpdateTxtRecord(t.Context(), "example.com.", "value", false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_UpdateTxtRecord_clear(t *testing.T) {
|
func TestClient_UpdateTxtRecord_clear(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/letsencrypt", http.StatusOK, "success.json")
|
client := setupTest(t, http.MethodGet, "/letsencrypt", http.StatusOK, "success.json")
|
||||||
|
|
||||||
err := client.UpdateTxtRecord(context.Background(), "example.com.", "value", true)
|
err := client.UpdateTxtRecord(t.Context(), "example.com.", "value", true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func (c *Client) GetDomainByName(ctx context.Context, domain string) (*Domain, e
|
||||||
|
|
||||||
// CreateTXTRecord creates a TXT record with the provided host (subdomain) and data.
|
// CreateTXTRecord creates a TXT record with the provided host (subdomain) and data.
|
||||||
// https://api.domeneshop.no/docs/#tag/dns/paths/~1domains~1{domainId}~1dns/post
|
// https://api.domeneshop.no/docs/#tag/dns/paths/~1domains~1{domainId}~1dns/post
|
||||||
func (c *Client) CreateTXTRecord(ctx context.Context, domain *Domain, host string, data string) error {
|
func (c *Client) CreateTXTRecord(ctx context.Context, domain *Domain, host, data string) error {
|
||||||
endpoint := c.baseURL.JoinPath("domains", strconv.Itoa(domain.ID), "dns")
|
endpoint := c.baseURL.JoinPath("domains", strconv.Itoa(domain.ID), "dns")
|
||||||
|
|
||||||
record := DNSRecord{
|
record := DNSRecord{
|
||||||
|
|
@ -92,7 +92,7 @@ func (c *Client) CreateTXTRecord(ctx context.Context, domain *Domain, host strin
|
||||||
|
|
||||||
// DeleteTXTRecord deletes the DNS record matching the provided host and data.
|
// DeleteTXTRecord deletes the DNS record matching the provided host and data.
|
||||||
// https://api.domeneshop.no/docs/#tag/dns/paths/~1domains~1{domainId}~1dns~1{recordId}/delete
|
// https://api.domeneshop.no/docs/#tag/dns/paths/~1domains~1{domainId}~1dns~1{recordId}/delete
|
||||||
func (c *Client) DeleteTXTRecord(ctx context.Context, domain *Domain, host string, data string) error {
|
func (c *Client) DeleteTXTRecord(ctx context.Context, domain *Domain, host, data string) error {
|
||||||
record, err := c.getDNSRecordByHostData(ctx, *domain, host, data)
|
record, err := c.getDNSRecordByHostData(ctx, *domain, host, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -110,7 +110,7 @@ func (c *Client) DeleteTXTRecord(ctx context.Context, domain *Domain, host strin
|
||||||
|
|
||||||
// getDNSRecordByHostData finds the first matching DNS record with the provided host and data.
|
// getDNSRecordByHostData finds the first matching DNS record with the provided host and data.
|
||||||
// https://api.domeneshop.no/docs/#operation/getDnsRecords
|
// https://api.domeneshop.no/docs/#operation/getDnsRecords
|
||||||
func (c *Client) getDNSRecordByHostData(ctx context.Context, domain Domain, host string, data string) (*DNSRecord, error) {
|
func (c *Client) getDNSRecordByHostData(ctx context.Context, domain Domain, host, data string) (*DNSRecord, error) {
|
||||||
endpoint := c.baseURL.JoinPath("domains", strconv.Itoa(domain.ID), "dns")
|
endpoint := c.baseURL.JoinPath("domains", strconv.Itoa(domain.ID), "dns")
|
||||||
|
|
||||||
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
req, err := newJSONRequest(ctx, http.MethodGet, endpoint, nil)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
@ -45,7 +44,7 @@ func TestClient_CreateTXTRecord(t *testing.T) {
|
||||||
_, _ = rw.Write([]byte(`{"id": 1}`))
|
_, _ = rw.Write([]byte(`{"id": 1}`))
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.CreateTXTRecord(context.Background(), &Domain{ID: 1}, "example", "txtTXTtxt")
|
err := client.CreateTXTRecord(t.Context(), &Domain{ID: 1}, "example", "txtTXTtxt")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +87,7 @@ func TestClient_DeleteTXTRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteTXTRecord(context.Background(), &Domain{ID: 1}, "example.com", "txtTXTtxt")
|
err := client.DeleteTXTRecord(t.Context(), &Domain{ID: 1}, "example.com", "txtTXTtxt")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +117,7 @@ func TestClient_getDNSRecordByHostData(t *testing.T) {
|
||||||
]`))
|
]`))
|
||||||
})
|
})
|
||||||
|
|
||||||
record, err := client.getDNSRecordByHostData(context.Background(), Domain{ID: 1}, "example.com", "txtTXTtxt")
|
record, err := client.getDNSRecordByHostData(t.Context(), Domain{ID: 1}, "example.com", "txtTXTtxt")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &DNSRecord{
|
expected := &DNSRecord{
|
||||||
|
|
@ -171,7 +170,7 @@ func TestClient_GetDomainByName(t *testing.T) {
|
||||||
]`))
|
]`))
|
||||||
})
|
})
|
||||||
|
|
||||||
domain, err := client.GetDomainByName(context.Background(), "example.com")
|
domain, err := client.GetDomainByName(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Domain{
|
expected := &Domain{
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient Creates a new Client.
|
// NewClient Creates a new Client.
|
||||||
func NewClient(customerName string, username string, password string) *Client {
|
func NewClient(customerName, username, password string) *Client {
|
||||||
baseURL, _ := url.Parse(defaultBaseURL)
|
baseURL, _ := url.Parse(defaultBaseURL)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -103,20 +102,20 @@ func unauthenticatedHandler(method string, status int, file string) http.Handler
|
||||||
func TestClient_Publish(t *testing.T) {
|
func TestClient_Publish(t *testing.T) {
|
||||||
client := setupTest(t, "/Zone/example.com", unauthenticatedHandler(http.MethodPut, http.StatusOK, "publish.json"))
|
client := setupTest(t, "/Zone/example.com", unauthenticatedHandler(http.MethodPut, http.StatusOK, "publish.json"))
|
||||||
|
|
||||||
err := client.Publish(context.Background(), "example.com", "my message")
|
err := client.Publish(t.Context(), "example.com", "my message")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_AddTXTRecord(t *testing.T) {
|
func TestClient_AddTXTRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/TXTRecord/example.com/example.com.", unauthenticatedHandler(http.MethodPost, http.StatusCreated, "create-txt-record.json"))
|
client := setupTest(t, "/TXTRecord/example.com/example.com.", unauthenticatedHandler(http.MethodPost, http.StatusCreated, "create-txt-record.json"))
|
||||||
|
|
||||||
err := client.AddTXTRecord(context.Background(), "example.com", "example.com.", "txt", 120)
|
err := client.AddTXTRecord(t.Context(), "example.com", "example.com.", "txt", 120)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_RemoveTXTRecord(t *testing.T) {
|
func TestClient_RemoveTXTRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/TXTRecord/example.com/example.com.", unauthenticatedHandler(http.MethodDelete, http.StatusOK, ""))
|
client := setupTest(t, "/TXTRecord/example.com/example.com.", unauthenticatedHandler(http.MethodDelete, http.StatusOK, ""))
|
||||||
|
|
||||||
err := client.RemoveTXTRecord(context.Background(), "example.com", "example.com.")
|
err := client.RemoveTXTRecord(t.Context(), "example.com", "example.com.")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,16 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mockContext() context.Context {
|
func mockContext(t *testing.T) context.Context {
|
||||||
return context.WithValue(context.Background(), tokenKey, "tok")
|
t.Helper()
|
||||||
|
|
||||||
|
return context.WithValue(t.Context(), tokenKey, "tok")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_login(t *testing.T) {
|
func TestClient_login(t *testing.T) {
|
||||||
client := setupTest(t, "/Session", unauthenticatedHandler(http.MethodPost, http.StatusOK, "login.json"))
|
client := setupTest(t, "/Session", unauthenticatedHandler(http.MethodPost, http.StatusOK, "login.json"))
|
||||||
|
|
||||||
sess, err := client.login(context.Background())
|
sess, err := client.login(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := session{Token: "tok", Version: "456"}
|
expected := session{Token: "tok", Version: "456"}
|
||||||
|
|
@ -27,14 +29,14 @@ func TestClient_login(t *testing.T) {
|
||||||
func TestClient_Logout(t *testing.T) {
|
func TestClient_Logout(t *testing.T) {
|
||||||
client := setupTest(t, "/Session", authenticatedHandler(http.MethodDelete, http.StatusOK, ""))
|
client := setupTest(t, "/Session", authenticatedHandler(http.MethodDelete, http.StatusOK, ""))
|
||||||
|
|
||||||
err := client.Logout(mockContext())
|
err := client.Logout(mockContext(t))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_CreateAuthenticatedContext(t *testing.T) {
|
func TestClient_CreateAuthenticatedContext(t *testing.T) {
|
||||||
client := setupTest(t, "/Session", unauthenticatedHandler(http.MethodPost, http.StatusOK, "login.json"))
|
client := setupTest(t, "/Session", unauthenticatedHandler(http.MethodPost, http.StatusOK, "login.json"))
|
||||||
|
|
||||||
ctx, err := client.CreateAuthenticatedContext(context.Background())
|
ctx, err := client.CreateAuthenticatedContext(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
at := getToken(ctx)
|
at := getToken(ctx)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -46,13 +45,13 @@ func setupTest(t *testing.T, message string) *Client {
|
||||||
func TestAddTXTRecord(t *testing.T) {
|
func TestAddTXTRecord(t *testing.T) {
|
||||||
client := setupTest(t, "success")
|
client := setupTest(t, "success")
|
||||||
|
|
||||||
err := client.AddTXTRecord(context.Background(), "example.com", "sub.example.com", "value")
|
err := client.AddTXTRecord(t.Context(), "example.com", "sub.example.com", "value")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTXTRecord_error(t *testing.T) {
|
func TestAddTXTRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, "error: authentification failed")
|
client := setupTest(t, "error: authentification failed")
|
||||||
|
|
||||||
err := client.AddTXTRecord(context.Background(), "example.com", "sub.example.com", "value")
|
err := client.AddTXTRecord(t.Context(), "example.com", "sub.example.com", "value")
|
||||||
require.EqualError(t, err, "error: authentification failed")
|
require.EqualError(t, err, "error: authentification failed")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -97,7 +96,7 @@ func TestGetRootDomain(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, http.MethodGet, test.pattern, test.status, test.file)
|
client := setupTest(t, http.MethodGet, test.pattern, test.status, test.file)
|
||||||
|
|
||||||
domain, err := client.GetRootDomain(context.Background(), "test.lego.freeddns.org")
|
domain, err := client.GetRootDomain(t.Context(), "test.lego.freeddns.org")
|
||||||
|
|
||||||
if test.expected.error != "" {
|
if test.expected.error != "" {
|
||||||
assert.EqualError(t, err, test.expected.error)
|
assert.EqualError(t, err, test.expected.error)
|
||||||
|
|
@ -185,7 +184,7 @@ func TestGetRecords(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, http.MethodGet, test.pattern, test.status, test.file)
|
client := setupTest(t, http.MethodGet, test.pattern, test.status, test.file)
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "_acme-challenge.lego.freeddns.org", "TXT")
|
records, err := client.GetRecords(t.Context(), "_acme-challenge.lego.freeddns.org", "TXT")
|
||||||
|
|
||||||
if test.expected.error != "" {
|
if test.expected.error != "" {
|
||||||
assert.EqualError(t, err, test.expected.error)
|
assert.EqualError(t, err, test.expected.error)
|
||||||
|
|
@ -245,7 +244,7 @@ func TestAddNewRecord(t *testing.T) {
|
||||||
TTL: 300,
|
TTL: 300,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.AddNewRecord(context.Background(), 9007481, record)
|
err := client.AddNewRecord(t.Context(), 9007481, record)
|
||||||
|
|
||||||
if test.expected.error != "" {
|
if test.expected.error != "" {
|
||||||
assert.EqualError(t, err, test.expected.error)
|
assert.EqualError(t, err, test.expected.error)
|
||||||
|
|
@ -292,7 +291,7 @@ func TestDeleteRecord(t *testing.T) {
|
||||||
|
|
||||||
client := setupTest(t, http.MethodDelete, test.pattern, test.status, test.file)
|
client := setupTest(t, http.MethodDelete, test.pattern, test.status, test.file)
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), 9007481, 6041418)
|
err := client.DeleteRecord(t.Context(), 9007481, 6041418)
|
||||||
|
|
||||||
if test.expected.error != "" {
|
if test.expected.error != "" {
|
||||||
assert.EqualError(t, err, test.expected.error)
|
assert.EqualError(t, err, test.expected.error)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient Creates a new Client.
|
// NewClient Creates a new Client.
|
||||||
func NewClient(token string, key string) *Client {
|
func NewClient(token, key string) *Client {
|
||||||
baseURL, _ := url.Parse(DefaultBaseURL)
|
baseURL, _ := url.Parse(DefaultBaseURL)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -70,7 +69,7 @@ func setupTest(t *testing.T, method, pattern string, status int, file string) *C
|
||||||
func TestClient_ListZones(t *testing.T) {
|
func TestClient_ListZones(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/zones/records/all/example.com", http.StatusOK, "list-zone.json")
|
client := setupTest(t, http.MethodGet, "/zones/records/all/example.com", http.StatusOK, "list-zone.json")
|
||||||
|
|
||||||
zones, err := client.ListZones(context.Background(), "example.com")
|
zones, err := client.ListZones(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []ZoneRecord{{
|
expected := []ZoneRecord{{
|
||||||
|
|
@ -90,7 +89,7 @@ func TestClient_ListZones(t *testing.T) {
|
||||||
func TestClient_ListZones_error(t *testing.T) {
|
func TestClient_ListZones_error(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/zones/records/all/example.com", http.StatusOK, "error1.json")
|
client := setupTest(t, http.MethodGet, "/zones/records/all/example.com", http.StatusOK, "error1.json")
|
||||||
|
|
||||||
_, err := client.ListZones(context.Background(), "example.com")
|
_, err := client.ListZones(t.Context(), "example.com")
|
||||||
require.EqualError(t, err, "code 420: Enhance Your Calm. Rate limit exceeded (too many requests) OR you did NOT provide any credentials with your request!")
|
require.EqualError(t, err, "code 420: Enhance Your Calm. Rate limit exceeded (too many requests) OR you did NOT provide any credentials with your request!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +105,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
Priority: "0",
|
Priority: "0",
|
||||||
}
|
}
|
||||||
|
|
||||||
recordID, err := client.AddRecord(context.Background(), "example.com", record)
|
recordID, err := client.AddRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "xxx", recordID)
|
assert.Equal(t, "xxx", recordID)
|
||||||
|
|
@ -124,13 +123,13 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
Priority: "0",
|
Priority: "0",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.AddRecord(context.Background(), "example.com", record)
|
_, err := client.AddRecord(t.Context(), "example.com", record)
|
||||||
require.EqualError(t, err, "code 420: Enhance Your Calm. Rate limit exceeded (too many requests) OR you did NOT provide any credentials with your request!")
|
require.EqualError(t, err, "code 420: Enhance Your Calm. Rate limit exceeded (too many requests) OR you did NOT provide any credentials with your request!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodDelete, "/zones/records/example.com/xxx", http.StatusOK, "")
|
client := setupTest(t, http.MethodDelete, "/zones/records/example.com/xxx", http.StatusOK, "")
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "example.com", "xxx")
|
err := client.DeleteRecord(t.Context(), "example.com", "xxx")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ type Client struct {
|
||||||
password string
|
password string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(hostname string, username string, password string) *Client {
|
func NewClient(hostname, username, password string) *Client {
|
||||||
baseURL, _ := url.Parse(fmt.Sprintf("https://%s/rest/", hostname))
|
baseURL, _ := url.Parse(fmt.Sprintf("https://%s/rest/", hostname))
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -72,7 +71,7 @@ func setupTest(t *testing.T, method, pattern string, status int, file string) *C
|
||||||
func TestListRecords(t *testing.T) {
|
func TestListRecords(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/dns_rr_list", http.StatusOK, "dns_rr_list.json")
|
client := setupTest(t, http.MethodGet, "/dns_rr_list", http.StatusOK, "dns_rr_list.json")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
records, err := client.ListRecords(ctx)
|
records, err := client.ListRecords(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -339,7 +338,7 @@ func TestListRecords(t *testing.T) {
|
||||||
func TestGetRecord(t *testing.T) {
|
func TestGetRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/dns_rr_info", http.StatusOK, "dns_rr_info.json")
|
client := setupTest(t, http.MethodGet, "/dns_rr_info", http.StatusOK, "dns_rr_info.json")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
record, err := client.GetRecord(ctx, "239")
|
record, err := client.GetRecord(ctx, "239")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -386,7 +385,7 @@ func TestGetRecord(t *testing.T) {
|
||||||
func TestAddRecord(t *testing.T) {
|
func TestAddRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodPost, "/dns_rr_add", http.StatusCreated, "dns_rr_add.json")
|
client := setupTest(t, http.MethodPost, "/dns_rr_add", http.StatusCreated, "dns_rr_add.json")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
r := ResourceRecord{
|
r := ResourceRecord{
|
||||||
RRName: "test.example.com",
|
RRName: "test.example.com",
|
||||||
|
|
@ -407,7 +406,7 @@ func TestAddRecord(t *testing.T) {
|
||||||
func TestDeleteRecord(t *testing.T) {
|
func TestDeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodDelete, "/dns_rr_delete", http.StatusOK, "dns_rr_delete.json")
|
client := setupTest(t, http.MethodDelete, "/dns_rr_delete", http.StatusOK, "dns_rr_delete.json")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
resp, err := client.DeleteRecord(ctx, DeleteInputParameters{RRID: "251"})
|
resp, err := client.DeleteRecord(ctx, DeleteInputParameters{RRID: "251"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -420,7 +419,7 @@ func TestDeleteRecord(t *testing.T) {
|
||||||
func TestDeleteRecord_error(t *testing.T) {
|
func TestDeleteRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodDelete, "/dns_rr_delete", http.StatusBadRequest, "dns_rr_delete-error.json")
|
client := setupTest(t, http.MethodDelete, "/dns_rr_delete", http.StatusBadRequest, "dns_rr_delete-error.json")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := t.Context()
|
||||||
|
|
||||||
_, err := client.DeleteRecord(ctx, DeleteInputParameters{RRID: "251"})
|
_, err := client.DeleteRecord(ctx, DeleteInputParameters{RRID: "251"})
|
||||||
require.ErrorAs(t, err, &APIError{})
|
require.ErrorAs(t, err, &APIError{})
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ func (c Client) CreateHostRecord(ctx context.Context, domain string, record Reco
|
||||||
|
|
||||||
// RemoveHostRecord removes a record for a domain.
|
// RemoveHostRecord removes a record for a domain.
|
||||||
// https://docs.userapi.epik.com/v2/#/DNS%20Host%20Records/removeHostRecord
|
// https://docs.userapi.epik.com/v2/#/DNS%20Host%20Records/removeHostRecord
|
||||||
func (c Client) RemoveHostRecord(ctx context.Context, domain string, recordID string) (*Data, error) {
|
func (c Client) RemoveHostRecord(ctx context.Context, domain, recordID string) (*Data, error) {
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("ID", recordID)
|
params.Set("ID", recordID)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -34,7 +33,7 @@ func TestClient_GetDNSRecords(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodGet, http.StatusOK, "getDnsRecord.json"))
|
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodGet, http.StatusOK, "getDnsRecord.json"))
|
||||||
|
|
||||||
records, err := client.GetDNSRecords(context.Background(), "example.com")
|
records, err := client.GetDNSRecords(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Record{
|
expected := []Record{
|
||||||
|
|
@ -93,7 +92,7 @@ func TestClient_GetDNSRecords_error(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetDNSRecords(context.Background(), "example.com")
|
_, err := client.GetDNSRecords(t.Context(), "example.com")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +109,7 @@ func TestClient_CreateHostRecord(t *testing.T) {
|
||||||
TTL: 300,
|
TTL: 300,
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := client.CreateHostRecord(context.Background(), "example.com", record)
|
data, err := client.CreateHostRecord(t.Context(), "example.com", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Data{
|
expected := &Data{
|
||||||
|
|
@ -134,7 +133,7 @@ func TestClient_CreateHostRecord_error(t *testing.T) {
|
||||||
TTL: 300,
|
TTL: 300,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.CreateHostRecord(context.Background(), "example.com", record)
|
_, err := client.CreateHostRecord(t.Context(), "example.com", record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +142,7 @@ func TestClient_RemoveHostRecord(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodDelete, http.StatusOK, "removeHostRecord.json"))
|
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodDelete, http.StatusOK, "removeHostRecord.json"))
|
||||||
|
|
||||||
data, err := client.RemoveHostRecord(context.Background(), "example.com", "abc123")
|
data, err := client.RemoveHostRecord(t.Context(), "example.com", "abc123")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Data{
|
expected := &Data{
|
||||||
|
|
@ -159,7 +158,7 @@ func TestClient_RemoveHostRecord_error(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
|
mux.HandleFunc("/domains/example.com/records", testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.RemoveHostRecord(context.Background(), "example.com", "abc123")
|
_, err := client.RemoveHostRecord(t.Context(), "example.com", "abc123")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,26 @@ type LogRecorder struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*LogRecorder) Fatal(args ...interface{}) {
|
func (*LogRecorder) Fatal(args ...any) {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*LogRecorder) Fatalln(args ...interface{}) {
|
func (*LogRecorder) Fatalln(args ...any) {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*LogRecorder) Fatalf(format string, args ...interface{}) {
|
func (*LogRecorder) Fatalf(format string, args ...any) {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*LogRecorder) Print(args ...interface{}) {
|
func (*LogRecorder) Print(args ...any) {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LogRecorder) Println(args ...interface{}) {
|
func (l *LogRecorder) Println(args ...any) {
|
||||||
l.Called(args...)
|
l.Called(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*LogRecorder) Printf(format string, args ...interface{}) {
|
func (*LogRecorder) Printf(format string, args ...any) {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ func (d *DNSProvider) findExistingZone(zoneName string) (*egoscale.DNSDomain, er
|
||||||
|
|
||||||
// findExistingRecordID Query Exoscale to find an existing record for this name.
|
// findExistingRecordID Query Exoscale to find an existing record for this name.
|
||||||
// Returns empty result if no record could be found.
|
// Returns empty result if no record could be found.
|
||||||
func (d *DNSProvider) findExistingRecordID(zoneID egoscale.UUID, recordName string, value string) (egoscale.UUID, error) {
|
func (d *DNSProvider) findExistingRecordID(zoneID egoscale.UUID, recordName, value string) (egoscale.UUID, error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
records, err := d.client.ListDNSDomainRecords(ctx, zoneID)
|
records, err := d.client.ListDNSDomainRecords(ctx, zoneID)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new Client.
|
// NewClient creates a new Client.
|
||||||
func NewClient(apiToken string, tenantName string) (*Client, error) {
|
func NewClient(apiToken, tenantName string) (*Client, error) {
|
||||||
if apiToken == "" {
|
if apiToken == "" {
|
||||||
return nil, errors.New("credentials missing")
|
return nil, errors.New("credentials missing")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -64,7 +63,7 @@ func TestClient_Create(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := client.CreateRRSet(context.Background(), "example.com", "groupA", rrSet)
|
result, err := client.CreateRRSet(t.Context(), "example.com", "groupA", rrSet)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &APIRRSet{
|
expected := &APIRRSet{
|
||||||
|
|
@ -94,14 +93,14 @@ func TestClient_Create_error(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.CreateRRSet(context.Background(), "example.com", "groupA", rrSet)
|
_, err := client.CreateRRSet(t.Context(), "example.com", "groupA", rrSet)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_Get(t *testing.T) {
|
func TestClient_Get(t *testing.T) {
|
||||||
client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json")
|
client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json")
|
||||||
|
|
||||||
result, err := client.GetRRSet(context.Background(), "example.com", "groupA", "www", "TXT")
|
result, err := client.GetRRSet(t.Context(), "example.com", "groupA", "www", "TXT")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &APIRRSet{
|
expected := &APIRRSet{
|
||||||
|
|
@ -125,7 +124,7 @@ func TestClient_Get(t *testing.T) {
|
||||||
func TestClient_Get_not_found(t *testing.T) {
|
func TestClient_Get_not_found(t *testing.T) {
|
||||||
client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusNotFound, "error_404.json")
|
client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusNotFound, "error_404.json")
|
||||||
|
|
||||||
result, err := client.GetRRSet(context.Background(), "example.com", "groupA", "www", "TXT")
|
result, err := client.GetRRSet(t.Context(), "example.com", "groupA", "www", "TXT")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Nil(t, result)
|
assert.Nil(t, result)
|
||||||
|
|
@ -134,14 +133,14 @@ func TestClient_Get_not_found(t *testing.T) {
|
||||||
func TestClient_Get_error(t *testing.T) {
|
func TestClient_Get_error(t *testing.T) {
|
||||||
client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "")
|
client := setupTest(t, "GET /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "")
|
||||||
|
|
||||||
_, err := client.GetRRSet(context.Background(), "example.com", "groupA", "www", "TXT")
|
_, err := client.GetRRSet(t.Context(), "example.com", "groupA", "www", "TXT")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_Delete(t *testing.T) {
|
func TestClient_Delete(t *testing.T) {
|
||||||
client := setupTest(t, "DELETE /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json")
|
client := setupTest(t, "DELETE /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusOK, "get.json")
|
||||||
|
|
||||||
result, err := client.DeleteRRSet(context.Background(), "example.com", "groupA", "www", "TXT")
|
result, err := client.DeleteRRSet(t.Context(), "example.com", "groupA", "www", "TXT")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &APIRRSet{
|
expected := &APIRRSet{
|
||||||
|
|
@ -165,7 +164,7 @@ func TestClient_Delete(t *testing.T) {
|
||||||
func TestClient_Delete_error(t *testing.T) {
|
func TestClient_Delete_error(t *testing.T) {
|
||||||
client := setupTest(t, "DELETE /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "")
|
client := setupTest(t, "DELETE /api/config/dns/namespaces/system/dns_zones/example.com/rrsets/groupA/www/TXT", http.StatusBadRequest, "")
|
||||||
|
|
||||||
_, err := client.DeleteRRSet(context.Background(), "example.com", "groupA", "www", "TXT")
|
_, err := client.DeleteRRSet(t.Context(), "example.com", "groupA", "www", "TXT")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +180,7 @@ func TestClient_Replace(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := client.ReplaceRRSet(context.Background(), "example.com", "groupA", "www", "TXT", rrSet)
|
result, err := client.ReplaceRRSet(t.Context(), "example.com", "groupA", "www", "TXT", rrSet)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &APIRRSet{
|
expected := &APIRRSet{
|
||||||
|
|
@ -214,6 +213,6 @@ func TestClient_Replace_error(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ReplaceRRSet(context.Background(), "example.com", "groupA", "www", "TXT", rrSet)
|
_, err := client.ReplaceRRSet(t.Context(), "example.com", "groupA", "www", "TXT", rrSet)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package gcloud
|
package gcloud
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -11,7 +12,6 @@ import (
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/platform/tester"
|
"github.com/go-acme/lego/v4/platform/tester"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/net/context"
|
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
"google.golang.org/api/dns/v1"
|
"google.golang.org/api/dns/v1"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func (c *Client) updateRRSet(ctx context.Context, zone, name string, record RRSe
|
||||||
return c.doRequest(ctx, http.MethodPut, endpoint, record, nil)
|
return c.doRequest(ctx, http.MethodPut, endpoint, record, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doRequest(ctx context.Context, method string, endpoint *url.URL, bodyParams any, result any) error {
|
func (c *Client) doRequest(ctx context.Context, method string, endpoint *url.URL, bodyParams, result any) error {
|
||||||
req, err := newJSONRequest(ctx, method, endpoint, bodyParams)
|
req, err := newJSONRequest(ctx, method, endpoint, bodyParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("new request: %w", err)
|
return fmt.Errorf("new request: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -44,7 +43,7 @@ func TestClient_GetZone(t *testing.T) {
|
||||||
next: handleJSONResponse(expected),
|
next: handleJSONResponse(expected),
|
||||||
})
|
})
|
||||||
|
|
||||||
zone, err := client.GetZone(context.Background(), "example.com")
|
zone, err := client.GetZone(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, expected, zone)
|
assert.Equal(t, expected, zone)
|
||||||
|
|
@ -58,7 +57,7 @@ func TestClient_GetZone_error(t *testing.T) {
|
||||||
next: handleAPIError(),
|
next: handleAPIError(),
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := client.GetZone(context.Background(), "example.com")
|
_, err := client.GetZone(t.Context(), "example.com")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +76,7 @@ func TestClient_GetRRSet(t *testing.T) {
|
||||||
next: handleJSONResponse(expected),
|
next: handleJSONResponse(expected),
|
||||||
})
|
})
|
||||||
|
|
||||||
rrSet, err := client.GetRRSet(context.Background(), "example.com", "foo.example.com")
|
rrSet, err := client.GetRRSet(t.Context(), "example.com", "foo.example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, expected, rrSet)
|
assert.Equal(t, expected, rrSet)
|
||||||
|
|
@ -91,7 +90,7 @@ func TestClient_GetRRSet_error(t *testing.T) {
|
||||||
next: handleAPIError(),
|
next: handleAPIError(),
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := client.GetRRSet(context.Background(), "example.com", "foo.example.com")
|
_, err := client.GetRRSet(t.Context(), "example.com", "foo.example.com")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +100,7 @@ func TestClient_DeleteRRSet(t *testing.T) {
|
||||||
mux.Handle("/v2/zones/test.example.com/my.test.example.com/"+txtRecordType,
|
mux.Handle("/v2/zones/test.example.com/my.test.example.com/"+txtRecordType,
|
||||||
validationHandler{method: http.MethodDelete})
|
validationHandler{method: http.MethodDelete})
|
||||||
|
|
||||||
err := client.DeleteRRSet(context.Background(), "test.example.com", "my.test.example.com.")
|
err := client.DeleteRRSet(t.Context(), "test.example.com", "my.test.example.com.")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +112,7 @@ func TestClient_DeleteRRSet_error(t *testing.T) {
|
||||||
next: handleAPIError(),
|
next: handleAPIError(),
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteRRSet(context.Background(), "test.example.com", "my.test.example.com.")
|
err := client.DeleteRRSet(t.Context(), "test.example.com", "my.test.example.com.")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,7 +182,7 @@ func TestClient_AddRRSet(t *testing.T) {
|
||||||
mux.Handle(pattern, handler)
|
mux.Handle(pattern, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := cl.AddRRSet(context.Background(), test.zone, test.recordName, test.value, testTTL)
|
err := cl.AddRRSet(t.Context(), test.zone, test.recordName, test.value, testTTL)
|
||||||
if test.wantErr {
|
if test.wantErr {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
return
|
return
|
||||||
|
|
@ -223,7 +222,7 @@ func handleAPIError() http.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleJSONResponse(data interface{}) http.HandlerFunc {
|
func handleJSONResponse(data any) http.HandlerFunc {
|
||||||
return func(rw http.ResponseWriter, req *http.Request) {
|
return func(rw http.ResponseWriter, req *http.Request) {
|
||||||
err := json.NewEncoder(rw).Encode(data)
|
err := json.NewEncoder(rw).Encode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ type Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(apiUser string, apiKey string) *Client {
|
func NewClient(apiUser, apiKey string) *Client {
|
||||||
baseURL, _ := url.Parse(defaultBaseURL)
|
baseURL, _ := url.Parse(defaultBaseURL)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -65,7 +64,7 @@ func setupTest(t *testing.T, method, pattern string, status int, file string) *C
|
||||||
func TestClient_AddTXTRecord(t *testing.T) {
|
func TestClient_AddTXTRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodPost, "/domain/addrecord", http.StatusOK, "add-record.json")
|
client := setupTest(t, http.MethodPost, "/domain/addrecord", http.StatusOK, "add-record.json")
|
||||||
|
|
||||||
recordID, err := client.AddTXTRecord(context.Background(), "example.com", "foo", "txt", 120)
|
recordID, err := client.AddTXTRecord(t.Context(), "example.com", "foo", "txt", 120)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, 123, recordID)
|
assert.Equal(t, 123, recordID)
|
||||||
|
|
@ -74,6 +73,6 @@ func TestClient_AddTXTRecord(t *testing.T) {
|
||||||
func TestClient_DeleteTXTRecord(t *testing.T) {
|
func TestClient_DeleteTXTRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodPost, "/domain/deleterecord", http.StatusOK, "delete-record.json")
|
client := setupTest(t, http.MethodPost, "/domain/deleterecord", http.StatusOK, "delete-record.json")
|
||||||
|
|
||||||
err := client.DeleteTXTRecord(context.Background(), 123)
|
err := client.DeleteTXTRecord(t.Context(), 123)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ type Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(apiKey string, apiSecret string) *Client {
|
func NewClient(apiKey, apiSecret string) *Client {
|
||||||
baseURL, _ := url.Parse(DefaultBaseURL)
|
baseURL, _ := url.Parse(DefaultBaseURL)
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -34,7 +33,7 @@ func TestClient_GetRecords(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/v1/domains/example.com/records/TXT/", testHandler(http.MethodGet, http.StatusOK, "getrecords.json"))
|
mux.HandleFunc("/v1/domains/example.com/records/TXT/", testHandler(http.MethodGet, http.StatusOK, "getrecords.json"))
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "example.com", "TXT", "")
|
records, err := client.GetRecords(t.Context(), "example.com", "TXT", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []DNSRecord{
|
expected := []DNSRecord{
|
||||||
|
|
@ -54,7 +53,7 @@ func TestClient_GetRecords_errors(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/v1/domains/example.com/records/TXT/", testHandler(http.MethodGet, http.StatusUnprocessableEntity, "errors.json"))
|
mux.HandleFunc("/v1/domains/example.com/records/TXT/", testHandler(http.MethodGet, http.StatusUnprocessableEntity, "errors.json"))
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "example.com", "TXT", "")
|
records, err := client.GetRecords(t.Context(), "example.com", "TXT", "")
|
||||||
require.EqualError(t, err, "[status code: 422] INVALID_BODY: Request body doesn't fulfill schema, see details in `fields`")
|
require.EqualError(t, err, "[status code: 422] INVALID_BODY: Request body doesn't fulfill schema, see details in `fields`")
|
||||||
assert.Nil(t, records)
|
assert.Nil(t, records)
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +83,7 @@ func TestClient_UpdateTxtRecords(t *testing.T) {
|
||||||
{Name: "_acme-challenge.lego", Type: "TXT", Data: "acme", TTL: 600},
|
{Name: "_acme-challenge.lego", Type: "TXT", Data: "acme", TTL: 600},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.UpdateTxtRecords(context.Background(), records, "example.com", "lego")
|
err := client.UpdateTxtRecords(t.Context(), records, "example.com", "lego")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +102,7 @@ func TestClient_UpdateTxtRecords_errors(t *testing.T) {
|
||||||
{Name: "_acme-challenge.lego", Type: "TXT", Data: "acme", TTL: 600},
|
{Name: "_acme-challenge.lego", Type: "TXT", Data: "acme", TTL: 600},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.UpdateTxtRecords(context.Background(), records, "example.com", "lego")
|
err := client.UpdateTxtRecords(t.Context(), records, "example.com", "lego")
|
||||||
require.EqualError(t, err, "[status code: 422] INVALID_BODY: Request body doesn't fulfill schema, see details in `fields`")
|
require.EqualError(t, err, "[status code: 422] INVALID_BODY: Request body doesn't fulfill schema, see details in `fields`")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +111,7 @@ func TestClient_DeleteTxtRecords(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/v1/domains/example.com/records/TXT/foo", testHandler(http.MethodDelete, http.StatusNoContent, ""))
|
mux.HandleFunc("/v1/domains/example.com/records/TXT/foo", testHandler(http.MethodDelete, http.StatusNoContent, ""))
|
||||||
|
|
||||||
err := client.DeleteTxtRecords(context.Background(), "example.com", "foo")
|
err := client.DeleteTxtRecords(t.Context(), "example.com", "foo")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +120,7 @@ func TestClient_DeleteTxtRecords_errors(t *testing.T) {
|
||||||
|
|
||||||
mux.HandleFunc("/v1/domains/example.com/records/TXT/foo", testHandler(http.MethodDelete, http.StatusConflict, "error-extended.json"))
|
mux.HandleFunc("/v1/domains/example.com/records/TXT/foo", testHandler(http.MethodDelete, http.StatusConflict, "error-extended.json"))
|
||||||
|
|
||||||
err := client.DeleteTxtRecords(context.Background(), "example.com", "foo")
|
err := client.DeleteTxtRecords(t.Context(), "example.com", "foo")
|
||||||
require.EqualError(t, err, "[status code: 409] ACCESS_DENIED: Authenticated user is not allowed access [test: content (path=/foo) (pathRelated=/bar)]")
|
require.EqualError(t, err, "[status code: 409] ACCESS_DENIED: Authenticated user is not allowed access [test: content (path=/foo) (pathRelated=/bar)]")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -66,7 +65,7 @@ func TestClient_GetTxtRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
record, err := client.GetTxtRecord(context.Background(), "test1", "txttxttxt", zoneID)
|
record, err := client.GetTxtRecord(t.Context(), "test1", "txttxttxt", zoneID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
fmt.Println(record)
|
fmt.Println(record)
|
||||||
|
|
@ -112,7 +111,7 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
ZoneID: zoneID,
|
ZoneID: zoneID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.CreateRecord(context.Background(), record)
|
err := client.CreateRecord(t.Context(), record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +133,7 @@ func TestClient_DeleteRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "recordID")
|
err := client.DeleteRecord(t.Context(), "recordID")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +168,7 @@ func TestClient_GetZoneID(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
zoneID, err := client.GetZoneID(context.Background(), "example.com")
|
zoneID, err := client.GetZoneID(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "zoneA", zoneID)
|
assert.Equal(t, "zoneA", zoneID)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -20,7 +19,7 @@ const testAPIKey = "secret"
|
||||||
func TestClient_GetZones(t *testing.T) {
|
func TestClient_GetZones(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones", testHandler(http.MethodGet, http.StatusOK, "zones.json"))
|
client := setupTest(t, "/user/v1/zones", testHandler(http.MethodGet, http.StatusOK, "zones.json"))
|
||||||
|
|
||||||
zones, err := client.GetZones(context.Background(), "", 100, 0)
|
zones, err := client.GetZones(t.Context(), "", 100, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Zone{
|
expected := []Zone{
|
||||||
|
|
@ -41,14 +40,14 @@ func TestClient_GetZones(t *testing.T) {
|
||||||
func TestClient_GetZones_error(t *testing.T) {
|
func TestClient_GetZones_error(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
client := setupTest(t, "/user/v1/zones", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetZones(context.Background(), "", 100, 0)
|
_, err := client.GetZones(t.Context(), "", 100, 0)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_GetZone(t *testing.T) {
|
func TestClient_GetZone(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones/123", testHandler(http.MethodGet, http.StatusOK, "zone.json"))
|
client := setupTest(t, "/user/v1/zones/123", testHandler(http.MethodGet, http.StatusOK, "zone.json"))
|
||||||
|
|
||||||
zone, err := client.GetZone(context.Background(), "123")
|
zone, err := client.GetZone(t.Context(), "123")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Zone{
|
expected := &Zone{
|
||||||
|
|
@ -67,14 +66,14 @@ func TestClient_GetZone(t *testing.T) {
|
||||||
func TestClient_GetZone_error(t *testing.T) {
|
func TestClient_GetZone_error(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones/123", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
client := setupTest(t, "/user/v1/zones/123", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetZone(context.Background(), "123")
|
_, err := client.GetZone(t.Context(), "123")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_GetRecords(t *testing.T) {
|
func TestClient_GetRecords(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones/123/records", testHandler(http.MethodGet, http.StatusOK, "records.json"))
|
client := setupTest(t, "/user/v1/zones/123/records", testHandler(http.MethodGet, http.StatusOK, "records.json"))
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "123", "TXT")
|
records, err := client.GetRecords(t.Context(), "123", "TXT")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Record{
|
expected := []Record{
|
||||||
|
|
@ -154,7 +153,7 @@ func TestClient_GetRecords(t *testing.T) {
|
||||||
func TestClient_GetRecords_error(t *testing.T) {
|
func TestClient_GetRecords_error(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones/123/records", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
client := setupTest(t, "/user/v1/zones/123/records", testHandler(http.MethodGet, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
_, err := client.GetRecords(context.Background(), "123", "TXT")
|
_, err := client.GetRecords(t.Context(), "123", "TXT")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +168,7 @@ func TestClient_AddRecord(t *testing.T) {
|
||||||
Comment: "example",
|
Comment: "example",
|
||||||
}
|
}
|
||||||
|
|
||||||
newRecord, err := client.AddRecord(context.Background(), "123", record)
|
newRecord, err := client.AddRecord(t.Context(), "123", record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Record{
|
expected := &Record{
|
||||||
|
|
@ -195,21 +194,21 @@ func TestClient_AddRecord_error(t *testing.T) {
|
||||||
Comment: "example",
|
Comment: "example",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.AddRecord(context.Background(), "123", record)
|
_, err := client.AddRecord(t.Context(), "123", record)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones/123/records/6", testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
|
client := setupTest(t, "/user/v1/zones/123/records/6", testHandler(http.MethodDelete, http.StatusUnauthorized, "error.json"))
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "123", "6")
|
err := client.DeleteRecord(t.Context(), "123", "6")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord_error(t *testing.T) {
|
func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, "/user/v1/zones/123/records/6", testHandler(http.MethodDelete, http.StatusNoContent, ""))
|
client := setupTest(t, "/user/v1/zones/123/records/6", testHandler(http.MethodDelete, http.StatusNoContent, ""))
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "123", "6")
|
err := client.DeleteRecord(t.Context(), "123", "6")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/challenge"
|
"github.com/go-acme/lego/v4/challenge"
|
||||||
|
|
@ -63,9 +62,9 @@ func NewDNSProvider() (*DNSProvider, error) {
|
||||||
return nil, fmt.Errorf("hurricane: %w", err)
|
return nil, fmt.Errorf("hurricane: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
credentials, err := parseCredentials(values[EnvTokens])
|
credentials, err := env.ParsePairs(values[EnvTokens])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("hurricane: %w", err)
|
return nil, fmt.Errorf("hurricane: credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Credentials = credentials
|
config.Credentials = credentials
|
||||||
|
|
@ -122,19 +121,3 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
||||||
func (d *DNSProvider) Sequential() time.Duration {
|
func (d *DNSProvider) Sequential() time.Duration {
|
||||||
return d.config.SequenceInterval
|
return d.config.SequenceInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCredentials(raw string) (map[string]string, error) {
|
|
||||||
credentials := make(map[string]string)
|
|
||||||
|
|
||||||
credStrings := strings.Split(strings.TrimSuffix(raw, ","), ",")
|
|
||||||
for _, credPair := range credStrings {
|
|
||||||
data := strings.Split(credPair, ":")
|
|
||||||
if len(data) != 2 {
|
|
||||||
return nil, fmt.Errorf("incorrect credential pair: %s", credPair)
|
|
||||||
}
|
|
||||||
|
|
||||||
credentials[strings.TrimSpace(data[0])] = strings.TrimSpace(data[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
return credentials, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,14 @@ func TestNewDNSProvider(t *testing.T) {
|
||||||
envVars: map[string]string{
|
envVars: map[string]string{
|
||||||
EnvTokens: ",",
|
EnvTokens: ",",
|
||||||
},
|
},
|
||||||
expected: "hurricane: incorrect credential pair: ",
|
expected: "hurricane: credentials: incorrect pair: ",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "invalid credentials, partial",
|
desc: "invalid credentials, partial",
|
||||||
envVars: map[string]string{
|
envVars: map[string]string{
|
||||||
EnvTokens: "example.org:123,example.net",
|
EnvTokens: "example.org:123,example.net",
|
||||||
},
|
},
|
||||||
expected: "hurricane: incorrect credential pair: example.net",
|
expected: "hurricane: credentials: incorrect pair: example.net",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "missing credentials",
|
desc: "missing credentials",
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ func NewClient(credentials map[string]string) *Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTxtRecord updates a TXT record.
|
// UpdateTxtRecord updates a TXT record.
|
||||||
func (c *Client) UpdateTxtRecord(ctx context.Context, hostname string, txt string) error {
|
func (c *Client) UpdateTxtRecord(ctx context.Context, hostname, txt string) error {
|
||||||
domain := strings.TrimPrefix(hostname, "_acme-challenge.")
|
domain := strings.TrimPrefix(hostname, "_acme-challenge.")
|
||||||
|
|
||||||
c.credMu.Lock()
|
c.credMu.Lock()
|
||||||
|
|
@ -101,7 +101,7 @@ func (c *Client) UpdateTxtRecord(ctx context.Context, hostname string, txt strin
|
||||||
return evaluateBody(string(bytes.TrimSpace(raw)), hostname)
|
return evaluateBody(string(bytes.TrimSpace(raw)), hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func evaluateBody(body string, hostname string) error {
|
func evaluateBody(body, hostname string) error {
|
||||||
code, _, _ := strings.Cut(body, " ")
|
code, _, _ := strings.Cut(body, " ")
|
||||||
|
|
||||||
switch code {
|
switch code {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -75,7 +74,7 @@ func TestClient_UpdateTxtRecord(t *testing.T) {
|
||||||
client.baseURL = server.URL
|
client.baseURL = server.URL
|
||||||
client.HTTPClient = server.Client()
|
client.HTTPClient = server.Client()
|
||||||
|
|
||||||
err := client.UpdateTxtRecord(context.Background(), "_acme-challenge.example.com", "foo")
|
err := client.UpdateTxtRecord(t.Context(), "_acme-challenge.example.com", "foo")
|
||||||
test.expected(t, err)
|
test.expected(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ func (c *Client) CreateRecordset(ctx context.Context, zoneID, recordType, name,
|
||||||
|
|
||||||
// DeleteRecordset deletes a recordset.
|
// DeleteRecordset deletes a recordset.
|
||||||
// https://api.hyperone.com/v2/docs#operation/dns_project_zone_recordset_delete
|
// https://api.hyperone.com/v2/docs#operation/dns_project_zone_recordset_delete
|
||||||
func (c *Client) DeleteRecordset(ctx context.Context, zoneID string, recordsetID string) error {
|
func (c *Client) DeleteRecordset(ctx context.Context, zoneID, recordsetID string) error {
|
||||||
// https://api.hyperone.com/v2/dns/{locationId}/project/{projectId}/zone/{zoneId}/recordset/{recordsetId}
|
// https://api.hyperone.com/v2/dns/{locationId}/project/{projectId}/zone/{zoneId}/recordset/{recordsetId}
|
||||||
endpoint := c.baseURL.JoinPath("zone", zoneID, "recordset", recordsetID)
|
endpoint := c.baseURL.JoinPath("zone", zoneID, "recordset", recordsetID)
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ func (c *Client) DeleteRecordset(ctx context.Context, zoneID string, recordsetID
|
||||||
|
|
||||||
// GetRecords gets all records within specified recordset.
|
// GetRecords gets all records within specified recordset.
|
||||||
// https://api.hyperone.com/v2/docs#operation/dns_project_zone_recordset_record_list
|
// https://api.hyperone.com/v2/docs#operation/dns_project_zone_recordset_record_list
|
||||||
func (c *Client) GetRecords(ctx context.Context, zoneID string, recordsetID string) ([]Record, error) {
|
func (c *Client) GetRecords(ctx context.Context, zoneID, recordsetID string) ([]Record, error) {
|
||||||
// https://api.hyperone.com/v2/dns/{locationId}/project/{projectId}/zone/{zoneId}/recordset/{recordsetId}/record
|
// https://api.hyperone.com/v2/dns/{locationId}/project/{projectId}/zone/{zoneId}/recordset/{recordsetId}/record
|
||||||
endpoint := c.baseURL.JoinPath("zone", zoneID, "recordset", recordsetID, "record")
|
endpoint := c.baseURL.JoinPath("zone", zoneID, "recordset", recordsetID, "record")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -25,7 +24,7 @@ func (s signerMock) GetJWT() (string, error) {
|
||||||
func TestClient_FindRecordset(t *testing.T) {
|
func TestClient_FindRecordset(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone/zone321/recordset", respFromFile("recordset.json"))
|
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone/zone321/recordset", respFromFile("recordset.json"))
|
||||||
|
|
||||||
recordset, err := client.FindRecordset(context.Background(), "zone321", "SOA", "example.com.")
|
recordset, err := client.FindRecordset(t.Context(), "zone321", "SOA", "example.com.")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Recordset{
|
expected := &Recordset{
|
||||||
|
|
@ -49,7 +48,7 @@ func TestClient_CreateRecordset(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodPost, "/dns/loc123/project/proj123/zone/zone123/recordset",
|
client := setupTest(t, http.MethodPost, "/dns/loc123/project/proj123/zone/zone123/recordset",
|
||||||
hasReqBody(expectedReqBody), respFromFile("createRecordset.json"))
|
hasReqBody(expectedReqBody), respFromFile("createRecordset.json"))
|
||||||
|
|
||||||
rs, err := client.CreateRecordset(context.Background(), "zone123", "TXT", "test.example.com.", "value", 3600)
|
rs, err := client.CreateRecordset(t.Context(), "zone123", "TXT", "test.example.com.", "value", 3600)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Recordset{RecordType: "TXT", Name: "test.example.com.", TTL: 3600, ID: "1234567890qwertyuiop"}
|
expected := &Recordset{RecordType: "TXT", Name: "test.example.com.", TTL: 3600, ID: "1234567890qwertyuiop"}
|
||||||
|
|
@ -59,14 +58,14 @@ func TestClient_CreateRecordset(t *testing.T) {
|
||||||
func TestClient_DeleteRecordset(t *testing.T) {
|
func TestClient_DeleteRecordset(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodDelete, "/dns/loc123/project/proj123/zone/zone321/recordset/rs322")
|
client := setupTest(t, http.MethodDelete, "/dns/loc123/project/proj123/zone/zone321/recordset/rs322")
|
||||||
|
|
||||||
err := client.DeleteRecordset(context.Background(), "zone321", "rs322")
|
err := client.DeleteRecordset(t.Context(), "zone321", "rs322")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_GetRecords(t *testing.T) {
|
func TestClient_GetRecords(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone/321/recordset/322/record", respFromFile("record.json"))
|
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone/321/recordset/322/record", respFromFile("record.json"))
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "321", "322")
|
records, err := client.GetRecords(t.Context(), "321", "322")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Record{
|
expected := []Record{
|
||||||
|
|
@ -88,7 +87,7 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodPost, "/dns/loc123/project/proj123/zone/z123/recordset/rs325/record",
|
client := setupTest(t, http.MethodPost, "/dns/loc123/project/proj123/zone/z123/recordset/rs325/record",
|
||||||
hasReqBody(expectedReqBody), respFromFile("createRecord.json"))
|
hasReqBody(expectedReqBody), respFromFile("createRecord.json"))
|
||||||
|
|
||||||
rs, err := client.CreateRecord(context.Background(), "z123", "rs325", "value")
|
rs, err := client.CreateRecord(t.Context(), "z123", "rs325", "value")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Record{ID: "123321qwerqwewqerq", Content: "value", Enabled: true}
|
expected := &Record{ID: "123321qwerqwewqerq", Content: "value", Enabled: true}
|
||||||
|
|
@ -98,14 +97,14 @@ func TestClient_CreateRecord(t *testing.T) {
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodDelete, "/dns/loc123/project/proj123/zone/321/recordset/322/record/323")
|
client := setupTest(t, http.MethodDelete, "/dns/loc123/project/proj123/zone/321/recordset/322/record/323")
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "321", "322", "323")
|
err := client.DeleteRecord(t.Context(), "321", "322", "323")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_FindZone(t *testing.T) {
|
func TestClient_FindZone(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone", respFromFile("zones.json"))
|
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone", respFromFile("zones.json"))
|
||||||
|
|
||||||
zone, err := client.FindZone(context.Background(), "example.com")
|
zone, err := client.FindZone(t.Context(), "example.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Zone{
|
expected := &Zone{
|
||||||
|
|
@ -122,7 +121,7 @@ func TestClient_FindZone(t *testing.T) {
|
||||||
func TestClient_GetZones(t *testing.T) {
|
func TestClient_GetZones(t *testing.T) {
|
||||||
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone", respFromFile("zones.json"))
|
client := setupTest(t, http.MethodGet, "/dns/loc123/project/proj123/zone", respFromFile("zones.json"))
|
||||||
|
|
||||||
zones, err := client.GetZones(context.Background())
|
zones, err := client.GetZones(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Zone{
|
expected := []Zone{
|
||||||
|
|
@ -183,7 +182,7 @@ func setupTest(t *testing.T, method, path string, handlers ...assertHandler) *Cl
|
||||||
|
|
||||||
type assertHandler func(http.ResponseWriter, *http.Request) (int, error)
|
type assertHandler func(http.ResponseWriter, *http.Request) (int, error)
|
||||||
|
|
||||||
func hasReqBody(v interface{}) assertHandler {
|
func hasReqBody(v any) assertHandler {
|
||||||
return func(rw http.ResponseWriter, req *http.Request) (int, error) {
|
return func(rw http.ResponseWriter, req *http.Request) (int, error) {
|
||||||
reqBody, err := io.ReadAll(req.Body)
|
reqBody, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/challenge"
|
"github.com/go-acme/lego/v4/challenge"
|
||||||
|
|
@ -14,6 +13,7 @@ import (
|
||||||
"github.com/go-acme/lego/v4/platform/config/env"
|
"github.com/go-acme/lego/v4/platform/config/env"
|
||||||
"github.com/iij/doapi"
|
"github.com/iij/doapi"
|
||||||
"github.com/iij/doapi/protocol"
|
"github.com/iij/doapi/protocol"
|
||||||
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Environment variables names.
|
// Environment variables names.
|
||||||
|
|
@ -226,26 +226,20 @@ func (d *DNSProvider) listZones() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitDomain(domain string, zones []string) (string, string, error) {
|
func splitDomain(domain string, zones []string) (string, string, error) {
|
||||||
parts := strings.Split(strings.Trim(domain, "."), ".")
|
base := dns01.UnFqdn(domain)
|
||||||
|
|
||||||
var owner string
|
for _, index := range dns.Split(base) {
|
||||||
var zone string
|
zone := base[index:]
|
||||||
|
|
||||||
for i := range len(parts) - 1 {
|
|
||||||
zone = strings.Join(parts[i:], ".")
|
|
||||||
if slices.Contains(zones, zone) {
|
if slices.Contains(zones, zone) {
|
||||||
baseOwner := strings.Join(parts[0:i], ".")
|
baseOwner := base[:index]
|
||||||
if baseOwner != "" {
|
if baseOwner != "" {
|
||||||
baseOwner = "." + baseOwner
|
baseOwner = "." + baseOwner
|
||||||
}
|
}
|
||||||
owner = "_acme-challenge" + baseOwner
|
|
||||||
break
|
return "_acme-challenge" + dns01.UnFqdn(baseOwner), zone, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if owner == "" {
|
return "", "", fmt.Errorf("%s not found", domain)
|
||||||
return "", "", fmt.Errorf("%s not found", domain)
|
|
||||||
}
|
|
||||||
|
|
||||||
return owner, zone, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,31 +161,31 @@ func TestSplitDomain(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "domain equals zone",
|
desc: "domain equals zone",
|
||||||
domain: "domain.com",
|
domain: "example.com",
|
||||||
zones: []string{"domain.com"},
|
zones: []string{"example.com"},
|
||||||
expectedOwner: "_acme-challenge",
|
expectedOwner: "_acme-challenge",
|
||||||
expectedZone: "domain.com",
|
expectedZone: "example.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "with a subdomain",
|
desc: "with a subdomain",
|
||||||
domain: "my.domain.com",
|
domain: "my.example.com",
|
||||||
zones: []string{"domain.com"},
|
zones: []string{"example.com"},
|
||||||
expectedOwner: "_acme-challenge.my",
|
expectedOwner: "_acme-challenge.my",
|
||||||
expectedZone: "domain.com",
|
expectedZone: "example.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "with a subdomain in a zone",
|
desc: "with a subdomain in a zone",
|
||||||
domain: "my.sub.domain.com",
|
domain: "my.sub.example.com",
|
||||||
zones: []string{"sub.domain.com", "domain.com"},
|
zones: []string{"sub.example.com", "example.com"},
|
||||||
expectedOwner: "_acme-challenge.my",
|
expectedOwner: "_acme-challenge.my",
|
||||||
expectedZone: "sub.domain.com",
|
expectedZone: "sub.example.com",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "with a sub-subdomain",
|
desc: "with a sub-subdomain",
|
||||||
domain: "my.sub.domain.com",
|
domain: "my.sub.example.com",
|
||||||
zones: []string{"domain1.com", "domain.com"},
|
zones: []string{"domain1.com", "example.com"},
|
||||||
expectedOwner: "_acme-challenge.my.sub",
|
expectedOwner: "_acme-challenge.my.sub",
|
||||||
expectedZone: "domain.com",
|
expectedZone: "example.com",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,6 +202,36 @@ func TestSplitDomain(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSplitDomain_error(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
domain string
|
||||||
|
zones []string
|
||||||
|
expectedOwner string
|
||||||
|
expectedZone string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "no zone",
|
||||||
|
domain: "example.com",
|
||||||
|
zones: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "domain does not contain zone",
|
||||||
|
domain: "example.com",
|
||||||
|
zones: []string{"example.org"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
_, _, err := splitDomain(test.domain, test.zones)
|
||||||
|
require.Error(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLivePresent(t *testing.T) {
|
func TestLivePresent(t *testing.T) {
|
||||||
if !envTest.IsLiveTest() {
|
if !envTest.IsLiveTest() {
|
||||||
t.Skip("skipping live test")
|
t.Skip("skipping live test")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -73,7 +72,7 @@ func TestClient_CreateDNSRecord(t *testing.T) {
|
||||||
TTL: 60,
|
TTL: 60,
|
||||||
}
|
}
|
||||||
|
|
||||||
recordID, err := client.CreateDNSRecord(context.Background(), domain, record)
|
recordID, err := client.CreateDNSRecord(t.Context(), domain, record)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "123", recordID)
|
assert.Equal(t, "123", recordID)
|
||||||
|
|
@ -128,7 +127,7 @@ func TestClient_GetDomainByName(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
domain, err := client.GetDomainByName(context.Background(), "one.two.three.example.com.")
|
domain, err := client.GetDomainByName(t.Context(), "one.two.three.example.com.")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &DNSDomain{ID: 123, CustomerName: "two.three.example.com"}
|
expected := &DNSDomain{ID: 123, CustomerName: "two.three.example.com"}
|
||||||
|
|
@ -156,6 +155,6 @@ func TestClient_DeleteDNSRecord(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err := client.DeleteDNSRecord(context.Background(), 123, "456")
|
err := client.DeleteDNSRecord(t.Context(), 123, "456")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package active24
|
package active24
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
@ -56,7 +55,7 @@ func setupTest(t *testing.T, pattern string, status int, filename string) *Clien
|
||||||
func TestClient_GetServices(t *testing.T) {
|
func TestClient_GetServices(t *testing.T) {
|
||||||
client := setupTest(t, "GET /v1/user/self/service", http.StatusOK, "services.json")
|
client := setupTest(t, "GET /v1/user/self/service", http.StatusOK, "services.json")
|
||||||
|
|
||||||
services, err := client.GetServices(context.Background())
|
services, err := client.GetServices(t.Context())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Service{
|
expected := []Service{
|
||||||
|
|
@ -86,7 +85,7 @@ func TestClient_GetServices(t *testing.T) {
|
||||||
func TestClient_GetServices_errors(t *testing.T) {
|
func TestClient_GetServices_errors(t *testing.T) {
|
||||||
client := setupTest(t, "GET /v1/user/self/service", http.StatusUnauthorized, "error_v1.json")
|
client := setupTest(t, "GET /v1/user/self/service", http.StatusUnauthorized, "error_v1.json")
|
||||||
|
|
||||||
_, err := client.GetServices(context.Background())
|
_, err := client.GetServices(t.Context())
|
||||||
require.EqualError(t, err, "401: No username or password.")
|
require.EqualError(t, err, "401: No username or password.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +98,7 @@ func TestClient_GetRecords(t *testing.T) {
|
||||||
Content: "txt",
|
Content: "txt",
|
||||||
}
|
}
|
||||||
|
|
||||||
records, err := client.GetRecords(context.Background(), "aaa", filter)
|
records, err := client.GetRecords(t.Context(), "aaa", filter)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := []Record{{
|
expected := []Record{{
|
||||||
|
|
@ -124,35 +123,35 @@ func TestClient_GetRecords_errors(t *testing.T) {
|
||||||
Content: "txt",
|
Content: "txt",
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.GetRecords(context.Background(), "aaa", filter)
|
_, err := client.GetRecords(t.Context(), "aaa", filter)
|
||||||
require.EqualError(t, err, "403: /errors/httpException: This action is unauthorized.")
|
require.EqualError(t, err, "403: /errors/httpException: This action is unauthorized.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_CreateRecord(t *testing.T) {
|
func TestClient_CreateRecord(t *testing.T) {
|
||||||
client := setupTest(t, "POST /v2/service/aaa/dns/record", http.StatusNoContent, "")
|
client := setupTest(t, "POST /v2/service/aaa/dns/record", http.StatusNoContent, "")
|
||||||
|
|
||||||
err := client.CreateRecord(context.Background(), "aaa", Record{})
|
err := client.CreateRecord(t.Context(), "aaa", Record{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_CreateRecord_errors(t *testing.T) {
|
func TestClient_CreateRecord_errors(t *testing.T) {
|
||||||
client := setupTest(t, "POST /v2/service/aaa/dns/record", http.StatusForbidden, "error_403.json")
|
client := setupTest(t, "POST /v2/service/aaa/dns/record", http.StatusForbidden, "error_403.json")
|
||||||
|
|
||||||
err := client.CreateRecord(context.Background(), "aaa", Record{})
|
err := client.CreateRecord(t.Context(), "aaa", Record{})
|
||||||
require.EqualError(t, err, "403: /errors/httpException: This action is unauthorized.")
|
require.EqualError(t, err, "403: /errors/httpException: This action is unauthorized.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord(t *testing.T) {
|
func TestClient_DeleteRecord(t *testing.T) {
|
||||||
client := setupTest(t, "DELETE /v2/service/aaa/dns/record/123", http.StatusNoContent, "")
|
client := setupTest(t, "DELETE /v2/service/aaa/dns/record/123", http.StatusNoContent, "")
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "aaa", "123")
|
err := client.DeleteRecord(t.Context(), "aaa", "123")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_DeleteRecord_error(t *testing.T) {
|
func TestClient_DeleteRecord_error(t *testing.T) {
|
||||||
client := setupTest(t, "DELETE /v2/service/aaa/dns/record/123", http.StatusForbidden, "error_403.json")
|
client := setupTest(t, "DELETE /v2/service/aaa/dns/record/123", http.StatusForbidden, "error_403.json")
|
||||||
|
|
||||||
err := client.DeleteRecord(context.Background(), "aaa", "123")
|
err := client.DeleteRecord(t.Context(), "aaa", "123")
|
||||||
require.EqualError(t, err, "403: /errors/httpException: This action is unauthorized.")
|
require.EqualError(t, err, "403: /errors/httpException: This action is unauthorized.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package hostingde
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -72,7 +71,7 @@ func TestClient_ListZoneConfigs(t *testing.T) {
|
||||||
Page: 1,
|
Page: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneResponse, err := client.ListZoneConfigs(context.Background(), zonesFind)
|
zoneResponse, err := client.ListZoneConfigs(t.Context(), zonesFind)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &ZoneResponse{
|
expected := &ZoneResponse{
|
||||||
|
|
@ -124,7 +123,7 @@ func TestClient_ListZoneConfigs_error(t *testing.T) {
|
||||||
Page: 1,
|
Page: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.ListZoneConfigs(context.Background(), zonesFind)
|
_, err := client.ListZoneConfigs(t.Context(), zonesFind)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +178,7 @@ func TestClient_UpdateZone(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := client.UpdateZone(context.Background(), request)
|
response, err := client.UpdateZone(t.Context(), request)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &Zone{
|
expected := &Zone{
|
||||||
|
|
@ -259,6 +258,6 @@ func TestClient_UpdateZone_error(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := client.UpdateZone(context.Background(), request)
|
_, err := client.UpdateZone(t.Context(), request)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package rimuhosting
|
package rimuhosting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
@ -99,7 +98,7 @@ func TestClient_FindTXTRecords(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
records, err := client.FindTXTRecords(context.Background(), test.domain)
|
records, err := client.FindTXTRecords(t.Context(), test.domain)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, test.expected, records)
|
assert.Equal(t, test.expected, records)
|
||||||
|
|
@ -291,7 +290,7 @@ func TestClient_DoActions(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
resp, err := client.DoActions(context.Background(), test.actions...)
|
resp, err := client.DoActions(t.Context(), test.actions...)
|
||||||
if test.expected.Error != "" {
|
if test.expected.Error != "" {
|
||||||
require.EqualError(t, err, test.expected.Error)
|
require.EqualError(t, err, test.expected.Error)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue