mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor Settings DB and Handling (#1786)
* Refactor config API
* Corrections
* Test Qt 6.8
* Revert "Test Qt 6.8"
This reverts commit eceebec49e
.
* Corrections 2
* Update Changelog
* Add configFilter element for getconfig call
* Do not create errors for DB updates when in read-only mode
* Have configuration migration and validation before Hyperion starts
* Correct Tests
* Corrections
* Add migration items
* Correct windows build
* Ensure that first instance as default one exists
* Remove dependency between AuthManager and SSDPHandler
* Correct typos
* Address CodeQL findings
* Replace CamkeSettings by Presets and provide debug scenarios
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QPair>
|
||||
#include <QStringList>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
namespace JsonUtils {
|
||||
///
|
||||
/// @brief read a json file and get the parsed result on success
|
||||
/// @brief read a JSON file and get the parsed result on success
|
||||
/// @param[in] path The file path to read
|
||||
/// @param[out] obj Returns the parsed QJsonObject
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
@@ -17,6 +18,7 @@ namespace JsonUtils {
|
||||
/// @return true on success else false
|
||||
///
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonObject& obj, Logger* log, bool ignError=false);
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonValue& obj, Logger* log, bool ignError=false);
|
||||
|
||||
///
|
||||
/// @brief read a schema file and resolve $refs
|
||||
@@ -28,18 +30,19 @@ namespace JsonUtils {
|
||||
bool readSchema(const QString& path, QJsonObject& obj, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonObject. Overloaded funtion
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @brief parse a JSON QString and get a QJsonObject. Overloaded funtion
|
||||
/// @param[in] path The file path/name context used for log messages
|
||||
/// @param[in] data Data to parse
|
||||
/// @param[out] obj Retuns the parsed QJsonObject
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log);
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonValue& value, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonArray. Overloaded function
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @brief parse a JSON QString and get a QJsonArray. Overloaded function
|
||||
/// @param[in] path The file path/name context used for log messages
|
||||
/// @param[in] data Data to parse
|
||||
/// @param[out] arr Retuns the parsed QJsonArray
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
@@ -48,8 +51,8 @@ namespace JsonUtils {
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonArray& arr, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonDocument
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @brief parse a JSON QString and get a QJsonDocument
|
||||
/// @param[in] path The file path/name context used for log messages
|
||||
/// @param[in] data Data to parse
|
||||
/// @param[out] doc Retuns the parsed QJsonDocument
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
@@ -58,29 +61,39 @@ namespace JsonUtils {
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonDocument& doc, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Validate json data against a schema
|
||||
/// @param[in] file The path/name of json file just used for log messages
|
||||
/// @param[in] json The json data
|
||||
/// @brief Validate JSON data against a schema
|
||||
/// @param[in] file The path/name of JSON file context used for log messages
|
||||
/// @param[in] json The JSON data
|
||||
/// @param[in] schemaP The schema path
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
/// @return true on success else false, plus validation errors
|
||||
///
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log);
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonValue& json, const QString& schemaPath, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Validate json data against a schema
|
||||
/// @param[in] file The path/name of json file just used for log messages
|
||||
/// @param[in] json The json data
|
||||
/// @brief Validate JSON data against a schema
|
||||
/// @param[in] file The path/name of JSON file context used for log messages
|
||||
/// @param[in] json The JSON data
|
||||
/// @param[in] schema The schema object
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
/// @return true on success else false, plus validation errors
|
||||
///
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QJsonObject& schema, Logger* log);
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonValue& json, const QJsonObject& schema, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Write json data to file
|
||||
/// @brief Validate JSON data against a schema
|
||||
/// @param[in] file The path/name of JSON file context used for log messages
|
||||
/// @param[in/out] json The JSON data
|
||||
/// @param[in] schema The schema object
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false, plus correction messages
|
||||
///
|
||||
QPair<bool, QStringList> correct(const QString& file, QJsonValue& json, const QJsonObject& schema, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Write JSON data to file
|
||||
/// @param[in] filenameThe file path to write
|
||||
/// @param[in] json The json data to write
|
||||
/// @param[in] json The JSON data to write
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
@@ -94,4 +107,15 @@ namespace JsonUtils {
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool resolveRefs(const QJsonObject& schema, QJsonObject& obj, Logger* log);
|
||||
|
||||
|
||||
///
|
||||
/// @brief Function to convert QJsonValue to QString using QJsonDocument
|
||||
///
|
||||
QString jsonValueToQString(const QJsonValue &value, QJsonDocument::JsonFormat format = QJsonDocument::Compact);
|
||||
|
||||
///
|
||||
/// @brief Function to merge two QJsonObjects
|
||||
///
|
||||
QJsonObject mergeJsonObjects(const QJsonObject &obj1, const QJsonObject &obj2, bool overrideObj1 = false);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
/// @return The first boolean is true when the arguments is valid according to the schema. The second is true when the schema contains no errors
|
||||
/// @return TODO: Check the Schema in SetSchema() function and remove the QPair result
|
||||
///
|
||||
QPair<bool, bool> validate(const QJsonObject& value, bool ignoreRequired = false);
|
||||
QPair<bool, bool> validate(const QJsonValue& value, bool ignoreRequired = false);
|
||||
|
||||
///
|
||||
/// @brief Auto correct a JSON structure
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
/// @param ignoreRequired Ignore the "required" keyword in hyperion schema. Default is false
|
||||
/// @return The corrected JSON structure
|
||||
///
|
||||
QJsonObject getAutoCorrectedConfig(const QJsonObject& value, bool ignoreRequired = false);
|
||||
QJsonValue getAutoCorrectedConfig(const QJsonValue& value, bool ignoreRequired = false);
|
||||
|
||||
///
|
||||
/// @return A list of error messages
|
||||
@@ -207,7 +207,7 @@ private:
|
||||
/// Auto correction variable
|
||||
QString _correct;
|
||||
/// The auto corrected json-configuration
|
||||
QJsonObject _autoCorrected;
|
||||
QJsonValue _autoCorrected;
|
||||
/// The current location into a json-configuration structure being checked
|
||||
QStringList _currentPath;
|
||||
/// The result messages collected during the schema verification
|
||||
|
@@ -11,7 +11,7 @@ class QJsonUtils
|
||||
{
|
||||
public:
|
||||
|
||||
static void modify(QJsonObject& value, QStringList path, const QJsonValue& newValue = QJsonValue::Null, QString propertyName = "")
|
||||
static void modify(QJsonValue& value, QStringList path, const QJsonValue& newValue = QJsonValue::Null, QString propertyName = "")
|
||||
{
|
||||
QJsonObject result;
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
*it = current.mid(1, current.size()-1);
|
||||
}
|
||||
|
||||
if (!value.isEmpty())
|
||||
if (! (value.toObject().isEmpty() && value.toArray().isEmpty()) )
|
||||
modifyValue(value, result, path, newValue, propertyName);
|
||||
else if (newValue != QJsonValue::Null && !propertyName.isEmpty())
|
||||
result[propertyName] = newValue;
|
||||
|
@@ -385,7 +385,7 @@ namespace semver {
|
||||
return -1;
|
||||
}
|
||||
|
||||
version& operator= (version& rgt)
|
||||
version& operator= (const version& rgt)
|
||||
{
|
||||
if ((*this) != rgt)
|
||||
{
|
||||
@@ -404,17 +404,17 @@ namespace semver {
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator== (version &lft, version &rgt)
|
||||
friend bool operator== (const version &lft, const version &rgt)
|
||||
{
|
||||
return !(lft != rgt);
|
||||
}
|
||||
|
||||
friend bool operator!= (version &lft, version &rgt)
|
||||
friend bool operator!= (const version &lft, const version &rgt)
|
||||
{
|
||||
return (lft > rgt) || (lft < rgt);
|
||||
}
|
||||
|
||||
friend bool operator> (version &lft, version &rgt)
|
||||
friend bool operator> (const version &lft, const version &rgt)
|
||||
{
|
||||
// Major
|
||||
if (lft.getMajor() < 0 && rgt.getMajor() >= 0)
|
||||
@@ -522,17 +522,17 @@ namespace semver {
|
||||
return false;
|
||||
}
|
||||
|
||||
friend bool operator>= (version &lft, version &rgt)
|
||||
friend bool operator>= (const version &lft, const version &rgt)
|
||||
{
|
||||
return (lft > rgt) || (lft == rgt);
|
||||
}
|
||||
|
||||
friend bool operator< (version &lft, version &rgt)
|
||||
friend bool operator< (const version &lft, const version &rgt)
|
||||
{
|
||||
return (rgt > lft);
|
||||
}
|
||||
|
||||
friend bool operator<= (version &lft, version &rgt)
|
||||
friend bool operator<= (const version &lft, const version &rgt)
|
||||
{
|
||||
return (lft < rgt) || (lft == rgt);
|
||||
}
|
||||
|
Reference in New Issue
Block a user