]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: api, add catalog in zone endpoint
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 13 Jul 2022 19:55:08 +0000 (21:55 +0200)
committermind04 <mind04@monshouwer.org>
Wed, 13 Jul 2022 23:47:22 +0000 (01:47 +0200)
docs/http-api/swagger/authoritative-api-swagger.yaml
modules/gsqlite3backend/gsqlite3backend.cc
modules/lmdbbackend/lmdbbackend.cc
pdns/ws-auth.cc
regression-tests.api/test_Zones.py

index 709a7f0ec76e52b284c3a45223592e518b443bc8..e4f006b3c16d16b95450644c4526d06a2f1de482 100644 (file)
@@ -250,7 +250,7 @@ paths:
 
     put:
       summary: Modifies basic zone data.
-      description: 'The only fields in the zone structure which can be modified are: kind, masters, account, soa_edit, soa_edit_api, api_rectify, dnssec, and nsec3param. All other fields are ignored.'
+      description: 'The only fields in the zone structure which can be modified are: kind, masters, catalog, account, soa_edit, soa_edit_api, api_rectify, dnssec, and nsec3param. All other fields are ignored.'
       operationId: putZone
       tags:
         - zones
@@ -988,7 +988,9 @@ definitions:
           - 'Native'
           - 'Master'
           - 'Slave'
-        description: 'Zone kind, one of “Native”, “Master”, “Slave”'
+          - 'Producer'
+          - 'Consumer'
+        description: 'Zone kind, one of “Native”, “Master”, “Slave”, “Producer”, “Consumer”'
       rrsets:
         type: array
         items:
@@ -1028,10 +1030,13 @@ definitions:
         description: 'The SOA-EDIT-API metadata item'
       api_rectify:
         type: boolean
-        description: ' Whether or not the zone will be rectified on data changes via the API'
+        description: 'Whether or not the zone will be rectified on data changes via the API'
       zone:
         type: string
         description: 'MAY contain a BIND-style zone file when creating a zone'
+      catalog:
+        type: string
+        description: 'The catalog this zone is a member of'
       account:
         type: string
         description: 'MAY be set. Its value is defined by local policy'
index df3aff2714f5d451ea595a58109df5d0829e9cb6..f966cc66eb8777393140c76a58a1e26645ad2664 100644 (file)
@@ -121,7 +121,7 @@ public:
     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-options-query", "", "update domains set options=:options where name=:domain");
-    declare(suffix, "update-catalog-query", "", "update domains set catalog=:options where name=:domain");
+    declare(suffix, "update-catalog-query", "", "update domains set catalog=:catalog 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");
index 514cbccacb3e7d672dfe2993f5784599d1e06627..1f200bc24c98558baeecf31633d80dbed0f83edb 100644 (file)
@@ -162,7 +162,7 @@ namespace serialization
       ar& tmp;
     }
     else
-      ar & "";
+      ar& std::string();
   }
 
   template <class Archive>
index 883cb0618de301d7374a330ee33c4942fe72fba3..b07be2bdc4fe3f55989bd19e30845f26e8681e0f 100644 (file)
@@ -319,18 +319,18 @@ static Json::object getZoneInfo(const DomainInfo& di, DNSSECKeeper* dk) {
     masters.push_back(m.toStringWithPortExcept(53));
   }
 
-  auto obj = Json::object {
+  auto obj = Json::object{
     // id is the canonical lookup key, which doesn't actually match the name (in some cases)
-    { "id", zoneId },
-    { "url", "/api/v1/servers/localhost/zones/" + zoneId },
-    { "name", di.zone.toString() },
-    { "kind", di.getKindString() },
-    { "account", di.account },
-    { "masters", std::move(masters) },
-    { "serial", (double)di.serial },
-    { "notified_serial", (double)di.notified_serial },
-    { "last_check", (double)di.last_check }
-  };
+    {"id", zoneId},
+    {"url", "/api/v1/servers/localhost/zones/" + zoneId},
+    {"name", di.zone.toString()},
+    {"kind", di.getKindString()},
+    {"catalog", (!di.catalog.empty() ? di.catalog.toString() : "")},
+    {"account", di.account},
+    {"masters", std::move(masters)},
+    {"serial", (double)di.serial},
+    {"notified_serial", (double)di.notified_serial},
+    {"last_check", (double)di.last_check}};
   if (dk) {
     obj["dnssec"] = dk->isSecuredZone(di.zone);
     string soa_edit;
@@ -612,8 +612,8 @@ static void throwUnableToSecure(const DNSName& zonename) {
       + "capable backends are loaded, or because the backends have DNSSEC disabled. Check your configuration.");
 }
 
