Fixing firmware inheritance rules.

This commit is contained in:
stephb9959
2021-10-27 14:42:42 -07:00
parent 7740c501f3
commit 66649d821e
4 changed files with 57 additions and 0 deletions

View File

@@ -43,6 +43,10 @@ namespace OpenWifi{
}
Answer.set("entries", Inner);
return ReturnObject(Answer);
} else if(HasParameter("computedAffected",Arg) && Arg=="true") {
Types::UUIDvec_t DeviceSerialNumbers;
DB_.GetListOfAffectedDevices(UUID,DeviceSerialNumbers);
return ReturnObject("affectedDevices", DeviceSerialNumbers);
} else if(QB_.AdditionalInfo) {
AddExtendedInfo(Existing,Answer);
}

View File

@@ -11,6 +11,7 @@
#include "framework/OpenWifiTypes.h"
#include "framework/MicroService.h"
#include "RESTObjects/RESTAPI_SecurityObjects.h"
#include "StorageService.h"
namespace OpenWifi {
@@ -42,6 +43,48 @@ namespace OpenWifi {
ConfigurationDB::ConfigurationDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) :
DB(T, "configurations", ConfigurationDB_Fields, ConfigurationDB_Indexes, P, L, "cfg") {}
bool ConfigurationDB::GetListOfAffectedDevices(const Types::UUID_t & ConfigUUID, Types::UUIDvec_t & DeviceSerialNumbers ) {
// find all the places where this configuration is used
// for each of them get the devices they oversee
ProvObjects::DeviceConfiguration Config;
if(!GetRecord("id",ConfigUUID,Config))
return false;
if(Config.inUse.empty())
return true;
std::set<std::string> SerialNumbers;
for(const auto &i:Config.inUse) {
auto Tokens = Poco::StringTokenizer(i,":");
if(Tokens.count()!=2)
continue;
if(Tokens[0] == "ent") {
ProvObjects::Entity E;
if(!StorageService()->EntityDB().GetRecord("id",Tokens[1],E))
continue;
for(const auto &j:E.devices)
SerialNumbers.insert(j);
} else if (Tokens[0] == "ven") {
ProvObjects::Venue V;
if(!StorageService()->VenueDB().GetRecord("id",Tokens[1],V))
continue;
for(const auto &j:V.devices)
SerialNumbers.insert(j);
} else if (Tokens[0] == "inv") {
ProvObjects::InventoryTag T;
if(!StorageService()->InventoryDB().GetRecord("id",Tokens[1],T))
continue;
SerialNumbers.insert(T.serialNumber);
}
}
std::for_each(cbegin(SerialNumbers),cend(SerialNumbers),
[&DeviceSerialNumbers](const std::string &S){ DeviceSerialNumbers.push_back(S); });
return true;
}
}
template<> void ORM::DB< OpenWifi::ConfigurationDBRecordType, OpenWifi::ProvObjects::DeviceConfiguration>::Convert(OpenWifi::ConfigurationDBRecordType &In, OpenWifi::ProvObjects::DeviceConfiguration &Out) {

View File

@@ -36,6 +36,7 @@ namespace OpenWifi {
class ConfigurationDB : public ORM::DB<ConfigurationDBRecordType, ProvObjects::DeviceConfiguration> {
public:
ConfigurationDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
bool GetListOfAffectedDevices(const Types::UUID_t & ConfigUUID, Types::UUIDvec_t & DeviceSerialNumbers );
private:
};
}

View File

@@ -449,6 +449,15 @@ addresscheck() {
wscat -c wss://${OWPROV}/api/v1/ws
}
affecteddevices() {
computedAffected
curl ${FLAGS} -X GET "https://${OWPROV}/api/v1/configurations/${1}?computedAffected=true" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "accept: application/json" > ${result_file}
jq < ${result_file}
}
shopt -s nocasematch
case "$1" in
"login") login; help ; logout ;;