if (req->method == "PUT") {
Document document;
req->json(document);
+ const Value &jlist = document["value"];
- if (!document.IsArray()) {
- throw ApiException("Supplied JSON must be an array");
+ if (!document.IsObject()) {
+ throw ApiException("Supplied JSON must be an object");
+ }
+
+ if (!jlist.IsArray()) {
+ throw ApiException("'value' must be an array");
}
ostringstream ss;
// Clear allow-from, and provide a "parent" value
ss << "allow-from=" << endl;
- for (SizeType i = 0; i < document.Size(); ++i) {
- ss << "allow-from+=" << document[i].GetString() << endl;
+ for (SizeType i = 0; i < jlist.Size(); ++i) {
+ ss << "allow-from+=" << jlist[i].GetString() << endl;
}
apiWriteConfigFile("allow-from", ss.str());
// Return currently configured ACLs
Document document;
- document.SetArray();
+ document.SetObject();
+
+ Value jlist;
+ jlist.SetArray();
vector<string> entries;
t_allowFrom->toStringVector(&entries);
BOOST_FOREACH(const string& entry, entries) {
Value jentry(entry.c_str(), document.GetAllocator()); // copy
- document.PushBack(jentry, document.GetAllocator());
+ jlist.PushBack(jentry, document.GetAllocator());
}
+ document.AddMember("name", "allow-from", document.GetAllocator());
+ document.AddMember("value", jlist, document.GetAllocator());
+
resp->setBody(document);
}
self.assertSuccessJson(r)
def test_ConfigAllowFromReplace(self):
- payload = ["127.0.0.1"]
+ payload = {'value': ["127.0.0.1"]}
r = self.session.put(
self.url("/servers/localhost/config/allow-from"),
data=json.dumps(payload),
headers={'content-type': 'application/json'})
self.assertSuccessJson(r)
data = r.json()
- self.assertEquals("127.0.0.1/32", data[0])
+ self.assertEquals("127.0.0.1/32", data["value"][0])