From 87c545230cf61224c3de087b194b44eb6a98fb75 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 1 Feb 2016 14:19:25 -0500 Subject: [PATCH] New API: Change the sysadm dispatcher access to use the built-in dispatcher system now instead of the old shell script. This new API will have the server queue up generic processes/commands as the user needs (main output will return through the event system). The example blow included a single command queue (procID1), as well an an example of chaining a couple commands together as a single process call (procID2). REST Request: ------------------------------- PUT /rpc/dispatcher { "action" : "run", "procID2" : [ "echo chainCmd1", "echo chainCmd2" ], "procID1" : "echo sample1" } REST Response: ------------------------------- { "args": { "started": [ "procID1", "procID2" ] } } WebSocket Request: ------------------------------- { "name" : "dispatcher", "namespace" : "rpc", "id" : "fooid", "args" : { "procID1" : "echo sample1", "procID2" : [ "echo chainCmd1", "echo chainCmd2" ], "action" : "run" } } WebSocket Response: ------------------------------- { "args": { "started": [ "procID1", "procID2" ] }, "id": "fooid", "name": "response", "namespace": "rpc" } --- src/server/WebBackend.cpp | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 76bd0f4..f618e3e 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -142,26 +142,32 @@ RestOutputStruct::ExitCode WebSocket::EvaluateDispatcherRequest(bool allaccess, QString act = in_args.toObject().value("action").toString().toLower(); //Determing the type of action to perform - if(act=="run"){ } - if(!allaccess){ - return RestOutputStruct::FORBIDDEN; //this user does not have permission to queue jobs + if(act=="run"){ + if(!allaccess){ return RestOutputStruct::FORBIDDEN; } //this user does not have permission to queue jobs + QStringList ids = in_args.toObject().keys(); + ids.removeAll("action"); //already handled the action + for(int i=0; iqueueProcess(ids[i], cmds); + } + //Return the PENDING result + out->insert("started", QJsonArray::fromStringList(ids)); + //}else if(act=="read"){ + + }else{ + return RestOutputStruct::BADREQUEST; } - - - //Parse the input arguments structure - /*if(in_args.isArray()){ in_req = JsonArrayToStringList(in_args.toArray()); } - else if(in_args.isObject()){ - QStringList keys = in_args.toObject().keys(); - for(int i=0; iinsert(in_req[i],values[i]); }*/ //Return Success return RestOutputStruct::OK; }