From: Chris Hofstaedtler Date: Sat, 12 Aug 2023 11:44:46 +0000 (+0200) Subject: API Auth: dedup "is API-RECTIFY enabled" code X-Git-Tag: rec-5.0.0-alpha1~24^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d71d2c883cf144712220ca3538b816cdf19fda93;p=thirdparty%2Fpdns.git API Auth: dedup "is API-RECTIFY enabled" code --- diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 6e0b25de27..8f6775c6e1 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -643,6 +643,15 @@ static void addDefaultDNSSECKeys(DNSSECKeeper& dk, const DNSName& zonename) { } } +static bool isZoneApiRectifyEnabled(const DomainInfo& di) { + string api_rectify; + di.backend->getDomainMetadataOne(di.zone, "API-RECTIFY", api_rectify); + if (api_rectify.empty() && ::arg().mustDo("default-api-rectify")) { + api_rectify = "1"; + } + return api_rectify == "1"; +} + static void extractDomainInfoFromDocument(const Json& document, boost::optional& kind, boost::optional>& masters, boost::optional& catalog, boost::optional& account) { if (document["kind"].is_string()) { @@ -818,14 +827,7 @@ static void updateDomainSettingsFromDocument(UeberBackend& B, DomainInfo& di, co if (shouldRectify && !isPresigned) { // Rectify - string api_rectify; - di.backend->getDomainMetadataOne(zonename, "API-RECTIFY", api_rectify); - if (api_rectify.empty()) { - if (::arg().mustDo("default-api-rectify")) { - api_rectify = "1"; - } - } - if (api_rectify == "1") { + if (isZoneApiRectifyEnabled(di)) { string info; string error_msg; if (!dk.rectifyZone(zonename, error_msg, info, false) && !di.isSecondaryType()) { @@ -2350,17 +2352,11 @@ static void patchZone(UeberBackend& B, HttpRequest* req, HttpResponse* resp) // // Rectify DNSSECKeeper dk(&B); - if (!zone_disabled && !dk.isPresigned(zonename)) { - string api_rectify; - if (!di.backend->getDomainMetadataOne(zonename, "API-RECTIFY", api_rectify) && ::arg().mustDo("default-api-rectify")) { - api_rectify = "1"; - } - if (api_rectify == "1") { - string info; - string error_msg; - if (!dk.rectifyZone(zonename, error_msg, info, false)) { - throw ApiException("Failed to rectify '" + zonename.toString() + "' " + error_msg); - } + if (!zone_disabled && !dk.isPresigned(zonename) && isZoneApiRectifyEnabled(di)) { + string info; + string error_msg; + if (!dk.rectifyZone(zonename, error_msg, info, false)) { + throw ApiException("Failed to rectify '" + zonename.toString() + "' " + error_msg); } }