mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 01:32:31 +00:00
Adding fetching of the schema from git
This commit is contained in:
@@ -5,10 +5,13 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "ConfigurationValidator.h"
|
||||
|
||||
#include "Utils.h"
|
||||
#include "Daemon.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
static const std::string GitUCentralJSONSchemaFile{"https://raw.githubusercontent.com/blogic/ucentral-schema/main/ucentral.schema.json"};
|
||||
|
||||
static json DefaultUCentralSchema = R"(
|
||||
{
|
||||
"$id": "https://openwrt.org/ucentral.schema.json",
|
||||
@@ -2158,19 +2161,23 @@ namespace OpenWifi {
|
||||
if(Initialized_)
|
||||
return;
|
||||
|
||||
std::string FileName{ Daemon()->DataDir() + "/ucentral.schema.json" };
|
||||
try {
|
||||
std::ifstream input(FileName);
|
||||
std::stringstream schema_file;
|
||||
schema_file << input.rdbuf();
|
||||
input.close();
|
||||
auto schema = json::parse(schema_file.str());
|
||||
Validator_->set_root_schema(schema);
|
||||
Initialized_ = Working_ = true;
|
||||
} catch (const std::exception &E ) {
|
||||
Validator_->set_root_schema(DefaultUCentralSchema);
|
||||
Initialized_ = Working_ = true;
|
||||
std::string GitSchema;
|
||||
if(Utils::wgets(GitUCentralJSONSchemaFile, GitSchema)) {
|
||||
|
||||
} else {
|
||||
std::string FileName{ Daemon()->DataDir() + "/ucentral.schema.json" };
|
||||
try {
|
||||
std::ifstream input(FileName);
|
||||
std::stringstream schema_file;
|
||||
schema_file << input.rdbuf();
|
||||
input.close();
|
||||
GitSchema = schema_file.str();
|
||||
} catch (const Poco::Exception &E) {
|
||||
GitSchema = DefaultUCentralSchema;
|
||||
}
|
||||
}
|
||||
Validator_->set_root_schema(GitSchema);
|
||||
Initialized_ = Working_ = true;
|
||||
}
|
||||
|
||||
bool ConfigurationValidator::Validate(const std::string &C) {
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include "Poco/File.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Path.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/Net/HTTPSClientSession.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
|
||||
#include "uCentralProtocol.h"
|
||||
#include "Daemon.h"
|
||||
@@ -488,4 +491,33 @@ namespace OpenWifi::Utils {
|
||||
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 SecondsToNiceText(uint64_t Seconds);
|
||||
|
||||
[[nodiscard]] bool wgets(const std::string &URL, std::string &Response);
|
||||
|
||||
template< typename T >
|
||||
std::string int_to_hex( T i )
|
||||
{
|
||||
|
||||
@@ -42,7 +42,11 @@
|
||||
{
|
||||
"type": "entity",
|
||||
"name": "BC",
|
||||
"children": [],
|
||||
"children": [{
|
||||
"type": "entity",
|
||||
"name": "Bowen",
|
||||
"children": [],
|
||||
"venues": []}],
|
||||
"venues": [{
|
||||
"type": "venue",
|
||||
"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