From e38e32b90621140fd66005e24bbb8a007afcf4e2 Mon Sep 17 00:00:00 2001 From: lubko <715624+lubko@users.noreply.github.com> Date: Wed, 14 Apr 2021 10:13:48 +0200 Subject: [PATCH] wedos: fix api call parameters (#1386) --- providers/dns/wedos/internal/client.go | 29 +++++++++++++-------- providers/dns/wedos/internal/client_test.go | 28 +++++++++----------- providers/dns/wedos/wedos.go | 4 +-- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/providers/dns/wedos/internal/client.go b/providers/dns/wedos/internal/client.go index be18c728..70d486ef 100644 --- a/providers/dns/wedos/internal/client.go +++ b/providers/dns/wedos/internal/client.go @@ -27,21 +27,28 @@ const ( ) type ResponsePayload struct { - Code int `json:"code,omitempty"` - Result string `json:"result,omitempty"` - Timestamp int `json:"timestamp,omitempty"` - SvTRID string `json:"svTRID,omitempty"` - Command string `json:"command,omitempty"` - Data json.RawMessage `json:"data"` - DNSRowsList []DNSRow + Code int `json:"code,omitempty"` + Result string `json:"result,omitempty"` + Timestamp int `json:"timestamp,omitempty"` + SvTRID string `json:"svTRID,omitempty"` + Command string `json:"command,omitempty"` + Data json.RawMessage `json:"data"` } type DNSRow struct { - ID string `json:"ID,omitempty"` + ID string `json:"ID,omitempty"` + Name string `json:"name,omitempty"` + TTL json.Number `json:"ttl,omitempty" type:"integer"` + Type string `json:"rdtype,omitempty"` + Data string `json:"rdata"` +} + +type DNSRowRequest struct { + ID string `json:"row_id,omitempty"` Domain string `json:"domain,omitempty"` Name string `json:"name,omitempty"` TTL json.Number `json:"ttl,omitempty" type:"integer"` - Type string `json:"rdtype,omitempty"` + Type string `json:"type,omitempty"` Data string `json:"rdata"` } @@ -96,7 +103,7 @@ func (c *Client) GetRecords(ctx context.Context, zone string) ([]DNSRow, error) // https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-add-row/ // https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-row-update/ func (c *Client) AddRecord(ctx context.Context, zone string, record DNSRow) error { - payload := DNSRow{ + payload := DNSRowRequest{ Domain: dns01.UnFqdn(zone), TTL: record.TTL, Type: record.Type, @@ -123,7 +130,7 @@ func (c *Client) AddRecord(ctx context.Context, zone string, record DNSRow) erro // If a record does not have an ID, it will be looked up. // https://kb.wedos.com/en/wapi-api-interface/wapi-command-dns-row-delete/ func (c *Client) DeleteRecord(ctx context.Context, zone string, recordID string) error { - payload := DNSRow{ + payload := DNSRowRequest{ Domain: dns01.UnFqdn(zone), ID: recordID, } diff --git a/providers/dns/wedos/internal/client_test.go b/providers/dns/wedos/internal/client_test.go index a56f879c..ac92e1ea 100644 --- a/providers/dns/wedos/internal/client_test.go +++ b/providers/dns/wedos/internal/client_test.go @@ -95,17 +95,16 @@ func TestClient_GetRecords(t *testing.T) { } func TestClient_AddRecord(t *testing.T) { - expectedForm := `{"request":{"user":"user","auth":"xxx","command":"dns-row-add","data":{"domain":"example.com","name":"foo","ttl":1800,"rdtype":"TXT","rdata":"foobar"}}}` + expectedForm := `{"request":{"user":"user","auth":"xxx","command":"dns-row-add","data":{"domain":"example.com","name":"foo","ttl":1800,"type":"TXT","rdata":"foobar"}}}` client := setupNew(t, expectedForm, commandDNSRowAdd) record := DNSRow{ - ID: "", - Domain: "example.com", - Name: "foo", - TTL: "1800", - Type: "TXT", - Data: "foobar", + ID: "", + Name: "foo", + TTL: "1800", + Type: "TXT", + Data: "foobar", } err := client.AddRecord(context.Background(), "example.com.", record) @@ -113,17 +112,16 @@ func TestClient_AddRecord(t *testing.T) { } func TestClient_AddRecord_update(t *testing.T) { - expectedForm := `{"request":{"user":"user","auth":"xxx","command":"dns-row-update","data":{"ID":"1","domain":"example.com","ttl":1800,"rdtype":"TXT","rdata":"foobar"}}}` + expectedForm := `{"request":{"user":"user","auth":"xxx","command":"dns-row-update","data":{"row_id":"1","domain":"example.com","ttl":1800,"type":"TXT","rdata":"foobar"}}}` client := setupNew(t, expectedForm, commandDNSRowUpdate) record := DNSRow{ - ID: "1", - Domain: "example.com", - Name: "foo", - TTL: "1800", - Type: "TXT", - Data: "foobar", + ID: "1", + Name: "foo", + TTL: "1800", + Type: "TXT", + Data: "foobar", } err := client.AddRecord(context.Background(), "example.com.", record) @@ -131,7 +129,7 @@ func TestClient_AddRecord_update(t *testing.T) { } func TestClient_DeleteRecord(t *testing.T) { - expectedForm := `{"request":{"user":"user","auth":"xxx","command":"dns-row-delete","data":{"ID":"1","domain":"example.com","rdata":""}}}` + expectedForm := `{"request":{"user":"user","auth":"xxx","command":"dns-row-delete","data":{"row_id":"1","domain":"example.com","rdata":""}}}` client := setupNew(t, expectedForm, commandDNSRowDelete) diff --git a/providers/dns/wedos/wedos.go b/providers/dns/wedos/wedos.go index b5cff3f5..250a3384 100644 --- a/providers/dns/wedos/wedos.go +++ b/providers/dns/wedos/wedos.go @@ -112,7 +112,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { return fmt.Errorf("wedos: could not determine zone for domain %q: %w", domain, err) } - subDomain := strings.TrimSuffix(fqdn, authZone) + subDomain := dns01.UnFqdn(strings.TrimSuffix(fqdn, authZone)) record := internal.DNSRow{ Name: subDomain, @@ -157,7 +157,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return fmt.Errorf("wedos: could not determine zone for domain %q: %w", domain, err) } - subDomain := strings.TrimSuffix(fqdn, authZone) + subDomain := dns01.UnFqdn(strings.TrimSuffix(fqdn, authZone)) records, err := d.client.GetRecords(ctx, authZone) if err != nil {