From 05776d2f75b42617a1f71d1b1330c2b5f272ee40 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Tue, 28 Jan 2014 01:03:54 +0100 Subject: [PATCH] webserver: add GET /servers/localhost/zones/ --- pdns/ws.cc | 10 ++++++++++ regression-tests.api/test_Zones.py | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/pdns/ws.cc b/pdns/ws.cc index ef5f088bc..4fb21a53e 100644 --- a/pdns/ws.cc +++ b/pdns/ws.cc @@ -582,6 +582,15 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) { resp->body = makeStringFromDocument(doc); } +static void apiServerZoneDetail(HttpRequest* req, HttpResponse* resp) { + string zonename = req->path_parameters["id"]; + + if(req->method != "GET") + throw HttpMethodNotAllowedException(); + + resp->body = getZone(zonename); +} + void StatWebServer::jsonstat(HttpRequest* req, HttpResponse* resp) { string command; @@ -885,6 +894,7 @@ void StatWebServer::launch() registerApiHandler("/servers/localhost/config", &apiServerConfig); registerApiHandler("/servers/localhost/search-log", &apiServerSearchLog); registerApiHandler("/servers/localhost/zones", &apiServerZones); + registerApiHandler("/servers/localhost/zones/", &apiServerZoneDetail); // legacy dispatch registerApiHandler("/jsonstat", boost::bind(&StatWebServer::jsonstat, this, _1, _2)); } diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index c63a1215d..42e09f57a 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -32,3 +32,14 @@ class Servers(ApiTestCase): self.assertIn(k, data) if k in payload: self.assertEquals(data[k], payload[k]) + + def test_GetZone(self): + r = self.session.get(self.url("/servers/localhost/zones")) + domains = r.json() + example_com = [domain for domain in domains if domain['name'] == u'example.com'][0] + r = self.session.get(self.url("/servers/localhost/zones/" + example_com['id'])) + self.assertSuccessJson(r) + data = r.json() + for k in ('id', 'url', 'name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial'): + self.assertIn(k, data) + self.assertEquals(data['name'], 'example.com') -- 2.40.0