Remove wait parameter, ttl is required, remove unnecessary checks

This commit is contained in:
Mattia Codato 2020-06-26 09:33:23 +02:00
parent cc6fa66ba6
commit 714e75bbd1
1 changed files with 8 additions and 16 deletions

View File

@ -579,6 +579,10 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
Dictionary::Ptr resolvedMacros; Dictionary::Ptr resolvedMacros;
bool useResolvedMacros; bool useResolvedMacros;
if (params->Contains("macros") && !params->Get("macros").IsObjectType<Dictionary>()) {
return ApiActions::CreateResult(400, "macros must be a dictionary");
}
if (params->Contains("macros")) { if (params->Contains("macros")) {
resolvedMacros = HttpUtility::GetLastParameter(params, "macros"); resolvedMacros = HttpUtility::GetLastParameter(params, "macros");
useResolvedMacros = true; useResolvedMacros = true;
@ -593,10 +597,6 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
useResolvedMacros useResolvedMacros
); );
/* Check if resolved_endpoint is not empty */
if (resolved_endpoint.IsEmpty())
return ApiActions::CreateResult(400, "Endpoint must not be empty.");
/* Check if endpoint exists */ /* Check if endpoint exists */
if (!Endpoint::GetByName(resolved_endpoint)) if (!Endpoint::GetByName(resolved_endpoint))
return ApiActions::CreateResult(404, "Can't find a valid endpoint for '" + resolved_endpoint + "'."); return ApiActions::CreateResult(404, "Can't find a valid endpoint for '" + resolved_endpoint + "'.");
@ -645,22 +645,16 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
} else if (command_type == "NotificationCommand") { } else if (command_type == "NotificationCommand") {
if (!EventCommand::GetByName(resolved_command)) if (!EventCommand::GetByName(resolved_command))
return ApiActions::CreateResult(400, "Command '" + resolved_command + "' is not of type '" + command_type + "'."); return ApiActions::CreateResult(400, "Command '" + resolved_command + "' is not of type '" + command_type + "'.");
} else }
return ApiActions::CreateResult(400, "Invalid command_type '" + command_type + "'.");
/* Get TTL param */ /* Get TTL param */
double ttl = 0; /* FIXME default value? */ if (!params->Contains("ttl"))
if (params->Contains("ttl")) return ApiActions::CreateResult(400, "ttl is required");
ttl = HttpUtility::GetLastParameter(params, "ttl");
double ttl = HttpUtility::GetLastParameter(params, "ttl");
if (ttl <= 0) if (ttl <= 0)
return ApiActions::CreateResult(400, "ttl must be greater than 0"); return ApiActions::CreateResult(400, "ttl must be greater than 0");
/* Get wait param */
bool wait = false;
if (params->Contains("wait"))
wait = HttpUtility::GetLastParameter(params, "wait");
/* This generates a UUID */ /* This generates a UUID */
String uuid = Utility::NewUniqueID(); String uuid = Utility::NewUniqueID();
@ -725,8 +719,6 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
listener->SyncSendMessage(Endpoint::GetByName(resolved_endpoint), execMessage); listener->SyncSendMessage(Endpoint::GetByName(resolved_endpoint), execMessage);
/* TODO handle the wait */
Dictionary::Ptr result = new Dictionary(); Dictionary::Ptr result = new Dictionary();
result->Set(checkable->GetName(), uuid); result->Set(checkable->GetName(), uuid);
return ApiActions::CreateResult(202, "Accepted", result); return ApiActions::CreateResult(202, "Accepted", result);