]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
webserver: add id and url fields to zones
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 28 Jan 2014 00:03:04 +0000 (01:03 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 28 Jan 2014 08:54:32 +0000 (09:54 +0100)
'url': Per the specification.
'id': web-safe lookup key for zones. Not implemented correctly yet,
and the specification is lacking a description.

pdns/ws.cc
regression-tests.api/test_Zones.py

index 65e021a3d927c61b4462aa733cf35ef1d0913418..20855ad704ffbc54e2d2f84512c20c2f895eca43 100644 (file)
@@ -337,7 +337,12 @@ static string getZone(const string& zonename) {
   Document doc;
   doc.SetObject();
 
-  doc.AddMember("name", zonename.c_str(), doc.GetAllocator());
+  // id is the canonical lookup key, which doesn't actually match the name (in some cases)
+  doc.AddMember("id", di.zone.c_str(), doc.GetAllocator());
+  string url = (boost::format("/servers/localhost/zones/%s") % di.zone).str();
+  Value jurl(url.c_str(), doc.GetAllocator()); // copy
+  doc.AddMember("url", jurl, doc.GetAllocator());
+  doc.AddMember("name", di.zone.c_str(), doc.GetAllocator());
   doc.AddMember("type", "Zone", doc.GetAllocator());
   doc.AddMember("kind", di.getKindString(), doc.GetAllocator());
   Value masters;
@@ -558,6 +563,11 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
   BOOST_FOREACH(const DomainInfo& di, domains) {
     Value jdi;
     jdi.SetObject();
+    // id is the canonical lookup key, which doesn't actually match the name (in some cases)
+    jdi.AddMember("id", di.zone.c_str(), doc.GetAllocator());
+    string url = (boost::format("/servers/localhost/zones/%s") % di.zone).str();
+    Value jurl(url.c_str(), doc.GetAllocator()); // copy
+    jdi.AddMember("url", jurl, doc.GetAllocator());
     jdi.AddMember("name", di.zone.c_str(), doc.GetAllocator());
     jdi.AddMember("kind", di.getKindString(), doc.GetAllocator());
     Value masters;
index f18767fb9ab86e852a5bb38c1d70ffe89958e7a5..4bc961074b09aa114daf4959e6c3ff0e8b9a7da8 100644 (file)
@@ -15,7 +15,7 @@ class Servers(ApiTestCase):
         example_com = [domain for domain in domains if domain['name'] == u'example.com']
         self.assertEquals(len(example_com), 1)
         example_com = example_com[0]
-        for k in ('name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial'):
+        for k in ('id', 'url', 'name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial'):
             self.assertIn(k, example_com)
 
     def test_CreateZone(self):
@@ -30,7 +30,7 @@ class Servers(ApiTestCase):
             headers={'content-type': 'application/json'})
         self.assertSuccessJson(r)
         data = r.json()
-        for k in ('name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial'):
+        for k in ('id', 'url', 'name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial'):
             self.assertIn(k, data)
             if k in payload:
                 self.assertEquals(data[k], payload[k])