Allowing signup in the default entity.

This commit is contained in:
stephb9959
2022-04-06 09:21:38 -07:00
parent 53b1434900
commit ce5250598c
18 changed files with 252 additions and 96 deletions

View File

@@ -136,7 +136,7 @@ add_executable(owprov
src/storage/storage_variables.cpp src/storage/storage_variables.h
src/RESTAPI/RESTAPI_variables_handler.cpp src/RESTAPI/RESTAPI_variables_handler.h
src/RESTAPI/RESTAPI_variables_list_handler.cpp src/RESTAPI/RESTAPI_variables_list_handler.h
src/FileDownloader.cpp src/FileDownloader.h src/Tasks/VenueConfigUpdater.cpp src/Tasks/VenueConfigUpdater.h src/Kafka_ProvUpdater.cpp src/Kafka_ProvUpdater.h)
src/FileDownloader.cpp src/FileDownloader.h src/Tasks/VenueConfigUpdater.cpp src/Tasks/VenueConfigUpdater.h src/Kafka_ProvUpdater.cpp src/Kafka_ProvUpdater.h src/storage/storage_operataor.cpp src/storage/storage_operataor.h)
target_link_libraries(owprov PUBLIC
${Poco_LIBRARIES}

2
build
View File

@@ -1 +1 @@
89
91

View File

@@ -950,6 +950,10 @@ components:
format: uuid
cost:
type: number
currency:
type: string
minLength: 3
maxLength: 3
period:
type: string
enum:
@@ -1075,6 +1079,8 @@ components:
serviceClass:
type: string
format: uuid
billingCode:
type: string
SubscriberDeviceList:
type: object
@@ -3394,6 +3400,8 @@ paths:
post:
summary: Create a new operator
operationId: createOperator
tags:
- Operators
parameters:
- in: path
name: uuid
@@ -3410,7 +3418,6 @@ paths:
$ref: '#/components/schemas/Operator'
responses:
200:
description: successfully created an operator
$ref: '#/components/schemas/Operator'
400:
$ref: '#/components/responses/BadRequest'
@@ -3421,6 +3428,8 @@ paths:
put:
summary: Update an existing operator
operationId: updateOperator
tags:
- Operators
parameters:
- in: path
name: uuid
@@ -3435,7 +3444,6 @@ paths:
$ref: '#/components/schemas/Operator'
responses:
200:
description: successfully created an operator
$ref: '#/components/schemas/Operator'
400:
$ref: '#/components/responses/BadRequest'

View File

@@ -30,9 +30,9 @@ namespace OpenWifi {
try {
std::string FileContent;
if (Utils::wgets(url, FileContent)) {
std::ofstream OF(Daemon()->AssetDir() + "/" + filename,
std::ofstream OutputStream(Daemon()->AssetDir() + "/" + filename,
std::ios_base::out | std::ios_base::trunc);
OF << FileContent;
OutputStream << FileContent;
Logger().warning(Poco::format("File %s was downloaded",url));
}
} catch(...) {

View File

@@ -75,17 +75,13 @@ namespace OpenWifi{
return OK();
}
#define __DBG__ std::cout << __LINE__ << std::endl;
void RESTAPI_configurations_handler::DoPost() {
__DBG__
auto UUID = GetBinding("uuid","");
if(UUID.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID);
}
std::string Arg;
__DBG__
if(HasParameter("validateOnly",Arg) && Arg=="true") {
auto Body = ParseStream();
if(!Body->has("configuration")) {
@@ -100,64 +96,49 @@ namespace OpenWifi{
return ReturnObject(Answer);
}
__DBG__
ProvObjects::DeviceConfiguration NewObject;
auto RawObject = ParseStream();
__DBG__
if (!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
__DBG__
if(!ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info)) {
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}
__DBG__
if(!NewObject.entity.empty() && !StorageService()->EntityDB().Exists("id",NewObject.entity)) {
return BadRequest(RESTAPI::Errors::EntityMustExist);
}
__DBG__
if(!NewObject.venue.empty() && !StorageService()->VenueDB().Exists("id",NewObject.venue)) {
return BadRequest(RESTAPI::Errors::VenueMustExist);
}
__DBG__
if(!NewObject.managementPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewObject.managementPolicy)) {
return BadRequest(RESTAPI::Errors::UnknownManagementPolicyUUID);
}
__DBG__
NewObject.inUse.clear();
if(NewObject.deviceTypes.empty() || !DeviceTypeCache()->AreAcceptableDeviceTypes(NewObject.deviceTypes, true)) {
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
}
std::string Error;
__DBG__
if(!ValidateConfigBlock(NewObject,Error)) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid + ", error: " + Error);
}
__DBG__
if(DB_.CreateRecord(NewObject)) {
__DBG__
MoveUsage(StorageService()->PolicyDB(),DB_,"",NewObject.managementPolicy,NewObject.info.id);
__DBG__
AddMembership(StorageService()->VenueDB(),&ProvObjects::Venue::configurations,NewObject.venue, NewObject.info.id);
__DBG__
AddMembership(StorageService()->EntityDB(),&ProvObjects::Entity::configurations,NewObject.entity, NewObject.info.id);
__DBG__
ConfigurationDB::RecordName AddedRecord;
DB_.GetRecord("id", NewObject.info.id, AddedRecord);
Poco::JSON::Object Answer;
AddedRecord.to_json(Answer);
__DBG__
return ReturnObject(Answer);
}
__DBG__
InternalError(RESTAPI::Errors::RecordNotCreated);
}

View File

@@ -41,10 +41,6 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::CannotDeleteRoot);
}
if(Existing.type=="subscriber" && Existing.defaultEntity) {
return BadRequest(RESTAPI::Errors::CannotDeleteSubEntity);
}
if( !Existing.children.empty() || !Existing.devices.empty() || !Existing.venues.empty() || !Existing.locations.empty()
|| !Existing.contacts.empty() || !Existing.configurations.empty()) {
return BadRequest(RESTAPI::Errors::StillInUse);
@@ -54,7 +50,6 @@ namespace OpenWifi{
DB_.DeleteRecord("id",UUID);
DB_.DeleteChild("id",Existing.parent,UUID);
return OK();
}
void RESTAPI_entity_handler::DoPost() {
@@ -73,14 +68,6 @@ namespace OpenWifi{
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
if(NewEntity.type.empty()) {
NewEntity.type = "normal";
}
if(!ValidEntityType(NewEntity.type)) {
return BadRequest(RESTAPI::Errors::InvalidEntityType);
}
if(!ProvObjects::CreateObjectInfo(Obj,UserInfo_.userinfo,NewEntity.info)) {
return BadRequest(RESTAPI::Errors::NameMustBeSet);
}

View File

@@ -242,7 +242,7 @@ namespace OpenWifi{
return NotFound();
}
auto RemoveSubscriber = GetParameter("removeSubscriber","");
auto RemoveSubscriber = GetParameter("removeSubscriber");
if(!RemoveSubscriber.empty()) {
if(Existing.subscriber == RemoveSubscriber) {
Logger().information(Poco::format("%s: removing subscriber (%s)", SerialNumber, RemoveSubscriber));
@@ -250,11 +250,13 @@ namespace OpenWifi{
if(StorageService()->ConfigurationDB().GetRecord("id",Existing.deviceConfiguration,DC)) {
Logger().information(Poco::format("%s: removing configuration for subscriber (%s)", SerialNumber, RemoveSubscriber));
if(DC.subscriberOnly) {
if(!StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration))
if(!StorageService()->ConfigurationDB().DeleteRecord("id", Existing.deviceConfiguration)) {
Logger().debug("Could not delete the subscriber configuration");
}
}
else
else {
Logger().debug("Configurations is not for a subscriber.");
}
Existing.deviceConfiguration = "";
}
Existing.subscriber = "";
@@ -266,6 +268,7 @@ namespace OpenWifi{
state.stringify(OO);
Existing.state = OO.str();
StorageService()->InventoryDB().UpdateRecord("id",Existing.info.id,Existing);
RemoveMembership(StorageService()->EntityDB(),&ProvObjects::Entity::devices,"id",Existing.info.id);
Poco::JSON::Object Answer;
Existing.to_json(Answer);
SDK::GW::Device::SetSubscriber(nullptr, SerialNumber, "");

View File

@@ -77,12 +77,13 @@ namespace OpenWifi{
}
return SendList(Tags, SerialOnly);
} else if(GetBoolParameter("subscribersOnly")) {
if(QB_.CountOnly) {
auto C = DB_.Count(" devClass='subscriber' and subscriber!='' ");
return ReturnCountOnly( C);
}
ProvObjects::InventoryTagVec Tags;
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags, " devClass='subscriber' and subscriber!='' ", OrderBy);
DB_.GetRecords(QB_.Offset, QB_.Limit, Tags," devClass='subscriber' and subscriber!='' ", OrderBy);
return SendList(Tags, SerialOnly);
} else if(GetBoolParameter("unassigned")) {
if(QB_.CountOnly) {

View File

@@ -98,8 +98,6 @@ namespace OpenWifi::ProvObjects {
field_to_json( Obj,"managementRoles", managementRoles);
field_to_json( Obj,"maps", maps);
field_to_json( Obj,"configurations", configurations);
field_to_json( Obj,"type", type);
field_to_json( Obj,"defaultEntity", defaultEntity);
}
bool Entity::from_json(const Poco::JSON::Object::Ptr &Obj) {
@@ -120,8 +118,6 @@ namespace OpenWifi::ProvObjects {
field_from_json( Obj,"managementRoles", managementRoles);
field_from_json( Obj,"maps", maps);
field_from_json( Obj,"configurations", configurations);
field_from_json( Obj,"type", type);
field_from_json( Obj,"defaultEntity", defaultEntity);
return true;
} catch(...) {
@@ -197,6 +193,37 @@ namespace OpenWifi::ProvObjects {
return false;
}
void Operator::to_json(Poco::JSON::Object &Obj) const {
info.to_json(Obj);
field_to_json( Obj,"contact",contact);
field_to_json( Obj,"location",location);
field_to_json( Obj,"managementPolicy",managementPolicy);
field_to_json( Obj,"managementRoles",managementRoles);
field_to_json( Obj,"rrm",rrm);
field_to_json( Obj,"firmwareUpgrade",firmwareUpgrade);
field_to_json( Obj,"firmwareRCOnly",firmwareRCOnly);
field_to_json( Obj,"variables",variables);
field_to_json( Obj,"defaultOperator",defaultOperator);
}
bool Operator::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
info.from_json(Obj);
field_from_json( Obj,"contact",contact);
field_from_json( Obj,"location",location);
field_from_json( Obj,"managementPolicy",managementPolicy);
field_from_json( Obj,"managementRoles",managementRoles);
field_from_json( Obj,"rrm",rrm);
field_from_json( Obj,"firmwareUpgrade",firmwareUpgrade);
field_from_json( Obj,"firmwareRCOnly",firmwareRCOnly);
field_from_json( Obj,"variables",variables);
field_from_json( Obj,"defaultOperator",defaultOperator);
return true;
} catch(...) {
}
return false;
}
void UserInfoDigest::to_json(Poco::JSON::Object &Obj) const {
field_to_json( Obj,"id",id);
field_to_json( Obj,"entity",loginId);

View File

@@ -79,8 +79,6 @@ namespace OpenWifi::ProvObjects {
Types::UUIDvec_t managementRoles;
Types::UUIDvec_t maps;
Types::UUIDvec_t configurations;
std::string type;
bool defaultEntity=false;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
@@ -296,6 +294,23 @@ namespace OpenWifi::ProvObjects {
};
typedef std::vector<DeviceConfiguration> DeviceConfigurationVec;
struct Operator {
ObjectInfo info;
Types::UUID_t contact;
Types::UUID_t location;
Types::UUID_t managementPolicy;
Types::UUIDvec_t managementRoles;
std::string rrm;
std::string firmwareUpgrade;
bool firmwareRCOnly=true;
Types::UUIDvec_t variables;
bool defaultOperator=false;
Types::StringVec sourceIP;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct InventoryTag {
ObjectInfo info;
std::string serialNumber;

View File

@@ -70,15 +70,9 @@ namespace OpenWifi {
IT.info.modified = OpenWifi::Now();
IT.realMacAddress = SE.macAddress;
if(IT.entity.empty()) {
IT.entity = StorageService()->DefaultSubscriberEntity();
} else {
// if the entity was not a subscriber entity, then we need to goto the default entity
ProvObjects::Entity TE;
if(StorageService()->EntityDB().GetRecord("id",IT.entity,TE) && (TE.type=="subscriber")) {
// then this is already the right Entity
} else {
IT.entity = StorageService()->DefaultSubscriberEntity();
}
}
Poco::JSON::Object NewState;
NewState.set("method", "signup");

View File

@@ -29,6 +29,7 @@ namespace OpenWifi {
MapDB_ = std::make_unique<OpenWifi::MapDB>(dbType_, *Pool_, Logger());
SignupDB_ = std::make_unique<OpenWifi::SignupDB>(dbType_, *Pool_, Logger());
VariablesDB_ = std::make_unique<OpenWifi::VariablesDB>(dbType_, *Pool_, Logger());
OperatorDB_ = std::make_unique<OpenWifi::OperatorDB>(dbType_, *Pool_, Logger());
EntityDB_->Create();
PolicyDB_->Create();
@@ -43,6 +44,7 @@ namespace OpenWifi {
MapDB_->Create();
SignupDB_->Create();
VariablesDB_->Create();
OperatorDB_->Create();
ExistFunc_[EntityDB_->Prefix()] = [=](const char *F, std::string &V) -> bool { return EntityDB_->Exists(F,V); };
ExistFunc_[PolicyDB_->Prefix()] = [=](const char *F, std::string &V) -> bool { return PolicyDB_->Exists(F,V); };
@@ -57,6 +59,7 @@ namespace OpenWifi {
ExistFunc_[MapDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return MapDB_->Exists(F,V); };
ExistFunc_[SignupDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return SignupDB_->Exists(F,V); };
ExistFunc_[VariablesDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return VariablesDB_->Exists(F,V); };
ExistFunc_[OperatorDB_->Prefix()] = [=](const char *F, std::string &V) ->bool { return OperatorDB_->Exists(F,V); };
ExpandFunc_[EntityDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) -> bool { return EntityDB_->GetNameAndDescription(F,V, Name, Description); };
ExpandFunc_[PolicyDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) -> bool { return PolicyDB_->GetNameAndDescription(F,V, Name, Description); };
@@ -71,13 +74,13 @@ namespace OpenWifi {
ExpandFunc_[MapDB_->Prefix()] = [=](const char *F, std::string &V, [[maybe_unused]] std::string &Name, [[maybe_unused]] std::string & Description) ->bool { return MapDB_->Exists(F,V);; };
ExpandFunc_[SignupDB_->Prefix()] = [=](const char *F, std::string &V, [[maybe_unused]] std::string &Name, [[maybe_unused]] std::string & Description) ->bool { return SignupDB_->Exists(F,V);; };
ExpandFunc_[VariablesDB_->Prefix()] = [=](const char *F, std::string &V, [[maybe_unused]] std::string &Name, [[maybe_unused]] std::string & Description) ->bool { return VariablesDB_->Exists(F,V);; };
ExpandFunc_[OperatorDB_->Prefix()] = [=](const char *F, std::string &V, std::string &Name, std::string & Description) ->bool { return OperatorDB_->GetNameAndDescription(F,V, Name, Description); };
EntityDB_->CheckForRoot();
InventoryDB_->InitializeSerialCache();
ConsistencyCheck();
CreateDefaultSubscriberEntity();
CreateDefaultSubscriberOperataor();
TimerCallback_ = std::make_unique<Poco::TimerCallback<Storage>>(*this,&Storage::onTimer);
Timer_.setStartInterval( 20 * 1000); // first run in 20 seconds
@@ -224,31 +227,8 @@ namespace OpenWifi {
}
void Storage::CreateDefaultSubscriberEntity() {
void Storage::CreateDefaultSubscriberOperataor() {
std::vector<ProvObjects::Entity> Entities;
if(EntityDB().GetRecords(0,1,Entities, " type='subscriber' and defaultEntity=true ")) {
DefaultSubscriberEntity_ = Entities[0].info.id;
} else {
ProvObjects::Entity DefEntity;
DefEntity.info.name = "Default Subscriber Entity";
DefaultSubscriberEntity_ = DefEntity.info.id = MicroService::CreateUUID();
DefEntity.type = "subscriber";
DefEntity.defaultEntity = true;
DefEntity.info.created = DefEntity.info.modified = OpenWifi::Now();
DefEntity.rrm = "inherit";
EntityDB().CreateRecord(DefEntity);
}
// To be backwards compatible, we need to assign all the subscribers that do not have an entity to
// the default entity.
// We also need to make sure that all entities have some type set.
std::vector<std::string> Script{
"update entities set type='normal', defaultEntity=false where type is null ",
fmt::format("update inventory set entity='{}' where entity='' and subscriber!='' ", DefaultSubscriberEntity_)
};
EntityDB().RunScript(Script);
}
}

View File

@@ -23,6 +23,7 @@
#include "storage/storage_maps.h"
#include "storage/storage_signup.h"
#include "storage/storage_variables.h"
#include "storage/storage_operataor.h"
namespace OpenWifi {
@@ -52,6 +53,7 @@ namespace OpenWifi {
OpenWifi::MapDB & MapDB() { return *MapDB_; };
OpenWifi::SignupDB & SignupDB() { return *SignupDB_; };
OpenWifi::VariablesDB & VariablesDB() { return *VariablesDB_; };
OpenWifi::OperatorDB & OperatorDB() { return *OperatorDB_; };
bool Validate(const Poco::URI::QueryParameters &P, std::string &Error);
bool Validate(const Types::StringVec &P, std::string &Error);
@@ -62,7 +64,7 @@ namespace OpenWifi {
void onTimer(Poco::Timer & timer);
inline const std::string & DefaultSubscriberEntity() { return DefaultSubscriberEntity_; }
inline const std::string & DefaultOperator() { return DefaultOperator_; }
private:
std::unique_ptr<OpenWifi::EntityDB> EntityDB_;
@@ -78,7 +80,8 @@ namespace OpenWifi {
std::unique_ptr<OpenWifi::MapDB> MapDB_;
std::unique_ptr<OpenWifi::SignupDB> SignupDB_;
std::unique_ptr<OpenWifi::VariablesDB> VariablesDB_;
std::string DefaultSubscriberEntity_;
std::unique_ptr<OpenWifi::OperatorDB> OperatorDB_;
std::string DefaultOperator_;
typedef std::function<bool(const char *FieldName, std::string &Value)> exist_func;
@@ -89,7 +92,7 @@ namespace OpenWifi {
std::unique_ptr<Poco::TimerCallback<Storage>> TimerCallback_;
void ConsistencyCheck();
void CreateDefaultSubscriberEntity();
void CreateDefaultSubscriberOperataor();
};

View File

@@ -72,6 +72,7 @@ using namespace std::chrono_literals;
#include "Poco/Util/PropertyFileConfiguration.h"
#include "Poco/SplitterChannel.h"
#include "Poco/JWT/Signer.h"
#include "Poco/DeflatingStream.h"
#include "cppkafka/cppkafka.h"
@@ -2217,6 +2218,22 @@ namespace OpenWifi {
inline void ReturnObject(Poco::JSON::Object &Object) {
PrepareResponse();
if(Request!= nullptr) {
// can we compress ???
auto AcceptedEncoding = Request->find("Accept-Encoding");
if(AcceptedEncoding!=Request->end()) {
if( AcceptedEncoding->second.find("gzip")!=std::string::npos ||
AcceptedEncoding->second.find("compress")!=std::string::npos) {
Response->set("Content-Encoding", "gzip");
std::cout << "Compressing output" << std::endl;
std::ostream &Answer = Response->send();
Poco::DeflatingOutputStream deflater(Answer, Poco::DeflatingStreamBuf::STREAM_GZIP);
Poco::JSON::Stringifier::stringify(Object, deflater);
deflater.close();
return;
}
}
}
std::ostream &Answer = Response->send();
Poco::JSON::Stringifier::stringify(Object, Answer);
}

View File

@@ -39,9 +39,7 @@ namespace OpenWifi {
ORM::Field{"managementPolicies",ORM::FieldType::FT_TEXT},
ORM::Field{"managementRoles",ORM::FieldType::FT_TEXT},
ORM::Field{"maps",ORM::FieldType::FT_TEXT},
ORM::Field{"configurations",ORM::FieldType::FT_TEXT},
ORM::Field{"type",ORM::FieldType::FT_TEXT},
ORM::Field{"defaultEntity",ORM::FieldType::FT_TEXT}
ORM::Field{"configurations",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec EntityDB_Indexes{
@@ -64,8 +62,6 @@ namespace OpenWifi {
"alter table " + TableName_ + " add column managementPolicies text",
"alter table " + TableName_ + " add column maps text",
"alter table " + TableName_ + " add column configurations text",
"alter table " + TableName_ + " add column type text",
"alter table " + TableName_ + " add column defaultEntity boolean",
"alter table " + TableName_ + " add column managementRoles text"
};
@@ -234,8 +230,6 @@ template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects:
Out.managementRoles = OpenWifi::RESTAPI_utils::to_object_array(In.get<19>());
Out.maps = OpenWifi::RESTAPI_utils::to_object_array(In.get<20>());
Out.configurations = OpenWifi::RESTAPI_utils::to_object_array(In.get<21>());
Out.type = In.get<22>();
Out.defaultEntity = In.get<23>();
}
template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects::Entity>::Convert(const OpenWifi::ProvObjects::Entity &In, OpenWifi::EntityDBRecordType &Out) {
@@ -261,6 +255,4 @@ template<> void ORM::DB< OpenWifi::EntityDBRecordType, OpenWifi::ProvObjects:
Out.set<19>(OpenWifi::RESTAPI_utils::to_string(In.managementRoles));
Out.set<20>(OpenWifi::RESTAPI_utils::to_string(In.maps));
Out.set<21>(OpenWifi::RESTAPI_utils::to_string(In.configurations));
Out.set<22>(In.type);
Out.set<23>(In.defaultEntity);
}

View File

@@ -35,9 +35,7 @@ namespace OpenWifi {
std::string,
std::string,
std::string,
std::string,
std::string,
bool
std::string
> EntityDBRecordType;
class EntityDB : public ORM::DB<EntityDBRecordType, ProvObjects::Entity> {

View File

@@ -0,0 +1,111 @@
//
// Created by stephane bourque on 2022-04-05.
//
#include "storage_operataor.h"
#include "framework/OpenWifiTypes.h"
#include "RESTObjects/RESTAPI_SecurityObjects.h"
#include "StorageService.h"
#include "framework/MicroService.h"
namespace OpenWifi {
static ORM::FieldVec OperatorDB_Fields{
// object info
ORM::Field{"id",64, true},
ORM::Field{"name",ORM::FieldType::FT_TEXT},
ORM::Field{"description",ORM::FieldType::FT_TEXT},
ORM::Field{"notes",ORM::FieldType::FT_TEXT},
ORM::Field{"created",ORM::FieldType::FT_BIGINT},
ORM::Field{"modified",ORM::FieldType::FT_BIGINT},
ORM::Field{"contact",ORM::FieldType::FT_TEXT},
ORM::Field{"location",ORM::FieldType::FT_TEXT},
ORM::Field{"managementPolicy",ORM::FieldType::FT_TEXT},
ORM::Field{"managementRoles",ORM::FieldType::FT_TEXT},
ORM::Field{"rrm",ORM::FieldType::FT_TEXT},
ORM::Field{"firmwareUpgrade",ORM::FieldType::FT_TEXT},
ORM::Field{"firmwareRCOnly",ORM::FieldType::FT_BOOLEAN},
ORM::Field{"variables",ORM::FieldType::FT_TEXT},
ORM::Field{"defaultOperator",ORM::FieldType::FT_BOOLEAN},
ORM::Field{"sourceIP",ORM::FieldType::FT_TEXT}
};
static ORM::IndexVec OperatorDB_Indexes{
{ std::string("operator_name_index"),
ORM::IndexEntryVec{
{std::string("name"),
ORM::Indextype::ASC} } }
};
OperatorDB::OperatorDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
DB(T, "operators", OperatorDB_Fields, OperatorDB_Indexes, P, L, "opr") {
}
bool OperatorDB::Upgrade([[maybe_unused]] uint32_t from, uint32_t &to) {
to = Version();
std::vector<std::string> Script{
};
RunScript(Script);
return true;
}
bool OperatorDB::GetByIP(const std::string &IP, std::string & uuid) {
try {
std::string UUID;
std::function<bool(const ProvObjects::Operator &E)> Function = [&UUID,IP] (const ProvObjects::Operator &E) ->bool {
if(E.sourceIP.empty())
return true;
if(CIDR::IpInRanges(IP, E.sourceIP)) {
UUID = E.info.id;
return false;
}
return true;
};
Iterate(Function);
uuid=UUID;
} catch (const Poco::Exception &E) {
Logger().log(E);
}
return false;
}
}
template<> void ORM::DB< OpenWifi::OperatorDBRecordType, OpenWifi::ProvObjects::Operator>::Convert(const OpenWifi::OperatorDBRecordType &In, OpenWifi::ProvObjects::Operator &Out) {
Out.info.id = In.get<0>();
Out.info.name = In.get<1>();
Out.info.description = In.get<2>();
Out.info.notes = OpenWifi::RESTAPI_utils::to_object_array<OpenWifi::SecurityObjects::NoteInfo>(In.get<3>());
Out.info.created = In.get<4>();
Out.info.modified = In.get<5>();
Out.contact = In.get<6>();
Out.location = In.get<7>();
Out.managementPolicy = In.get<8>();
Out.managementRoles = OpenWifi::RESTAPI_utils::to_object_array(In.get<9>());
Out.rrm = In.get<10>();
Out.firmwareUpgrade = In.get<11>();
Out.firmwareRCOnly = In.get<12>();
Out.variables = OpenWifi::RESTAPI_utils::to_object_array(In.get<13>());
Out.defaultOperator = In.get<14>();
Out.sourceIP = OpenWifi::RESTAPI_utils::to_object_array(In.get<15>());
}
template<> void ORM::DB< OpenWifi::OperatorDBRecordType, OpenWifi::ProvObjects::Operator>::Convert(const OpenWifi::ProvObjects::Operator &In, OpenWifi::OperatorDBRecordType &Out) {
Out.set<0>(In.info.id);
Out.set<1>(In.info.name);
Out.set<2>(In.info.description);
Out.set<3>(OpenWifi::RESTAPI_utils::to_string(In.info.notes));
Out.set<4>(In.info.created);
Out.set<5>(In.info.modified);
Out.set<6>(In.contact);
Out.set<7>(In.location);
Out.set<8>(In.managementPolicy);
Out.set<9>(OpenWifi::RESTAPI_utils::to_string(In.managementRoles));
Out.set<10>(In.rrm);
Out.set<11>(In.firmwareUpgrade);
Out.set<12>(In.firmwareRCOnly);
Out.set<13>(OpenWifi::RESTAPI_utils::to_string(In.variables));
Out.set<14>(In.defaultOperator);
Out.set<15>(OpenWifi::RESTAPI_utils::to_string(In.sourceIP));
}

View File

@@ -0,0 +1,39 @@
//
// Created by stephane bourque on 2022-04-05.
//
#pragma once
#include "framework/orm.h"
#include "RESTObjects/RESTAPI_ProvObjects.h"
namespace OpenWifi {
typedef Poco::Tuple<
std::string,
std::string,
std::string,
std::string,
uint64_t,
uint64_t,
std::string,
std::string,
std::string,
std::string,
std::string,
std::string,
bool,
std::string,
bool,
std::string
> OperatorDBRecordType;
class OperatorDB : public ORM::DB<OperatorDBRecordType, ProvObjects::Operator> {
public:
OperatorDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
virtual ~OperatorDB() {};
bool GetByIP(const std::string &IP, std::string & uuid);
bool Upgrade(uint32_t from, uint32_t &to) override;
private:
};
}