From ab0ce827cf67892892aa9ae4afc764338350555f Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 28 Mar 2016 11:50:31 -0400 Subject: [PATCH] Add a new API call: sysadm/pkg, "action"="pkg_install". This will install the given packages on the system. Required arguments: "pkg_origins" = (single origin string or array of origin strings). Optional arguments: "repo": Name of the remote repository to use (if not supplied, pkg will automatically determine repository). NOTE: The actual information will be returned as a Dispatcher event - this API call just queues up the pkg operation (limitation of pkg - only one process call at a time) REST Request: ------------------------------- PUT /sysadm/pkg { "pkg_origins" : "games/angband", "action" : "pkg_install", "repo" : "pcbsd-major" } WebSocket Request: ------------------------------- { "name" : "pkg", "namespace" : "sysadm", "id" : "fooid", "args" : { "action" : "pkg_install", "pkg_origins" : "games/angband", "repo" : "pcbsd-major" } } Response: ------------------------------- { "args": { "pkg_install": { "proc_cmd": "pkg install -y --repository \"pcbsd-major\" games/angband", "proc_id": "sysadm_pkg_install-{ae444472-47df-4a65-91eb-013cc82ce4ad}", "status": "pending" } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/server/WebBackend.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index e32a6de..57943af 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -711,7 +711,9 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPkgRequest(const QJsonValue //Parse the action and perform accordingly if(act=="pkg_info"){ - //OPTIONAL: "result" + //OPTIONAL: "pkg_origins" OR "category" + //OPTIONAL: "repo" + //OPTIONAL: "result" = "full" or "simple" (Default: "simple") bool fullresults = false; if(in_args.toObject().contains("result")){ fullresults = (in_args.toObject().value("result").toString()=="full"); } @@ -720,10 +722,11 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPkgRequest(const QJsonValue if(!info.isEmpty()){ out->insert("pkg_info",info); } else{ return RestOutputStruct::NOCONTENT; } - }else if(act=="pkg_search"){ - //REQUIRED - QString srch; - if(in_args.toObject().contains("search_term")){ srch = in_args.toObject().value("search_term").toString(); } + }else if(act=="pkg_search" && in_args.toObject().contains("search_term")){ + //REQUIRED: "search_term" (string to search for) + //OPTIONAL: "repo" + //OPTIONAL: "category" + QString srch = in_args.toObject().value("search_term").toString(); if(srch.isEmpty()){ return RestOutputStruct::BADREQUEST; } QStringList pkgs = sysadm::PKG::pkg_search(repo, srch, cat); if(!pkgs.isEmpty()){ @@ -734,6 +737,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPkgRequest(const QJsonValue } }else if(act=="list_categories"){ + //OPTIONAL: "repo" QJsonArray cats = sysadm::PKG::list_categories(repo); if(!cats.isEmpty()){ out->insert("list_categories", cats); } else{ return RestOutputStruct::NOCONTENT; } @@ -745,10 +749,14 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmPkgRequest(const QJsonValue }else if(act=="pkg_install" && !pkgs.isEmpty() ){ //REQUIRED: "pkg_origins" - - }else if(act=="pkg_remove" && !pkgs.isEmpty() ){ + //OPTIONAL: "repo" (pkg will determine the best repo to use if not supplied) + out->insert("pkg_install", sysadm::PKG::pkg_install(pkgs,repo)); + /*}else if(act=="pkg_remove" && !pkgs.isEmpty() ){ //REQUIRED: "pkg_origins" - + //OPTIONAL: "recursive"="true" or "false" (default: "true") + bool recursive = true; + if(in_args.toObject().contains("recursive")){ recursive = in_args.toObject().value("recursive").toString()=="false"; } + out->insert("pkg_remove", sysadm::PKG::pkg_remove(pkgs, recursive));*/ }else if(act=="pkg_lock" && !pkgs.isEmpty() ){ //REQUIRED: "pkg_origins" out->insert("pkg_lock", sysadm::PKG::pkg_lock(pkgs));