mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-03 12:08:08 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -3,6 +3,98 @@
|
||||
//
|
||||
|
||||
#include "RESTAPI_openroaming_orion_acct_handler.h"
|
||||
#include "OpenRoamin_GlobalReach.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
void RESTAPI_openroaming_orion_acct_handler::DoGet() {
|
||||
auto Account = GetBinding("id","");
|
||||
if(Account.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
ProvObjects::GooglOrionAccountInfo Record;
|
||||
if(DB_.GetRecord("id",Account,Record)) {
|
||||
return ReturnObject(Record);
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
void RESTAPI_openroaming_orion_acct_handler::DoDelete() {
|
||||
auto Account = GetBinding("id","");
|
||||
if(Account.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
ProvObjects::GooglOrionAccountInfo Record;
|
||||
if(!DB_.GetRecord("id",Account,Record)) {
|
||||
return NotFound();
|
||||
}
|
||||
DB_.DeleteRecord("id", Account);
|
||||
return OK();
|
||||
}
|
||||
|
||||
void RESTAPI_openroaming_orion_acct_handler::DoPost() {
|
||||
auto Account = GetBinding("id","");
|
||||
if(Account.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
const auto &RawObject = ParsedBody_;
|
||||
ProvObjects::GooglOrionAccountInfo NewObject;
|
||||
if( !NewObject.from_json(RawObject)) {
|
||||
return BadRequest(OpenWifi::RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if( NewObject.privateKey.empty() ||
|
||||
NewObject.certificate.empty() ||
|
||||
NewObject.cacerts.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
if( !Utils::VerifyRSAKey(NewObject.privateKey) ||
|
||||
!Utils::ValidX509Certificate(NewObject.certificate) ||
|
||||
!Utils::ValidX509Certificate(NewObject.cacerts)) {
|
||||
return BadRequest(RESTAPI::Errors::NotAValidECKey);
|
||||
}
|
||||
|
||||
ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info);
|
||||
|
||||
if(DB_.CreateRecord(NewObject)) {
|
||||
ProvObjects::GooglOrionAccountInfo StoredObject;
|
||||
DB_.GetRecord("id",NewObject.info.id,StoredObject);
|
||||
return ReturnObject(StoredObject);
|
||||
}
|
||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
void RESTAPI_openroaming_orion_acct_handler::DoPut() {
|
||||
auto Account = GetBinding("account","");
|
||||
if(Account.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
const auto &RawObject = ParsedBody_;
|
||||
ProvObjects::GLBLRAccountInfo Modify;
|
||||
if(!Modify.from_json(RawObject)) {
|
||||
return BadRequest(OpenWifi::RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
ProvObjects::GooglOrionAccountInfo Existing;
|
||||
if(!DB_.GetRecord("id",Account,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if(!ProvObjects::UpdateObjectInfo(RawObject,UserInfo_.userinfo,Existing.info)) {
|
||||
return BadRequest(OpenWifi::RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
|
||||
if(DB_.UpdateRecord("id",Existing.info.id,Existing)) {
|
||||
ProvObjects::GooglOrionAccountInfo StoredObject;
|
||||
DB_.GetRecord("id",Existing.info.id,StoredObject);
|
||||
return ReturnObject(StoredObject);
|
||||
}
|
||||
return BadRequest(RESTAPI::Errors::RecordNotUpdated);
|
||||
}
|
||||
|
||||
} // OpenWifi
|
||||
@@ -2,15 +2,29 @@
|
||||
// Created by stephane bourque on 2023-09-15.
|
||||
//
|
||||
|
||||
#ifndef OWPROV_RESTAPI_OPENROAMING_ORION_ACCT_HANDLER_H
|
||||
#define OWPROV_RESTAPI_OPENROAMING_ORION_ACCT_HANDLER_H
|
||||
#pragma once
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_Handler.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class RESTAPI_openroaming_orion_acct_handler : public RESTAPIHandler {
|
||||
public:
|
||||
RESTAPI_openroaming_orion_acct_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
|
||||
RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
|
||||
bool Internal)
|
||||
: RESTAPIHandler(bindings, L,
|
||||
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
|
||||
Poco::Net::HTTPRequest::HTTP_DELETE,
|
||||
Poco::Net::HTTPRequest::HTTP_POST,
|
||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||
Server, TransactionId, Internal) {}
|
||||
static auto PathName() { return std::list<std::string>{"/api/v1/openroaming/orion/account/{id}"}; };
|
||||
|
||||
class RESTAPI_openroaming_orion_acct_handler {
|
||||
|
||||
private:
|
||||
OrionAccountsDB &DB_ = StorageService()->OrionAccountsDB();
|
||||
void DoGet() final;
|
||||
void DoPost() final;
|
||||
void DoPut() final;
|
||||
void DoDelete() final;
|
||||
};
|
||||
|
||||
} // OpenWifi
|
||||
|
||||
#endif //OWPROV_RESTAPI_OPENROAMING_ORION_ACCT_HANDLER_H
|
||||
} // namespace OpenWifi
|
||||
|
||||
@@ -4,5 +4,18 @@
|
||||
|
||||
#include "RESTAPI_openroaming_orion_list_acct_handler.h"
|
||||
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
void RESTAPI_openroaming_orion_list_acct_handler::DoGet() {
|
||||
|
||||
if(GetBoolParameter("countOnly")) {
|
||||
return ReturnCountOnly(DB_.Count());
|
||||
}
|
||||
|
||||
std::vector<ProvObjects::GooglOrionAccountInfo> Accounts;
|
||||
DB_.GetRecords(QB_.Offset,QB_.Limit,Accounts);
|
||||
return ReturnObject(Accounts);
|
||||
}
|
||||
|
||||
} // OpenWifi
|
||||
@@ -2,15 +2,28 @@
|
||||
// Created by stephane bourque on 2023-09-15.
|
||||
//
|
||||
|
||||
#ifndef OWPROV_RESTAPI_OPENROAMING_ORION_LIST_ACCT_HANDLER_H
|
||||
#define OWPROV_RESTAPI_OPENROAMING_ORION_LIST_ACCT_HANDLER_H
|
||||
#pragma once
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_Handler.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
class RESTAPI_openroaming_orion_list_acct_handler : public RESTAPIHandler {
|
||||
public:
|
||||
RESTAPI_openroaming_orion_list_acct_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
|
||||
RESTAPI_GenericServerAccounting &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 auto PathName() { return std::list<std::string>{"/api/v1/openroaming/orion/accounts"}; };
|
||||
|
||||
class RESTAPI_openroaming_orion_list_acct_handler {
|
||||
|
||||
private:
|
||||
OrionAccountsDB &DB_ = StorageService()->OrionAccountsDB();
|
||||
void DoGet() final;
|
||||
void DoPost() final{};
|
||||
void DoPut() final{};
|
||||
void DoDelete() final{};
|
||||
};
|
||||
} // namespace OpenWifi
|
||||
|
||||
} // OpenWifi
|
||||
|
||||
#endif //OWPROV_RESTAPI_OPENROAMING_ORION_LIST_ACCT_HANDLER_H
|
||||
|
||||
Reference in New Issue
Block a user