Permalink
Browse files

API: allow writing to domains.account field

  • Loading branch information...
1 parent d82f632 commit 102602f341042a78a29046dc9eae77770e8ca72a @zeha zeha committed with mind04 Feb 7, 2015
@@ -72,7 +72,7 @@ class gMySQLFactory : public BackendFactory
declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver='%s'");
declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%s'");
- declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE','%s')");
+ declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE','%s','%s')");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s','%d')");
@@ -92,6 +92,7 @@ class gMySQLFactory : public BackendFactory
declare(suffix,"update-master-query","", "update domains set master='%s' where name='%s'");
declare(suffix,"update-kind-query","", "update domains set type='%s' where name='%s'");
+ declare(suffix,"update-account-query","", "update domains set account='%s' where name='%s'");
declare(suffix,"update-serial-query","", "update domains set notified_serial=%d where id=%d");
declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
@@ -66,7 +66,7 @@ class gPgSQLFactory : public BackendFactory
declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver=E'%s'");
declare(suffix,"supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver=E'%s' and account=E'%s'");
- declare(suffix,"insert-zone-query","", "insert into domains (type,name) values('NATIVE',E'%s')");
+ declare(suffix,"insert-zone-query","", "insert into domains (type,name,account) values('NATIVE',E'%s',E'%s')");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',E'%s',E'%s',E'%s')");
declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values (E'%s',%d,%d,'%s',%d,%d::bool,E'%s','%d')");
@@ -86,6 +86,7 @@ class gPgSQLFactory : public BackendFactory
declare(suffix,"update-master-query","", "update domains set master='%s' where name='%s'");
declare(suffix,"update-kind-query","", "update domains set type='%s' where name='%s'");
+ declare(suffix,"update-account-query","", "update domains set account=E'%s' where name=E'%s'");
declare(suffix,"update-serial-query","", "update domains set notified_serial=%d where id=%d");
declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
declare(suffix,"zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
@@ -82,7 +82,7 @@ class gSQLite3Factory : public BackendFactory
declare( suffix, "supermaster-query", "", "select account from supermasters where ip='%s' and nameserver='%s'");
declare( suffix, "supermaster-name-to-ips", "", "select ip,account from supermasters where nameserver='%s' and account='%s'");
- declare( suffix, "insert-zone-query", "", "insert into domains (type,name) values('NATIVE','%s')");
+ declare( suffix, "insert-zone-query", "", "insert into domains (type,name,account) values('NATIVE','%s','%s')");
declare( suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
declare(suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,disabled,name,auth) values ('%s',%d,%d,'%s',%d,%d,'%s',%d)");
@@ -102,6 +102,7 @@ class gSQLite3Factory : public BackendFactory
declare( suffix, "update-master-query", "", "update domains set master='%s' where name='%s'");
declare( suffix, "update-kind-query", "", "update domains set type='%s' where name='%s'");
+ declare( suffix, "update-account-query","", "update domains set account='%s' where name='%s'");
declare( suffix, "update-serial-query", "", "update domains set notified_serial=%d where id=%d");
declare( suffix, "update-lastcheck-query", "", "update domains set last_check=%d where id=%d");
declare (suffix, "zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
@@ -127,6 +127,19 @@ bool GSQLBackend::setKind(const string &domain, const DomainInfo::DomainKind kin
return true;
}
+bool GSQLBackend::setAccount(const string &domain, const string &account)
+{
+ string query = (GSQLformat(d_UpdateAccountOfZoneQuery) % sqlEscape(account) % sqlEscape(toLower(domain))).str();
+
+ try {
+ d_db->doCommand(query);
+ }
+ 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:
@@ -293,6 +306,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
d_InsertEntQuery=getArg("insert-ent-query");
d_UpdateMasterOfZoneQuery=getArg("update-master-query");
d_UpdateKindOfZoneQuery=getArg("update-kind-query");
+ d_UpdateAccountOfZoneQuery=getArg("update-account-query");
d_UpdateSerialOfZoneQuery=getArg("update-serial-query");
d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
d_ZoneLastChangeQuery=getArg("zone-lastchange-query");
@@ -52,6 +52,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);
@@ -116,6 +117,7 @@ private:
string d_InsertEntOrderQuery;
string d_UpdateMasterOfZoneQuery;
string d_UpdateKindOfZoneQuery;
+ string d_UpdateAccountOfZoneQuery;
string d_UpdateSerialOfZoneQuery;
string d_UpdateLastCheckofZoneQuery;
string d_InfoOfAllMasterDomainsQuery;
View
@@ -337,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);
View
@@ -498,6 +498,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) {
@@ -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 = [

0 comments on commit 102602f

Please sign in to comment.