Skip to content

Commit bf75bdb

Browse files
committed
Add an API endpoint to get backend storage layout version for a given zone.
Signed-off-by: Miod Vallat <[email protected]>
1 parent 327b348 commit bf75bdb

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

.github/actions/spell-check/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ stickysidebar
13391339
Stillaway
13401340
Stirnimann
13411341
Stolte
1342+
storageversion
13421343
Storbeck
13431344
Storesund
13441345
stou

docs/http-api/swagger/authoritative-api-swagger.yaml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
swagger: '2.0'
22
info:
3-
version: "0.0.17"
3+
version: "0.0.18"
44
title: PowerDNS Authoritative HTTP API
55
license:
66
name: MIT
@@ -79,6 +79,30 @@ paths:
7979
$ref: '#/definitions/Server'
8080
<<: *commonErrors
8181

82+
'/servers/{server_id}/backends/{backend_id}/storageversion':
83+
get:
84+
summary: 'Return the backend storage version used to store zone data.'
85+
description: 'This returns a backend-dependent version information. Currently only supported by the LMDB backend.'
86+
tags:
87+
- zones
88+
parameters:
89+
- name: server_id
90+
in: path
91+
required: true
92+
description: The id of the server to retrieve
93+
type: string
94+
- name: backend_id
95+
type: string
96+
in: path
97+
required: true
98+
description: The name of the backend to query
99+
responses:
100+
'200':
101+
description: Storage version number
102+
schema:
103+
$ref: '#/definitions/StorageVersion'
104+
<<: *commonErrors
105+
82106
'/servers/{server_id}/cache/flush':
83107
put:
84108
summary: Flush a cache-entry by name
@@ -1611,3 +1635,10 @@ definitions:
16111635
items:
16121636
$ref: '#/definitions/Network'
16131637

1638+
StorageVersion:
1639+
title: StorageVersion
1640+
description: 'The version number of the backend storage for a zone'
1641+
properties:
1642+
storageversion:
1643+
type: number
1644+

pdns/ws-auth.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,30 @@ static void apiServerAutoprimariesPOST(HttpRequest* req, HttpResponse* resp)
19261926
resp->status = 201;
19271927
}
19281928

1929+
static void apiServerBackendStorageVersion(HttpRequest* req, HttpResponse* resp)
1930+
{
1931+
const std::string backendName = req->parameters["id"];
1932+
UeberBackend backend;
1933+
for (auto& onebackend : backend.backends) {
1934+
if (onebackend->getPrefix() == backendName) {
1935+
auto version = onebackend->getStorageLayoutVersion();
1936+
if (version < 0) {
1937+
throw ApiException("Storage layout version not available");
1938+
}
1939+
1940+
if (req->accept_json) {
1941+
resp->setJsonBody(Json::object{{"storageversion", version}});
1942+
}
1943+
else {
1944+
resp->headers["Content-Type"] = "text/plain; charset=us-ascii";
1945+
resp->body = std::to_string(version);
1946+
}
1947+
return;
1948+
}
1949+
}
1950+
throw ApiException("Unknown backend");
1951+
}
1952+
19291953
// create new zone
19301954
static void apiServerZonesPOST(HttpRequest* req, HttpResponse* resp)
19311955
{
@@ -3020,6 +3044,7 @@ void AuthWebServer::webThread()
30203044
d_ws->registerApiHandler("/api/v1/servers/localhost/autoprimaries/<ip>/<nameserver>", &apiServerAutoprimaryDetailDELETE, "DELETE");
30213045
d_ws->registerApiHandler("/api/v1/servers/localhost/autoprimaries", &apiServerAutoprimariesGET, "GET");
30223046
d_ws->registerApiHandler("/api/v1/servers/localhost/autoprimaries", &apiServerAutoprimariesPOST, "POST");
3047+
d_ws->registerApiHandler("/api/v1/servers/localhost/backends/<id>/storageversion", apiServerBackendStorageVersion, "GET");
30233048
d_ws->registerApiHandler("/api/v1/servers/localhost/networks", apiServerNetworksGET, "GET");
30243049
d_ws->registerApiHandler("/api/v1/servers/localhost/networks/<ip>/<prefixlen>", apiServerNetworksGET, "GET");
30253050
d_ws->registerApiHandler("/api/v1/servers/localhost/networks/<ip>/<prefixlen>", apiServerNetworksPUT, "PUT");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import print_function
2+
import json
3+
import operator
4+
import unittest
5+
import requests.exceptions
6+
from test_helper import ApiTestCase, is_auth, is_auth_lmdb, BACKEND
7+
8+
@unittest.skipIf(not is_auth(), "Not applicable")
9+
class AuthBackends(ApiTestCase):
10+
11+
def test_storage_version(self):
12+
# Require a json answer to GET
13+
self.session.headers['Content-Type'] = 'application/json'
14+
r = self.session.get(self.url("/api/v1/servers/localhost/backends/" + BACKEND + "/storageversion"))
15+
if is_auth_lmdb():
16+
self.assertEqual(r.status_code, 200)
17+
self.assertGreater(r.json()['storageversion'], 5)
18+
else:
19+
self.assertEqual(r.status_code, 422)
20+

0 commit comments

Comments
 (0)