mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-30 10:12:29 +00:00
Adding fetching of the schema from git
This commit is contained in:
@@ -5,10 +5,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "ConfigurationValidator.h"
|
#include "ConfigurationValidator.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
|
|
||||||
namespace OpenWifi {
|
namespace OpenWifi {
|
||||||
|
|
||||||
|
static const std::string GitUCentralJSONSchemaFile{"https://raw.githubusercontent.com/blogic/ucentral-schema/main/ucentral.schema.json"};
|
||||||
|
|
||||||
static json DefaultUCentralSchema = R"(
|
static json DefaultUCentralSchema = R"(
|
||||||
{
|
{
|
||||||
"$id": "https://openwrt.org/ucentral.schema.json",
|
"$id": "https://openwrt.org/ucentral.schema.json",
|
||||||
@@ -2158,20 +2161,24 @@ namespace OpenWifi {
|
|||||||
if(Initialized_)
|
if(Initialized_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::string GitSchema;
|
||||||
|
if(Utils::wgets(GitUCentralJSONSchemaFile, GitSchema)) {
|
||||||
|
|
||||||
|
} else {
|
||||||
std::string FileName{ Daemon()->DataDir() + "/ucentral.schema.json" };
|
std::string FileName{ Daemon()->DataDir() + "/ucentral.schema.json" };
|
||||||
try {
|
try {
|
||||||
std::ifstream input(FileName);
|
std::ifstream input(FileName);
|
||||||
std::stringstream schema_file;
|
std::stringstream schema_file;
|
||||||
schema_file << input.rdbuf();
|
schema_file << input.rdbuf();
|
||||||
input.close();
|
input.close();
|
||||||
auto schema = json::parse(schema_file.str());
|
GitSchema = schema_file.str();
|
||||||
Validator_->set_root_schema(schema);
|
} catch (const Poco::Exception &E) {
|
||||||
Initialized_ = Working_ = true;
|
GitSchema = DefaultUCentralSchema;
|
||||||
} catch (const std::exception &E ) {
|
|
||||||
Validator_->set_root_schema(DefaultUCentralSchema);
|
|
||||||
Initialized_ = Working_ = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Validator_->set_root_schema(GitSchema);
|
||||||
|
Initialized_ = Working_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfigurationValidator::Validate(const std::string &C) {
|
bool ConfigurationValidator::Validate(const std::string &C) {
|
||||||
Init();
|
Init();
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
#include "Poco/File.h"
|
#include "Poco/File.h"
|
||||||
#include "Poco/StreamCopier.h"
|
#include "Poco/StreamCopier.h"
|
||||||
#include "Poco/Path.h"
|
#include "Poco/Path.h"
|
||||||
|
#include "Poco/URI.h"
|
||||||
|
#include "Poco/Net/HTTPSClientSession.h"
|
||||||
|
#include "Poco/Net/HTTPResponse.h"
|
||||||
|
|
||||||
#include "uCentralProtocol.h"
|
#include "uCentralProtocol.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
@@ -488,4 +491,33 @@ namespace OpenWifi::Utils {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wgets(const std::string &URL, std::string &Response) {
|
||||||
|
try {
|
||||||
|
Poco::URI uri(URL);
|
||||||
|
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
|
||||||
|
|
||||||
|
// prepare path
|
||||||
|
std::string path(uri.getPathAndQuery());
|
||||||
|
if (path.empty()) {
|
||||||
|
path = "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
// send request
|
||||||
|
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1);
|
||||||
|
session.sendRequest(req);
|
||||||
|
|
||||||
|
Poco::Net::HTTPResponse res;
|
||||||
|
std::istream &is = session.receiveResponse(res);
|
||||||
|
std::ostringstream os;
|
||||||
|
|
||||||
|
Poco::StreamCopier::copyStream(is,os);
|
||||||
|
Response = os.str();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (...) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ namespace OpenWifi::Utils {
|
|||||||
[[nodiscard]] std::string BinaryFileToHexString( const Poco::File &F);
|
[[nodiscard]] std::string BinaryFileToHexString( const Poco::File &F);
|
||||||
[[nodiscard]] std::string SecondsToNiceText(uint64_t Seconds);
|
[[nodiscard]] std::string SecondsToNiceText(uint64_t Seconds);
|
||||||
|
|
||||||
|
[[nodiscard]] bool wgets(const std::string &URL, std::string &Response);
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::string int_to_hex( T i )
|
std::string int_to_hex( T i )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,11 @@
|
|||||||
{
|
{
|
||||||
"type": "entity",
|
"type": "entity",
|
||||||
"name": "BC",
|
"name": "BC",
|
||||||
|
"children": [{
|
||||||
|
"type": "entity",
|
||||||
|
"name": "Bowen",
|
||||||
"children": [],
|
"children": [],
|
||||||
|
"venues": []}],
|
||||||
"venues": [{
|
"venues": [{
|
||||||
"type": "venue",
|
"type": "venue",
|
||||||
"name": "BC Place",
|
"name": "BC Place",
|
||||||
|
|||||||
2139
test_scripts/curl/ucentral.schema.json
Normal file
2139
test_scripts/curl/ucentral.schema.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user