@@ -54,8 +54,11 @@ Dictionary::Ptr ApiActions::CreateResult(int code, const String& status,
5454 return result;
5555}
5656
57- Dictionary::Ptr ApiActions::ProcessCheckResult (const ConfigObject::Ptr& object,
58- const Dictionary::Ptr& params)
57+ Dictionary::Ptr ApiActions::ProcessCheckResult (
58+ const ConfigObject::Ptr& object,
59+ const ApiUser::Ptr&,
60+ const Dictionary::Ptr& params
61+ )
5962{
6063 using Result = Checkable::ProcessingResult;
6164
@@ -141,8 +144,11 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
141144 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" );
142145}
143146
144- Dictionary::Ptr ApiActions::RescheduleCheck (const ConfigObject::Ptr& object,
145- const Dictionary::Ptr& params)
147+ Dictionary::Ptr ApiActions::RescheduleCheck (
148+ const ConfigObject::Ptr& object,
149+ const ApiUser::Ptr&,
150+ const Dictionary::Ptr& params
151+ )
146152{
147153 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
148154
@@ -166,8 +172,11 @@ Dictionary::Ptr ApiActions::RescheduleCheck(const ConfigObject::Ptr& object,
166172 return ApiActions::CreateResult (200 , " Successfully rescheduled check for object '" + checkable->GetName () + " '." );
167173}
168174
169- Dictionary::Ptr ApiActions::SendCustomNotification (const ConfigObject::Ptr& object,
170- const Dictionary::Ptr& params)
175+ Dictionary::Ptr ApiActions::SendCustomNotification (
176+ const ConfigObject::Ptr& object,
177+ const ApiUser::Ptr&,
178+ const Dictionary::Ptr& params
179+ )
171180{
172181 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
173182
@@ -189,8 +198,11 @@ Dictionary::Ptr ApiActions::SendCustomNotification(const ConfigObject::Ptr& obje
189198 return ApiActions::CreateResult (200 , " Successfully sent custom notification for object '" + checkable->GetName () + " '." );
190199}
191200
192- Dictionary::Ptr ApiActions::DelayNotification (const ConfigObject::Ptr& object,
193- const Dictionary::Ptr& params)
201+ Dictionary::Ptr ApiActions::DelayNotification (
202+ const ConfigObject::Ptr& object,
203+ const ApiUser::Ptr&,
204+ const Dictionary::Ptr& params
205+ )
194206{
195207 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
196208
@@ -207,8 +219,11 @@ Dictionary::Ptr ApiActions::DelayNotification(const ConfigObject::Ptr& object,
207219 return ApiActions::CreateResult (200 , " Successfully delayed notifications for object '" + checkable->GetName () + " '." );
208220}
209221
210- Dictionary::Ptr ApiActions::AcknowledgeProblem (const ConfigObject::Ptr& object,
211- const Dictionary::Ptr& params)
222+ Dictionary::Ptr ApiActions::AcknowledgeProblem (
223+ const ConfigObject::Ptr& object,
224+ const ApiUser::Ptr&,
225+ const Dictionary::Ptr& params
226+ )
212227{
213228 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
214229
@@ -269,8 +284,11 @@ Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object,
269284 return ApiActions::CreateResult (200 , " Successfully acknowledged problem for object '" + checkable->GetName () + " '." );
270285}
271286
272- Dictionary::Ptr ApiActions::RemoveAcknowledgement (const ConfigObject::Ptr& object,
273- const Dictionary::Ptr& params)
287+ Dictionary::Ptr ApiActions::RemoveAcknowledgement (
288+ const ConfigObject::Ptr& object,
289+ const ApiUser::Ptr&,
290+ const Dictionary::Ptr& params
291+ )
274292{
275293 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
276294
@@ -293,8 +311,11 @@ Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& objec
293311 return ApiActions::CreateResult (200 , " Successfully removed acknowledgement for object '" + checkable->GetName () + " '." );
294312}
295313
296- Dictionary::Ptr ApiActions::AddComment (const ConfigObject::Ptr& object,
297- const Dictionary::Ptr& params)
314+ Dictionary::Ptr ApiActions::AddComment (
315+ const ConfigObject::Ptr& object,
316+ const ApiUser::Ptr&,
317+ const Dictionary::Ptr& params
318+ )
298319{
299320 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
300321
@@ -332,8 +353,11 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
332353 + " '." , additional);
333354}
334355
335- Dictionary::Ptr ApiActions::RemoveComment (const ConfigObject::Ptr& object,
336- const Dictionary::Ptr& params)
356+ Dictionary::Ptr ApiActions::RemoveComment (
357+ const ConfigObject::Ptr& object,
358+ const ApiUser::Ptr&,
359+ const Dictionary::Ptr& params
360+ )
337361{
338362 ConfigObjectsSharedLock lock (std::try_to_lock);
339363
@@ -366,8 +390,11 @@ Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
366390 return ApiActions::CreateResult (200 , " Successfully removed comment '" + commentName + " '." );
367391}
368392
369- Dictionary::Ptr ApiActions::ScheduleDowntime (const ConfigObject::Ptr& object,
370- const Dictionary::Ptr& params)
393+ Dictionary::Ptr ApiActions::ScheduleDowntime (
394+ const ConfigObject::Ptr& object,
395+ const ApiUser::Ptr&,
396+ const Dictionary::Ptr& params
397+ )
371398{
372399 Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
373400
@@ -536,8 +563,11 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
536563 downtimeName + " ' for object '" + checkable->GetName () + " '." , additional);
537564}
538565
539- Dictionary::Ptr ApiActions::RemoveDowntime (const ConfigObject::Ptr& object,
540- const Dictionary::Ptr& params)
566+ Dictionary::Ptr ApiActions::RemoveDowntime (
567+ const ConfigObject::Ptr& object,
568+ const ApiUser::Ptr&,
569+ const Dictionary::Ptr& params
570+ )
541571{
542572 ConfigObjectsSharedLock lock (std::try_to_lock);
543573
@@ -589,24 +619,29 @@ Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
589619 }
590620}
591621
592- Dictionary::Ptr ApiActions::ShutdownProcess (const ConfigObject::Ptr&,
593- [[maybe_unused]] const Dictionary::Ptr& params)
622+ Dictionary::Ptr ApiActions::ShutdownProcess (
623+ const ConfigObject::Ptr&,
624+ const ApiUser::Ptr&,
625+ [[maybe_unused]] const Dictionary::Ptr& params
626+ )
594627{
595628 Application::RequestShutdown ();
596629
597630 return ApiActions::CreateResult (200 , " Shutting down Icinga 2." );
598631}
599632
600- Dictionary::Ptr ApiActions::RestartProcess (const ConfigObject::Ptr&,
601- [[maybe_unused]] const Dictionary::Ptr& params)
633+ Dictionary::Ptr ApiActions::RestartProcess (
634+ const ConfigObject::Ptr&,
635+ const ApiUser::Ptr&,
636+ [[maybe_unused]] const Dictionary::Ptr& params
637+ )
602638{
603639 Application::RequestRestart ();
604640
605641 return ApiActions::CreateResult (200 , " Restarting Icinga 2." );
606642}
607643
608- Dictionary::Ptr ApiActions::GenerateTicket (const ConfigObject::Ptr&,
609- const Dictionary::Ptr& params)
644+ Dictionary::Ptr ApiActions::GenerateTicket (const ConfigObject::Ptr&, const ApiUser::Ptr&, const Dictionary::Ptr& params)
610645{
611646 if (!params->Contains (" cn" ))
612647 return ApiActions::CreateResult (400 , " Option 'cn' is required" );
@@ -654,7 +689,11 @@ Value ApiActions::GetSingleObjectByNameUsingPermissions(const String& type, cons
654689 return objs.at (0 );
655690};
656691
657- Dictionary::Ptr ApiActions::ExecuteCommand (const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
692+ Dictionary::Ptr ApiActions::ExecuteCommand (
693+ const ConfigObject::Ptr& object,
694+ const ApiUser::Ptr& apiUser,
695+ const Dictionary::Ptr& params
696+ )
658697{
659698 ApiListener::Ptr listener = ApiListener::GetInstance ();
660699
@@ -718,11 +757,11 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
718757 nullptr , MacroProcessor::EscapeCallback (), nullptr , false
719758 );
720759
721- if (!ActionsHandler::AuthenticatedApiUser )
760+ if (!apiUser )
722761 BOOST_THROW_EXCEPTION (std::invalid_argument (" Can't find API user." ));
723762
724763 /* Get endpoint */
725- Endpoint::Ptr endpointPtr = GetSingleObjectByNameUsingPermissions (Endpoint::GetTypeName (), resolved_endpoint, ActionsHandler::AuthenticatedApiUser );
764+ Endpoint::Ptr endpointPtr = GetSingleObjectByNameUsingPermissions (Endpoint::GetTypeName (), resolved_endpoint, apiUser );
726765
727766 if (!endpointPtr)
728767 return ApiActions::CreateResult (404 , " Can't find a valid endpoint for '" + resolved_endpoint + " '." );
@@ -780,7 +819,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
780819 Dictionary::Ptr execParams = new Dictionary ();
781820
782821 if (command_type == " CheckCommand" ) {
783- CheckCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (CheckCommand::GetTypeName (), resolved_command, ActionsHandler::AuthenticatedApiUser );
822+ CheckCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (CheckCommand::GetTypeName (), resolved_command, apiUser );
784823
785824 if (!cmd)
786825 return ApiActions::CreateResult (404 , " Can't find a valid " + command_type + " for '" + resolved_command + " '." );
@@ -792,7 +831,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
792831 cmd->Execute (checkable, cr, listener->GetWaitGroup (), execMacros, false );
793832 }
794833 } else if (command_type == " EventCommand" ) {
795- EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (EventCommand::GetTypeName (), resolved_command, ActionsHandler::AuthenticatedApiUser );
834+ EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (EventCommand::GetTypeName (), resolved_command, apiUser );
796835
797836 if (!cmd)
798837 return ApiActions::CreateResult (404 , " Can't find a valid " + command_type + " for '" + resolved_command + " '." );
@@ -804,7 +843,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
804843 cmd->Execute (checkable, execMacros, false );
805844 }
806845 } else if (command_type == " NotificationCommand" ) {
807- NotificationCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (NotificationCommand::GetTypeName (), resolved_command, ActionsHandler::AuthenticatedApiUser );
846+ NotificationCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions (NotificationCommand::GetTypeName (), resolved_command, apiUser );
808847
809848 if (!cmd)
810849 return ApiActions::CreateResult (404 , " Can't find a valid " + command_type + " for '" + resolved_command + " '." );
@@ -821,7 +860,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
821860 MacroProcessor::EscapeCallback (), nullptr , false
822861 );
823862
824- User::Ptr user = GetSingleObjectByNameUsingPermissions (User::GetTypeName (), resolved_user, ActionsHandler::AuthenticatedApiUser );
863+ User::Ptr user = GetSingleObjectByNameUsingPermissions (User::GetTypeName (), resolved_user, apiUser );
825864
826865 if (!user)
827866 return ApiActions::CreateResult (404 , " Can't find a valid user for '" + resolved_user + " '." );
@@ -840,7 +879,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
840879 MacroProcessor::EscapeCallback (), nullptr , false
841880 );
842881
843- Notification::Ptr notification = GetSingleObjectByNameUsingPermissions (Notification::GetTypeName (), resolved_notification, ActionsHandler::AuthenticatedApiUser );
882+ Notification::Ptr notification = GetSingleObjectByNameUsingPermissions (Notification::GetTypeName (), resolved_notification, apiUser );
844883
845884 if (!notification)
846885 return ApiActions::CreateResult (404 , " Can't find a valid notification for '" + resolved_notification + " '." );
@@ -853,7 +892,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
853892 });
854893
855894 cmd->Execute (notification, user, cr, NotificationType::NotificationCustom,
856- ActionsHandler::AuthenticatedApiUser ->GetName (), " " , execMacros, false );
895+ apiUser ->GetName (), " " , execMacros, false );
857896 }
858897 }
859898
0 commit comments