Refactor Hyperion JSON-API (#1727)

This commit is contained in:
LordGrey
2024-05-08 22:06:32 +02:00
committed by GitHub
parent 94850d890a
commit cf287f5adb
64 changed files with 4203 additions and 2962 deletions

View File

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