From: Mark Schouten Date: Wed, 28 May 2014 08:45:33 +0000 (+0200) Subject: Implement the /cryptokeys[/key-id] url in the JSON API. X-Git-Tag: rec-3.6.0~10^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=38809e972716609676f5e2bbae68064617c91178;p=thirdparty%2Fpdns.git Implement the /cryptokeys[/key-id] url in the JSON API. When querying /servers/localhost/zones//cryptokeys, you get all the available cryptokeys and dses asociated with them. When querying /servers/localhost/zones//cryptokeys/, you get just that cryptokey, its dses and the content of the key. --- diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 88cd261002..5e10c8fffd 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -499,42 +499,45 @@ static void apiZoneCryptokeys(HttpRequest* req, HttpResponse* resp) { doc.SetArray(); BOOST_FOREACH(DNSSECKeeper::keyset_t::value_type value, keyset) { + if (req->path_parameters.count("key_id")) { + int keyid = lexical_cast(req->path_parameters["key_id"]); + int curid = lexical_cast(value.second.id); + if (keyid != curid) + continue; + } Value key; key.SetObject(); key.AddMember("type", "Cryptokey", doc.GetAllocator()); key.AddMember("id", value.second.id, doc.GetAllocator()); key.AddMember("active", value.second.active, doc.GetAllocator()); key.AddMember("keytype", (value.second.keyOrZone ? "ksk" : "zsk"), doc.GetAllocator()); - Value content(value.first.getDNSKEY().getZoneRepresentation().c_str(), doc.GetAllocator()); - key.AddMember("content", content, doc.GetAllocator()); + if (req->path_parameters.count("key_id")) { + Value content(value.first.getDNSKEY().getZoneRepresentation().c_str(), doc.GetAllocator()); + key.AddMember("content", content, doc.GetAllocator()); + } if (value.second.keyOrZone) { Value dses; dses.SetArray(); - Value ds; - ds.SetString(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 1).getZoneRepresentation().c_str()); + Value ds(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 1).getZoneRepresentation().c_str(), doc.GetAllocator()); dses.PushBack(ds, doc.GetAllocator()); - Value ds2; - ds2.SetString(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 2).getZoneRepresentation().c_str()); + Value ds2(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 2).getZoneRepresentation().c_str(), doc.GetAllocator()); dses.PushBack(ds2, doc.GetAllocator()); try { - Value ds3; - ds3.SetString(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 3).getZoneRepresentation().c_str()); - dses.PushBack(ds3, doc.GetAllocator()); + Value ds3(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 3).getZoneRepresentation().c_str(), doc.GetAllocator()); + dses.PushBack(ds3, doc.GetAllocator()); } catch(...) { } try { - Value ds4; - ds4.SetString(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 4).getZoneRepresentation().c_str()); - dses.PushBack(ds4, doc.GetAllocator()); + Value ds4(makeDSFromDNSKey(zonename, value.first.getDNSKEY(), 4).getZoneRepresentation().c_str(), doc.GetAllocator()); + dses.PushBack(ds4, doc.GetAllocator()); } catch(...) { } - key.AddMember("ds", dses, doc.GetAllocator()); }