|
19 | 19 | check_pdns_search_allowed, |
20 | 20 | check_pdns_cryptokeys_allowed, |
21 | 21 | check_pdns_tsigkeys_allowed, |
| 22 | + check_pdns_config_allowed, |
| 23 | + check_pdns_statistics_allowed, |
22 | 24 | check_pdns_zone_admin, |
23 | 25 | check_pdns_zone_allowed, |
24 | 26 | dependency_check_token_defined, |
@@ -216,31 +218,64 @@ async def get_server(server_id: str): |
216 | 218 |
|
217 | 219 |
|
218 | 220 | @router_pdns.get( |
219 | | - "/servers/{server_id}/configuration", |
| 221 | + "/servers/{server_id}/config", |
220 | 222 | ) |
221 | | -async def get_configuration(server_id: str): |
| 223 | +async def get_configuration(server_id: str, X_API_Key: str = Header()): |
222 | 224 | """ |
223 | 225 | Retrieve a list of configuration items for the server. |
224 | | - Currently returns empty, as we don't want to expose the global backend configuration. |
| 226 | +
|
| 227 | + Requires global_config permission. |
225 | 228 | """ |
226 | | - _ = server_id |
227 | | - raise RessourceNotAllowedException() |
| 229 | + environment = get_environment_for_token(config, X_API_Key) |
| 230 | + if not check_pdns_config_allowed(environment): |
| 231 | + raise RessourceNotAllowedException() |
| 232 | + |
| 233 | + resp = await pdns.get(f"/api/v1/servers/{server_id}/config") |
| 234 | + pdns_response = await handle_pdns_response(resp) |
| 235 | + status_code = pdns_response.raise_for_error() |
| 236 | + return JSONResponse(content=pdns_response.data, status_code=status_code) |
228 | 237 |
|
229 | 238 |
|
230 | 239 | @router_pdns.get( |
231 | | - "/servers/{server_id}/statistics", |
| 240 | + "/servers/{server_id}/config/{config_setting_name}", |
232 | 241 | ) |
233 | | -async def get_statistics( |
234 | | - server_id: str, |
| 242 | +async def get_configuration_setting( |
| 243 | + server_id: str, config_setting_name: str, X_API_Key: str = Header() |
235 | 244 | ): |
| 245 | + """ |
| 246 | + Retrieve a single configuration setting. |
| 247 | +
|
| 248 | + Requires global_config permission. |
| 249 | + """ |
| 250 | + environment = get_environment_for_token(config, X_API_Key) |
| 251 | + if not check_pdns_config_allowed(environment): |
| 252 | + raise RessourceNotAllowedException() |
| 253 | + |
| 254 | + resp = await pdns.get(f"/api/v1/servers/{server_id}/config/{config_setting_name}") |
| 255 | + pdns_response = await handle_pdns_response(resp) |
| 256 | + status_code = pdns_response.raise_for_error() |
| 257 | + return JSONResponse(content=pdns_response.data, status_code=status_code) |
| 258 | + |
| 259 | + |
| 260 | +@router_pdns.get( |
| 261 | + "/servers/{server_id}/statistics", |
| 262 | +) |
| 263 | +async def get_statistics(server_id: str, X_API_Key: str = Header()): |
236 | 264 | """ |
237 | 265 | Retrieve a list of statistics about the server. |
238 | | - Currently returns empty, as we don't want to expose the global backend statistics. |
| 266 | +
|
| 267 | + Requires global_statistics permission. |
239 | 268 |
|
240 | 269 | <https://doc.powerdns.com/authoritative/http-api/statistics.html#get--servers-server_id-statistics> |
241 | 270 | """ |
242 | | - _ = server_id |
243 | | - raise RessourceNotAllowedException() |
| 271 | + environment = get_environment_for_token(config, X_API_Key) |
| 272 | + if not check_pdns_statistics_allowed(environment): |
| 273 | + raise RessourceNotAllowedException() |
| 274 | + |
| 275 | + resp = await pdns.get(f"/api/v1/servers/{server_id}/statistics") |
| 276 | + pdns_response = await handle_pdns_response(resp) |
| 277 | + status_code = pdns_response.raise_for_error() |
| 278 | + return JSONResponse(content=pdns_response.data, status_code=status_code) |
244 | 279 |
|
245 | 280 |
|
246 | 281 | @router_pdns.get( |
|
0 commit comments