Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-13434
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Feb 20, 2024
1 parent 5bee5b1 commit 094bba4
Show file tree
Hide file tree
Showing 9 changed files with 4,795 additions and 215 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79
81
18 changes: 18 additions & 0 deletions openapi/owgw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,15 @@ paths:
schema:
type: string
required: true
- in: query
name: deviceType
schema:
type: string
enum:
- AP
- SWITCH
required: false
default: AP
requestBody:
description: Information used to create the new device
content:
Expand Down Expand Up @@ -2009,6 +2018,15 @@ paths:
schema:
type: string
required: true
- in: query
name: deviceType
schema:
type: string
enum:
- AP
- SWITCH
required: false
default: AP
requestBody:
description: Configuration details
content:
Expand Down
8 changes: 6 additions & 2 deletions src/RESTAPI/RESTAPI_default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::ModelIDListCannotBeEmpty);
}

auto DeviceType = GetParameter("deviceType", "AP");
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(DefConfig.Configuration, Error,
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceType),
DefConfig.Configuration, Error,
GetBoolParameter("strict", false))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Expand Down Expand Up @@ -89,8 +91,10 @@ namespace OpenWifi {
}

if (!NewConfig.Configuration.empty()) {
auto DeviceType = GetParameter("deviceType", "AP");
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(NewConfig.Configuration, Error,
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceType),
NewConfig.Configuration, Error,
GetBoolParameter("strict", false))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Expand Down
7 changes: 6 additions & 1 deletion src/RESTAPI/RESTAPI_device_commandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,15 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::SerialNumberMismatch);
}

GWObjects::Device DeviceInfo;
if (!StorageService()->GetDevice(SerialNumber_, DeviceInfo)) {
return NotFound();
}
auto Configuration =
GetS(RESTAPI::Protocol::CONFIGURATION, Obj, uCentralProtocol::EMPTY_JSON_DOC);
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(Configuration, Error,
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceInfo.DeviceType),
Configuration, Error,
GetBoolParameter("strict", false))) {
CallCanceled("CONFIGURE", CMD_UUID, CMD_RPC, RESTAPI::Errors::ConfigBlockInvalid);
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
Expand Down
9 changes: 6 additions & 3 deletions src/RESTAPI/RESTAPI_device_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ namespace OpenWifi {
auto Config = Obj->get("configuration").toString();
Poco::JSON::Object Answer;
std::vector<std::string> Error;
auto DeviceType = GetParameter("deviceType", "AP");
auto Res =
ValidateUCentralConfiguration(Config, Error, GetBoolParameter("strict", false));
ValidateUCentralConfiguration(ConfigurationValidator::GetType(DeviceType),Config, Error, GetBoolParameter("strict", false));
Answer.set("valid", Res);
if (!Error.empty())
Answer.set("error", Error);
Expand All @@ -126,7 +127,8 @@ namespace OpenWifi {
std::vector<std::string> Error;
if (Device.Configuration.empty() ||
(!Device.Configuration.empty() &&
!ValidateUCentralConfiguration(Device.Configuration, Error,
!ValidateUCentralConfiguration(ConfigurationValidator::GetType(Device.DeviceType),
Device.Configuration, Error,
GetBoolParameter("strict", false)))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Expand Down Expand Up @@ -170,7 +172,8 @@ namespace OpenWifi {

if (!NewDevice.Configuration.empty()) {
std::vector<std::string> Error;
if (!ValidateUCentralConfiguration(NewDevice.Configuration, Error,
if (!ValidateUCentralConfiguration(ConfigurationValidator::GetType(Existing.DeviceType),
NewDevice.Configuration, Error,
GetBoolParameter("strict", false))) {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Expand Down
6 changes: 6 additions & 0 deletions src/RESTObjects/RESTAPI_ProvObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ namespace OpenWifi::ProvObjects {
field_to_json(Obj, "locale", locale);
field_to_json(Obj, "realMacAddress", realMacAddress);
field_to_json(Obj, "doNotAllowOverrides", doNotAllowOverrides);
field_to_json(Obj, "imported", imported);
field_to_json(Obj, "connected", connected);
field_to_json(Obj, "platform", platform);
}

bool InventoryTag::from_json(const Poco::JSON::Object::Ptr &Obj) {
Expand All @@ -609,6 +612,9 @@ namespace OpenWifi::ProvObjects {
field_from_json(Obj, "locale", locale);
field_from_json(Obj, "realMacAddress", realMacAddress);
field_from_json(Obj, "doNotAllowOverrides", doNotAllowOverrides);
field_from_json(Obj, "imported", imported);
field_from_json(Obj, "connected", connected);
field_from_json(Obj, "platform", platform);
return true;
} catch (...) {
}
Expand Down
4 changes: 3 additions & 1 deletion src/RESTObjects/RESTAPI_ProvObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ namespace OpenWifi::ProvObjects {
std::string locale;
std::string realMacAddress;
bool doNotAllowOverrides = false;
std::uint64_t imported=0;
std::uint64_t connected=0;
std::string platform{"AP"};

void to_json(Poco::JSON::Object &Obj) const;

bool from_json(const Poco::JSON::Object::Ptr &Obj);
};

Expand Down
Loading

0 comments on commit 094bba4

Please sign in to comment.