string q = req->getvars["q"];
string sMax = req->getvars["max"];
- string sType = req->getvars["type"];
+ string sObjectType = req->getvars["object_type"];
int maxEnts = 100;
int ents = 0;
// the following types of data can be searched for using the api
- enum class Type
+ enum class ObjectType
{
ALL,
ZONE,
RECORD,
COMMENT
- } type;
+ } objectType;
if (q.empty())
throw ApiException("Query q can't be blank");
if (maxEnts < 1)
throw ApiException("Maximum entries must be larger than 0");
- if (sType.empty())
- type = Type::ALL;
- else if (sType == "all")
- type = Type::ALL;
- else if (sType == "zone")
- type = Type::ZONE;
- else if (sType == "record")
- type = Type::RECORD;
- else if (sType == "comment")
- type = Type::COMMENT;
+ if (sObjectType.empty())
+ objectType = ObjectType::ALL;
+ else if (sObjectType == "all")
+ objectType = ObjectType::ALL;
+ else if (sObjectType == "zone")
+ objectType = ObjectType::ZONE;
+ else if (sObjectType == "record")
+ objectType = ObjectType::RECORD;
+ else if (sObjectType == "comment")
+ objectType = ObjectType::COMMENT;
else
- throw ApiException("Type must be one of the following options: all, zone, record, comment");
+ throw ApiException("object_type must be one of the following options: all, zone, record, comment");
SimpleMatch sm(q,true);
UeberBackend B;
for(const DomainInfo di: domains)
{
- if ((type == Type::ALL || type == Type::ZONE) && ents < maxEnts && sm.match(di.zone)) {
+ if ((objectType == ObjectType::ALL || objectType == ObjectType::ZONE) && ents < maxEnts && sm.match(di.zone)) {
doc.push_back(Json::object {
{ "object_type", "zone" },
{ "zone_id", apiZoneNameToId(di.zone) },
zoneIdZone[di.id] = di; // populate cache
}
- if ((type == Type::ALL || type == Type::RECORD) && B.searchRecords(q, maxEnts, result_rr))
+ if ((objectType == ObjectType::ALL || objectType == ObjectType::RECORD) && B.searchRecords(q, maxEnts, result_rr))
{
for(const DNSResourceRecord& rr: result_rr)
{
}
}
- if ((type == Type::ALL || type == Type::COMMENT) && B.searchComments(q, maxEnts, result_c))
+ if ((objectType == ObjectType::ALL || objectType == ObjectType::COMMENT) && B.searchComments(q, maxEnts, result_c))
{
for(const Comment &c: result_c)
{
name = unique_zone_name()
data_type = "zone"
self.create_zone(name=name, serial=22, soa_edit_api='')
- r = self.session.get(self.url("/api/v1/servers/localhost/search-data?q=" + name.rstrip('.') + "&type=" + data_type))
+ r = self.session.get(self.url("/api/v1/servers/localhost/search-data?q=" + name.rstrip('.') + "&object_type=" + data_type))
self.assert_success_json(r)
print(r.json())
self.assertEquals(r.json(), [
name = unique_zone_name()
data_type = "record"
self.create_zone(name=name, serial=22, soa_edit_api='')
- r = self.session.get(self.url("/api/v1/servers/localhost/search-data?q=" + name.rstrip('.') + "&type=" + data_type))
+ r = self.session.get(self.url("/api/v1/servers/localhost/search-data?q=" + name.rstrip('.') + "&object_type=" + data_type))
self.assert_success_json(r)
print(r.json())
self.assertEquals(r.json(), [