Adding DeviceInformation API

This commit is contained in:
stephb9959
2022-03-04 10:23:04 -08:00
parent b6f035b54e
commit b17fd923ed
11 changed files with 174 additions and 27 deletions

View File

@@ -100,7 +100,7 @@ add_executable( owfms
src/NewCommandHandler.cpp src/NewCommandHandler.h
src/storage/orm_history.cpp src/storage/orm_history.h
src/storage/orm_firmwares.cpp src/storage/orm_firmwares.h
src/storage/orm_deviceInfo.cpp src/storage/orm_deviceInfo.h)
src/storage/orm_deviceInfo.cpp src/storage/orm_deviceInfo.h src/RESTAPI/RESTAPI_deviceInformation_handler.cpp src/RESTAPI/RESTAPI_deviceInformation_handler.h)
target_link_libraries(owfms PUBLIC
${Poco_LIBRARIES} ${MySQL_LIBRARIES}

2
build
View File

@@ -1 +1 @@
8
11

View File

@@ -257,6 +257,28 @@ components:
totalSecondsOld:
$ref: '#/components/schemas/TagIntPairList'
DeviceInformation:
type: object
properties:
serialNumber:
type: string
history:
$ref: '#/components/schemas/RevisionHistoryEntryList'
currentFirmware:
type: string
currentFirmwareDate:
type: integer
format: int64
latestFirmware:
type: string
latestFirmwareDate:
type: integer
format: int64
latestFirmwareURI:
type: string
latestFirmwareAvailable:
type: boolean
#########################################################################################
##
## These are endpoints that all services in the uCentral stack must provide
@@ -788,6 +810,28 @@ paths:
404:
$ref: '#/components/responses/NotFound'
/deviceInformation/{serialNumber}:
get:
tags:
- Device Information
summary: receive a repor on a single decide
parameters:
- in: path
name: serialNumber
schema:
type: string
example:
aabbccdd1234
required: true
responses:
200:
$ref: '#/components/schemas/DeviceInformation'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
#########################################################################################
##
## These are endpoints that all services in the uCentral stack must provide

View File

@@ -28,7 +28,6 @@ namespace OpenWifi {
std::shared_ptr<FMSObjects::Firmware> GetFirmware(const std::string & DeviceType, const std::string & Revision);
std::shared_ptr<FMSObjects::Firmware> AddFirmware(const FMSObjects::Firmware &F);
private:
std::atomic_bool Running_=false;
FirmwareCacheMap Cache_;

View File

@@ -11,31 +11,37 @@
#include "RESTAPI/RESTAPI_connectedDevicesHandler.h"
#include "RESTAPI/RESTAPI_historyHandler.h"
#include "RESTAPI/RESTAPI_deviceReportHandler.h"
#include "RESTAPI/RESTAPI_deviceInformation_handler.h"
namespace OpenWifi {
Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
return RESTAPI_Router<
RESTAPI_firmwaresHandler,
RESTAPI_firmwareHandler,
RESTAPI_system_command,
RESTAPI_firmwareAgeHandler,
RESTAPI_connectedDevicesHandler,
RESTAPI_connectedDeviceHandler,
RESTAPI_historyHandler,
RESTAPI_deviceReportHandler
RESTAPI_firmwaresHandler,
RESTAPI_firmwareHandler,
RESTAPI_system_command,
RESTAPI_firmwareAgeHandler,
RESTAPI_connectedDevicesHandler,
RESTAPI_connectedDeviceHandler,
RESTAPI_historyHandler,
RESTAPI_deviceReportHandler,
RESTAPI_deviceInformation_handler
>(Path,Bindings,L, S, TransactionId);
}
Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
return RESTAPI_Router_I<
RESTAPI_firmwaresHandler,
RESTAPI_firmwareHandler,
RESTAPI_system_command,
RESTAPI_connectedDevicesHandler,
RESTAPI_connectedDeviceHandler
RESTAPI_firmwaresHandler,
RESTAPI_firmwareHandler,
RESTAPI_system_command,
RESTAPI_firmwareAgeHandler,
RESTAPI_connectedDevicesHandler,
RESTAPI_connectedDeviceHandler,
RESTAPI_historyHandler,
RESTAPI_deviceReportHandler,
RESTAPI_deviceInformation_handler
>(Path, Bindings, L, S, TransactionId);
}
}

View File

