mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 09:42:38 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -370,3 +370,38 @@ paths:
|
||||
404:
|
||||
$ref: '#/components/responses/NotFound'
|
||||
|
||||
put:
|
||||
tags:
|
||||
- RadiusEndpointTypes-Global Reach Certificate
|
||||
operationId: updateOpenRoamingGlobalReachCertificate
|
||||
summary: Update certificate information.
|
||||
parameters:
|
||||
- in: path
|
||||
description: The account name - this is the provisioning ID for the account. Not the GlobalReach ID.
|
||||
name: account
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
- in: path
|
||||
description: the UUID of the certificate
|
||||
name: id
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
- in: query
|
||||
description: Must be set to "1"
|
||||
name: updateCertificate
|
||||
schema:
|
||||
type: boolean
|
||||
default: false
|
||||
required: false
|
||||
responses:
|
||||
200:
|
||||
$ref: '#/components/schemas/GLBLRCertificateInfo'
|
||||
400:
|
||||
$ref: '#/components/responses/BadRequest'
|
||||
403:
|
||||
$ref: '#/components/responses/Unauthorized'
|
||||
404:
|
||||
$ref: '#/components/responses/NotFound'
|
||||
|
||||
|
||||
@@ -146,6 +146,18 @@ components:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
RADIUSEndpointUpdateStatus:
|
||||
type: object
|
||||
properties:
|
||||
lastUpdate:
|
||||
type: integer
|
||||
format: int64
|
||||
lastConfigurationChange:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
|
||||
|
||||
paths:
|
||||
/RADIUSEndPoints:
|
||||
get:
|
||||
@@ -174,7 +186,7 @@ paths:
|
||||
required: false
|
||||
- in: query
|
||||
description: return the last update time
|
||||
name: lastUpdate
|
||||
name: currentStatus
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
@@ -188,11 +200,8 @@ paths:
|
||||
- type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/RADIUSEndPoint'
|
||||
- type: object
|
||||
properties:
|
||||
lastUpdate:
|
||||
type: integer
|
||||
format: int64
|
||||
- type:
|
||||
$ref: '#/components/schemas/RADIUSEndpointUpdateStatus'
|
||||
400:
|
||||
$ref: '#/components/responses/BadRequest'
|
||||
403:
|
||||
|
||||
@@ -79,4 +79,35 @@ namespace OpenWifi {
|
||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
void RESTAPI_openroaming_gr_cert_handler::DoPut() {
|
||||
auto Account = GetBinding("account","");
|
||||
auto Id = GetBinding("id","");
|
||||
auto UpdateCertificate = GetBoolParameter("updateCertificate",false);
|
||||
|
||||
if(Account.empty() || Id.empty() || !UpdateCertificate){
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
ProvObjects::GLBLRAccountInfo AccountInfo;
|
||||
if(!StorageService()->GLBLRAccountInfoDB().GetRecord("id",Account, AccountInfo)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidGlobalReachAccount);
|
||||
}
|
||||
|
||||
ProvObjects::GLBLRCertificateInfo Existing;
|
||||
if(!DB_.GetRecord("id",Id,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if(OpenRoaming_GlobalReach()->CreateRADSECCertificate(AccountInfo.GlobalReachAcctId,Existing.name,AccountInfo.CSR, Existing)) {
|
||||
Existing.created = Utils::Now();
|
||||
DB_.UpdateRecord("id",Existing.id,Existing);
|
||||
RecordType CreatedObject;
|
||||
DB_.GetRecord("id",Existing.id,CreatedObject);
|
||||
ProvObjects::RADIUSEndpointUpdateStatus Status;
|
||||
Status.ChangeConfiguration();
|
||||
return ReturnObject(CreatedObject);
|
||||
}
|
||||
return BadRequest(RESTAPI::Errors::RecordNotUpdated);
|
||||
}
|
||||
|
||||
} // OpenWifi
|
||||
@@ -16,6 +16,7 @@ namespace OpenWifi {
|
||||
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
|
||||
Poco::Net::HTTPRequest::HTTP_DELETE,
|
||||
Poco::Net::HTTPRequest::HTTP_POST,
|
||||
Poco::Net::HTTPRequest::HTTP_PUT,
|
||||
Poco::Net::HTTPRequest::HTTP_OPTIONS},
|
||||
Server, TransactionId, Internal) {}
|
||||
static auto PathName() { return std::list<std::string>{"/api/v1/openroaming/globalreach/certificate/{account}/{id}"}; };
|
||||
@@ -25,7 +26,7 @@ namespace OpenWifi {
|
||||
GLBLRCertsDB &DB_ = StorageService()->GLBLRCertsDB();
|
||||
void DoGet() final;
|
||||
void DoPost() final;
|
||||
void DoPut() final {};
|
||||
void DoPut() final ;
|
||||
void DoDelete() final;
|
||||
};
|
||||
} // namespace OpenWifi
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace OpenWifi {
|
||||
RecordType Record;
|
||||
if(DB_.GetRecord("id",id,Record)) {
|
||||
DB_.DeleteRecord("id",id);
|
||||
ProvObjects::RADIUSEndpointUpdateStatus Status;
|
||||
Status.ChangeConfiguration();
|
||||
return OK();
|
||||
}
|
||||
return NotFound();
|
||||
@@ -158,6 +160,8 @@ namespace OpenWifi {
|
||||
if(DB_.CreateRecord(NewRecord)) {
|
||||
RecordType AddedRecord;
|
||||
DB_.GetRecord("id", NewRecord.info.id, AddedRecord);
|
||||
ProvObjects::RADIUSEndpointUpdateStatus Status;
|
||||
Status.ChangeConfiguration();
|
||||
return ReturnObject(AddedRecord);
|
||||
}
|
||||
return BadRequest(RESTAPI::Errors::RecordNotCreated);
|
||||
@@ -187,6 +191,8 @@ namespace OpenWifi {
|
||||
if(DB_.UpdateRecord("id", Existing.info.id, Existing)) {
|
||||
RecordType AddedRecord;
|
||||
DB_.GetRecord("id", Existing.info.id, AddedRecord);
|
||||
ProvObjects::RADIUSEndpointUpdateStatus Status;
|
||||
Status.ChangeConfiguration();
|
||||
return ReturnObject(AddedRecord);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@ namespace OpenWifi {
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
if(GetBoolParameter("currentStatus")) {
|
||||
ProvObjects::RADIUSEndpointUpdateStatus Status;
|
||||
Status.Read();
|
||||
return ReturnObject(Status);
|
||||
}
|
||||
|
||||
if(QB_.CountOnly) {
|
||||
return ReturnCountOnly(DB_.Count());
|
||||
}
|
||||
|
||||
@@ -1384,4 +1384,53 @@ namespace OpenWifi::ProvObjects {
|
||||
return false;
|
||||
}
|
||||
|
||||
void RADIUSEndpointUpdateStatus::to_json(Poco::JSON::Object &Obj) const {
|
||||
field_to_json(Obj, "lastUpdate", lastUpdate);
|
||||
field_to_json(Obj, "lastConfigurationChange", lastConfigurationChange);
|
||||
}
|
||||
|
||||
bool RADIUSEndpointUpdateStatus::from_json(const Poco::JSON::Object::Ptr &Obj) {
|
||||
try {
|
||||
field_from_json(Obj, "lastUpdate", lastUpdate);
|
||||
field_from_json(Obj, "lastConfigurationChange", lastConfigurationChange);
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RADIUSEndpointUpdateStatus::Read() {
|
||||
Poco::File F(OpenWifi::MicroServiceDataDirectory()+"/RADIUSEndpointUpdateStatus.json");
|
||||
try {
|
||||
if (F.exists()) {
|
||||
Poco::JSON::Parser P;
|
||||
std::ifstream ifs(F.path(), std::ios_base::in | std::ios_base::binary);
|
||||
auto Obj = P.parse(ifs);
|
||||
return from_json(Obj.extract<Poco::JSON::Object::Ptr>());
|
||||
}
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RADIUSEndpointUpdateStatus::Save() {
|
||||
Poco::File F(OpenWifi::MicroServiceDataDirectory()+"/RADIUSEndpointUpdateStatus.json");
|
||||
try {
|
||||
Poco::JSON::Object Obj;
|
||||
to_json(Obj);
|
||||
std::ofstream O(F.path(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
|
||||
Poco::JSON::Stringifier::stringify(Obj, O);
|
||||
return true;
|
||||
} catch (...) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RADIUSEndpointUpdateStatus::ChangeConfiguration() {
|
||||
Read();
|
||||
lastConfigurationChange = Utils::Now();
|
||||
return Save();
|
||||
}
|
||||
|
||||
} // namespace OpenWifi::ProvObjects
|
||||
|
||||
@@ -901,4 +901,17 @@ namespace OpenWifi::ProvObjects {
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
};
|
||||
|
||||
struct RADIUSEndpointUpdateStatus {
|
||||
std::uint64_t lastUpdate=0;
|
||||
std::uint64_t lastConfigurationChange=0;
|
||||
|
||||
void to_json(Poco::JSON::Object &Obj) const;
|
||||
bool from_json(const Poco::JSON::Object::Ptr &Obj);
|
||||
bool Read();
|
||||
bool Save();
|
||||
bool ChangeConfiguration();
|
||||
};
|
||||
|
||||
|
||||
}; // namespace OpenWifi::ProvObjects
|
||||
|
||||
@@ -76,7 +76,6 @@ namespace OpenWifi {
|
||||
ProvObjects::GLBLRCertificateInfo &NewCertificate) {
|
||||
|
||||
try {
|
||||
std::cout << __LINE__ << ":" << GlobalReachAccountId << std::endl;
|
||||
auto BearerToken = MakeToken(GlobalReachAccountId);
|
||||
Poco::URI URI{"https://config.openro.am/v1/radsec/issue"};
|
||||
std::string Path(URI.getPathAndQuery());
|
||||
|
||||
@@ -194,8 +194,10 @@ namespace OpenWifi {
|
||||
GWObjects::RadiusProxyPoolList NewPools;
|
||||
Poco::JSON::Object ErrorObj;
|
||||
if(SDK::GW::RADIUS::SetConfiguration(Client, Pools, NewPools, ErrorObj)) {
|
||||
AppServiceRegistry().Set("radiusEndpointLastUpdate", Utils::Now());
|
||||
return true;
|
||||
ProvObjects::RADIUSEndpointUpdateStatus Status;
|
||||
Status.Read();
|
||||
Status.lastConfigurationChange = Status.lastUpdate = Utils::Now();
|
||||
return Status.Save();
|
||||
}
|
||||
/*
|
||||
ErrorCode:
|
||||
|
||||
Reference in New Issue
Block a user