Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wedos: fix api call parameters #1386

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions providers/dns/wedos/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
Expand Down
28 changes: 13 additions & 15 deletions providers/dns/wedos/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,43 +95,41 @@ 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)
require.NoError(t, err)
}

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)
require.NoError(t, err)
}

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)

Expand Down
4 changes: 2 additions & 2 deletions providers/dns/wedos/wedos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down