Fixing ORM default constructor

This commit is contained in:
stephb9959
2021-10-02 20:25:51 -07:00
parent e109764a84
commit b7618bdfb3
9 changed files with 252 additions and 4 deletions

View File

@@ -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/ConfigurationValidator.cpp src/ConfigurationValidator.h src/RESTAPI_GenericServer.cpp src/RESTAPI_GenericServer.h src/AutoDiscovery.cpp src/AutoDiscovery.h src/CIDRUtils.cpp src/CIDRUtils.h src/SDK_stubs.cpp src/SDK_stubs.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 src/RESTAPI_GenericServer.cpp src/RESTAPI_GenericServer.h src/AutoDiscovery.cpp src/AutoDiscovery.h src/CIDRUtils.cpp src/CIDRUtils.h src/SDK_stubs.cpp src/SDK_stubs.h src/ConfigSanityChecker.cpp src/ConfigSanityChecker.h src/storage_tags.cpp src/storage_tags.h)
target_link_libraries(owprov PUBLIC
${Poco_LIBRARIES} ${MySQL_LIBRARIES}

16
SANITY_CHECK.md Normal file
View File

@@ -0,0 +1,16 @@
# Sanity checks
## downstream interfaces with a vlan need the matching upstream interface with vlan
## an ssid with enterprise encryption needs a radius server
## f you have not defined as many radios as a device has, we will warn you
## If you defined 2 radios bur your config does not use both radios in the interfaces for example.
## If you keys/certs do not match, we will fail the configuration.
## We will also report things that are entered but not in the schema.

16
TAG_SYSTEM.md Normal file
View File

@@ -0,0 +1,16 @@
# Build a tag system for multiple tables
## Tables
Tags are stored as 5 bytes hex for each symbol, include a leading space. When searching
### Symbol table
Create a simple table with 2 columns
1 NUM INTEGER
2 VARCHAR(0) VALUE
### Usage table
1 UUID UUID OF RECORD
2 TABLE VARCHAR(TableName)
3 VARCHAR(255) TAGS

2
build
View File

@@ -1 +1 @@
250
252

View File

@@ -0,0 +1,53 @@
//
// Created by stephane bourque on 2021-10-01.
//
#include "ConfigSanityChecker.h"
#include "nlohmann/json.hpp"
#include <iostream>
#include <iomanip>
namespace OpenWifi {
bool ConfigSanityChecker::Check() {
try {
auto Doc = nlohmann::json::parse(Config_);
for(const auto &[key,value]:Doc.items()) {
for(const auto &i:Funcs_)
if(i.first==key)
i.second(value);
}
return true;
} catch ( ... ) {
}
return false;
}
void ConfigSanityChecker::Check_radios(nlohmann::json &d) {
std::cout << "Validating radios" << std::endl;
};
void ConfigSanityChecker::Check_interfaces(nlohmann::json &d) {
std::cout << "Validating interfaces" << std::endl;
};
void ConfigSanityChecker::Check_metrics(nlohmann::json &d) {
std::cout << "Validating metrics" << std::endl;
};
void ConfigSanityChecker::Check_services(nlohmann::json &d) {
std::cout << "Validating services" << std::endl;
};
void ConfigSanityChecker::Check_uuid(nlohmann::json &d) {
std::cout << "Validating uuid" << std::endl;
};
}

65
src/ConfigSanityChecker.h Normal file
View File

@@ -0,0 +1,65 @@
//
// Created by stephane bourque on 2021-10-01.
//
#ifndef OWPROV_CONFIGSANITYCHECKER_H
#define OWPROV_CONFIGSANITYCHECKER_H
#include <string>
#include <list>
#include <functional>
#include <map>
#include <vector>
#include <utility>
#include "nlohmann/json.hpp"
namespace OpenWifi {
struct SanityError {
std::string Cause;
std::string Reason;
std::string Severity;
};
typedef std::list<SanityError> SanityErrorList;
class ConfigSanityChecker {
public:
explicit ConfigSanityChecker(std::string Config, std::string DeviceType) :
Config_(std::move(Config)),
DeviceType_(std::move(DeviceType)){}
bool Check();
const SanityErrorList & Errors() { return Errors_; }
const SanityErrorList & Warnings() { return Warnings_; }
typedef std::function<void(nlohmann::json &)> CheckFuncType;
struct KeyToFunc {
std::string Key;
CheckFuncType Func;
};
typedef std::pair<std::string, CheckFuncType> FuncPair;
typedef std::vector<FuncPair> FuncList;
void Check_radios(nlohmann::json &);
void Check_interfaces(nlohmann::json &);
void Check_metrics(nlohmann::json &);
void Check_services(nlohmann::json &);
void Check_uuid(nlohmann::json &);
private:
std::string Config_;
std::string DeviceType_;
SanityErrorList Errors_;
SanityErrorList Warnings_;
FuncList Funcs_{
std::make_pair("radios", [this](nlohmann::json &d){ this->Check_radios(d);} ) ,
std::make_pair("interfaces", [this](nlohmann::json &d){ this->Check_interfaces(d);} ),
std::make_pair("metrics", [this](nlohmann::json &d){ this->Check_metrics(d);} ),
std::make_pair("services", [this](nlohmann::json &d){ this->Check_services(d);} ),
std::make_pair("uuid", [this](nlohmann::json &d){ this->Check_uuid(d);} )
};
};
}
#endif //OWPROV_CONFIGSANITYCHECKER_H

View File

@@ -52,6 +52,12 @@ namespace ORM {
bool Index=false;
Field(std::string N, FieldType T, int S=0, bool Index=false) :
Name(std::move(N)),
Type(T),
Size(S),
Index(Index) {}
explicit Field(std::string N) :
Name(std::move(N))
{
@@ -61,13 +67,19 @@ namespace ORM {
Field(std::string N, int S) :
Name(std::move(N)), Size(S)
{
Type = FT_TEXT;
if(Size>0 && Size<255)
Type = FT_VARCHAR;
else
Type = FT_TEXT;
}
Field(std::string N, int S, bool I):
Name(std::move(N)), Size(S), Index(I)
{
Type = FT_TEXT;
if(Size>0 && Size<255)
Type = FT_VARCHAR;
else
Type = FT_TEXT;
}
};
typedef std::vector<Field> FieldVec;

39
src/storage_tags.cpp Normal file
View File

@@ -0,0 +1,39 @@
//
// Created by stephane bourque on 2021-10-02.
//
#include "storage_tags.h"
#include "OpenWifiTypes.h"
#include "RESTAPI_utils.h"
#include "StorageService.h"
#include <functional>
namespace OpenWifi {
static ORM::FieldVec TagsDictionary_Fields{
// object info
ORM::Field{"id",ORM::FieldType::FT_INT, 0,true},
ORM::Field{"name",ORM::FieldType::FT_TEXT, 32, }
};
static ORM::IndexVec TagsDictionaryDB_Indexes{
{ std::string("tags_dictionary_name_index"),
ORM::IndexEntryVec{
{std::string("name"),
ORM::Indextype::ASC} } }
};
TagsDictionaryDB::TagsDictionaryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
DB(T, "tagsdictionary", TagsDictionary_Fields, TagsDictionaryDB_Indexes, P, L, "tgd") {}
}
template<> void ORM::DB< OpenWifi::TagsDictionaryRecordType, OpenWifi::TagsDictionary>::Convert(OpenWifi::TagsDictionaryRecordType &In, OpenWifi::TagsDictionary &Out) {
Out.id = In.get<0>();
Out.name = In.get<1>();
}
template<> void ORM::DB< OpenWifi::TagsDictionaryRecordType, OpenWifi::TagsDictionary>::Convert(OpenWifi::TagsDictionary &In, OpenWifi::TagsDictionaryRecordType &Out) {
Out.set<0>(In.id);
Out.set<1>(In.name);
}

47
src/storage_tags.h Normal file
View File

@@ -0,0 +1,47 @@
//
// Created by stephane bourque on 2021-10-02.
//
#ifndef OWPROV_STORAGE_TAGS_H
#define OWPROV_STORAGE_TAGS_H
#include "orm.h"
#include "OpenWifiTypes.h"
namespace OpenWifi {
struct TagsDictionary {
uint32_t id=0;
std::string name;
};
typedef Poco::Tuple<
uint32_t,
std::string
> TagsDictionaryRecordType;
struct TagsObject {
std::string uuid;
std::string prefix;
Types::StringVec entries;
};
typedef Poco::Tuple<
std::string,
std::string,
std::string
> TagsObjectRecordType;
class TagsDictionaryDB : public ORM::DB<TagsDictionaryRecordType, TagsDictionary> {
public:
TagsDictionaryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
private:
};
class TagsObjectDB : public ORM::DB<TagsObjectRecordType, TagsObject> {
public:
TagsObjectDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
private:
};
}
#endif //OWPROV_STORAGE_TAGS_H