Adding configuration validation.

This commit is contained in:
stephb9959
2021-09-14 16:53:53 -07:00
parent c01e0668be
commit 7af151c697
5 changed files with 29 additions and 2 deletions

View File

@@ -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.

2
build
View File

@@ -1 +1 @@
156
158

View File

@@ -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:

View File

@@ -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

View File

@@ -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)) {