-
-static void extractDomainInfoFromDocument(const Json& document, boost::optional<DomainInfo::DomainKind>& kind, boost::optional<vector<ComboAddress>>& masters, boost::optional<string>& account) {
+static void extractDomainInfoFromDocument(const Json& document, boost::optional<DomainInfo::DomainKind>& kind, boost::optional<vector<ComboAddress>>& masters, boost::optional<DNSName>& catalog, boost::optional<string>& account)
+{
   if (document["kind"].is_string()) {
     kind = DomainInfo::stringToKind(stringFromJson(document, "kind"));
   } else {
@@ -636,6 +636,14 @@ static void extractDomainInfoFromDocument(const Json& document, boost::optional<
     masters = boost::none;
   }
 
+  if (document["catalog"].is_string()) {
+    string catstring = document["catalog"].string_value();
+    catalog = (!catstring.empty() ? DNSName(catstring) : DNSName());
+  }
+  else {
+    catalog = boost::none;
+  }
+
   if (document["account"].is_string()) {
     account = document["account"].string_value();
   } else {
@@ -646,9 +654,10 @@ static void extractDomainInfoFromDocument(const Json& document, boost::optional<
 static void updateDomainSettingsFromDocument(UeberBackend& B, const DomainInfo& di, const DNSName& zonename, const Json& document, bool rectifyTransaction=true) {
   boost::optional<DomainInfo::DomainKind> kind;
   boost::optional<vector<ComboAddress>> masters;
+  boost::optional<DNSName> catalog;
   boost::optional<string> account;
 
-  extractDomainInfoFromDocument(document, kind, masters, account);
+  extractDomainInfoFromDocument(document, kind, masters, catalog, account);
 
   if (kind) {
     di.backend->setKind(zonename, *kind);
@@ -656,6 +665,9 @@ static void updateDomainSettingsFromDocument(UeberBackend& B, const DomainInfo&
   if (masters) {
     di.backend->setMasters(zonename, *masters);
   }
+  if (catalog) {
+    di.backend->setCatalog(zonename, *catalog);
+  }
   if (account) {
     di.backend->setAccount(zonename, *account);
   }
@@ -1795,8 +1807,9 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
 
     boost::optional<DomainInfo::DomainKind> kind;
     boost::optional<vector<ComboAddress>> masters;
+    boost::optional<DNSName> catalog;
     boost::optional<string> account;
-    extractDomainInfoFromDocument(document, kind, masters, account);
+    extractDomainInfoFromDocument(document, kind, masters, catalog, account);
 
     // no going back after this
     if(!B.createDomain(zonename, kind.get_value_or(DomainInfo::Native), masters.get_value_or(vector<ComboAddress>()), account.get_value_or("")))
index d9291f5c2db9cc19b3a9a1eea8867bf33ba9c6c1..4a5173700a19ac0d7c97e5641d80509101d84522 100644 (file)
@@ -145,6 +145,15 @@ class AuthZones(ApiTestCase, AuthZonesHelperMixin):
         self.assertGreater(soa_serial, payload['serial'])
         self.assertEqual(soa_serial, data['serial'])
 
+    def test_create_zone_with_catalog(self):
+        # soa_edit_api wins over serial
+        name, payload, data = self.create_zone(catalog='catalog.invalid.', serial=10)
+        print(data)
+        for k in ('catalog', ):
+            self.assertIn(k, data)
+            if k in payload:
+                self.assertEqual(data[k], payload[k])
+
     def test_create_zone_with_account(self):
         # soa_edit_api wins over serial
         name, payload, data = self.create_zone(account='anaccount', serial=10)
@@ -1053,6 +1062,7 @@ $ORIGIN %NAME%
         payload = {
             'kind': 'Master',
             'masters': ['192.0.2.1', '192.0.2.2'],
+            'catalog': 'catalog.invalid.',
             'soa_edit_api': 'EPOCH',
             'soa_edit': 'EPOCH'
         }
@@ -1068,6 +1078,7 @@ $ORIGIN %NAME%
         # update, back to Native and empty(off)
         payload = {
             'kind': 'Native',
+            'catalog': '',
             'soa_edit_api': '',
             'soa_edit': ''
         }