mirror of https://github.com/Icinga/icinga2.git
Get API user from ActionsHandler
This commit is contained in:
parent
670835fd9a
commit
27a6fd6b40
|
@ -15,6 +15,7 @@
|
|||
#include "remote/httputility.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include "base/convert.hpp"
|
||||
#include "remote/actionshandler.hpp"
|
||||
#include <fstream>
|
||||
|
||||
using namespace icinga;
|
||||
|
@ -688,9 +689,10 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
|
|||
return ApiActions::CreateResult(404, "Can't find a valid notification for '" + resolved_notification + "'.");
|
||||
|
||||
/* Get author */
|
||||
String author = "";
|
||||
if (params->Contains("author"))
|
||||
author = HttpUtility::GetLastParameter(params, "author");
|
||||
if (!authenticatedApiUser)
|
||||
return ApiActions::CreateResult(401, "Can't find API user");
|
||||
|
||||
String author = authenticatedApiUser->GetName();
|
||||
|
||||
cmd->Execute(notification, user, cr, NotificationType::NotificationCustom, author, "", execMacros, false);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
#include "remote/httputility.hpp"
|
||||
#include "remote/filterutility.hpp"
|
||||
#include "remote/apiaction.hpp"
|
||||
#include "base/defer.hpp"
|
||||
#include "base/exception.hpp"
|
||||
#include "base/logger.hpp"
|
||||
#include <set>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
thread_local ApiUser::Ptr authenticatedApiUser;
|
||||
|
||||
REGISTER_URLHANDLER("/v1/actions", ActionsHandler);
|
||||
|
||||
bool ActionsHandler::HandleRequest(
|
||||
|
@ -71,6 +74,11 @@ bool ActionsHandler::HandleRequest(
|
|||
|
||||
bool verbose = false;
|
||||
|
||||
authenticatedApiUser = user;
|
||||
Defer a ([&]() {
|
||||
authenticatedApiUser = nullptr;
|
||||
});
|
||||
|
||||
if (params)
|
||||
verbose = HttpUtility::GetLastParameter(params, "verbose");
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "remote/httphandler.hpp"
|
||||
|
||||
extern thread_local icinga::ApiUser::Ptr authenticatedApiUser;
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue