]> granicus.if.org Git - pdns/commitdiff
API: move shared DomainInfo reader into it's own function
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Sun, 8 Feb 2015 12:36:24 +0000 (13:36 +0100)
committermind04 <mind04@monshouwer.org>
Thu, 26 Feb 2015 19:39:54 +0000 (20:39 +0100)
And test that listing zones also returns account now.
(cherry picked from commit c04b58702c28006df2b8931d660674ab8b390771)

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

index 7346575392239363fee65a89bd8f35c69c961c8a..5f233dbac1085a9ae31572520bab09e55ae26b4c 100644 (file)
@@ -286,44 +286,47 @@ void AuthWebServer::indexfunction(HttpRequest* req, HttpResponse* resp)
   resp->status = 200;
 }
 
+static void fillZoneInfo(const DomainInfo& di, Value& jdi, Document& doc) {
+  DNSSECKeeper dk;
+  jdi.SetObject();
+  // id is the canonical lookup key, which doesn't actually match the name (in some cases)
+  string zoneId = apiZoneNameToId(di.zone);
+  Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy
+  jdi.AddMember("id", jzoneId, doc.GetAllocator());
+  string url = "/servers/localhost/zones/" + zoneId;
+  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());
+  jdi.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator());
+  jdi.AddMember("account", di.account.c_str(), doc.GetAllocator());
+  Value masters;
+  masters.SetArray();
+  BOOST_FOREACH(const string& master, di.masters) {
+    Value value(master.c_str(), doc.GetAllocator());
+    masters.PushBack(value, doc.GetAllocator());
+  }
+  jdi.AddMember("masters", masters, doc.GetAllocator());
+  jdi.AddMember("serial", di.serial, doc.GetAllocator());
+  jdi.AddMember("notified_serial", di.notified_serial, doc.GetAllocator());
+  jdi.AddMember("last_check", (unsigned int) di.last_check, doc.GetAllocator());
+}
+
 static void fillZone(const string& zonename, HttpResponse* resp) {
   UeberBackend B;
   DomainInfo di;
-  DNSSECKeeper dk;
   if(!B.getDomainInfo(zonename, di))
     throw ApiException("Could not find domain '"+zonename+"'");
 
   Document doc;
-  doc.SetObject();
-
-  // id is the canonical lookup key, which doesn't actually match the name (in some cases)
-  string zoneId = apiZoneNameToId(di.zone);
-  Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy
-  doc.AddMember("id", jzoneId, doc.GetAllocator());
-  string url = "/servers/localhost/zones/" + zoneId;
-  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());
-  doc.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator());
-  doc.AddMember("account", di.account.c_str(), doc.GetAllocator());
+  fillZoneInfo(di, doc, doc);
+  // extra stuff fillZoneInfo doesn't do for us (more expensive)
   string soa_edit_api;
   di.backend->getDomainMetadataOne(zonename, "SOA-EDIT-API", soa_edit_api);
   doc.AddMember("soa_edit_api", soa_edit_api.c_str(), doc.GetAllocator());
   string soa_edit;
   di.backend->getDomainMetadataOne(zonename, "SOA-EDIT", soa_edit);
   doc.AddMember("soa_edit", soa_edit.c_str(), doc.GetAllocator());
-  Value masters;
-  masters.SetArray();
-  BOOST_FOREACH(const string& master, di.masters) {
-    Value value(master.c_str(), doc.GetAllocator());
-    masters.PushBack(value, doc.GetAllocator());
-  }
-  doc.AddMember("masters", masters, doc.GetAllocator());
-  doc.AddMember("serial", di.serial, doc.GetAllocator());
-  doc.AddMember("notified_serial", di.notified_serial, doc.GetAllocator());
-  doc.AddMember("last_check", (unsigned int) di.last_check, doc.GetAllocator());
 
   // fill records
   DNSResourceRecord rr;
@@ -761,27 +764,7 @@ 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)
-    string zoneId = apiZoneNameToId(di.zone);
-    Value jzoneId(zoneId.c_str(), doc.GetAllocator()); // copy
-    jdi.AddMember("id", jzoneId, doc.GetAllocator());
-    string url = "/servers/localhost/zones/" + zoneId;
-    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());
-    jdi.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator());
-    Value masters;
-    masters.SetArray();
-    BOOST_FOREACH(const string& master, di.masters) {
-      Value value(master.c_str(), doc.GetAllocator());
-      masters.PushBack(value, doc.GetAllocator());
-    }
-    jdi.AddMember("masters", masters, doc.GetAllocator());
-    jdi.AddMember("serial", di.serial, doc.GetAllocator());
-    jdi.AddMember("notified_serial", di.notified_serial, doc.GetAllocator());
-    jdi.AddMember("last_check", (unsigned int) di.last_check, doc.GetAllocator());
+    fillZoneInfo(di, jdi, doc);
     doc.PushBack(jdi, doc.GetAllocator());
   }
   resp->setBody(doc);
index a440265c90a4ca416eb7cbaf10dc1b6ffde1d754..a035c875d1972313a8ace2f608c8e40970f788d1 100644 (file)
@@ -15,7 +15,7 @@ class Zones(ApiTestCase):
         example_com = example_com[0]
         required_fields = ['id', 'url', 'name', 'kind']
         if is_auth():
-            required_fields = required_fields + ['masters', 'last_check', 'notified_serial', 'serial']
+            required_fields = required_fields + ['masters', 'last_check', 'notified_serial', 'serial', 'account']
         elif is_recursor():
             required_fields = required_fields + ['recursion_desired', 'servers']
         for field in required_fields: