MCPcopy Create free account
hub / github.com/Icinga/icinga2 / AutocompleteScriptHelper

Method AutocompleteScriptHelper

lib/remote/consolehandler.cpp:203–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203bool ConsoleHandler::AutocompleteScriptHelper(const HttpApiRequest& request, HttpApiResponse& response,
204 const String& command, const String& session, bool sandboxed)
205{
206 namespace http = boost::beast::http;
207
208 Log(LogInformation, "Console")
209 << "Auto-completing expression: " << command;
210
211 EnsureFrameCleanupTimer();
212
213 auto lsf = GetOrCreateScriptFrame(session);
214
215 std::unique_lock frameLock(lsf->Mutex, std::try_to_lock);
216 if (!frameLock) {
217 HttpUtility::SendJsonError(response, request.Params(), 409, "Session is currently in use by another request.");
218 return true;
219 }
220
221 lsf->Seen = Utility::GetTime();
222
223 if (!lsf->Locals)
224 lsf->Locals = new Dictionary();
225
226
227 ScriptFrame frame(true);
228 frame.Locals = lsf->Locals;
229 frame.Self = lsf->Locals;
230 frame.Sandboxed = sandboxed;
231
232 Dictionary::Ptr result1 = new Dictionary({
233 { "code", 200 },
234 { "status", "Auto-completed successfully." },
235 { "suggestions", Array::FromVector(GetAutocompletionSuggestions(command, frame)) }
236 });
237
238 Dictionary::Ptr result = new Dictionary({
239 { "results", new Array({ result1 }) }
240 });
241
242 response.result(http::status::ok);
243 HttpUtility::SendJsonBody(response, request.Params(), result);
244
245 return true;
246}
247
248static void AddSuggestion(std::vector<String>& matches, const String& word, const String& suggestion)
249{

Callers

nothing calls this directly

Calls 4

LogClass · 0.85
EnsureFrameCleanupTimerFunction · 0.85
GetOrCreateScriptFrameFunction · 0.85
ParamsMethod · 0.80

Tested by

no test coverage detected