Adding inventoryHandle API

This commit is contained in:
stephb9959
2021-08-23 20:40:22 -07:00
parent 83c613ec60
commit ceff684d66
3 changed files with 30 additions and 5 deletions

View File

@@ -64,9 +64,9 @@ namespace OpenWifi {
}
void RESTAPIHandler::ParseParameters(Poco::Net::HTTPServerRequest &request) {
Poco::URI uri(request.getURI());
Parameters_ = uri.getQueryParameters();
InitQueryBlock();
}
static bool is_number(const std::string &s) {
@@ -385,6 +385,9 @@ namespace OpenWifi {
}
bool RESTAPIHandler::InitQueryBlock() {
if(QueryBlockInitialized_)
return true;
QueryBlockInitialized_=true;
QB_.SerialNumber = GetParameter(RESTAPI::Protocol::SERIALNUMBER, "");
QB_.StartDate = GetParameter(RESTAPI::Protocol::STARTDATE, 0);
QB_.EndDate = GetParameter(RESTAPI::Protocol::ENDDATE, 0);
@@ -397,7 +400,8 @@ namespace OpenWifi {
QB_.LastOnly = GetBoolParameter(RESTAPI::Protocol::LASTONLY,false);
QB_.Newest = GetBoolParameter(RESTAPI::Protocol::NEWEST,false);
if(QB_.Offset<1) return false;
if(QB_.Offset<1)
QB_.Offset=1;
return true;
}

View File

@@ -158,6 +158,7 @@ namespace OpenWifi {
std::vector<std::string> Methods_;
QueryBlock QB_;
bool Internal_=false;
bool QueryBlockInitialized_=false;
};
class RESTAPI_UnknownRequestHandler : public RESTAPIHandler {

View File

@@ -49,7 +49,7 @@ login() {
exit 13
fi
echo "${token}" > token.json
setfms
setprov
}
findbrowser() {
@@ -72,7 +72,7 @@ findbrowser() {
fi
}
setfms() {
setprov() {
curl ${FLAGS} -X GET "https://${UCENTRALSEC}/api/v1/systemEndpoints" \
-H "accept: application/json" \
-H "Authorization: Bearer ${token}" > ${result_file}
@@ -131,7 +131,25 @@ setroot() {
addentity() {
payload="{ \"name\" : \"$1\", \"description\" : \"sub entity.\", \"parent\" : \"0000-0000-0000\", \"notes\" : [ {\"note\" : \"CLI added\"} ] }";
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/entity/1" \
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/inventory/1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "accept: application/json" \
-d "$payload" > ${result_file}
jq < ${result_file}
}
getentities() {
curl ${FLAGS} "https://${OWPROV}/api/v1/entity" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "accept: application/json" > ${result_file}
jq < ${result_file}
}
addtag() {
payload="{ \"name\" : \"$1\",\"entity\" : \"$2\", \"serialNumber\" : \"$1\", \"deviceType\" : \"linksys_ea8300\" }";
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/inventory/1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "accept: application/json" \
@@ -145,6 +163,8 @@ case "$1" in
"getroot") login; getroot; logout;;
"setroot") login; setroot; logout;;
"addentity") login; addentity "$2" ; logout;;
"addtag") login; addtag $2 $3; logout;;
"getentities") login; getentities ; logout;;
*) help ;;
esac