From 3c5acf6717bff737a735b06d4a27429c9621dcd1 Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Wed, 27 Nov 2019 17:29:35 +0100 Subject: [PATCH] check before foxx-heal (#10512) * check before foxx-heal * be more graceful --- arangod/RestHandler/RestStatusHandler.cpp | 1 + arangosh/Restore/RestoreFeature.cpp | 25 ++++++++++++++++--- .../test-hardened-rest-apis.js | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/arangod/RestHandler/RestStatusHandler.cpp b/arangod/RestHandler/RestStatusHandler.cpp index e1ee319836..36e143ff01 100644 --- a/arangod/RestHandler/RestStatusHandler.cpp +++ b/arangod/RestHandler/RestStatusHandler.cpp @@ -79,6 +79,7 @@ RestStatus RestStatusHandler::execute() { auto& serverFeature = server.getFeature(); result.add("mode", VPackValue(serverFeature.operationModeString())); // to be deprecated - 3.3 compat result.add("operationMode", VPackValue(serverFeature.operationModeString())); + result.add("foxxApi", VPackValue(!security.isFoxxApiDisabled())); std::string host = ServerState::instance()->getHost(); diff --git a/arangosh/Restore/RestoreFeature.cpp b/arangosh/Restore/RestoreFeature.cpp index 2419a2fd83..5afac2deaa 100644 --- a/arangosh/Restore/RestoreFeature.cpp +++ b/arangosh/Restore/RestoreFeature.cpp @@ -816,13 +816,32 @@ arangodb::Result restoreView(arangodb::httpclient::SimpleHttpClient& httpClient, arangodb::Result triggerFoxxHeal(arangodb::httpclient::SimpleHttpClient& httpClient) { using arangodb::Logger; using arangodb::httpclient::SimpleHttpResult; - const std::string FoxxHealUrl = "/_api/foxx/_local/heal"; - std::string body = ""; + // check if the foxx api is available. + const std::string statusUrl = "/_admin/status"; std::unique_ptr response( - httpClient.request(arangodb::rest::RequestType::POST, FoxxHealUrl, + httpClient.request(arangodb::rest::RequestType::POST, statusUrl, body.c_str(), body.length())); + + auto res = ::checkHttpResponse(httpClient, response, "check status", body); + if (res.ok() && response) { + try { + if(!response->getBodyVelocyPack()->slice().get("foxxApi").getBool()) { + LOG_TOPIC("9e9b9", INFO, Logger::RESTORE) + << "skipping foxx self-healing because Foxx API is disabled"; + return { }; + } + } catch (...) { + //API Not available because of older version or whatever + } + } + + const std::string FoxxHealUrl = "/_api/foxx/_local/heal"; + response.reset( + httpClient.request(arangodb::rest::RequestType::POST, FoxxHealUrl, + body.c_str(), body.length()) + ); return ::checkHttpResponse(httpClient, response, "trigger self heal", body); } diff --git a/tests/js/client/server_permissions/test-hardened-rest-apis.js b/tests/js/client/server_permissions/test-hardened-rest-apis.js index 7d9c51a818..f43141ac1d 100644 --- a/tests/js/client/server_permissions/test-hardened-rest-apis.js +++ b/tests/js/client/server_permissions/test-hardened-rest-apis.js @@ -100,6 +100,7 @@ function testSuite() { assertTrue(result.hasOwnProperty("serverInfo")); assertTrue(result.hasOwnProperty("server")); assertTrue(result.hasOwnProperty("pid")); + assertTrue(result.hasOwnProperty("foxxApi")); }, testCanAccessAdminStatusRo : function() { @@ -111,6 +112,7 @@ function testSuite() { assertFalse(result.hasOwnProperty("serverInfo")); assertFalse(result.hasOwnProperty("server")); assertFalse(result.hasOwnProperty("pid")); + assertFalse(result.hasOwnProperty("foxxApi")); }, testCanAccessAdminLogRw : function() {