@@ -0,0 +1,42 @@
//
// Created by stephane bourque on 2022-03-04.
//
#include "RESTAPI_deviceInformation_handler.h"
#include "StorageService.h"
#include "LatestFirmwareCache.h"
namespace OpenWifi {
void RESTAPI_deviceInformation_handler::DoGet() {
auto SerialNumber = GetBinding("serialNumber","");
if(SerialNumber.empty() || !Utils::ValidSerialNumber(SerialNumber)) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
FMSObjects::DeviceInformation DI;
// Let's get the history
StorageService()->HistoryDB().GetHistory(SerialNumber,0,100,DI.history.history);
// Let's get the DeviceConnectionInformation
FMSObjects::DeviceConnectionInformation DCI;
StorageService()->DevicesDB().GetDevice(SerialNumber,DCI);
LatestFirmwareCacheEntry LFE;
LatestFirmwareCache()->FindLatestFirmware(DCI.deviceType,LFE);
DI.serialNumber = SerialNumber;
DI.currentFirmware = DCI.revision;
DI.latestFirmware = LFE.Revision;
DI.latestFirmwareDate = LFE.TimeStamp;
FirmwaresDB::RecordName FI;
StorageService()->FirmwaresDB().GetFirmwareByRevision(DCI.revision,DCI.deviceType,FI);
DI.currentFirmwareDate = FI.imageDate;
Poco::JSON::Object Answer;
DI.to_json(Answer);
return ReturnObject(Answer);
}
}

View File

@@ -0,0 +1,26 @@
//
// Created by stephane bourque on 2022-03-04.
//
#pragma once
#include "framework/MicroService.h"
namespace OpenWifi {
class RESTAPI_deviceInformation_handler : public RESTAPIHandler {
public:
RESTAPI_deviceInformation_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L,
std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server,
TransactionId,
Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1//deviceInformation/{serialNumber}"};}
void DoGet() final;
void DoDelete() final {};
void DoPost() final {};
void DoPut() final {};
};
}

View File

@@ -2,8 +2,7 @@
// Created by stephane bourque on 2021-07-19.
//
#ifndef UCENTRALFMS_RESTAPI_DEVICEREPORTHANDLER_H
#define UCENTRALFMS_RESTAPI_DEVICEREPORTHANDLER_H
#pragma once
#include "framework/MicroService.h"
@@ -25,6 +24,3 @@ namespace OpenWifi {
void DoPut() final {};
};
}
#endif //UCENTRALFMS_RESTAPI_DEVICEREPORTHANDLER_H

View File

@@ -2,9 +2,7 @@
// Created by stephane bourque on 2021-07-13.
//
#ifndef UCENTRALFMS_RESTAPI_HISTORYHANDLER_H
#define UCENTRALFMS_RESTAPI_HISTORYHANDLER_H
#pragma once
#include "framework/MicroService.h"
@@ -27,6 +25,3 @@ namespace OpenWifi {
void DoPut() final {};
};
}
#endif //UCENTRALFMS_RESTAPI_HISTORYHANDLER_H

View File

@@ -245,4 +245,30 @@ namespace OpenWifi::FMSObjects {
}
return false;
}
void DeviceInformation::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "serialNumber",serialNumber);
field_to_json(Obj, "history", history);
field_to_json(Obj, "currentFirmware", currentFirmware);
field_to_json(Obj, "currentFirmwareDate", currentFirmwareDate);
field_to_json(Obj, "latestFirmware", latestFirmware);
field_to_json(Obj, "latestFirmwareDate", latestFirmwareDate);
field_to_json(Obj, "latestFirmwareAvailable",latestFirmwareAvailable);
}
bool DeviceInformation::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "serialNumber",serialNumber);
field_from_json(Obj, "history", history);
field_from_json(Obj, "currentFirmware", currentFirmware);
field_from_json(Obj, "currentFirmwareDate", currentFirmwareDate);
field_from_json(Obj, "latestFirmware", latestFirmware);
field_from_json(Obj, "latestFirmwareDate", latestFirmwareDate);
field_from_json(Obj, "latestFirmwareAvailable",latestFirmwareAvailable);
return true;
} catch(...) {
}
return false;
}
}

View File

@@ -127,6 +127,19 @@ namespace OpenWifi::FMSObjects {
void reset();
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
struct DeviceInformation {
std::string serialNumber;
RevisionHistoryEntryList history;
std::string currentFirmware;
uint64_t currentFirmwareDate=0;
std::string latestFirmware;
uint64_t latestFirmwareDate=0;
bool latestFirmwareAvailable;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
}