@@ -53,8 +53,11 @@ Dictionary::Ptr ApiActions::CreateResult(int code, const String& status,
5353 return result;
5454}
5555
56- Dictionary::Ptr ApiActions::ProcessCheckResult (const ConfigObject::Ptr& object,
57- const Dictionary::Ptr& params)
56+ Dictionary::Ptr ApiActions::ProcessCheckResult (
57+ const ConfigObject::Ptr& object,
58+ const ApiUser::Ptr&,
59+ const Dictionary::Ptr& params
60+ )
5861{
5962 using Result = Checkable::ProcessingResult;
6063
@@ -140,8 +143,11 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
140143 return ApiActions::CreateResult (500 , " Unexpected result (" + std::to_string (static_cast <int >(result)) + " ) for object '" + checkable->GetName () + " '. Please submit a bug report at https://github.com/Icinga/icinga2" );
141144}
142145
143- Dictionary::Ptr ApiActions::RescheduleCheck (const ConfigObject::Ptr& object,
144- const Dictionary::Ptr& params)
146+ Dictionary::Ptr ApiActions::RescheduleCheck (
147+ const ConfigObject::Ptr& object,
148+ const ApiUser::Ptr&,
149+ const Dictionary::Ptr& params
150+ )
145151{
146152 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
147153
@@ -165,8 +171,11 @@ Dictionary::Ptr ApiActions::RescheduleCheck(const ConfigObject::Ptr& object,
165171 return ApiActions::CreateResult (200 , " Successfully rescheduled check for object '" + checkable->GetName () + " '." );
166172}
167173
168- Dictionary::Ptr ApiActions::SendCustomNotification (const ConfigObject::Ptr& object,
169- const Dictionary::Ptr& params)
174+ Dictionary::Ptr ApiActions::SendCustomNotification (
175+ const ConfigObject::Ptr& object,
176+ const ApiUser::Ptr&,
177+ const Dictionary::Ptr& params
178+ )
170179{
171180 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
172181
@@ -188,8 +197,11 @@ Dictionary::Ptr ApiActions::SendCustomNotification(const ConfigObject::Ptr& obje
188197 return ApiActions::CreateResult (200 , " Successfully sent custom notification for object '" + checkable->GetName () + " '." );
189198}
190199
191- Dictionary::Ptr ApiActions::DelayNotification (const ConfigObject::Ptr& object,
192- const Dictionary::Ptr& params)
200+ Dictionary::Ptr ApiActions::DelayNotification (
201+ const ConfigObject::Ptr& object,
202+ const ApiUser::Ptr&,
203+ const Dictionary::Ptr& params
204+ )
193205{
194206 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
195207
@@ -206,8 +218,11 @@ Dictionary::Ptr ApiActions::DelayNotification(const ConfigObject::Ptr& object,
206218 return ApiActions::CreateResult (200 , " Successfully delayed notifications for object '" + checkable->GetName () + " '." );
207219}
208220
209- Dictionary::Ptr ApiActions::AcknowledgeProblem (const ConfigObject::Ptr& object,
210- const Dictionary::Ptr& params)
221+ Dictionary::Ptr ApiActions::AcknowledgeProblem (
222+ const ConfigObject::Ptr& object,
223+ const ApiUser::Ptr&,
224+ const Dictionary::Ptr& params
225+ )
211226{
212227 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
213228
@@ -268,8 +283,11 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object,
268283 return ApiActions::CreateResult (200 , " Successfully acknowledged problem for object '" + checkable->GetName () + " '." );
269284}
270285
271- Dictionary::Ptr ApiActions::RemoveAcknowledgement (const ConfigObject::Ptr& object,
272- const Dictionary::Ptr& params)
286+ Dictionary::Ptr ApiActions::RemoveAcknowledgement (
287+ const ConfigObject::Ptr& object,
288+ const ApiUser::Ptr&,
289+ const Dictionary::Ptr& params
290+ )
273291{
274292 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
275293
@@ -292,8 +310,11 @@ Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& objec
292310 return ApiActions::CreateResult (200 , " Successfully removed acknowledgement for object '" + checkable->GetName () + " '." );
293311}
294312
295- Dictionary::Ptr ApiActions::AddComment (const ConfigObject::Ptr& object,
296- const Dictionary::Ptr& params)
313+ Dictionary::Ptr ApiActions::AddComment (
314+ const ConfigObject::Ptr& object,
315+ const ApiUser::Ptr&,
316+ const Dictionary::Ptr& params
317+ )
297318{
298319 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
299320
@@ -331,8 +352,11 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
331352 + " '." , additional);
332353}
333354
334- Dictionary::Ptr ApiActions::RemoveComment (const ConfigObject::Ptr& object,
335- const Dictionary::Ptr& params)
355+ Dictionary::Ptr ApiActions::RemoveComment (
356+ const ConfigObject::Ptr& object,
357+ const ApiUser::Ptr&,
358+ const Dictionary::Ptr& params
359+ )
336360{
337361 ConfigObjectsSharedLock lock (std::try_to_lock);
338362
@@ -365,8 +389,11 @@ Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
365389 return ApiActions::CreateResult (200 , " Successfully removed comment '" + commentName + " '." );
366390}
367391
368- Dictionary::Ptr ApiActions::ScheduleDowntime (const ConfigObject::Ptr& object,
369- const Dictionary::Ptr& params)
392+ Dictionary::Ptr ApiActions::ScheduleDowntime (
393+ const ConfigObject::Ptr& object,
394+ const ApiUser::Ptr&,
395+ const Dictionary::Ptr& params
396+ )
370397{
371398 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
372399
@@ -535,8 +562,11 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
535562 downtimeName + " ' for object '" + checkable->GetName () + " '." , additional);
536563}
537564
538- Dictionary::Ptr ApiActions::RemoveDowntime (const ConfigObject::Ptr& object,
539- const Dictionary::Ptr& params)
565+ Dictionary::Ptr ApiActions::RemoveDowntime (
566+ const ConfigObject::Ptr& object,
567+ const ApiUser::Ptr&,
568+ const Dictionary::Ptr& params
569+ )
540570{
541571 ConfigObjectsSharedLock lock (std::try_to_lock);
542572
@@ -588,24 +618,21 @@ Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
588618 }
589619}
590620
591- Dictionary::Ptr ApiActions::ShutdownProcess (const ConfigObject::Ptr& object,
592- const Dictionary::Ptr& params)
621+ Dictionary::Ptr ApiActions::ShutdownProcess (const ConfigObject::Ptr&, const ApiUser::Ptr&, const Dictionary::Ptr&)
593622{
594623 Application::RequestShutdown ();
595624
596625 return ApiActions::CreateResult (200 , " Shutting down Icinga 2." );
597626}
598627
599- Dictionary::Ptr ApiActions::RestartProcess (const ConfigObject::Ptr& object,
600- const Dictionary::Ptr& params)
628+ Dictionary::Ptr ApiActions::RestartProcess (const ConfigObject::Ptr&, const ApiUser::Ptr&, const Dictionary::Ptr&)
601629{
602630 Application::RequestRestart ();
603631
604632 return ApiActions::CreateResult (200 , " Restarting Icinga 2." );
605633}
606634
607- Dictionary::Ptr ApiActions::GenerateTicket (const ConfigObject::Ptr&,
608- const Dictionary::Ptr& params)
635+ Dictionary::Ptr ApiActions::GenerateTicket (const ConfigObject::Ptr&, const ApiUser::Ptr&, const Dictionary::Ptr& params)
609636{
610637 if (!params->Contains (" cn" ))
611638 return ApiActions::CreateResult (400 , " Option 'cn' is required" );
@@ -653,7 +680,11 @@ Value ApiActions::GetSingleObjectByNameUsingPermissions(const String& type, cons
653680 return objs.at (0 );
654681};
655682
656- Dictionary::Ptr ApiActions::ExecuteCommand (const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
683+ Dictionary::Ptr ApiActions::ExecuteCommand (
684+ const ConfigObject::Ptr& object,
685+ const ApiUser::Ptr& apiUser,
686+ const Dictionary::Ptr& params
687+ )
657688{
658689 ApiListener::Ptr listener = ApiListener::GetInstance ();
659690
@@ -717,11 +748,11 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
717748 nullptr , MacroProcessor::EscapeCallback (), nullptr , false
718749 );
719750
720- if (!ActionsHandler::AuthenticatedApiUser )
751+ if (!apiUser )
721752 BOOST_THROW_EXCEPTION (std::invalid_argument (" Can't find API user." ));
722753
723754 /* Get endpoint */
724- Endpoint::Ptr endpointPtr = GetSingleObjectByNameUsingPermissions (Endpoint::GetTypeName (), resolved_endpoint, ActionsHandler::AuthenticatedApiUser );
755+ Endpoint::Ptr endpointPtr = GetSingleObjectByNameUsingPermissions (Endpoint::GetTypeName (), resolved_endpoint, apiUser );
725756
726757 if (!endpointPtr)
727758 return ApiActions::CreateResult (404 , " Can't find a valid endpoint for '" + resolved_endpoint + " '." );
@@ -779,7 +810,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
779810 Dictionary::Ptr execParams = new Dictionary ();
780811
781812 if (command_type == " CheckCommand" ) {
782- CheckCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (CheckCommand::GetTypeName (), resolved_command, ActionsHandler::AuthenticatedApiUser );
813+ CheckCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (CheckCommand::GetTypeName (), resolved_command, apiUser );
783814
784815 if (!cmd)
785816 return ApiActions::CreateResult (404 , " Can't find a valid " + command_type + " for '" + resolved_command + " '." );
@@ -791,7 +822,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
791822 cmd->Execute (checkable, cr, listener->GetWaitGroup (), execMacros, false );
792823 }
793824 } else if (command_type == " EventCommand" ) {
794- EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (EventCommand::GetTypeName (), resolved_command, ActionsHandler::AuthenticatedApiUser );
825+ EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (EventCommand::GetTypeName (), resolved_command, apiUser );
795826
796827 if (!cmd)
797828 return ApiActions::CreateResult (404 , " Can't find a valid " + command_type + " for '" + resolved_command + " '." );
@@ -803,7 +834,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
803834 cmd->Execute (checkable, execMacros, false );
804835 }
805836 } else if (command_type == " NotificationCommand" ) {
806- NotificationCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (NotificationCommand::GetTypeName (), resolved_command, ActionsHandler::AuthenticatedApiUser );
837+ NotificationCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (NotificationCommand::GetTypeName (), resolved_command, apiUser );
807838
808839 if (!cmd)
809840 return ApiActions::CreateResult (404 , " Can't find a valid " + command_type + " for '" + resolved_command + " '." );
@@ -820,7 +851,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
820851 MacroProcessor::EscapeCallback (), nullptr , false
821852 );
822853
823- User::Ptr user = GetSingleObjectByNameUsingPermissions (User::GetTypeName (), resolved_user, ActionsHandler::AuthenticatedApiUser );
854+ User::Ptr user = GetSingleObjectByNameUsingPermissions (User::GetTypeName (), resolved_user, apiUser );
824855
825856 if (!user)
826857 return ApiActions::CreateResult (404 , " Can't find a valid user for '" + resolved_user + " '." );
@@ -839,7 +870,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
839870 MacroProcessor::EscapeCallback (), nullptr , false
840871 );
841872
842- Notification::Ptr notification = GetSingleObjectByNameUsingPermissions (Notification::GetTypeName (), resolved_notification, ActionsHandler::AuthenticatedApiUser );
873+ Notification::Ptr notification = GetSingleObjectByNameUsingPermissions (Notification::GetTypeName (), resolved_notification, apiUser );
843874
844875 if (!notification)
845876 return ApiActions::CreateResult (404 , " Can't find a valid notification for '" + resolved_notification + " '." );
@@ -852,7 +883,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
852883 });
853884
854885 cmd->Execute (notification, user, cr, NotificationType::NotificationCustom,
855- ActionsHandler::AuthenticatedApiUser ->GetName (), " " , execMacros, false );
886+ apiUser ->GetName (), " " , execMacros, false );
856887 }
857888 }
858889
0 commit comments