Fix Dynu DNS record updates to use POST endpoint

This commit is contained in:
beatz174-bit
2026-04-29 13:46:17 +10:00
parent 99fcdef286
commit 821dc055c1
5 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -216,7 +216,7 @@ func (c *Client) CreateDNSRecord(ctx context.Context, domainID int64, req Create
func (c *Client) UpdateDNSRecord(ctx context.Context, domainID int64, recordID int64, req UpdateDNSRecordRequest) (*DNSRecord, error) { func (c *Client) UpdateDNSRecord(ctx context.Context, domainID int64, recordID int64, req UpdateDNSRecordRequest) (*DNSRecord, error) {
var resp getDNSRecordResponse var resp getDNSRecordResponse
if err := c.doRequest(ctx, http.MethodPut, fmt.Sprintf("/dns/%d/record/%d", domainID, recordID), buildDNSRecordUpsertPayload(req.RecordType, req.NodeName, req.Content, req.TTL, req.State, req.Group, req.Host), &resp); err != nil { if err := c.doRequest(ctx, http.MethodPost, fmt.Sprintf("/dns/%d/record/%d", domainID, recordID), buildDNSRecordUpsertPayload(req.RecordType, req.NodeName, req.Content, req.TTL, req.State, req.Group, req.Host), &resp); err != nil {
return nil, err return nil, err
} }
normalizeDNSRecord(&resp.DNSRecord) normalizeDNSRecord(&resp.DNSRecord)
+1 -1
View File
@@ -200,7 +200,7 @@ func TestClientCreateDNSRecordSendsIPv4AddressForARecord(t *testing.T) {
func TestClientUpdateDNSRecordSendsIPv6AddressForAAAARecord(t *testing.T) { func TestClientUpdateDNSRecordSendsIPv6AddressForAAAARecord(t *testing.T) {
var captured map[string]any var captured map[string]any
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPut || r.URL.Path != "/dns/1001/record/2002" { if r.Method != http.MethodPost || r.URL.Path != "/dns/1001/record/2002" {
t.Fatalf("unexpected request %s %s", r.Method, r.URL.Path) t.Fatalf("unexpected request %s %s", r.Method, r.URL.Path)
} }
if err := json.NewDecoder(r.Body).Decode(&captured); err != nil { if err := json.NewDecoder(r.Body).Decode(&captured); err != nil {
@@ -195,7 +195,7 @@ func TestIntegrationResourceDNSRecordDynamicAStateStableAndTransitionToStatic(t
} }
updatePlan := state updatePlan := state
updatePlan.Content = types.StringValue("192.0.2.42") updatePlan.Content = types.StringValue("1.1.1.1")
updatePlan.Dynamic = types.BoolValue(false) updatePlan.Dynamic = types.BoolValue(false)
plan = tfsdk.Plan{Schema: schemaResp.Schema} plan = tfsdk.Plan{Schema: schemaResp.Schema}
@@ -214,7 +214,7 @@ func TestIntegrationResourceDNSRecordDynamicAStateStableAndTransitionToStatic(t
if state.Dynamic.ValueBool() { if state.Dynamic.ValueBool() {
t.Fatalf("expected static A after setting content") t.Fatalf("expected static A after setting content")
} }
if state.Content.ValueString() != "192.0.2.42" { if state.Content.ValueString() != "1.1.1.1" {
t.Fatalf("expected static content after update, got %q", state.Content.ValueString()) t.Fatalf("expected static content after update, got %q", state.Content.ValueString())
} }
} }
@@ -26,8 +26,8 @@ func TestParseDNSRecordIDInvalid(t *testing.T) {
} }
func TestValidateDNSRecordContentForType(t *testing.T) { func TestValidateDNSRecordContentForType(t *testing.T) {
ipv4 := "192.0.2.123" ipv4 := "8.8.8.8"
ipv6 := "2001:db8::123" ipv6 := "2606:4700:4700::1111"
nonEmpty := "hello" nonEmpty := "hello"
blank := "" blank := ""
@@ -75,7 +75,7 @@ func TestResolveDynamicIntent(t *testing.T) {
} }
diags = diag.Diagnostics{} diags = diag.Diagnostics{}
dynamic, ok = resolveDynamicIntent("A", types.StringValue("192.0.2.10"), types.BoolNull(), &diags) dynamic, ok = resolveDynamicIntent("A", types.StringValue("8.8.4.4"), types.BoolNull(), &diags)
if !ok || dynamic || diags.HasError() { if !ok || dynamic || diags.HasError() {
t.Fatalf("expected static A content to resolve to dynamic=false, got dynamic=%v ok=%v diags=%v", dynamic, ok, diags) t.Fatalf("expected static A content to resolve to dynamic=false, got dynamic=%v ok=%v diags=%v", dynamic, ok, diags)
} }
+1 -1
View File
@@ -241,7 +241,7 @@ func (s *Server) serveRecordRoutes(w http.ResponseWriter, r *http.Request, segme
case http.MethodGet: case http.MethodGet:
s.handleGetRecord(w, domainID, recordID) s.handleGetRecord(w, domainID, recordID)
return return
case http.MethodPut: case http.MethodPut, http.MethodPost:
s.handleUpdateRecord(w, r, domainID, recordID) s.handleUpdateRecord(w, r, domainID, recordID)
return return
case http.MethodDelete: case http.MethodDelete: