From 0bd91de64d5baac62eafc4cf9ff4661ca6f3bec4 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Fri, 8 Feb 2019 12:24:59 +0100 Subject: [PATCH] Rename type to object_type --- .../swagger/authoritative-api-swagger.yaml | 2 +- pdns/ws-auth.cc | 34 +++++++++---------- regression-tests.api/test_Zones.py | 4 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/http-api/swagger/authoritative-api-swagger.yaml b/docs/http-api/swagger/authoritative-api-swagger.yaml index ce9918ade..0c4570e69 100644 --- a/docs/http-api/swagger/authoritative-api-swagger.yaml +++ b/docs/http-api/swagger/authoritative-api-swagger.yaml @@ -436,7 +436,7 @@ paths: required: true description: 'Maximum number of entries to return' type: integer - - name: type + - name: object_type in: query required: false description: 'Type of data to search for, one of “all”, “zone”, “record”, “comment”' diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index fbd5cb506..e97a37993 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -2041,19 +2041,19 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { 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"); @@ -2062,18 +2062,18 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { 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; @@ -2088,7 +2088,7 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { 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) }, @@ -2099,7 +2099,7 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { 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) { @@ -2122,7 +2122,7 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { } } - 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) { diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 636ea439e..ae9cf4b91 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -1621,7 +1621,7 @@ fred IN A 192.168.0.4 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(), [ @@ -1632,7 +1632,7 @@ fred IN A 192.168.0.4 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(), [ -- 2.49.0