mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
synced 2025-11-08 22:53:19 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -21,14 +21,14 @@ namespace OpenWifi {
|
||||
void RESTAPI_device_handler::DoGet() {
|
||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
|
||||
|
||||
if(!Utils::NormalizeMac(SerialNumber)) {
|
||||
if (!Utils::NormalizeMac(SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
}
|
||||
|
||||
GWObjects::Device Device;
|
||||
if (StorageService()->GetDevice(SerialNumber, Device)) {
|
||||
Poco::JSON::Object Answer;
|
||||
if(GetBoolParameter("completeInfo",false)) {
|
||||
Poco::JSON::Object Answer;
|
||||
if (GetBoolParameter("completeInfo", false)) {
|
||||
CompleteDeviceInfo(Device, Answer);
|
||||
return ReturnObject(Answer);
|
||||
} else {
|
||||
@@ -41,34 +41,34 @@ namespace OpenWifi {
|
||||
void RESTAPI_device_handler::DoDelete() {
|
||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
|
||||
|
||||
if(!Utils::NormalizeMac(SerialNumber)) {
|
||||
if (!Utils::NormalizeMac(SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
}
|
||||
|
||||
std::string Arg;
|
||||
if(HasParameter("oui",Arg) && Arg=="true" && SerialNumber.size()==6) {
|
||||
if (HasParameter("oui", Arg) && Arg == "true" && SerialNumber.size() == 6) {
|
||||
|
||||
std::set<std::string> Set;
|
||||
std::vector<GWObjects::Device> Devices;
|
||||
std::set<std::string> Set;
|
||||
std::vector<GWObjects::Device> Devices;
|
||||
|
||||
bool Done = false;
|
||||
uint64_t Offset=1;
|
||||
while(!Done) {
|
||||
uint64_t Offset = 1;
|
||||
while (!Done) {
|
||||
|
||||
StorageService()->GetDevices(Offset,500,Devices);
|
||||
for(const auto &i:Devices) {
|
||||
if(i.SerialNumber.substr(0,6) == SerialNumber) {
|
||||
StorageService()->GetDevices(Offset, 500, Devices);
|
||||
for (const auto &i : Devices) {
|
||||
if (i.SerialNumber.substr(0, 6) == SerialNumber) {
|
||||
Set.insert(i.SerialNumber);
|
||||
}
|
||||
}
|
||||
|
||||
if(Devices.size()<500)
|
||||
Done=true;
|
||||
if (Devices.size() < 500)
|
||||
Done = true;
|
||||
|
||||
Offset += Devices.size();
|
||||
}
|
||||
|
||||
for(auto &i:Set) {
|
||||
for (auto &i : Set) {
|
||||
std::string SNum{i};
|
||||
StorageService()->DeleteDevice(SNum);
|
||||
}
|
||||
@@ -85,23 +85,24 @@ namespace OpenWifi {
|
||||
void RESTAPI_device_handler::DoPost() {
|
||||
|
||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
|
||||
if(!Utils::NormalizeMac(SerialNumber)) {
|
||||
if (!Utils::NormalizeMac(SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
}
|
||||
|
||||
const auto &Obj = ParsedBody_;
|
||||
std::string Arg;
|
||||
if(HasParameter("validateOnly",Arg) && Arg=="true") {
|
||||
if(!Obj->has("configuration")) {
|
||||
if (HasParameter("validateOnly", Arg) && Arg == "true") {
|
||||
if (!Obj->has("configuration")) {
|
||||
return BadRequest(RESTAPI::Errors::MustHaveConfigElement);
|
||||
}
|
||||
auto Config=Obj->get("configuration").toString();
|
||||
Poco::JSON::Object Answer;
|
||||
std::vector<std::string> Error;
|
||||
auto Res = ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict",false));
|
||||
Answer.set("valid",Res);
|
||||
if(!Error.empty())
|
||||
Answer.set("error",Error);
|
||||
auto Config = Obj->get("configuration").toString();
|
||||
Poco::JSON::Object Answer;
|
||||
std::vector<std::string> Error;
|
||||
auto Res =
|
||||
ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict", false));
|
||||
Answer.set("valid", Res);
|
||||
if (!Error.empty())
|
||||
Answer.set("error", Error);
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
@@ -110,20 +111,23 @@ namespace OpenWifi {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(!Utils::NormalizeMac(Device.SerialNumber)) {
|
||||
return BadRequest( RESTAPI::Errors::InvalidSerialNumber);
|
||||
if (!Utils::NormalizeMac(Device.SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidSerialNumber);
|
||||
}
|
||||
|
||||
if(SerialNumber!=Device.SerialNumber) {
|
||||
if (SerialNumber != Device.SerialNumber) {
|
||||
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
|
||||
}
|
||||
|
||||
std::vector<std::string> Error;
|
||||
if(Device.Configuration.empty() || (!Device.Configuration.empty() && !ValidateUCentralConfiguration(Device.Configuration,Error, GetBoolParameter("strict",false)))) {
|
||||
if (Device.Configuration.empty() ||
|
||||
(!Device.Configuration.empty() &&
|
||||
!ValidateUCentralConfiguration(Device.Configuration, Error,
|
||||
GetBoolParameter("strict", false)))) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
|
||||
}
|
||||
|
||||
for(auto &i:Device.Notes) {
|
||||
for (auto &i : Device.Notes) {
|
||||
i.createdBy = UserInfo_.userinfo.email;
|
||||
i.created = Utils::Now();
|
||||
}
|
||||
@@ -145,7 +149,7 @@ namespace OpenWifi {
|
||||
void RESTAPI_device_handler::DoPut() {
|
||||
std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
|
||||
|
||||
if(!Utils::ValidSerialNumber(SerialNumber)) {
|
||||
if (!Utils::ValidSerialNumber(SerialNumber)) {
|
||||
return BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
}
|
||||
|
||||
@@ -155,14 +159,15 @@ namespace OpenWifi {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
GWObjects::Device Existing;
|
||||
if(!StorageService()->GetDevice(SerialNumber, Existing)) {
|
||||
GWObjects::Device Existing;
|
||||
if (!StorageService()->GetDevice(SerialNumber, Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if(!NewDevice.Configuration.empty()) {
|
||||
if (!NewDevice.Configuration.empty()) {
|
||||
std::vector<std::string> Error;
|
||||
if (!ValidateUCentralConfiguration(NewDevice.Configuration, Error, GetBoolParameter("strict",false))) {
|
||||
if (!ValidateUCentralConfiguration(NewDevice.Configuration, Error,
|
||||
GetBoolParameter("strict", false))) {
|
||||
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
|
||||
}
|
||||
Config::Config NewConfig(NewDevice.Configuration);
|
||||
@@ -178,7 +183,7 @@ namespace OpenWifi {
|
||||
AssignIfPresent(Obj, "subscriber", Existing.subscriber);
|
||||
AssignIfPresent(Obj, "entity", Existing.entity);
|
||||
|
||||
for(auto &i:NewDevice.Notes) {
|
||||
for (auto &i : NewDevice.Notes) {
|
||||
i.createdBy = UserInfo_.userinfo.email;
|
||||
i.created = Utils::Now();
|
||||
Existing.Notes.push_back(i);
|
||||
@@ -193,4 +198,4 @@ namespace OpenWifi {
|
||||
}
|
||||
InternalError(RESTAPI::Errors::RecordNotUpdated);
|
||||
}
|
||||
}
|
||||
} // namespace OpenWifi
|
||||
Reference in New Issue
Block a user