backend work for source control api

This commit is contained in:
q5sys
2017-11-02 10:02:03 -04:00
parent ce53715265
commit 62655ebd41
4 changed files with 71 additions and 3 deletions

View File

@@ -10,6 +10,8 @@
#include "EventWatcher.h"
#include "Dispatcher.h"
#include "library/sysadm-update.h"
#include "library/sysadm-sourcectl.h"
QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObject log, bool full_log){
//NOTE: full_log = true when the process has finished. If it is false, the process is still running and you are probably getting an incremental update of the process log
@@ -79,8 +81,33 @@ QJsonObject Dispatcher::CreateDispatcherEventNotification(QString ID, QJsonObjec
args.insert("impacts_pkgs",QJsonArray::fromStringList(effects));
}
// == sysadm/sourcecrl ==
}else if(ID.startsWith("sysadm_sourcectl")){
if(ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){
namesp = "sysadm"; name="soucectl";
//No special parsing here: the git output should be available as-is
args.insert("update_log",cLog);
}else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadsource"){
//qDebug() << "Got update check process finished";
sysadm::sourcectl::saveSourceLog(cLog); //save this for use later
}
}else if(ID.startsWith("sysadm_sourcectl")){
if(ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){
namesp = "sysadm"; name="soucectl";
//No special parsing here: the git output should be available as-is
args.insert("update_log",cLog);
}else if(full_log && ID.section("::",0,0)=="sysadm_sourcectl_downloadports"){
//qDebug() << "Got update check process finished";
sysadm::sourcectl::savePortsLog(cLog); //save this for use later
}
}
//Now assemble the output as needed
if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event
args.insert("event_system",namesp+"/"+name);
return args;
//Now assemble the output as needed
if(namesp.isEmpty() || name.isEmpty()){ return QJsonObject(); } //no event
args.insert("event_system",namesp+"/"+name);

View File

@@ -25,6 +25,7 @@
#include "library/sysadm-firewall.h"
#include "library/sysadm-moused.h"
#include "library/sysadm-powerd.h"
#include "library/sysadm-sourcectl.h"
#define DEBUG 0
//#define SCLISTDELIM QString("::::") //SysCache List Delimiter
@@ -45,7 +46,6 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
out->insert("sysadm/beadm", "read/write");
}
// - dispatcher (Internal to server - always available)
//"read" is the event notifications, "write" is the ability to queue up jobs
out->insert("rpc/dispatcher", allaccess ? "read/write" : "read");
@@ -104,6 +104,10 @@ RestOutputStruct::ExitCode WebSocket::AvailableSubsystems(bool allaccess, QJsonO
if(QFile::exists("/usr/sbin/powerd")){
out->insert("sysadm/powerd", "read/write");
}
// - sourcectl
if(QFile::exists("/usr/local/bin/git")){
out->insert("sysadm/sourcectl", "read/write");
}
return RestOutputStruct::OK;
}
@@ -164,6 +168,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(const RestInputStru
return EvaluateSysadmMousedRequest(IN.args, out);
}else if(namesp=="sysadm" && name=="powerd"){
return EvaluateSysadmPowerdRequest(IN.args, out);
}else if(namesp=="sysadm" && name=="sourcectl"){
return EvaluateSysadmSourceCTLRequest(IN.args, out);
}else{
return RestOutputStruct::BADREQUEST;
}
@@ -1329,3 +1335,33 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPowerdRequest(const QJsonVal
return RestOutputStruct::BADREQUEST;
}
}
// ==== SYSADM SOURCECTL API ====
RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSourceCTLRequest(const QJsonValue in_args, QJsonObject *out){
QString action = in_args.toObject().value("action").toString();
QJsonObject outobj;
if(action == "downloadports"){
outobj = sysadm::sourcectl::downloadports();
}else if(action == "updateports"){
outobj = sysadm::sourcectl::updateports();
}else if(action == "deleteports"){
outobj = sysadm::sourcectl::deleteports();
}else if(action == "stopports"){
outobj = sysadm::sourcectl::stopports();
}else if(action == "downloadsource"){
outobj = sysadm::sourcectl::downloadsource();
}else if(action == "updatesource"){
outobj = sysadm::sourcectl::updatesource();
}else if(action == "deletesource"){
outobj = sysadm::sourcectl::deletesource();
}else if(action == "stopsource"){
outobj = sysadm::sourcectl::stopsource();
//check return structure for validity
if(!outobj.keys().isEmpty()){
out->insert(action, outobj);
return RestOutputStruct::OK;
}else{
return RestOutputStruct::BADREQUEST;
}
}
}

View File

@@ -100,6 +100,8 @@ private:
RestOutputStruct::ExitCode EvaluateSysadmMousedRequest(const QJsonValue in_args, QJsonObject *out);
// -- sysadm powerd API
RestOutputStruct::ExitCode EvaluateSysadmPowerdRequest(const QJsonValue in_args, QJsonObject *out);
// -- sysadm sourcectl API
RestOutputStruct::ExitCode EvaluateSysadmSourceCTLRequest(const QJsonValue in_args, QJsonObject *out);
private slots:
void sendReply(QString msg);

View File

@@ -17,7 +17,9 @@ HEADERS += $${PWD}/sysadm-global.h \
$${PWD}/sysadm-zfs.h \
$${PWD}/sysadm-pkg.h \
$${PWD}/sysadm-moused.h \
$${PWD}/sysadm-powerd.h
$${PWD}/sysadm-powerd.h \
$${PWD}/sysadm-sourcectl.h
SOURCES += $${PWD}/NetDevice.cpp \
$${PWD}/sysadm-general.cpp \
@@ -35,4 +37,5 @@ SOURCES += $${PWD}/NetDevice.cpp \
$${PWD}/sysadm-zfs.cpp \
$${PWD}/sysadm-pkg.cpp \
$${PWD}/sysadm-moused.cpp \
$${PWD}/sysadm-powerd.cpp
$${PWD}/sysadm-powerd.cpp \
$${PWD}/sysadm-sourcectl.cpp