Skip to content

Commit

Permalink
njalla: fix record id unmarshal error (#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel2258 committed Aug 3, 2022
1 parent 978eeed commit 0aeafc6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion providers/dns/njalla/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Client) AddRecord(record Record) (*Record, error) {
}

// RemoveRecord removes a record.
func (c *Client) RemoveRecord(id int, domain string) error {
func (c *Client) RemoveRecord(id string, domain string) error {
data := APIRequest{
Method: "remove-record",
Params: Record{
Expand Down
18 changes: 9 additions & 9 deletions providers/dns/njalla/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestClient_AddRecord(t *testing.T) {
return
}

apiReq.Params.ID = 123
apiReq.Params.ID = "123"

resp := map[string]interface{}{
"jsonrpc": "2.0",
Expand All @@ -83,7 +83,7 @@ func TestClient_AddRecord(t *testing.T) {
require.NoError(t, err)

expected := &Record{
ID: 123,
ID: "123",
Content: "foobar",
Domain: "test",
Name: "example.com",
Expand Down Expand Up @@ -130,15 +130,15 @@ func TestClient_ListRecords(t *testing.T) {
"result": Records{
Records: []Record{
{
ID: 1,
ID: "1",
Domain: apiReq.Params.Domain,
Content: "test",
Name: "test01",
TTL: 300,
Type: "TXT",
},
{
ID: 2,
ID: "2",
Domain: apiReq.Params.Domain,
Content: "txtTxt",
Name: "test02",
Expand All @@ -161,15 +161,15 @@ func TestClient_ListRecords(t *testing.T) {

expected := []Record{
{
ID: 1,
ID: "1",
Domain: "example.com",
Content: "test",
Name: "test01",
TTL: 300,
Type: "TXT",
},
{
ID: 2,
ID: "2",
Domain: "example.com",
Content: "txtTxt",
Name: "test02",
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestClient_RemoveRecord(t *testing.T) {
return
}

if apiReq.Params.ID == 0 {
if apiReq.Params.ID == "" {
_, _ = rw.Write([]byte(`{"jsonrpc":"2.0", "Error": {"code": 400, "message": ""missing ID"}}`))
return
}
Expand All @@ -217,14 +217,14 @@ func TestClient_RemoveRecord(t *testing.T) {
_, _ = rw.Write([]byte(`{"jsonrpc":"2.0"}`))
})

err := client.RemoveRecord(123, "example.com")
err := client.RemoveRecord("123", "example.com")
require.NoError(t, err)
}

func TestClient_RemoveRecord_error(t *testing.T) {
client := setup(t, nil)
client.token = "invalid"

err := client.RemoveRecord(123, "example.com")
err := client.RemoveRecord("123", "example.com")
require.Error(t, err)
}
2 changes: 1 addition & 1 deletion providers/dns/njalla/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (a APIError) Error() string {

// Record is a DNS record.
type Record struct {
ID int `json:"id,omitempty"`
ID string `json:"id,omitempty"`
Content string `json:"content,omitempty"`
Domain string `json:"domain,omitempty"`
Name string `json:"name,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions providers/dns/njalla/njalla.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type DNSProvider struct {
config *Config
client *internal.Client

recordIDs map[string]int
recordIDs map[string]string
recordIDsMu sync.Mutex
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
return &DNSProvider{
config: config,
client: client,
recordIDs: make(map[string]int),
recordIDs: make(map[string]string),
}, nil
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {

err = d.client.RemoveRecord(recordID, dns01.UnFqdn(rootDomain))
if err != nil {
return fmt.Errorf("njalla: failed to delete TXT records: fqdn=%s, recordID=%d: %w", fqdn, recordID, err)
return fmt.Errorf("njalla: failed to delete TXT records: fqdn=%s, recordID=%s: %w", fqdn, recordID, err)
}

// deletes record ID from map
Expand Down

0 comments on commit 0aeafc6

Please sign in to comment.