(&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),
}
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<()>;
static void apiServerOTConditionDetailGET(HttpRequest* req, HttpResponse* resp)
{
try {
- Netmask netmask{req->parameters["id"]};
+ Netmask netmask{req->parameters["acl"]};
fillOTCondition(netmask, resp);
}
catch (NetmaskException& ex) {
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);
}
}
-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);
}
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;
WRAPPER(apiServerOTConditionsGET)
WRAPPER(apiServerOTConditionDetailGET)
WRAPPER(apiServerOTConditionDetailDELETE)
-WRAPPER(apiServerOTConditionDetailPUT)
+WRAPPER(apiServerOTConditionDetailPOST)
WRAPPER(prometheusMetrics)
WRAPPER(serveStuff)