]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Cleanup things a bit, use POST for new OT conditions
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 14 Jan 2026 14:23:42 +0000 (15:23 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 14 Jan 2026 14:23:42 +0000 (15:23 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/rec-rust-lib/rust/src/bridge.hh
pdns/recursordist/rec-rust-lib/rust/src/web.rs
pdns/recursordist/rec-web-stubs.hh
pdns/recursordist/ws-recursor.cc

index 7cfcb1d0d27f3a1951929481f4d685f998edd4b1..4c71ae3021afe21e67ab1e9f56a99a18bd7f0317 100644 (file)
@@ -101,5 +101,5 @@ void apiServerZoneDetailDELETE(const Request& rustRequest, Response& rustRespons
 void apiServerOTConditionsGET(const Request& rustRequest, Response& rustResponse);
 void apiServerOTConditionDetailGET(const Request& rustRequest, Response& rustResponse);
 void apiServerOTConditionDetailDELETE(const Request& rustRequest, Response& rustResponse);
-void apiServerOTConditionDetailPUT(const Request& rustRequest, Response& rustResponse);
+void apiServerOTConditionDetailPOST(const Request& rustRequest, Response& rustResponse);
 }
index 782846c6a8abab3c13cf182e608c588118dbe227..500d0ad2a2c700dde455bc1a721f5e78adf0341c 100644 (file)
@@ -402,38 +402,30 @@ fn matcher(
         (&Method::GET, ["api", "v1", "servers", "localhost", "otconditions"]) => {
             *apifunc = Some(rustweb::apiServerOTConditionsGET);
         }
-        (&Method::GET, ["api", "v1", "servers", "localhost", "otconditions", id]) => {
-            let decoded = form_urlencoded::parse(id.as_bytes());
+        (&Method::GET, ["api", "v1", "servers", "localhost", "otconditions", acl]) => {
+            let decoded = form_urlencoded::parse(acl.as_bytes());
             // decoded should contain a single key without value
             if let Some(kv) = decoded.last() {
                 request.parameters.push(rustweb::KeyValue {
-                    key: String::from("id"),
+                    key: String::from("acl"),
                     value: kv.0.to_string(),
                 });
             }
             *apifunc = Some(rustweb::apiServerOTConditionDetailGET)
         }
-        (&Method::DELETE, ["api", "v1", "servers", "localhost", "otconditions", id]) => {
-            let decoded = form_urlencoded::parse(id.as_bytes());
+        (&Method::DELETE, ["api", "v1", "servers", "localhost", "otconditions", acl]) => {
+            let decoded = form_urlencoded::parse(acl.as_bytes());
             // decoded should contain a single key without value
             if let Some(kv) = decoded.last() {
                 request.parameters.push(rustweb::KeyValue {
-                    key: String::from("id"),
+                    key: String::from("acl"),
                     value: kv.0.to_string(),
                 });
             }
             *apifunc = Some(rustweb::apiServerOTConditionDetailDELETE)
         }
-        (&Method::PUT, ["api", "v1", "servers", "localhost", "otconditions", id]) => {
-            let decoded = form_urlencoded::parse(id.as_bytes());
-            // decoded should contain a single key without value
-            if let Some(kv) = decoded.last() {
-                request.parameters.push(rustweb::KeyValue {
-                    key: String::from("id"),
-                    value: kv.0.to_string(),
-                });
-            }
-            *apifunc = Some(rustweb::apiServerOTConditionDetailPUT)
+        (&Method::POST, ["api", "v1", "servers", "localhost", "otconditions"]) => {
+            *apifunc = Some(rustweb::apiServerOTConditionDetailPOST)
         }
         _ => *filefunc = Some(file),
     }
@@ -1185,7 +1177,7 @@ mod rustweb {
         fn apiServerOTConditionsGET(request: &Request, response: &mut Response) -> Result<()>;
         fn apiServerOTConditionDetailGET(request: &Request, response: &mut Response) -> Result<()>;
         fn apiServerOTConditionDetailDELETE(request: &Request, response: &mut Response) -> Result<()>;
-        fn apiServerOTConditionDetailPUT(request: &Request, response: &mut Response) -> Result<()>;
+        fn apiServerOTConditionDetailPOST(request: &Request, response: &mut Response) -> Result<()>;
         fn jsonstat(request: &Request, response: &mut Response) -> Result<()>;
         fn prometheusMetrics(request: &Request, response: &mut Response) -> Result<()>;
         fn serveStuff(request: &Request, response: &mut Response) -> Result<()>;
index 335b04b8ecbdaebc08f685c079d906be097c49d3..fd2f0935424c5bf358a0a38ac1d055cd64e08693 100644 (file)
@@ -29,7 +29,7 @@ WRAPPER(apiServerZonesPOST)
 WRAPPER(apiServerOTConditionsGET)
 WRAPPER(apiServerOTConditionDetailGET)
 WRAPPER(apiServerOTConditionDetailDELETE)
-WRAPPER(apiServerOTConditionDetailPUT)
+WRAPPER(apiServerOTConditionDetailPOST)
 WRAPPER(jsonstat)
 WRAPPER(prometheusMetrics)
 WRAPPER(serveStuff)
index b6d799335a19447e1999bff4b4ce1c60cdb0364d..b640bac64ebe79914779dc0fc4975408426be900 100644 (file)
@@ -617,7 +617,7 @@ static void fillOTCondition(const Netmask& netmask, HttpResponse* resp)
 static void apiServerOTConditionDetailGET(HttpRequest* req, HttpResponse* resp)
 {
   try {
-    Netmask netmask{req->parameters["id"]};
+    Netmask netmask{req->parameters["acl"]};
     fillOTCondition(netmask, resp);
   }
   catch (NetmaskException& ex) {
@@ -628,7 +628,7 @@ static void apiServerOTConditionDetailGET(HttpRequest* req, HttpResponse* resp)
 static void apiServerOTConditionDetailDELETE(HttpRequest* req, HttpResponse* resp)
 {
   try {
-    Netmask netmask{req->parameters["id"]};
+    Netmask netmask{req->parameters["acl"]};
     auto lock = g_initialOpenTelemetryConditions.lock();
     if (*lock) {
       auto condition = (*lock)->lookup(netmask);
@@ -648,13 +648,17 @@ static void apiServerOTConditionDetailDELETE(HttpRequest* req, HttpResponse* res
   }
 }
 
-static void apiServerOTConditionDetailPUT(HttpRequest* req, HttpResponse* resp)
+static void apiServerOTConditionDetailPOST(HttpRequest* req, HttpResponse* resp)
 {
   Netmask netmask;
   try {
     Json document = req->json();
-    netmask = Netmask{req->parameters["id"]};
-
+    if (auto acl = document["acl"]; acl != Json()) {
+      netmask = Netmask{acl.string_value()};
+    }
+    else {
+      throw ApiException("Required parameter acl missing");
+    }
     auto lock = g_initialOpenTelemetryConditions.lock();
     if (*lock) {
       auto conditionPtr = (*lock)->lookup(netmask);
@@ -663,29 +667,27 @@ static void apiServerOTConditionDetailPUT(HttpRequest* req, HttpResponse* resp)
       }
 
       OpenTelemetryTraceCondition condition;
-      if (auto traceid_only = document["traceid_only"]; traceid_only != Json()) {
+      if (auto traceid_only = document["traceid_only"]; traceid_only.is_bool()) {
         condition.d_traceid_only = traceid_only.bool_value();
       }
-      if (auto edns = document["edns_option_required"]; edns != Json()) {
+      if (auto edns = document["edns_option_required"]; edns.is_bool()) {
         condition.d_edns_option_required = edns.bool_value();
       }
-      auto qnames = document["qnames"].array_items();
-      if (!qnames.empty()) {
+      if (auto qnames = document["qnames"]; qnames.is_array() && !qnames.array_items().empty()) {
         condition.d_qnames = SuffixMatchNode();
-        for (const auto& qname : qnames) {
+        for (const auto& qname : qnames.array_items()) {
           condition.d_qnames->add(DNSName(qname.string_value()));
         }
       }
-      auto qtypes = document["qtypes"].array_items();
-      if (!qtypes.empty()) {
+      if (auto qtypes = document["qtypes"]; qtypes.is_array() && !qtypes.array_items().empty()) {
         condition.d_qtypes = std::unordered_set<QType>();
-        for (const auto& qtype : qtypes) {
+        for (const auto& qtype : qtypes.array_items()) {
           if (auto qcode = QType::chartocode(qtype.string_value().c_str()); qcode > 0) {
             condition.d_qtypes->insert(qcode);
           }
         }
       }
-      if (auto qid = document["qid"]; qid != Json()) {
+      if (auto qid = document["qid"]; qid.is_number()) {
         condition.d_qid = qid.int_value();
       }
       (*lock)->insert(netmask).second = condition;
@@ -1275,7 +1277,7 @@ WRAPPER(apiServerZonesPOST)
 WRAPPER(apiServerOTConditionsGET)
 WRAPPER(apiServerOTConditionDetailGET)
 WRAPPER(apiServerOTConditionDetailDELETE)
-WRAPPER(apiServerOTConditionDetailPUT)
+WRAPPER(apiServerOTConditionDetailPOST)
 WRAPPER(prometheusMetrics)
 WRAPPER(serveStuff)