From d7db5eb2d1bf7fb9d6bb70e1e31c3aaa8aa132e2 Mon Sep 17 00:00:00 2001 From: travisladuke Date: Mon, 29 Jan 2024 09:23:34 -0800 Subject: [PATCH] Add `name` field to embedded controller networks --- controller/EmbeddedNetworkController.cpp | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index a01b68a9d6..6b5df02374 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -872,6 +872,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane( std::string networkPath = "/controller/network/([0-9a-fA-F]{16})"; std::string oldAndBustedNetworkCreatePath = "/controller/network/([0-9a-fA-F]{10})______"; std::string memberListPath = "/controller/network/([0-9a-fA-F]{16})/member"; + std::string memberListPath2 = "/controller/network/([0-9a-fA-F]{16})/member2"; std::string memberPath = "/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})"; auto controllerGet = [&, setContent](const httplib::Request &req, httplib::Response &res) { @@ -1035,6 +1036,38 @@ void EmbeddedNetworkController::configureHTTPControlPlane( s.Get(memberListPath, memberListGet); sv6.Get(memberListPath, memberListGet); + auto memberListGet2 = [&, setContent](const httplib::Request &req, httplib::Response &res) { + auto networkID = req.matches[1]; + uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str()); + json network; + if (!_db.get(nwid, network)) { + res.status = 404; + return; + } + + json out = json::object(); + auto out2 = nlohmann::json::array(); + std::vector memTmp; + if (_db.get(nwid, network, memTmp)) { + for (auto m = memTmp.begin(); m != memTmp.end(); ++m) { + std::string id = OSUtils::jsonString((*m)["id"], ""); + std::string name = OSUtils::jsonString((*m)["name"], ""); + bool authorized = OSUtils::jsonBool((*m)["authorized"], false); + + if (id.length() == 10) { + out["id"] = id; + out["authorized"] = authorized; + out["name"] = name; + out2.push_back(out); + } + } + } + + setContent(req, res, out2.dump()); + }; + s.Get(memberListPath2, memberListGet2); + sv6.Get(memberListPath2, memberListGet2); + auto memberGet = [&, setContent](const httplib::Request &req, httplib::Response &res) { auto networkID = req.matches[1]; auto memberID = req.matches[2]; @@ -1068,6 +1101,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane( if (b.count("noAutoAssignIps")) member["noAutoAssignIps"] = OSUtils::jsonBool(b["noAutoAssignIps"], false); if (b.count("authenticationExpiryTime")) member["authenticationExpiryTime"] = (uint64_t)OSUtils::jsonInt(b["authenticationExpiryTime"], 0ULL); if (b.count("authenticationURL")) member["authenticationURL"] = OSUtils::jsonString(b["authenticationURL"], ""); + if (b.count("name")) member["name"] = OSUtils::jsonString(b["name"], ""); if (b.count("remoteTraceTarget")) { const std::string rtt(OSUtils::jsonString(b["remoteTraceTarget"],""));