]> granicus.if.org Git - pdns/commitdiff
webserver: add GET /servers/localhost/zones/<id>
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 28 Jan 2014 00:03:54 +0000 (01:03 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 28 Jan 2014 08:55:25 +0000 (09:55 +0100)
pdns/ws.cc
regression-tests.api/test_Zones.py

index ef5f088bc553953f5dc410c9ac7f61361f3594af..4fb21a53e5fdda4e0272d557677b0ec43dd7098d 100644 (file)
@@ -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/<id>", &apiServerZoneDetail);
       // legacy dispatch
       registerApiHandler("/jsonstat", boost::bind(&StatWebServer::jsonstat, this, _1, _2));
     }
index c63a1215d6f8975b25bb453e2841befa72a89492..42e09f57afdcb40b8f1263b79ecf81a018535bda 100644 (file)
@@ -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')