mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-31 00:23:58 +00:00
Create an alternate members list endpoint
The current api at /controller/network/1111111111767f2f/member Lists only the members' ID and revision number. If you want details, you have to query each specific member. So if you want to make a members list, and you have 10000 members on a network, you need to make 10000 http requests. It's also in a hard to specify and use shape { [member-id-1]: 13, [member-id-2]: 14, ... } GET http://localhost:9993/unstable/controller/network/1111111111767f2f/member -> ``` { data: [ {...member1}, {...member2}, ...], meta: { totalCount: 4, authorizedCount: 3 } } ```
This commit is contained in:
parent
06399c86f6
commit
0b83f850e4
@ -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 = "/unstable/controller/network/([0-9a-fA-F]{16})/member";
|
||||
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,41 @@ 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;
|
||||
}
|
||||
|
||||
auto out = nlohmann::json::object();
|
||||
auto meta = nlohmann::json::object();
|
||||
auto members = nlohmann::json::array();
|
||||
std::vector<json> memTmp;
|
||||
if (_db.get(nwid, network, memTmp)) {
|
||||
members.push_back(memTmp);
|
||||
}
|
||||
|
||||
uint64_t authorizedCount = 0;
|
||||
uint64_t totalCount = memTmp.size();
|
||||
for (auto m = memTmp.begin(); m != memTmp.end(); ++m) {
|
||||
bool a = OSUtils::jsonBool((*m)["authorized"], 0);
|
||||
if (a) { authorizedCount++; }
|
||||
}
|
||||
|
||||
meta["totalCount"] = totalCount;
|
||||
meta["authorizedCount"] = authorizedCount;
|
||||
|
||||
out["data"] = members;
|
||||
out["meta"] = meta;
|
||||
|
||||
setContent(req, res, out.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];
|
||||
|
Loading…
x
Reference in New Issue
Block a user