Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: expose domains.account #2203

Merged
merged 2 commits into from
Feb 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/markdown/httpapi/api_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ zone_collection
"presigned": <bool>,
"soa_edit": "<string>",
"soa_edit_api": "<string>",
"account": "<string>",
"nameservers": ["<string>", ...],
"servers": ["<string>", ...],
"recursion_desired": <bool>,
Expand Down Expand Up @@ -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.

Expand Down
7 changes: 4 additions & 3 deletions modules/gmysqlbackend/gmysqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class gMySQLFactory : public BackendFactory

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=?");
declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=? and account=?");

declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',?)");
declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE',?,?)");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',?,?,?)");

declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (?,?,?,?,?,?,?,?)");
Expand All @@ -92,6 +92,7 @@ class gMySQLFactory : public BackendFactory

declare(suffix,"update-master-query","", "update domains set master=? where name=?");
declare(suffix,"update-kind-query","", "update domains set type=? where name=?");
declare(suffix,"update-account-query","", "update domains set account=? where name=?");
declare(suffix,"update-serial-query","", "update domains set notified_serial=? where id=?");
declare(suffix,"update-lastcheck-query","", "update domains set last_check=? where id=?");
declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=?");
Expand All @@ -117,7 +118,7 @@ class gMySQLFactory : public BackendFactory
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 (?, ?, ?, ?, ?, ?)");
Expand Down
7 changes: 4 additions & 3 deletions modules/gpgsqlbackend/gpgsqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ class gPgSQLFactory : public BackendFactory

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");
declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=$1 and account=$2");

declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',$1)");
declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE',$1,$2)");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',$1,$2,$3)");

declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ($1,$2,$3,$4,$5,$6,$7,$8)");
Expand All @@ -86,6 +86,7 @@ class gPgSQLFactory : public BackendFactory

declare(suffix,"update-master-query","", "update domains set master=$1 where name=$2");
declare(suffix,"update-kind-query","", "update domains set type=$1 where name=$2");
declare(suffix,"update-account-query","", "update domains set account=$1 where name=$2");
declare(suffix,"update-serial-query","", "update domains set notified_serial=$1 where id=$2");
declare(suffix,"update-lastcheck-query","", "update domains set last_check=$1 where id=$2");
declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=$1");
Expand All @@ -111,7 +112,7 @@ class gPgSQLFactory : public BackendFactory
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)");
Expand Down
7 changes: 4 additions & 3 deletions modules/gsqlite3backend/gsqlite3backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class gSQLite3Factory : public BackendFactory

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");
declare(suffix, "supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=:nameserver and account=:account");

declare(suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE',:domain)");
declare(suffix, "insert-zone-query", "", "insert into domains (type,name,account) values('NATIVE',:domain,:account)");
declare(suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE',:domain,:masters,:account)");

declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (:content,:ttl,:priority,:qtype,:domain_id,:disabled,:qname,:auth)");
Expand All @@ -103,6 +103,7 @@ class gSQLite3Factory : public BackendFactory

declare(suffix, "update-master-query", "", "update domains set master=:master where name=:domain");
declare(suffix, "update-kind-query", "", "update domains set type=:kind where name=:domain");
declare(suffix, "update-account-query","", "update domains set account=:account where name=:domain");
declare(suffix, "update-serial-query", "", "update domains set notified_serial=:serial where id=:domain_id");
declare(suffix, "update-lastcheck-query", "", "update domains set last_check=:last_check where id=:domain_id");
declare(suffix, "zone-lastchange-query", "", "select max(change_date) from records where domain_id=:domain_id");
Expand All @@ -128,7 +129,7 @@ class gSQLite3Factory : public BackendFactory
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)");
Expand Down
27 changes: 23 additions & 4 deletions pdns/backends/gsql/gsqlbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
d_UpdateKindOfZoneQuery=getArg("update-kind-query");
d_UpdateSerialOfZoneQuery=getArg("update-serial-query");
d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
d_UpdateAccountOfZoneQuery=getArg("update-account-query");
d_ZoneLastChangeQuery=getArg("zone-lastchange-query");
d_InfoOfAllMasterDomainsQuery=getArg("info-all-master-query");
d_DeleteDomainQuery=getArg("delete-domain-query");
Expand Down Expand Up @@ -142,6 +143,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
d_UpdateKindOfZoneQuery_stmt = NULL;
d_UpdateSerialOfZoneQuery_stmt = NULL;
d_UpdateLastCheckofZoneQuery_stmt = NULL;
d_UpdateAccountOfZoneQuery_stmt = NULL;
d_InfoOfAllMasterDomainsQuery_stmt = NULL;
d_DeleteDomainQuery_stmt = NULL;
d_DeleteZoneQuery_stmt = NULL;
Expand Down Expand Up @@ -270,10 +272,25 @@ bool GSQLBackend::setKind(const string &domain, const DomainInfo::DomainKind kin
return true;
}

bool GSQLBackend::setAccount(const string &domain, const string &account)
{
try {
d_UpdateAccountOfZoneQuery_stmt->
bind("account", account)->
bind("domain", toLower(domain))->
execute()->
reset();
}
catch (SSqlException &e) {
throw PDNSException("GSQLBackend unable to set account of domain \""+domain+"\": "+e.txtReason());
}
return true;
}

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))->
Expand All @@ -295,6 +312,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;
Expand Down Expand Up @@ -1153,15 +1171,16 @@ 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;
else if (pdns_iequals(row[3], "SLAVE"))
Expand Down
7 changes: 6 additions & 1 deletion pdns/backends/gsql/gsqlbackend.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ public:
d_InfoOfAllSlaveDomainsQuery_stmt = d_db->prepare(d_InfoOfAllSlaveDomainsQuery, 0);
d_SuperMasterInfoQuery_stmt = d_db->prepare(d_SuperMasterInfoQuery, 2);
d_GetSuperMasterIPs_stmt = d_db->prepare(d_GetSuperMasterIPs, 2);
d_InsertZoneQuery_stmt = d_db->prepare(d_InsertZoneQuery, 1);
d_InsertZoneQuery_stmt = d_db->prepare(d_InsertZoneQuery, 2);
d_InsertSlaveZoneQuery_stmt = d_db->prepare(d_InsertSlaveZoneQuery, 3);
d_InsertRecordQuery_stmt = d_db->prepare(d_InsertRecordQuery, 8);
d_InsertEntQuery_stmt = d_db->prepare(d_InsertEntQuery, 3);
d_InsertRecordOrderQuery_stmt = d_db->prepare(d_InsertRecordOrderQuery, 9);
d_InsertEntOrderQuery_stmt = d_db->prepare(d_InsertEntOrderQuery, 4);
d_UpdateMasterOfZoneQuery_stmt = d_db->prepare(d_UpdateMasterOfZoneQuery, 2);
d_UpdateKindOfZoneQuery_stmt = d_db->prepare(d_UpdateKindOfZoneQuery, 2);
d_UpdateAccountOfZoneQuery_stmt = d_db->prepare(d_UpdateAccountOfZoneQuery, 2);
d_UpdateSerialOfZoneQuery_stmt = d_db->prepare(d_UpdateSerialOfZoneQuery, 2);
d_UpdateLastCheckofZoneQuery_stmt = d_db->prepare(d_UpdateLastCheckofZoneQuery, 2);
d_InfoOfAllMasterDomainsQuery_stmt = d_db->prepare(d_InfoOfAllMasterDomainsQuery, 0);
Expand Down Expand Up @@ -115,6 +116,7 @@ public:
release(&d_InsertEntOrderQuery_stmt);
release(&d_UpdateMasterOfZoneQuery_stmt);
release(&d_UpdateKindOfZoneQuery_stmt);
release(&d_UpdateAccountOfZoneQuery_stmt);
release(&d_UpdateSerialOfZoneQuery_stmt);
release(&d_UpdateLastCheckofZoneQuery_stmt);
release(&d_InfoOfAllMasterDomainsQuery_stmt);
Expand Down Expand Up @@ -180,6 +182,7 @@ public:
void setNotified(uint32_t domain_id, uint32_t serial);
bool setMaster(const string &domain, const string &ip);
bool setKind(const string &domain, const DomainInfo::DomainKind kind);
bool setAccount(const string &domain, const string &account);

