Make authenticatedApiUser a static property of ActionsHandler

This commit is contained in:
Mattia Codato 2020-07-03 11:00:40 +02:00
parent 27a6fd6b40
commit 08c6e9bc42
3 changed files with 9 additions and 10 deletions

View File

@ -689,12 +689,11 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
return ApiActions::CreateResult(404, "Can't find a valid notification for '" + resolved_notification + "'."); return ApiActions::CreateResult(404, "Can't find a valid notification for '" + resolved_notification + "'.");
/* Get author */ /* Get author */
if (!authenticatedApiUser) if (!ActionsHandler::authenticatedApiUser)
return ApiActions::CreateResult(401, "Can't find API user"); BOOST_THROW_EXCEPTION(std::invalid_argument("Can't find API user."));
String author = authenticatedApiUser->GetName(); cmd->Execute(notification, user, cr, NotificationType::NotificationCustom,
ActionsHandler::authenticatedApiUser->GetName(), "", execMacros, false);
cmd->Execute(notification, user, cr, NotificationType::NotificationCustom, author, "", execMacros, false);
} }
} }

View File

@ -11,7 +11,7 @@
using namespace icinga; using namespace icinga;
thread_local ApiUser::Ptr authenticatedApiUser; thread_local ApiUser::Ptr ActionsHandler::authenticatedApiUser;
REGISTER_URLHANDLER("/v1/actions", ActionsHandler); REGISTER_URLHANDLER("/v1/actions", ActionsHandler);
@ -74,9 +74,9 @@ bool ActionsHandler::HandleRequest(
bool verbose = false; bool verbose = false;
authenticatedApiUser = user; ActionsHandler::authenticatedApiUser = user;
Defer a ([&]() { Defer a ([&]() {
authenticatedApiUser = nullptr; ActionsHandler::authenticatedApiUser = nullptr;
}); });
if (params) if (params)

View File

@ -5,8 +5,6 @@
#include "remote/httphandler.hpp" #include "remote/httphandler.hpp"
extern thread_local icinga::ApiUser::Ptr authenticatedApiUser;
namespace icinga namespace icinga
{ {
@ -15,6 +13,8 @@ class ActionsHandler final : public HttpHandler
public: public:
DECLARE_PTR_TYPEDEFS(ActionsHandler); DECLARE_PTR_TYPEDEFS(ActionsHandler);
static thread_local ApiUser::Ptr authenticatedApiUser;
bool HandleRequest( bool HandleRequest(
AsioTlsStream& stream, AsioTlsStream& stream,
const ApiUser::Ptr& user, const ApiUser::Ptr& user,