mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor Hyperion JSON-API (#1727)
This commit is contained in:
@@ -15,7 +15,6 @@ AuthManager::AuthManager(QObject *parent, bool readonlyMode)
|
||||
, _authTable(new AuthTable("", this, readonlyMode))
|
||||
, _metaTable(new MetaTable(this, readonlyMode))
|
||||
, _pendingRequests()
|
||||
, _authRequired(true)
|
||||
, _timer(new QTimer(this))
|
||||
, _authBlockTimer(new QTimer(this))
|
||||
{
|
||||
@@ -36,13 +35,13 @@ AuthManager::AuthManager(QObject *parent, bool readonlyMode)
|
||||
connect(_authBlockTimer, &QTimer::timeout, this, &AuthManager::checkAuthBlockTimeout);
|
||||
|
||||
// init with default user and password
|
||||
if (!_authTable->userExist("Hyperion"))
|
||||
if (!_authTable->userExist(hyperion::DEFAULT_USER))
|
||||
{
|
||||
_authTable->createUser("Hyperion", "hyperion");
|
||||
_authTable->createUser(hyperion::DEFAULT_USER, hyperion::DEFAULT_PASSWORD);
|
||||
}
|
||||
|
||||
// update Hyperion user token on startup
|
||||
_authTable->setUserToken("Hyperion");
|
||||
_authTable->setUserToken(hyperion::DEFAULT_USER);
|
||||
}
|
||||
|
||||
AuthManager::AuthDefinition AuthManager::createToken(const QString &comment)
|
||||
@@ -201,6 +200,8 @@ QVector<AuthManager::AuthDefinition> AuthManager::getPendingRequests() const
|
||||
def.comment = entry.comment;
|
||||
def.id = entry.id;
|
||||
def.timeoutTime = entry.timeoutTime - QDateTime::currentMSecsSinceEpoch();
|
||||
def.tan = entry.tan;
|
||||
def.caller = nullptr;
|
||||
finalVec.append(def);
|
||||
}
|
||||
return finalVec;
|
||||
@@ -208,20 +209,26 @@ QVector<AuthManager::AuthDefinition> AuthManager::getPendingRequests() const
|
||||
|
||||
bool AuthManager::renameToken(const QString &id, const QString &comment)
|
||||
{
|
||||
if (_authTable->renameToken(id, comment))
|
||||
if (_authTable->idExist(id))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
if (_authTable->renameToken(id, comment))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthManager::deleteToken(const QString &id)
|
||||
{
|
||||
if (_authTable->deleteToken(id))
|
||||
if (_authTable->idExist(id))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
if (_authTable->deleteToken(id))
|
||||
{
|
||||
emit tokenChange(getTokenList());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -231,9 +238,7 @@ void AuthManager::handleSettingsUpdate(settings::type type, const QJsonDocument
|
||||
if (type == settings::NETWORK)
|
||||
{
|
||||
const QJsonObject &obj = config.object();
|
||||
_authRequired = obj["apiAuth"].toBool(true);
|
||||
_localAuthRequired = obj["localApiAuth"].toBool(false);
|
||||
_localAdminAuthRequired = obj["localAdminAuth"].toBool(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -550,6 +550,11 @@ QList<int> Hyperion::getActivePriorities() const
|
||||
return _muxer->getPriorities();
|
||||
}
|
||||
|
||||
Hyperion::InputsMap Hyperion::getPriorityInfo() const
|
||||
{
|
||||
return _muxer->getInputInfo();
|
||||
}
|
||||
|
||||
Hyperion::InputInfo Hyperion::getPriorityInfo(int priority) const
|
||||
{
|
||||
return _muxer->getInputInfo(priority);
|
||||
|
@@ -45,6 +45,11 @@ QVector<QVariantMap> HyperionIManager::getInstanceData() const
|
||||
return instances;
|
||||
}
|
||||
|
||||
QList<quint8> HyperionIManager::getRunningInstanceIdx() const
|
||||
{
|
||||
return _runningInstances.keys();
|
||||
}
|
||||
|
||||
void HyperionIManager::startAll()
|
||||
{
|
||||
for(const auto & entry : _instanceTable->getAllInstances(true))
|
||||
|
@@ -128,6 +128,11 @@ bool PriorityMuxer::hasPriority(int priority) const
|
||||
return (priority == PriorityMuxer::LOWEST_PRIORITY) ? true : _activeInputs.contains(priority);
|
||||
}
|
||||
|
||||
PriorityMuxer::InputsMap PriorityMuxer::getInputInfo() const
|
||||
{
|
||||
return _activeInputs;
|
||||
}
|
||||
|
||||
PriorityMuxer::InputInfo PriorityMuxer::getInputInfo(int priority) const
|
||||
{
|
||||
auto elemIt = _activeInputs.constFind(priority);
|
||||
|
@@ -52,7 +52,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly
|
||||
|
||||
// get default config
|
||||
QJsonObject defaultConfig;
|
||||
if (!JsonUtils::readFile(":/hyperion_default.config", defaultConfig, _log))
|
||||
if (!JsonUtils::readFile(":/hyperion_default.config", defaultConfig, _log).first)
|
||||
{
|
||||
throw std::runtime_error("Failed to read default config");
|
||||
}
|
||||
|
@@ -4,26 +4,13 @@
|
||||
"required" : true,
|
||||
"properties" :
|
||||
{
|
||||
"apiAuth" :
|
||||
{
|
||||
"type" : "boolean",
|
||||
"title" : "edt_conf_net_apiAuth_title",
|
||||
"required" : true,
|
||||
"default" : true,
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"internetAccessAPI" :
|
||||
{
|
||||
"type" : "boolean",
|
||||
"title" : "edt_conf_net_internetAccessAPI_title",
|
||||
"required" : true,
|
||||
"default" : false,
|
||||
"options": {
|
||||
"dependencies": {
|
||||
"apiAuth": true
|
||||
}
|
||||
},
|
||||
"propertyOrder" : 2
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"restirctedInternetAccessAPI" :
|
||||
{
|
||||
@@ -36,7 +23,7 @@
|
||||
"internetAccessAPI": true
|
||||
}
|
||||
},
|
||||
"propertyOrder" : 3
|
||||
"propertyOrder" : 2
|
||||
},
|
||||
"ipWhitelist" :
|
||||
{
|
||||
@@ -53,7 +40,7 @@
|
||||
"restirctedInternetAccessAPI": true
|
||||
}
|
||||
},
|
||||
"propertyOrder" : 4
|
||||
"propertyOrder" : 3
|
||||
},
|
||||
"localApiAuth" :
|
||||
{
|
||||
@@ -66,15 +53,7 @@
|
||||
"apiAuth": true
|
||||
}
|
||||
},
|
||||
"propertyOrder" : 5
|
||||
},
|
||||
"localAdminAuth" :
|
||||
{
|
||||
"type" : "boolean",
|
||||
"title" : "edt_conf_net_localAdminAuth_title",
|
||||
"required" : true,
|
||||
"default" : true,
|
||||
"propertyOrder" : 5
|
||||
"propertyOrder" : 4
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
|
Reference in New Issue
Block a user