Permalink
Browse files

API: read and expose domain account field

  • Loading branch information...
1 parent 2b06977 commit d82f632c174a7c36f0ce72771e82f31474507d5a @zeha zeha committed with mind04 Feb 7, 2015
@@ -66,7 +66,7 @@ class gMySQLFactory : public BackendFactory
declare(suffix,"master-zone-query","Data", "select master from domains where name='%s' and type='SLAVE'");
- declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type from domains where name='%s'");
+ declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type,account from domains where name='%s'");
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='%s' and nameserver='%s'");
@@ -117,7 +117,7 @@ class gMySQLFactory : public BackendFactory
declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
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 %d");
+ 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 %d");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')");
@@ -60,7 +60,7 @@ class gPgSQLFactory : public BackendFactory
declare(suffix,"master-zone-query","Data", "select master from domains where name=E'%s' and type='SLAVE'");
- declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type from domains where name=E'%s'");
+ declare(suffix,"info-zone-query","","select id,name,master,last_check,notified_serial,type,account from domains where name=E'%s'");
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='%s' and nameserver=E'%s'");
@@ -111,7 +111,7 @@ class gPgSQLFactory : public BackendFactory
declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
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 %d::bool");
+ 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 %d::bool");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, E'%s', E'%s', %d, E'%s', E'%s')");
@@ -76,7 +76,7 @@ class gSQLite3Factory : public BackendFactory
declare( suffix, "master-zone-query", "Data", "select master from domains where name='%s' and type='SLAVE'");
- declare( suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type from domains where name='%s'");
+ declare( suffix, "info-zone-query", "","select id,name,master,last_check,notified_serial,type,account from domains where name='%s'");
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='%s' and nameserver='%s'");
@@ -127,7 +127,7 @@ class gSQLite3Factory : public BackendFactory
declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
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 %d");
+ 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 %d");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')");
@@ -130,7 +130,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 */
char output[1024];
snprintf(output,sizeof(output)-1,d_InfoOfDomainsZoneQuery.c_str(),
sqlEscape(domain).c_str());
@@ -151,6 +151,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;
@@ -994,14 +995,15 @@ void GSQLBackend::getAllDomains(vector<DomainInfo> *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;
View
@@ -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;
@@ -287,6 +287,7 @@ zone_collection
"presigned": <bool>,
"soa_edit": "<string>",
"soa_edit_api": "<string>",
+ "account": "<string>",
"nameservers": ["<string>", ...],
"servers": ["<string>", ...],
"recursion_desired": <bool>,
@@ -328,6 +329,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.
View
@@ -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());
@@ -49,7 +49,7 @@ def create_zone(self, name=None, **kwargs):
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])

0 comments on commit d82f632

Please sign in to comment.