From: Christian Hofstaedtler Date: Sun, 8 Feb 2015 12:36:24 +0000 (+0100) Subject: API: move shared DomainInfo reader into it's own function X-Git-Tag: auth-3.4.3~1^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca44706a87f57587d1ccf2f524a0caa7d27c01bc;p=pdns API: move shared DomainInfo reader into it's own function And test that listing zones also returns account now. (cherry picked from commit c04b58702c28006df2b8931d660674ab8b390771) --- diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 734657539..5f233dbac 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -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); diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index a440265c9..a035c875d 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -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: