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:
@@ -90,7 +90,7 @@ add_executable(owprov
|
||||
src/storage_setup.cpp
|
||||
src/storage_configurations.cpp src/storage_configurations.h
|
||||
src/RESTAPI_configurations_handler.cpp src/RESTAPI_configurations_handler.h
|
||||
src/RESTAPI_webSocketServer.h src/RESTAPI_webSocketServer.cpp src/RESTAPI_contact_list_handler.cpp src/RESTAPI_contact_list_handler.h src/RESTAPI_location_list_handler.cpp src/RESTAPI_location_list_handler.h src/RESTAPI_venue_list_handler.cpp src/RESTAPI_venue_list_handler.h src/RESTAPI_managementPolicy_list_handler.cpp src/RESTAPI_managementPolicy_list_handler.h src/RESTAPI_managementRole_handler.cpp src/RESTAPI_managementRole_handler.h src/RESTAPI_managementRole_list_handler.cpp src/RESTAPI_managementRole_list_handler.h src/RESTAPI_configurations_list_handler.cpp src/RESTAPI_configurations_list_handler.h src/SecurityDBProxy.cpp src/SecurityDBProxy.h src/APConfig.cpp src/APConfig.h src/RESTAPI_errors.h)
|
||||
src/RESTAPI_webSocketServer.h src/RESTAPI_webSocketServer.cpp src/RESTAPI_contact_list_handler.cpp src/RESTAPI_contact_list_handler.h src/RESTAPI_location_list_handler.cpp src/RESTAPI_location_list_handler.h src/RESTAPI_venue_list_handler.cpp src/RESTAPI_venue_list_handler.h src/RESTAPI_managementPolicy_list_handler.cpp src/RESTAPI_managementPolicy_list_handler.h src/RESTAPI_managementRole_handler.cpp src/RESTAPI_managementRole_handler.h src/RESTAPI_managementRole_list_handler.cpp src/RESTAPI_managementRole_list_handler.h src/RESTAPI_configurations_list_handler.cpp src/RESTAPI_configurations_list_handler.h src/SecurityDBProxy.cpp src/SecurityDBProxy.h src/APConfig.cpp src/APConfig.h src/RESTAPI_errors.h src/ConfigurationValidator.cpp src/ConfigurationValidator.h)
|
||||
|
||||
target_link_libraries(owprov PUBLIC
|
||||
${Poco_LIBRARIES} ${MySQL_LIBRARIES}
|
||||
|
||||
94
config-samples/basic-config-no-uuid.json
Normal file
94
config-samples/basic-config-no-uuid.json
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"radios": [
|
||||
{
|
||||
"band": "5G",
|
||||
"channel": 52,
|
||||
"channel-mode": "HE",
|
||||
"channel-width": 80,
|
||||
"country": "CA"
|
||||
},
|
||||
{
|
||||
"band": "2G",
|
||||
"channel": 11,
|
||||
"channel-mode": "HE",
|
||||
"channel-width": 20,
|
||||
"country": "CA"
|
||||
}
|
||||
],
|
||||
|
||||
"interfaces": [
|
||||
{
|
||||
"name": "WAN",
|
||||
"role": "upstream",
|
||||
"services": [ "lldp" ],
|
||||
"ethernet": [
|
||||
{
|
||||
"select-ports": [
|
||||
"WAN*"
|
||||
]
|
||||
}
|
||||
],
|
||||
"ipv4": {
|
||||
"addressing": "dynamic"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "LAN",
|
||||
"role": "downstream",
|
||||
"services": [ "ssh", "lldp" ],
|
||||
"ethernet": [
|
||||
{
|
||||
"select-ports": [
|
||||
"LAN*"
|
||||
]
|
||||
}
|
||||
],
|
||||
"ipv4": {
|
||||
"addressing": "static",
|
||||
"subnet": "192.168.1.1/24",
|
||||
"dhcp": {
|
||||
"lease-first": 10,
|
||||
"lease-count": 100,
|
||||
"lease-time": "6h"
|
||||
}
|
||||
},
|
||||
"ssids": [
|
||||
{
|
||||
"name": "OpenWifi",
|
||||
"role": "downstream",
|
||||
"wifi-bands": [
|
||||
"2G", "5G"
|
||||
],
|
||||
"bss-mode": "ap",
|
||||
"encryption": {
|
||||
"proto": "psk2",
|
||||
"key": "OpenWifi",
|
||||
"ieee80211w": "optional"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
],
|
||||
"metrics": {
|
||||
"statistics": {
|
||||
"interval": 120,
|
||||
"types": [ "ssids", "lldp", "clients" ]
|
||||
},
|
||||
"health": {
|
||||
"interval": 120
|
||||
},
|
||||
"wifi-frames": {
|
||||
"filters": [ "probe", "auth" ]
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"lldp": {
|
||||
"describe": "uCentral",
|
||||
"location": "universe"
|
||||
},
|
||||
"ssh": {
|
||||
"port": 22
|
||||
}
|
||||
}
|
||||
}
|
||||
2115
src/ConfigurationValidator.cpp
Normal file
2115
src/ConfigurationValidator.cpp
Normal file
File diff suppressed because it is too large
Load Diff
62
src/ConfigurationValidator.h
Normal file
62
src/ConfigurationValidator.h
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-09-14.
|
||||
//
|
||||
|
||||
#ifndef OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
#define OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
|
||||
using nlohmann::json;
|
||||
using nlohmann::json_schema::json_validator;
|
||||
|
||||
namespace OpenWifi {
|
||||
class ConfigurationValidator {
|
||||
public:
|
||||
ConfigurationValidator() {
|
||||
Validator_ = std::make_unique<json_validator>(nullptr, my_format_checker);
|
||||
}
|
||||
|
||||
static ConfigurationValidator *instance() {
|
||||
if(instance_== nullptr)
|
||||
instance_ = new ConfigurationValidator;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
bool Validate(const std::string &C);
|
||||
static void my_format_checker(const std::string &format, const std::string &value)
|
||||
{
|
||||
/*
|
||||
"format": "uc-mac"
|
||||
"format": "uc-timeout",
|
||||
"format": "uc-cidr4",
|
||||
"format": "uc-cidr6",
|
||||
"uc-format": "cidr",
|
||||
"format": "fqdn",
|
||||
"format": "uc-host",
|
||||
"format": "uri"
|
||||
"format": "hostname"
|
||||
"format": "uc-base64"
|
||||
|
||||
|
||||
if (format == "something") {
|
||||
return;
|
||||
if (!check_value_for_something(value))
|
||||
throw std::invalid_argument("value is not a good something");
|
||||
} else
|
||||
throw std::logic_error("Don't know how to validate " + format);
|
||||
*/
|
||||
}
|
||||
|
||||
private:
|
||||
static ConfigurationValidator * instance_;
|
||||
bool Initialized_=false;
|
||||
bool Working_=false;
|
||||
void Init();
|
||||
std::unique_ptr<json_validator> Validator_;
|
||||
};
|
||||
|
||||
bool ValidateUCentralConfiguration(const std::string &C) { return ConfigurationValidator::instance()->Validate(C); }
|
||||
}
|
||||
|
||||
#endif //OWPROV_CONFIGURATIONVALIDATOR_H
|
||||
Reference in New Issue
Block a user