Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-12068
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Feb 28, 2023
1 parent b6a9411 commit 3c7fa2c
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
15
73 changes: 73 additions & 0 deletions openpapi/owsec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/RESTObjects/RESTAPI_SecurityObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion src/RESTObjects/RESTAPI_SecurityObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 31 additions & 12 deletions src/framework/RESTAPI_SystemConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#pragma once

#include "framework/MicroServiceFuncs.h"
#include "framework/RESTAPI_Handler.h"
#include "framework/MicroServiceFuncs.h"

using namespace std::chrono_literals;

Expand All @@ -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,
Expand All @@ -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);
}

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) {
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
}

0 comments on commit 3c7fa2c

Please sign in to comment.