Skip to content

Commit

Permalink
API: move shared DomainInfo reader into it's own function
Browse files Browse the repository at this point in the history
And test that listing zones also returns account now.
(cherry picked from commit c04b587)
  • Loading branch information
zeha authored and mind04 committed Feb 26, 2015
1 parent 102602f commit ca44706
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 47 deletions.
75 changes: 29 additions & 46 deletions pdns/ws-auth.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion regression-tests.api/test_Zones.py
Expand Up @@ -15,7 +15,7 @@ def test_list_zones(self):
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:
Expand Down

0 comments on commit ca44706

Please sign in to comment.