From b7618bdfb3b9443b18acfee4e24552307964cc6c Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sat, 2 Oct 2021 20:25:51 -0700 Subject: [PATCH] Fixing ORM default constructor --- CMakeLists.txt | 2 +- SANITY_CHECK.md | 16 +++++++++ TAG_SYSTEM.md | 16 +++++++++ build | 2 +- src/ConfigSanityChecker.cpp | 53 ++++++++++++++++++++++++++++++ src/ConfigSanityChecker.h | 65 +++++++++++++++++++++++++++++++++++++ src/orm.h | 16 +++++++-- src/storage_tags.cpp | 39 ++++++++++++++++++++++ src/storage_tags.h | 47 +++++++++++++++++++++++++++ 9 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 SANITY_CHECK.md create mode 100644 TAG_SYSTEM.md create mode 100644 src/ConfigSanityChecker.cpp create mode 100644 src/ConfigSanityChecker.h create mode 100644 src/storage_tags.cpp create mode 100644 src/storage_tags.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9107679..0756ae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/SANITY_CHECK.md b/SANITY_CHECK.md new file mode 100644 index 0000000..5d2e2e6 --- /dev/null +++ b/SANITY_CHECK.md @@ -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. + + diff --git a/TAG_SYSTEM.md b/TAG_SYSTEM.md new file mode 100644 index 0000000..5dbcf56 --- /dev/null +++ b/TAG_SYSTEM.md @@ -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 + + diff --git a/build b/build index 8a32cf7..1c5fd03 100644 --- a/build +++ b/build @@ -1 +1 @@ -250 \ No newline at end of file +252 \ No newline at end of file diff --git a/src/ConfigSanityChecker.cpp b/src/ConfigSanityChecker.cpp new file mode 100644 index 0000000..8dcc45e --- /dev/null +++ b/src/ConfigSanityChecker.cpp @@ -0,0 +1,53 @@ +// +// Created by stephane bourque on 2021-10-01. +// + +#include "ConfigSanityChecker.h" +#include "nlohmann/json.hpp" +#include +#include + +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; + + }; + +} \ No newline at end of file diff --git a/src/ConfigSanityChecker.h b/src/ConfigSanityChecker.h new file mode 100644 index 0000000..989c48d --- /dev/null +++ b/src/ConfigSanityChecker.h @@ -0,0 +1,65 @@ +// +// Created by stephane bourque on 2021-10-01. +// + +#ifndef OWPROV_CONFIGSANITYCHECKER_H +#define OWPROV_CONFIGSANITYCHECKER_H + +#include +#include +#include +#include +#include +#include +#include "nlohmann/json.hpp" + +namespace OpenWifi { + struct SanityError { + std::string Cause; + std::string Reason; + std::string Severity; + }; + + typedef std::list 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 CheckFuncType; + + struct KeyToFunc { + std::string Key; + CheckFuncType Func; + }; + typedef std::pair FuncPair; + typedef std::vector 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 diff --git a/src/orm.h b/src/orm.h index bf8e22e..8b6d0c6 100644 --- a/src/orm.h +++ b/src/orm.h @@ -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 FieldVec; diff --git a/src/storage_tags.cpp b/src/storage_tags.cpp new file mode 100644 index 0000000..3626ac3 --- /dev/null +++ b/src/storage_tags.cpp @@ -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 + +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); +} diff --git a/src/storage_tags.h b/src/storage_tags.h new file mode 100644 index 0000000..c68eb9e --- /dev/null +++ b/src/storage_tags.h @@ -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 { + public: + TagsDictionaryDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L); + private: + }; + + class TagsObjectDB : public ORM::DB { + public: + TagsObjectDB( ORM::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L); + private: + }; +} + +#endif //OWPROV_STORAGE_TAGS_H