stephb9959
2023-02-27 22:28:02 -08:00
parent b6a941197a
commit 3c7fa2ce9e
5 changed files with 130 additions and 14 deletions

2
build
View File

@@ -1 +1 @@
14
15

View File

@@ -493,6 +493,16 @@ components:
sms:
type: string
ExtraSystemConfiguration:
type: array
items:
type: object
properties:
parameterName:
type: string
parameterValue:
type: string
#########################################################################################
##
## These are endpoints that all services in the uCentral stack must provide
@@ -2057,6 +2067,69 @@ paths:
404:
$ref: '#/components/responses/NotFound'
/systemConfiguration:
get:
tags:
- SystemConfiguration
summary: Retrieve system configuration items
operationId: getSystemConfiguration
parameters:
- in: query
description: Which parameters you want to retrieve
name: entries
schema:
type: string
example:
- element1
- element1,element2,element3
required: false
responses:
200:
description: List of configuration elements
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ExtraSystemConfiguration'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
put:
tags:
- SystemConfiguration
summary: Set some or all system configuration
operationId: setSystemConfiguration
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ExtraSystemConfiguration'
responses:
200:
$ref: '#/components/schemas/ExtraSystemConfiguration'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
delete:
tags:
- SystemConfiguration
summary: Delete all additional system configuration
operationId: deleteSystemConfiguration
responses:
200:
$ref: '#/components/responses/Success'
403:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
#########################################################################################
##
## These are endpoints that all services in the uCentral stack must provide

View File

@@ -721,4 +721,20 @@ namespace OpenWifi::SecurityObjects {
return false;
}
void ExtraSystemConfiguration::to_json(Poco::JSON::Object &Obj) const {
field_to_json(Obj, "parameterName", parameterName);
field_to_json(Obj, "parameterValue", parameterValue);
}
bool ExtraSystemConfiguration::from_json(const Poco::JSON::Object::Ptr &Obj) {
try {
field_from_json(Obj, "parameterName", parameterName);
field_from_json(Obj, "parameterValue", parameterValue);
return true;
} catch (...) {
std::cout << "Cannot parse: Token" << std::endl;
}
return false;
}
} // namespace OpenWifi::SecurityObjects

View File

@@ -367,5 +367,13 @@ namespace OpenWifi {
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
} // namespace SecurityObjects
struct ExtraSystemConfiguration {
std::string parameterName;
std::string parameterValue;
void to_json(Poco::JSON::Object &Obj) const;
bool from_json(const Poco::JSON::Object::Ptr &Obj);
};
} // namespace SecurityObjects
} // namespace OpenWifi

View File

@@ -4,8 +4,8 @@
#pragma once
#include "framework/MicroServiceFuncs.h"
#include "framework/RESTAPI_Handler.h"
#include "framework/MicroServiceFuncs.h"
using namespace std::chrono_literals;
@@ -14,8 +14,8 @@ namespace OpenWifi {
class RESTAPI_system_configuration : public RESTAPIHandler {
public:
RESTAPI_system_configuration(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L,
RESTAPI_GenericServerAccounting &Server,
uint64_t TransactionId, bool Internal)
RESTAPI_GenericServerAccounting &Server, uint64_t TransactionId,
bool Internal)
: RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_PUT,
Poco::Net::HTTPRequest::HTTP_GET,
@@ -27,23 +27,42 @@ namespace OpenWifi {
inline void DoPost() final {}
inline void DoGet() final { return OK(); }
inline void DoGet() final {
auto entries = GetParameter("entries","");
if(entries.empty()) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}
inline void DoPut() final {
if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT) {
auto entriesArray = Poco::StringTokenizer(entries,",",Poco::StringTokenizer::TOK_TRIM);
Poco::JSON::Array Array;
for(const auto &entry:entriesArray) {
SecurityObjects::ExtraSystemConfiguration X;
X.parameterName = entry;
X.parameterValue = MicroServiceConfigGetString(entry,"");
Poco::JSON::Object E;
X.to_json(E);
Array.add(E);
}
std::ostringstream os;
Array.stringify(os);
return ReturnRawJSON(os.str());
}
inline void DoPut() final{
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT) {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
return OK();
return BadRequest(RESTAPI::Errors::NotImplemented);
};
inline void DoDelete() final {
if (UserInfo_.userinfo.userRole != SecurityObjects::ROOT) {
inline void DoDelete() final{
if(UserInfo_.userinfo.userRole!=SecurityObjects::ROOT) {
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
}
MicroServiceDeleteOverrideConfiguration();
return OK();
return BadRequest(RESTAPI::Errors::NotImplemented);
};
};
} // namespace OpenWifi
}