virtual bool getBeforeAndAfterNamesAbsolute(uint32_t id, const std::string& qname, std::string& unhashed, std::string& before, std::string& after);
bool updateDNSSECOrderAndAuth(uint32_t domain_id, const std::string& zonename, const std::string& qname, bool auth);
Expand Down Expand Up @@ -244,6 +247,7 @@ private:
string d_InsertEntOrderQuery;
string d_UpdateMasterOfZoneQuery;
string d_UpdateKindOfZoneQuery;
string d_UpdateAccountOfZoneQuery;
string d_UpdateSerialOfZoneQuery;
string d_UpdateLastCheckofZoneQuery;
string d_InfoOfAllMasterDomainsQuery;
Expand Down Expand Up @@ -312,6 +316,7 @@ private:
SSqlStatement* d_InsertEntOrderQuery_stmt;
SSqlStatement* d_UpdateMasterOfZoneQuery_stmt;
SSqlStatement* d_UpdateKindOfZoneQuery_stmt;
SSqlStatement* d_UpdateAccountOfZoneQuery_stmt;
SSqlStatement* d_UpdateSerialOfZoneQuery_stmt;
SSqlStatement* d_UpdateLastCheckofZoneQuery_stmt;
SSqlStatement* d_InfoOfAllMasterDomainsQuery_stmt;
Expand Down
7 changes: 7 additions & 0 deletions pdns/dnsbackend.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -336,6 +337,12 @@ public:
return false;
}

//! Called when the Account of a domain should be changed
virtual bool setAccount(const string &domain, const string &account)
{
return false;
}

//! Can be called to seed the getArg() function with a prefix
void setArgPrefix(const string &prefix);

Expand Down
4 changes: 4 additions & 0 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -469,6 +470,9 @@ static void updateDomainSettingsFromDocument(const DomainInfo& di, const string&
if (document["soa_edit"].IsString()) {
di.backend->setDomainMetadataOne(zonename, "SOA-EDIT", document["soa_edit"].GetString());
}
if (document["account"].IsString()) {
di.backend->setAccount(zonename, document["account"].GetString());
}
}

static void apiZoneCryptokeys(HttpRequest* req, HttpResponse* resp) {
Expand Down
11 changes: 10 additions & 1 deletion regression-tests.api/test_Zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -75,6 +75,15 @@ def test_create_zone_with_soa_edit_api(self):
self.assertGreater(soa_serial, payload['serial'])
self.assertEquals(soa_serial, data['serial'])

def test_create_zone_with_account(self):
# soa_edit_api wins over serial
payload, data = self.create_zone(account='anaccount', serial=10)
print data
for k in ('account', ):
self.assertIn(k, data)
if k in payload:
self.assertEquals(data[k], payload[k])

def test_create_zone_with_records(self):
name = unique_zone_name()
records = [
Expand Down