mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 17:52:28 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -92,7 +92,7 @@ namespace OpenWifi {
|
||||
auto Config = RawObject->get("configuration").toString();
|
||||
Poco::JSON::Object Answer;
|
||||
auto deviceType = GetParameter("deviceType", "AP");
|
||||
std::vector<std::string> Error;
|
||||
std::string Error;
|
||||
auto Res =
|
||||
ValidateUCentralConfiguration(ConfigurationValidator::GetType(deviceType),Config, Error, GetBoolParameter("strict", true));
|
||||
Answer.set("valid", Res);
|
||||
|
||||
@@ -460,9 +460,11 @@ namespace OpenWifi {
|
||||
}
|
||||
|
||||
try {
|
||||
if (ValidateUCentralConfiguration(Type,i.configuration, Errors, true)) {
|
||||
std::string Error;
|
||||
if (ValidateUCentralConfiguration(Type,i.configuration, Error, true)) {
|
||||
// std::cout << "Block: " << i.name << " is valid" << std::endl;
|
||||
} else {
|
||||
Errors.push_back(Error);
|
||||
return false;
|
||||
}
|
||||
} catch (...) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
//
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
#include "ConfigurationValidator.h"
|
||||
@@ -8114,11 +8113,10 @@ namespace OpenWifi {
|
||||
bool ConfigurationValidator::SetSchema(ConfigurationType Type, const std::string &SchemaStr) {
|
||||
try {
|
||||
Poco::JSON::Parser P;
|
||||
SchemaDocPtr_[static_cast<int>(Type)] = P.parse(SchemaStr).extract<Poco::JSON::Object::Ptr>();
|
||||
RootSchema_[static_cast<int>(Type)] = std::make_unique<valijson::Schema>();
|
||||
SchemaParser_[static_cast<int>(Type)] = std::make_unique<valijson::SchemaParser>();
|
||||
PocoJsonAdapter_[static_cast<int>(Type)] = std::make_unique<valijson::adapters::PocoJsonAdapter>(SchemaDocPtr_);
|
||||
SchemaParser_[static_cast<int>(Type)]->populateSchema(*PocoJsonAdapter_[static_cast<int>(Type)], *RootSchema_[static_cast<int>(Type)]);
|
||||
auto SchemaDocPtr = P.parse(SchemaStr).extract<Poco::JSON::Object::Ptr>();
|
||||
valijson::SchemaParser SchemaParser;
|
||||
valijson::adapters::PocoJsonAdapter Adaptor(SchemaDocPtr);
|
||||
SchemaParser.populateSchema(Adaptor, RootSchema_[static_cast<int>(Type)]);
|
||||
Initialized_ = Working_ = true;
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
@@ -8140,7 +8138,8 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
void ConfigurationValidator::Init() {
|
||||
if (Initialized_)
|
||||
|
||||
if (Initialized_)
|
||||
return;
|
||||
|
||||
std::string GitSchema;
|
||||
@@ -8175,7 +8174,7 @@ namespace OpenWifi {
|
||||
}
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
|
||||
Logger().log(E);
|
||||
} catch (...) {
|
||||
}
|
||||
SetSchema(ConfigurationType::AP, DefaultAPSchema);
|
||||
@@ -8184,7 +8183,7 @@ namespace OpenWifi {
|
||||
"Using uCentral data model validation schema from built-in default.");
|
||||
}
|
||||
|
||||
bool ConfigurationValidator::Validate(ConfigurationType Type, const std::string &C, std::vector<std::string> &Errors,
|
||||
bool ConfigurationValidator::Validate(ConfigurationType Type, const std::string &C, std::string &Errors,
|
||||
bool Strict) {
|
||||
if (Working_) {
|
||||
try {
|
||||
@@ -8193,12 +8192,24 @@ namespace OpenWifi {
|
||||
valijson::adapters::PocoJsonAdapter Tester(Doc);
|
||||
valijson::Validator Validator;
|
||||
valijson::ValidationResults Results;
|
||||
if (Validator.validate(*RootSchema_[static_cast<int>(Type)], Tester, &Results)) {
|
||||
if (Validator.validate(RootSchema_[static_cast<int>(Type)], Tester, &Results)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Poco::JSON::Array ErrorArray;
|
||||
for (const auto &error : Results) {
|
||||
Errors.push_back(error.description);
|
||||
Poco::JSON::Array ContextArray;
|
||||
for(const auto &context : error.context) {
|
||||
ContextArray.add(context);
|
||||
}
|
||||
Poco::JSON::Object ErrorObject;
|
||||
ErrorObject.set("context", ContextArray);
|
||||
ErrorObject.set("description", error.description);
|
||||
ErrorArray.add(ErrorObject);
|
||||
}
|
||||
std::stringstream os;
|
||||
ErrorArray.stringify(os);
|
||||
Errors = os.str();
|
||||
return false;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenWifi {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
bool Validate(ConfigurationType Type, const std::string &C, std::vector<std::string> &Errors, bool Strict);
|
||||
bool Validate(ConfigurationType Type, const std::string &C, std::string &Errors, bool Strict);
|
||||
int Start() override;
|
||||
void Stop() override;
|
||||
void reinitialize(Poco::Util::Application &self) override;
|
||||
@@ -43,10 +43,7 @@ namespace OpenWifi {
|
||||
bool Initialized_ = false;
|
||||
bool Working_ = false;
|
||||
void Init();
|
||||
std::array<std::unique_ptr<valijson::Schema>,2> RootSchema_;
|
||||
std::array<std::unique_ptr<valijson::SchemaParser>,2> SchemaParser_;
|
||||
std::array<std::unique_ptr<valijson::adapters::PocoJsonAdapter>,2> PocoJsonAdapter_;
|
||||
std::array<Poco::JSON::Object::Ptr,2> SchemaDocPtr_;
|
||||
std::array<valijson::Schema,2> RootSchema_;
|
||||
bool SetSchema(ConfigurationType Type, const std::string &SchemaStr);
|
||||
|
||||
ConfigurationValidator()
|
||||
@@ -54,8 +51,8 @@ namespace OpenWifi {
|
||||
};
|
||||
|
||||
inline auto ConfigurationValidator() { return ConfigurationValidator::instance(); }
|
||||
inline bool ValidateUCentralConfiguration(ConfigurationValidator::ConfigurationType Type, const std::string &C, std::vector<std::string> &Error,
|
||||
inline bool ValidateUCentralConfiguration(ConfigurationValidator::ConfigurationType Type, const std::string &C, std::string &Errors,
|
||||
bool strict) {
|
||||
return ConfigurationValidator::instance()->Validate(Type, C, Error, strict);
|
||||
return ConfigurationValidator::instance()->Validate(Type, C, Errors, strict);
|
||||
}
|
||||
} // namespace OpenWifi
|
||||
|
||||
Reference in New Issue
Block a user