Skip to content

Commit

Permalink
WIP - Create an alternate members list endpoint
Browse files Browse the repository at this point in the history
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/controller/network/1111111111767f2f/member2 ->

```
[
  {
    "authorized": false,
    "id": "1122334455",
    "name": "bob",
    ...
  },
  {
    "authorized": true,
    "id": "46254ec531",
    "name": "wakka",
    ...
  },
  {
    "authorized": false,
    "id": "2456246824",
    "name": "bob2",
    ...
  }
]
```
  • Loading branch information
laduke committed Jan 30, 2024
1 parent 3f8d3b3 commit d42d873
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions controller/EmbeddedNetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<json> 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];
Expand Down

0 comments on commit d42d873

Please sign in to comment.