mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 01:32:31 +00:00
Adding configuration block management.
This commit is contained in:
@@ -89,6 +89,42 @@ namespace OpenWifi{
|
||||
BadRequest(Request, Response, "Internal error. Consult documentation and try again.");
|
||||
}
|
||||
|
||||
// interfaces
|
||||
// metrics
|
||||
// radios
|
||||
// services
|
||||
// globals
|
||||
// unit
|
||||
bool RESTAPI_configurations_handler::ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config,
|
||||
Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response) {
|
||||
static const std::vector<std::string> SectionNames{ "globals", "interfaces", "metrics", "radios", "services", "unit" };
|
||||
|
||||
try {
|
||||
for(const auto &i:Config.configuration) {
|
||||
Poco::JSON::Parser P;
|
||||
|
||||
if(i.name.empty()) {
|
||||
BadRequest(Request, Response, "The configuration block name must be included.");
|
||||
return false;
|
||||
}
|
||||
auto Blocks = P.parse(i.configuration).extract<Poco::JSON::Object::Ptr>();
|
||||
auto N = Blocks->getNames();
|
||||
|
||||
for(const auto &j:N) {
|
||||
if(std::find(SectionNames.cbegin(),SectionNames.cend(),j)==SectionNames.cend()) {
|
||||
BadRequest(Request, Response, "Configuration block type invalid.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
BadRequest(Request, Response, "Invalid configuration portion.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RESTAPI_configurations_handler::DoPost(Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response) {
|
||||
try {
|
||||
@@ -127,20 +163,8 @@ namespace OpenWifi{
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
for(const auto &i:C.configuration) {
|
||||
Poco::JSON::Parser P;
|
||||
// std::cout << "Config:>>>" << std::endl << i.configuration << std::endl << "<<<" << std::endl;
|
||||
if(i.name.empty()) {
|
||||
BadRequest(Request, Response, "The configuration block name must be included.");
|
||||
return;
|
||||
}
|
||||
P.parse(i.configuration).extract<Poco::JSON::Object::Ptr>();
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
BadRequest(Request, Response, "Invalid configuration portion.");
|
||||
if(!ValidateConfigBlock(C, Request, Response))
|
||||
return;
|
||||
}
|
||||
|
||||
if(Storage()->ConfigurationDB().CreateRecord(C)) {
|
||||
Storage()->ConfigurationDB().GetRecord("id", C.info.id, C);
|
||||
@@ -208,23 +232,8 @@ namespace OpenWifi{
|
||||
|
||||
NewConfig.info.modified = std::time(nullptr);
|
||||
|
||||
if(!NewConfig.configuration.empty()) {
|
||||
try {
|
||||
for(const auto &i:NewConfig.configuration) {
|
||||
if(i.name.empty()) {
|
||||
BadRequest(Request, Response, "The configuration block name must be included.");
|
||||
return;
|
||||
}
|
||||
Poco::JSON::Parser P;
|
||||
auto T = P.parse(i.configuration).extract<Poco::JSON::Object>();
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
BadRequest(Request, Response, "Invalid configuration portion.");
|
||||
return;
|
||||
}
|
||||
|
||||
Existing.configuration = NewConfig.configuration;
|
||||
}
|
||||
if(!ValidateConfigBlock(NewConfig, Request, Response))
|
||||
return;
|
||||
|
||||
if(!NewConfig.variables.empty())
|
||||
Existing.variables = NewConfig.variables;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "RESTAPI_handler.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "RESTAPI_ProvObjects.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class RESTAPI_configurations_handler : public RESTAPIHandler {
|
||||
@@ -34,6 +35,10 @@ namespace OpenWifi {
|
||||
Poco::Net::HTTPServerResponse &Response);
|
||||
void DoDelete(Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response);
|
||||
private:
|
||||
bool ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config,
|
||||
Poco::Net::HTTPServerRequest &Request,
|
||||
Poco::Net::HTTPServerResponse &Response);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +1,71 @@
|
||||
{
|
||||
"type" : "entity",
|
||||
"name" : "world",
|
||||
"children" : [{
|
||||
"type" : "entity",
|
||||
"name" : "root" ,
|
||||
"children" : [ {
|
||||
"type" : "entity" ,
|
||||
"name" : "sub-root1" ,
|
||||
"children" : [{
|
||||
"type" : "entity" ,
|
||||
"name" : "sub-1.1" ,
|
||||
"children" : [] ,
|
||||
"venues" : []
|
||||
},
|
||||
{
|
||||
"type" : "entity" ,
|
||||
"name" : "sub-1.2" ,
|
||||
"children" : [] ,
|
||||
"venues" : []
|
||||
}
|
||||
] ,
|
||||
"venues" : [{
|
||||
"type" : "venue" ,
|
||||
"name" : "sub-r1-v1" ,
|
||||
"venues" : []
|
||||
},
|
||||
{
|
||||
"type" : "venue" ,
|
||||
"name" : "sub-r1-v2" ,
|
||||
"venues" : []
|
||||
}]
|
||||
},
|
||||
{
|
||||
"type" : "entity" ,
|
||||
"name" : "sub-root2" ,
|
||||
"children" : [] ,
|
||||
"venues" : []
|
||||
}
|
||||
] ,
|
||||
"venues" : [ {
|
||||
"type" : "venue" ,
|
||||
"name" : "sub-v1" ,
|
||||
"venues" : []
|
||||
},
|
||||
{
|
||||
"type" : "venue" ,
|
||||
"name" : "sub-v2" ,
|
||||
"venues" : []
|
||||
}]
|
||||
}],
|
||||
"venues" : []
|
||||
}
|
||||
"type": "entity",
|
||||
"name": "world",
|
||||
"children": [{
|
||||
"type": "entity",
|
||||
"name": "Canada",
|
||||
"children": [{
|
||||
"type": "entity",
|
||||
"name": "Provinces",
|
||||
"children": [{
|
||||
"type": "entity",
|
||||
"name": "Quebec",
|
||||
"children": [],
|
||||
"venues": [{
|
||||
"type": "venue",
|
||||
"name": "Bell Center",
|
||||
"venues": []
|
||||
},
|
||||
{
|
||||
"type": "venue",
|
||||
"name": "Olymic Statium",
|
||||
"venues": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "entity",
|
||||
"name": "Ontario",
|
||||
"children": [],
|
||||
"venues": [{
|
||||
"type": "venue",
|
||||
"name": "CN Tower",
|
||||
"venues": []
|
||||
},
|
||||
{
|
||||
"type": "venue",
|
||||
"name": "Rogers Center",
|
||||
"venues": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "entity",
|
||||
"name": "BC",
|
||||
"children": [],
|
||||
"venues": [{
|
||||
"type": "venue",
|
||||
"name": "BC Place",
|
||||
"venues": []
|
||||
},
|
||||
{
|
||||
"type": "venue",
|
||||
"name": "Stanley Park",
|
||||
"venues": []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"venues": []
|
||||
}],
|
||||
"venues": []
|
||||
},
|
||||
{
|
||||
"type": "entity",
|
||||
"name": "Mexico",
|
||||
"children": [],
|
||||
"venues": []
|
||||
}
|
||||
],
|
||||
"venues": []
|
||||
}
|
||||
Reference in New Issue
Block a user