njalla: fix record id unmarshal error (#1686)

This commit is contained in:
Manuel Schmidbauer 2022-08-04 01:06:25 +02:00 committed by GitHub
parent 978eeed867
commit 0aeafc68cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 14 deletions

View file

@ -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{

View file

@ -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",
@ -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",
@ -130,7 +130,7 @@ func TestClient_ListRecords(t *testing.T) {
"result": Records{
Records: []Record{
{
ID: 1,
ID: "1",
Domain: apiReq.Params.Domain,
Content: "test",
Name: "test01",
@ -138,7 +138,7 @@ func TestClient_ListRecords(t *testing.T) {
Type: "TXT",
},
{
ID: 2,
ID: "2",
Domain: apiReq.Params.Domain,
Content: "txtTxt",
Name: "test02",
@ -161,7 +161,7 @@ func TestClient_ListRecords(t *testing.T) {
expected := []Record{
{
ID: 1,
ID: "1",
Domain: "example.com",
Content: "test",
Name: "test01",
@ -169,7 +169,7 @@ func TestClient_ListRecords(t *testing.T) {
Type: "TXT",
},
{
ID: 2,
ID: "2",
Domain: "example.com",
Content: "txtTxt",
Name: "test02",
@ -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
}
@ -217,7 +217,7 @@ 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)
}
@ -225,6 +225,6 @@ 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)
}

View file

@ -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"`

View file

@ -52,7 +52,7 @@ type DNSProvider struct {
config *Config
client *internal.Client
recordIDs map[string]int
recordIDs map[string]string
recordIDsMu sync.Mutex
}
@ -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
}
@ -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