From: Christian Jurk Date: Tue, 12 Jul 2016 10:49:56 +0000 (+0200) Subject: HTTP API doc updates, POST to metadata shall not overwrite existing entries X-Git-Tag: dnsdist-1.1.0-beta2~141^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6720e79b4cecd7e3c794ace54d52c9801790b41;p=thirdparty%2Fpdns.git HTTP API doc updates, POST to metadata shall not overwrite existing entries --- diff --git a/docs/markdown/httpapi/api_spec.md b/docs/markdown/httpapi/api_spec.md index bdcb78cff1..2a23766fa4 100644 --- a/docs/markdown/httpapi/api_spec.md +++ b/docs/markdown/httpapi/api_spec.md @@ -614,12 +614,17 @@ zone\_metadata\_resource ] } -Valid values for `` are specified in +##### Parameters: + +`kind`: valid values for `` are specified in [the `domainmetadata` documentation](../authoritative/domainmetadata.md). -Clients MUST NOT modify `NSEC3PARAM`, `NSEC3NARROW` or `PRESIGNED` -through this interface. The server SHOULD reject updates to these -metadata. +`metadata`: an array with all values for this metadata kind. + +Clients MUST NOT modify `NSEC3PARAM`, `NSEC3NARROW`, `PRESIGNED` and +`LUA-AXFR-SCRIPT` through this interface. The server rejects updates to +these metadata. Modifications to custom metadata kinds are rejected +through this interface. URL: /api/v1/servers/:server\_id/zones/:zone\_name/metadata @@ -629,14 +634,39 @@ Collection access. Allowed methods: `GET`, `POST` -**TODO**: Not yet implemented. +#### GET + +Returns all metadata entries for the zone. + + +#### POST + +Creates a set of metadata entries of given kind for the zone. + +* existing metadata entries for the zone with the same kind are not overwritten. + URL: /api/v1/servers/:server\_id/zones/:zone\_name/metadata/:metadata\_kind --------------------------------------------------------------------------- Allowed methods: `GET`, `PUT`, `DELETE` -**TODO**: Not yet implemented. +#### GET + +Returns all metadata entries of a given kind for the zone. + + +#### DELETE + +Deletes all metadata entries of a given kind for the zone. + + +#### PUT + +Modifies the metadata entries of a given kind for the zone. + +This returns `200 OK` on success. + CryptoKeys ========== diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index a374d5d1bc..c21f759dda 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -615,6 +615,11 @@ static void apiZoneMetadata(HttpRequest* req, HttpResponse *resp) { throw ApiException("Unsupported metadata kind '" + kind + "'"); vector vecMetadata; + + if (!B.getDomainMetadata(zonename, kind, vecMetadata)) + throw ApiException("Could not retrieve metadata entries for domain '" + + zonename.toString() + "'"); + auto& metadata = document["metadata"]; if (!metadata.is_array()) throw ApiException("metadata is not specified or not an array"); @@ -622,13 +627,29 @@ static void apiZoneMetadata(HttpRequest* req, HttpResponse *resp) { for (const auto& i : metadata.array_items()) { if (!i.is_string()) throw ApiException("metadata must be strings"); - vecMetadata.push_back(i.string_value()); + else if (std::find(vecMetadata.cbegin(), + vecMetadata.cend(), + i.string_value()) == vecMetadata.cend()) { + vecMetadata.push_back(i.string_value()); + } } if (!B.setDomainMetadata(zonename, kind, vecMetadata)) - throw ApiException("Could not update metadata entries for domain '" + zonename.toString() + "'"); + throw ApiException("Could not update metadata entries for domain '" + + zonename.toString() + "'"); + + Json::array respMetadata; + for (const string& s : vecMetadata) + respMetadata.push_back(s); + + Json::object key { + { "type", "Metadata" }, + { "kind", document["kind"] }, + { "metadata", respMetadata } + }; resp->status = 201; + resp->setBody(key); } else throw HttpMethodNotAllowedException(); }