From: Christian Hofstaedtler Date: Tue, 28 Jan 2014 00:03:04 +0000 (+0100) Subject: webserver: add id and url fields to zones X-Git-Tag: rec-3.6.0-rc1~213^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=418aa2463b5a4ea893dd7d1d46bf2f326e5e1bd6;p=thirdparty%2Fpdns.git webserver: add id and url fields to zones 'url': Per the specification. 'id': web-safe lookup key for zones. Not implemented correctly yet, and the specification is lacking a description. --- diff --git a/pdns/ws.cc b/pdns/ws.cc index 65e021a3d9..20855ad704 100644 --- a/pdns/ws.cc +++ b/pdns/ws.cc @@ -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; diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index f18767fb9a..4bc961074b 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -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])