From: Christian Hofstaedtler Date: Sat, 7 Feb 2015 14:01:26 +0000 (+0100) Subject: API: read and expose domain account field X-Git-Tag: rec-3.7.0~14^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ffb7a9bab0d6adc4879f9cb1ce73ded65fa92be;p=pdns API: read and expose domain account field --- diff --git a/docs/markdown/httpapi/api_spec.md b/docs/markdown/httpapi/api_spec.md index be462982b..c33bcb82e 100644 --- a/docs/markdown/httpapi/api_spec.md +++ b/docs/markdown/httpapi/api_spec.md @@ -297,6 +297,7 @@ zone_collection "presigned": , "soa_edit": "", "soa_edit_api": "", + "account": "", "nameservers": ["", ...], "servers": ["", ...], "recursion_desired": , @@ -338,6 +339,9 @@ zone_collection the SOA-EDIT-API rules. (Which are the same as the SOA-EDIT rules.) **Note**: Authoritative only. +* `account` MAY be set. It's value is defined by local policy. + **Note**: Authoritative only. + * `notified_serial`, `serial` MUST NOT be sent in client bodies. **Note**: Authoritative only. diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index 316e06035..6320c3170 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -66,7 +66,7 @@ public: declare(suffix,"master-zone-query","Data", "select master from domains where name=? and type='SLAVE'"); - declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type from domains where name=?"); + declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type,account from domains where name=?"); declare(suffix,"info-all-slaves-query","","select id,name,master,last_check,type from domains where type='SLAVE'"); declare(suffix,"supermaster-query","", "select account from supermasters where ip=? and nameserver=?"); @@ -117,7 +117,7 @@ public: declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name=?"); declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR ?"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR ?"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=?"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (?, ?, ?, ?, ?, ?)"); diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index cf3d8c8c4..25d65e8d3 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -60,7 +60,7 @@ public: declare(suffix,"master-zone-query","Data", "select master from domains where name=$1 and type='SLAVE'"); - declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type from domains where name=$1"); + declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type,account from domains where name=$1"); declare(suffix,"info-all-slaves-query","","select id,name,master,last_check,type from domains where type='SLAVE'"); declare(suffix,"supermaster-query","", "select account from supermasters where ip=$1 and nameserver=$2"); @@ -111,7 +111,7 @@ public: declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name=$1"); declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=false OR $1"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=false OR $1"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=$1"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES ($1, $2, $3, $4, $5, $6)"); diff --git a/modules/gsqlite3backend/gsqlite3backend.cc b/modules/gsqlite3backend/gsqlite3backend.cc index 33aab4831..a8bbf231c 100644 --- a/modules/gsqlite3backend/gsqlite3backend.cc +++ b/modules/gsqlite3backend/gsqlite3backend.cc @@ -77,7 +77,7 @@ public: declare(suffix, "master-zone-query", "Data", "select master from domains where name=:domain and type='SLAVE'"); - declare(suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type from domains where name=:domain"); + declare(suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type,account from domains where name=:domain"); declare(suffix, "info-all-slaves-query", "","select id,name,master,last_check,type from domains where type='SLAVE'"); declare(suffix, "supermaster-query", "", "select account from supermasters where ip=:ip and nameserver=:nameserver"); @@ -128,7 +128,7 @@ public: declare(suffix, "delete-tsig-key-query","", "delete from tsigkeys where name=:key_name"); declare(suffix, "get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys"); - declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR :include_disabled"); + declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check, domains.account from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR :include_disabled"); declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=:domain_id"); declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (:domain_id, :qname, :qtype, :modified_at, :account, :content)"); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 5c79f4b0e..c45aa2ac4 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -273,7 +273,7 @@ bool GSQLBackend::setKind(const string &domain, const DomainInfo::DomainKind kin bool GSQLBackend::getDomainInfo(const string &domain, DomainInfo &di) { /* fill DomainInfo from database info: - id,name,master IP(s),last_check,notified_serial,type */ + id,name,master IP(s),last_check,notified_serial,type,account */ try { d_InfoOfDomainsZoneQuery_stmt-> bind("domain", toLower(domain))-> @@ -295,6 +295,7 @@ bool GSQLBackend::getDomainInfo(const string &domain, DomainInfo &di) di.last_check=atol(d_result[0][3].c_str()); di.notified_serial = atol(d_result[0][4].c_str()); string type=d_result[0][5]; + di.account=d_result[0][6]; di.backend=this; di.serial = 0; @@ -1153,15 +1154,16 @@ void GSQLBackend::getAllDomains(vector *domains, bool include_disabl if (!row[4].empty()) { stringtok(di.masters, row[4], " ,\t"); } - di.last_check=atol(row[6].c_str()); - + SOAData sd; fillSOAData(row[2], sd); di.serial = sd.serial; if (!row[5].empty()) { di.notified_serial = atol(row[5].c_str()); } - + di.last_check = atol(row[6].c_str()); + di.account = row[7]; + if (pdns_iequals(row[3], "MASTER")) di.kind = DomainInfo::Master; else if (pdns_iequals(row[3], "SLAVE")) diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index 794e38ac2..c07a27b05 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -51,6 +51,7 @@ struct DomainInfo uint32_t notified_serial; uint32_t serial; time_t last_check; + string account; enum DomainKind { Master, Slave, Native } kind; DNSBackend *backend; diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index baa35d020..828542201 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -307,6 +307,7 @@ static void fillZone(const string& zonename, HttpResponse* resp) { doc.AddMember("type", "Zone", doc.GetAllocator()); doc.AddMember("kind", di.getKindString(), doc.GetAllocator()); doc.AddMember("dnssec", dk.isSecuredZone(di.zone), doc.GetAllocator()); + doc.AddMember("account", di.account.c_str(), doc.GetAllocator()); string soa_edit_api; di.backend->getDomainMetadataOne(zonename, "SOA-EDIT-API", soa_edit_api); doc.AddMember("soa_edit_api", soa_edit_api.c_str(), doc.GetAllocator()); diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 3e2087297..3daf9ddb3 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -49,7 +49,7 @@ class AuthZones(ApiTestCase): def test_create_zone(self): payload, data = self.create_zone(serial=22) - for k in ('id', 'url', 'name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial', 'soa_edit_api', 'soa_edit'): + for k in ('id', 'url', 'name', 'masters', 'kind', 'last_check', 'notified_serial', 'serial', 'soa_edit_api', 'soa_edit', 'account'): self.assertIn(k, data) if k in payload: self.assertEquals(data[k], payload[k])