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. // RemoveRecord removes a record.
func (c *Client) RemoveRecord(id int, domain string) error { func (c *Client) RemoveRecord(id string, domain string) error {
data := APIRequest{ data := APIRequest{
Method: "remove-record", Method: "remove-record",
Params: Record{ Params: Record{

View file

@ -56,7 +56,7 @@ func TestClient_AddRecord(t *testing.T) {
return return
} }
apiReq.Params.ID = 123 apiReq.Params.ID = "123"
resp := map[string]interface{}{ resp := map[string]interface{}{
"jsonrpc": "2.0", "jsonrpc": "2.0",
@ -83,7 +83,7 @@ func TestClient_AddRecord(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
expected := &Record{ expected := &Record{
ID: 123, ID: "123",
Content: "foobar", Content: "foobar",
Domain: "test", Domain: "test",
Name: "example.com", Name: "example.com",
@ -130,7 +130,7 @@ func TestClient_ListRecords(t *testing.T) {
"result": Records{ "result": Records{
Records: []Record{ Records: []Record{
{ {
ID: 1, ID: "1",
Domain: apiReq.Params.Domain, Domain: apiReq.Params.Domain,
Content: "test", Content: "test",
Name: "test01", Name: "test01",
@ -138,7 +138,7 @@ func TestClient_ListRecords(t *testing.T) {
Type: "TXT", Type: "TXT",
}, },
{ {
ID: 2, ID: "2",
Domain: apiReq.Params.Domain, Domain: apiReq.Params.Domain,
Content: "txtTxt", Content: "txtTxt",
Name: "test02", Name: "test02",
@ -161,7 +161,7 @@ func TestClient_ListRecords(t *testing.T) {
expected := []Record{ expected := []Record{
{ {
ID: 1, ID: "1",
Domain: "example.com", Domain: "example.com",
Content: "test", Content: "test",
Name: "test01", Name: "test01",
@ -169,7 +169,7 @@ func TestClient_ListRecords(t *testing.T) {
Type: "TXT", Type: "TXT",
}, },
{ {
ID: 2, ID: "2",
Domain: "example.com", Domain: "example.com",
Content: "txtTxt", Content: "txtTxt",
Name: "test02", Name: "test02",
@ -204,7 +204,7 @@ func TestClient_RemoveRecord(t *testing.T) {
return return
} }
if apiReq.Params.ID == 0 { if apiReq.Params.ID == "" {
_, _ = rw.Write([]byte(`{"jsonrpc":"2.0", "Error": {"code": 400, "message": ""missing ID"}}`)) _, _ = rw.Write([]byte(`{"jsonrpc":"2.0", "Error": {"code": 400, "message": ""missing ID"}}`))
return return
} }
@ -217,7 +217,7 @@ func TestClient_RemoveRecord(t *testing.T) {
_, _ = rw.Write([]byte(`{"jsonrpc":"2.0"}`)) _, _ = rw.Write([]byte(`{"jsonrpc":"2.0"}`))
}) })
err := client.RemoveRecord(123, "example.com") err := client.RemoveRecord("123", "example.com")
require.NoError(t, err) require.NoError(t, err)
} }
@ -225,6 +225,6 @@ func TestClient_RemoveRecord_error(t *testing.T) {
client := setup(t, nil) client := setup(t, nil)
client.token = "invalid" client.token = "invalid"
err := client.RemoveRecord(123, "example.com") err := client.RemoveRecord("123", "example.com")
require.Error(t, err) require.Error(t, err)
} }

View file

@ -31,7 +31,7 @@ func (a APIError) Error() string {
// Record is a DNS record. // Record is a DNS record.
type Record struct { type Record struct {
ID int `json:"id,omitempty"` ID string `json:"id,omitempty"`
Content string `json:"content,omitempty"` Content string `json:"content,omitempty"`
Domain string `json:"domain,omitempty"` Domain string `json:"domain,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`

View file

@ -52,7 +52,7 @@ type DNSProvider struct {
config *Config config *Config
client *internal.Client client *internal.Client
recordIDs map[string]int recordIDs map[string]string
recordIDsMu sync.Mutex recordIDsMu sync.Mutex
} }
@ -89,7 +89,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
return &DNSProvider{ return &DNSProvider{
config: config, config: config,
client: client, client: client,
recordIDs: make(map[string]int), recordIDs: make(map[string]string),
}, nil }, nil
} }
@ -147,7 +147,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
err = d.client.RemoveRecord(recordID, dns01.UnFqdn(rootDomain)) err = d.client.RemoveRecord(recordID, dns01.UnFqdn(rootDomain))
if err != nil { 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 // deletes record ID from map