mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 09:42:38 +00:00
Adding configuration validation.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
# OpenWiFi Provisioning
|
||||
|
||||
## Build from source.
|
||||
You need: https://github.com/pboettch/json-schema-validator.git
|
||||
You need: https://github.com/nlohmann/json.git
|
||||
build and install them.
|
||||
|
||||
## Root entity
|
||||
It's UUID value is 0000-0000-0000. Its parent entity must be empty.
|
||||
|
||||
|
||||
@@ -1934,6 +1934,11 @@ paths:
|
||||
format: uuid
|
||||
example: When creating the root entity, the uuid 0000-0000-0000 must be entered. When creating a non-root entity, uuid must be 1
|
||||
required: true
|
||||
- in: query
|
||||
name: validateOnly
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
requestBody:
|
||||
description: Information used to create the new entity
|
||||
content:
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenWifi {
|
||||
std::unique_ptr<json_validator> Validator_;
|
||||
};
|
||||
|
||||
bool ValidateUCentralConfiguration(const std::string &C) { return ConfigurationValidator::instance()->Validate(C); }
|
||||
inline bool ValidateUCentralConfiguration(const std::string &C) { return ConfigurationValidator::instance()->Validate(C); }
|
||||
}
|
||||
|
||||
#endif //OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "Daemon.h"
|
||||
#include "RESTAPI_errors.h"
|
||||
|
||||
#include "ConfigurationValidator.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
|
||||
void RESTAPI_configurations_handler::DoGet() {
|
||||
@@ -103,6 +105,21 @@ namespace OpenWifi{
|
||||
return;
|
||||
}
|
||||
|
||||
std::string Arg;
|
||||
if(HasParameter("validateOnly",Arg) && Arg=="true") {
|
||||
auto Body = ParseStream();
|
||||
if(!Body->has("configuration")) {
|
||||
BadRequest("Must have 'configuration' element.");
|
||||
return;
|
||||
}
|
||||
auto Config=Body->get("configuration").toString();
|
||||
Poco::JSON::Object Answer;
|
||||
auto Res = ValidateUCentralConfiguration(Config);
|
||||
Answer.set("valid",Res);
|
||||
ReturnObject(Answer);
|
||||
return;
|
||||
}
|
||||
|
||||
ProvObjects::DeviceConfiguration C;
|
||||
Poco::JSON::Object::Ptr Obj = ParseStream();
|
||||
if (!C.from_json(Obj)) {
|
||||
|
||||
Reference in New Issue
Block a user