Skip to content

Commit 5eb8768

Browse files
jotasildez
andauthored
pdns: reconstruct zone URLs to enable non-root folder API endpoints (#2141)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent f89e257 commit 5eb8768

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

providers/dns/pdns/internal/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (c *Client) GetHostedZone(ctx context.Context, authZone string) (*HostedZon
117117
}
118118

119119
func (c *Client) UpdateRecords(ctx context.Context, zone *HostedZone, sets RRSets) error {
120-
endpoint := c.joinPath("/", zone.URL)
120+
endpoint := c.joinPath("/", "servers", c.serverName, "zones", zone.ID)
121121

122122
req, err := newJSONRequest(ctx, http.MethodPatch, endpoint, sets)
123123
if err != nil {
@@ -137,7 +137,7 @@ func (c *Client) Notify(ctx context.Context, zone *HostedZone) error {
137137
return nil
138138
}
139139

140-
endpoint := c.joinPath("/", zone.URL, "/notify")
140+
endpoint := c.joinPath("/", "servers", c.serverName, "zones", zone.ID, "notify")
141141

142142
req, err := newJSONRequest(ctx, http.MethodPut, endpoint, nil)
143143
if err != nil {

providers/dns/pdns/internal/client_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ func TestClient_GetHostedZone_v0(t *testing.T) {
256256
func TestClient_UpdateRecords(t *testing.T) {
257257
client := setupTest(t, http.MethodPatch, "/api/v1/servers/localhost/zones/example.org.", http.StatusOK, "zone.json")
258258
client.apiVersion = 1
259+
client.serverName = "localhost"
259260

260261
zone := &HostedZone{
261262
ID: "example.org.",
@@ -282,9 +283,41 @@ func TestClient_UpdateRecords(t *testing.T) {
282283
require.NoError(t, err)
283284
}
284285

286+
func TestClient_UpdateRecords_NonRootApi(t *testing.T) {
287+
client := setupTest(t, http.MethodPatch, "/some/path/api/v1/servers/localhost/zones/example.org.", http.StatusOK, "zone.json")
288+
client.Host = client.Host.JoinPath("some", "path")
289+
client.apiVersion = 1
290+
client.serverName = "localhost"
291+
292+
zone := &HostedZone{
293+
ID: "example.org.",
294+
Name: "example.org.",
295+
URL: "some/path/api/v1/servers/server/zones/example.org.",
296+
Kind: "Master",
297+
}
298+
299+
rrSets := RRSets{
300+
RRSets: []RRSet{{
301+
Name: "example.org.",
302+
Type: "NS",
303+
ChangeType: "REPLACE",
304+
Records: []Record{{
305+
Content: "192.0.2.5",
306+
Name: "ns1.example.org.",
307+
TTL: 86400,
308+
Type: "A",
309+
}},
310+
}},
311+
}
312+
313+
err := client.UpdateRecords(context.Background(), zone, rrSets)
314+
require.NoError(t, err)
315+
}
316+
285317
func TestClient_UpdateRecords_v0(t *testing.T) {
286318
client := setupTest(t, http.MethodPatch, "/servers/localhost/zones/example.org.", http.StatusOK, "zone.json")
287319
client.apiVersion = 0
320+
client.serverName = "localhost"
288321

289322
zone := &HostedZone{
290323
ID: "example.org.",
@@ -314,6 +347,7 @@ func TestClient_UpdateRecords_v0(t *testing.T) {
314347
func TestClient_Notify(t *testing.T) {
315348
client := setupTest(t, http.MethodPut, "/api/v1/servers/localhost/zones/example.org./notify", http.StatusOK, "")
316349
client.apiVersion = 1
350+
client.serverName = "localhost"
317351

318352
zone := &HostedZone{
319353
ID: "example.org.",
@@ -326,8 +360,26 @@ func TestClient_Notify(t *testing.T) {
326360
require.NoError(t, err)
327361
}
328362

363+
func TestClient_Notify_NonRootApi(t *testing.T) {
364+
client := setupTest(t, http.MethodPut, "/some/path/api/v1/servers/localhost/zones/example.org./notify", http.StatusOK, "")
365+
client.Host = client.Host.JoinPath("some", "path")
366+
client.apiVersion = 1
367+
client.serverName = "localhost"
368+
369+
zone := &HostedZone{
370+
ID: "example.org.",
371+
Name: "example.org.",
372+
URL: "/some/path/api/v1/servers/server/zones/example.org.",
373+
Kind: "Master",
374+
}
375+
376+
err := client.Notify(context.Background(), zone)
377+
require.NoError(t, err)
378+
}
379+
329380
func TestClient_Notify_v0(t *testing.T) {
330381
client := setupTest(t, http.MethodPut, "/api/v1/servers/localhost/zones/example.org./notify", http.StatusOK, "")
382+
client.apiVersion = 0
331383

332384
zone := &HostedZone{
333385
ID: "example.org.",

0 commit comments

Comments
 (0)