forked from TrueCloudLab/lego
wedos: fix api call parameters (#1386)
This commit is contained in:
parent
9002e5c4ab
commit
e38e32b906
3 changed files with 33 additions and 28 deletions
|
@ -33,18 +33,25 @@ type ResponsePayload struct {
|
|||
SvTRID string `json:"svTRID,omitempty"`
|
||||
Command string `json:"command,omitempty"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
DNSRowsList []DNSRow
|
||||
}
|
||||
|
||||
type DNSRow struct {
|
||||
ID string `json:"ID,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
TTL json.Number `json:"ttl,omitempty" type:"integer"`
|
||||
Type string `json:"rdtype,omitempty"`
|
||||
Data string `json:"rdata"`
|
||||
}
|
||||
|
||||
type 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:"type,omitempty"`
|
||||
Data string `json:"rdata"`
|
||||
}
|
||||
|
||||
type APIRequest struct {
|
||||
User string `json:"user,omitempty"`
|
||||
Auth string `json:"auth,omitempty"`
|
||||
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -95,13 +95,12 @@ 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",
|
||||
|
@ -113,13 +112,12 @@ 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",
|
||||
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue