]> granicus.if.org Git - pdns/commitdiff
Implement the /cryptokeys[/key-id] url in the JSON API.
authorMark Schouten <mark@tuxis.nl>
Wed, 28 May 2014 08:45:33 +0000 (10:45 +0200)
committerMark Schouten <mark@tuxis.nl>
Wed, 28 May 2014 08:45:33 +0000 (10:45 +0200)
When querying /servers/localhost/zones/<zonename>/cryptokeys, you get all the available cryptokeys and dses asociated with them.

When querying /servers/localhost/zones/<zonename>/cryptokeys/<id>, you get just that cryptokey, its dses and the content of the key.

pdns/ws-auth.cc

index 88cd26100233fec5e8af472be7871ca3ace7fe22..5e10c8fffd8183ac2543ce22c01260b3d970fa8b 100644 (file)
@@ -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<int>(req->path_parameters["key_id"]);
+      int curid = lexical_cast<int>(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());
     }