mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-28 09:27:16 +00:00
massive api changes: replace public method results to Result<T, E>
This commit is contained in:
parent
de0653f038
commit
bdb1dd0101
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "sources/3rdparty/result"]
|
||||||
|
path = sources/3rdparty/result
|
||||||
|
url = https://github.com/arcan1s/result.git
|
1
sources/3rdparty/result
vendored
Submodule
1
sources/3rdparty/result
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e03dc8efb056f468b108c5034e19fec96e5b976b
|
@ -17,7 +17,7 @@ else ()
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# some flags
|
# some flags
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# verbose output for debug builds
|
# verbose output for debug builds
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[Administrator]
|
[Administrator]
|
||||||
Username = root
|
Username = root
|
||||||
Password = 0dd3e512642c97ca3f747f9a76e374fbda73f9292823c0313be9d78add7cdd8f72235af0c553dd26797e78e1854edee0ae002f8aba074b066dfce1af114e32f8
|
Password = 9bc0798aa9d5de1f41e56ea4654cf86694dae080912d7df83cf293e7c7beb1b62e2811ed88bb24553a50d53f5cf85458928d25aea19aca5dc42fb316ba9c0e2c
|
||||||
|
Salt = suzMBxyKxtyQtu7c4vVfbQTB
|
||||||
|
|
||||||
[Database]
|
[Database]
|
||||||
Driver = QSQLITE
|
Driver = QSQLITE
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "QueuedApplicationInterface.h"
|
#include "QueuedApplicationInterface.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QDBusMetaType>
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
@ -33,6 +34,9 @@ QueuedApplicationInterface::QueuedApplicationInterface(
|
|||||||
, m_application(parent)
|
, m_application(parent)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
qRegisterMetaType<QueuedResult<QStringList>>("QueuedResult<QStringList>");
|
||||||
|
qDBusRegisterMetaType<QueuedResult<QStringList>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -42,17 +46,17 @@ QueuedApplicationInterface::~QueuedApplicationInterface()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedApplicationInterface::Active() const
|
QDBusVariant QueuedApplicationInterface::Active() const
|
||||||
{
|
{
|
||||||
return true;
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList QueuedApplicationInterface::UIDs() const
|
QDBusVariant QueuedApplicationInterface::UIDs() const
|
||||||
{
|
{
|
||||||
QStringList uids;
|
QStringList uids;
|
||||||
uids.append(QString::number(::getuid()));
|
uids.append(QString::number(::getuid()));
|
||||||
uids.append(QString::number(::geteuid()));
|
uids.append(QString::number(::geteuid()));
|
||||||
|
|
||||||
return uids;
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QStringList>(uids));
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#define QUEUEDAPPLICATIONINTERFACE_H
|
#define QUEUEDAPPLICATIONINTERFACE_H
|
||||||
|
|
||||||
#include <QDBusAbstractAdaptor>
|
#include <QDBusAbstractAdaptor>
|
||||||
|
#include <QDBusVariant>
|
||||||
|
|
||||||
#include "QueuedConfig.h"
|
#include "QueuedConfig.h"
|
||||||
|
|
||||||
@ -34,8 +35,8 @@ public:
|
|||||||
virtual ~QueuedApplicationInterface();
|
virtual ~QueuedApplicationInterface();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool Active() const;
|
QDBusVariant Active() const;
|
||||||
QStringList UIDs() const;
|
QDBusVariant UIDs() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QueuedApplication *m_application = nullptr;
|
QueuedApplication *m_application = nullptr;
|
||||||
|
@ -35,12 +35,11 @@ QueuedApplication *instance = nullptr;
|
|||||||
|
|
||||||
bool existingSessionOperation(const QString &operation)
|
bool existingSessionOperation(const QString &operation)
|
||||||
{
|
{
|
||||||
QVariantList arguments = QueuedCoreAdaptor::sendRequest(
|
auto res = QueuedCoreAdaptor::sendRequest<bool>(
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_APPLICATION_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_APPLICATION_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, operation, QVariantList());
|
QueuedConfig::DBUS_SERVICE, operation, QVariantList());
|
||||||
|
|
||||||
return (!arguments.isEmpty() && arguments.at(0).type() == QVariant::Bool
|
return ((res.type() == Result::Content::Value) && res.get());
|
||||||
&& arguments[0].toBool());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,17 +45,21 @@ void QueuedServer::init()
|
|||||||
{
|
{
|
||||||
m_server->init(QueuedCoreAdaptor::getOption(
|
m_server->init(QueuedCoreAdaptor::getOption(
|
||||||
QueuedConfig::QueuedSettings::ServerTimeout)
|
QueuedConfig::QueuedSettings::ServerTimeout)
|
||||||
|
.get()
|
||||||
.toInt());
|
.toInt());
|
||||||
QString address = QueuedCoreAdaptor::getOption(
|
QString address = QueuedCoreAdaptor::getOption(
|
||||||
QueuedConfig::QueuedSettings::ServerAddress)
|
QueuedConfig::QueuedSettings::ServerAddress)
|
||||||
|
.get()
|
||||||
.toString();
|
.toString();
|
||||||
ushort port
|
ushort port
|
||||||
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerPort)
|
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerPort)
|
||||||
|
.get()
|
||||||
.toUInt();
|
.toUInt();
|
||||||
m_server->listen(QHostAddress(address), port);
|
m_server->listen(QHostAddress(address), port);
|
||||||
m_server->setMaxPendingConnections(
|
m_server->setMaxPendingConnections(
|
||||||
QueuedCoreAdaptor::getOption(
|
QueuedCoreAdaptor::getOption(
|
||||||
QueuedConfig::QueuedSettings::ServerMaxConnections)
|
QueuedConfig::QueuedSettings::ServerMaxConnections)
|
||||||
|
.get()
|
||||||
.toInt());
|
.toInt());
|
||||||
|
|
||||||
qCInfo(LOG_SERV) << "Server listen on" << m_server->serverAddress()
|
qCInfo(LOG_SERV) << "Server listen on" << m_server->serverAddress()
|
||||||
|
@ -42,7 +42,7 @@ typedef struct {
|
|||||||
QString type;
|
QString type;
|
||||||
bool valid;
|
bool valid;
|
||||||
} Request;
|
} Request;
|
||||||
const QHash<int, QByteArray> HTTPCodeMap
|
static const QHash<int, QByteArray> HTTPCodeMap
|
||||||
= {{100, "Continue"},
|
= {{100, "Continue"},
|
||||||
{101, "Switching Protocols"},
|
{101, "Switching Protocols"},
|
||||||
{200, "OK"},
|
{200, "OK"},
|
||||||
|
@ -139,7 +139,10 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getStatus()
|
|||||||
{
|
{
|
||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
|
|
||||||
auto data = QueuedCoreAdaptor::getStatus();
|
auto res = QueuedCoreAdaptor::getStatus();
|
||||||
|
if (res.type() != Result::Content::Value)
|
||||||
|
return {};
|
||||||
|
auto data = res.get();
|
||||||
auto sections = data.keys();
|
auto sections = data.keys();
|
||||||
sections.sort();
|
sections.sort();
|
||||||
for (auto §ion : sections) {
|
for (auto §ion : sections) {
|
||||||
|
@ -25,9 +25,17 @@ QVariantHash QueuedTcpServerResponseHelperAuth::auth(const QVariantHash &_data)
|
|||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
if (_data.contains("user") && _data.contains("password")) {
|
if (_data.contains("user") && _data.contains("password")) {
|
||||||
output["token"] = QueuedCoreAdaptor::auth(_data["user"].toString(),
|
auto res = QueuedCoreAdaptor::auth(_data["user"].toString(),
|
||||||
_data["password"].toString());
|
_data["password"].toString());
|
||||||
output["code"] = output["token"].toString().isEmpty() ? 401 : 200;
|
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const QString &val) {
|
||||||
|
output = {{"code", 200}, {"token", val}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 401}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
output = {{"code", 400}, {"message", "No required fields found"}};
|
output = {{"code", 400}, {"message", "No required fields found"}};
|
||||||
}
|
}
|
||||||
@ -40,5 +48,11 @@ bool QueuedTcpServerResponseHelperAuth::tryAuth(const QString &_token)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Try auth with" << _token;
|
qCDebug(LOG_APP) << "Try auth with" << _token;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::auth(_token);
|
auto res = QueuedCoreAdaptor::auth(_token);
|
||||||
|
|
||||||
|
bool ret = true;
|
||||||
|
Result::match(res, [&ret](const bool val) { ret = val; },
|
||||||
|
[&ret](const QueuedError &err) { ret = false; });
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,18 @@ QueuedTcpServerResponseHelperOption::getOption(const QString &_option)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get option" << _option;
|
qCDebug(LOG_SERV) << "Get option" << _option;
|
||||||
|
|
||||||
return {{"code", 200}, {"value", QueuedCoreAdaptor::getOption(_option)}};
|
auto res = QueuedCoreAdaptor::getOption(_option);
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output = {{"code", 200}, {"token", val}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &) {
|
||||||
|
output = {{"code", 404}, {"message", "Option not found"}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -36,8 +47,18 @@ QVariantHash QueuedTcpServerResponseHelperOption::setOption(
|
|||||||
if (!_value.contains("value"))
|
if (!_value.contains("value"))
|
||||||
return {{"code", 400}, {"message", "No required fields found"}};
|
return {{"code", 400}, {"message", "No required fields found"}};
|
||||||
|
|
||||||
return {{"code",
|
auto res
|
||||||
QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token)
|
= QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token);
|
||||||
? 200
|
|
||||||
: 400}};
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const QVariant &) {
|
||||||
|
output = {{"code", 200}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,20 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(
|
|||||||
if (permission == QueuedEnums::Permission::Invalid)
|
if (permission == QueuedEnums::Permission::Invalid)
|
||||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||||
|
|
||||||
return {{"code",
|
auto res
|
||||||
QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token)
|
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||||
? 200
|
|
||||||
: 400}};
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const QVariant &) {
|
||||||
|
output = {{"code", 200}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,8 +62,18 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(
|
|||||||
if (permission == QueuedEnums::Permission::Invalid)
|
if (permission == QueuedEnums::Permission::Invalid)
|
||||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||||
|
|
||||||
return {{"code", QueuedCoreAdaptor::sendUserPermissionRemove(
|
auto res
|
||||||
_id, permission, _token)
|
= QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||||
? 200
|
|
||||||
: 400}};
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const QVariant &) {
|
||||||
|
output = {{"code", 200}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,38 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Add plugin" << _name;
|
qCDebug(LOG_SERV) << "Add plugin" << _name;
|
||||||
|
|
||||||
return {
|
auto res = QueuedCoreAdaptor::sendPluginAdd(_name, _token);
|
||||||
{"code", QueuedCoreAdaptor::sendPluginAdd(_name, _token) ? 200 : 400}};
|
|
||||||
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const bool) {
|
||||||
|
output = {{"code", 200}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||||
{
|
{
|
||||||
return {{"code", 200},
|
auto res
|
||||||
{"plugins", QueuedCoreAdaptor::getOption(
|
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins);
|
||||||
QueuedConfig::QueuedSettings::Plugins)}};
|
|
||||||
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output = {{"code", 200}, {"plugins", val.toStringList()}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +66,17 @@ QueuedTcpServerResponseHelperPlugins::removePlugin(const QString &_name,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Remove plugin" << _name;
|
qCDebug(LOG_SERV) << "Remove plugin" << _name;
|
||||||
|
|
||||||
return {{"code",
|
auto res = QueuedCoreAdaptor::sendPluginRemove(_name, _token);
|
||||||
QueuedCoreAdaptor::sendPluginRemove(_name, _token) ? 200 : 400}};
|
|
||||||
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const bool) {
|
||||||
|
output = {{"code", 200}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,33 @@ QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(
|
|||||||
qCDebug(LOG_SERV) << "Add or edit task" << _id << "with data" << _data;
|
qCDebug(LOG_SERV) << "Add or edit task" << _id << "with data" << _data;
|
||||||
|
|
||||||
auto defs = getDefinitions(_data);
|
auto defs = getDefinitions(_data);
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
if (_id > 0) {
|
if (_id > 0) {
|
||||||
// edit existing task
|
// edit existing task
|
||||||
bool status = QueuedCoreAdaptor::sendTaskEdit(_id, defs, _token);
|
auto res = QueuedCoreAdaptor::sendTaskEdit(_id, defs, _token);
|
||||||
return {{"code", status ? 200 : 400}};
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const bool val) {
|
||||||
|
output = {{"code", val ? 200 : 500}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// add new task
|
// add new task
|
||||||
auto id = QueuedCoreAdaptor::sendTaskAdd(defs, _token);
|
auto res = QueuedCoreAdaptor::sendTaskAdd(defs, _token);
|
||||||
return {{"code", id > 0 ? 200 : 400}, {"id", id}};
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const long long val) {
|
||||||
|
output = {{"code", val ? 200 : 500}, {"id", val}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,11 +96,25 @@ QueuedTcpServerResponseHelperTask::getTask(const long long _id,
|
|||||||
auto property = _data["property"].toString();
|
auto property = _data["property"].toString();
|
||||||
|
|
||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
if (property.isEmpty())
|
if (property.isEmpty()) {
|
||||||
output["properties"] = QueuedCoreAdaptor::getTask(_id);
|
auto res = QueuedCoreAdaptor::getTask(_id);
|
||||||
else
|
Result::match(
|
||||||
output["properties"] = QVariantHash(
|
res,
|
||||||
{{property, QueuedCoreAdaptor::getTask(_id, property)}});
|
[&output](const QVariantHash &val) { output["properties"] = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
auto res = QueuedCoreAdaptor::getTask(_id, property);
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output, &property](const QVariant &val) {
|
||||||
|
output["properties"] = {{property, val}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -100,13 +132,20 @@ QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
|||||||
QDateTime stop
|
QDateTime stop
|
||||||
= QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
= QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||||
|
|
||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output;
|
||||||
// some conversion magic
|
// some conversion magic
|
||||||
QVariantList outputReport;
|
QVariantList outputReport;
|
||||||
auto report = QueuedCoreAdaptor::getTasks(userId, start, stop, _token);
|
auto res = QueuedCoreAdaptor::getTasks(userId, start, stop, _token);
|
||||||
for (auto &user : report)
|
Result::match(
|
||||||
outputReport.append(user);
|
res,
|
||||||
output["report"] = outputReport;
|
[&output, &outputReport](const QList<QVariantHash> &val) {
|
||||||
|
for (auto &user : val)
|
||||||
|
outputReport += user;
|
||||||
|
output = {{"code", 200}, {"report", outputReport}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -118,15 +157,63 @@ QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Change task state" << _id;
|
qCDebug(LOG_SERV) << "Change task state" << _id;
|
||||||
|
|
||||||
QVariantHash task = QueuedCoreAdaptor::getTask(_id);
|
auto res = QueuedCoreAdaptor::getTask(_id);
|
||||||
if (task.isEmpty())
|
|
||||||
return {{"code", 400}, {"message", "No task found"}};
|
|
||||||
|
|
||||||
if (task["startTime"].toString().isEmpty()
|
QVariantHash output;
|
||||||
|| !task["endTime"].toString().isEmpty())
|
Result::match(
|
||||||
return {{"code",
|
res,
|
||||||
QueuedCoreAdaptor::sendTaskStart(_id, _token) ? 200 : 400}};
|
[&output, &_id, &_token](const QVariantHash &val) {
|
||||||
else
|
if (val["startTime"].toString().isEmpty()
|
||||||
return {
|
|| !val["endTime"].toString().isEmpty())
|
||||||
{"code", QueuedCoreAdaptor::sendTaskStop(_id, _token) ? 200 : 400}};
|
output = startTask(_id, _token);
|
||||||
|
else
|
||||||
|
output = stopTask(_id, _token);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 400}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash QueuedTcpServerResponseHelperTask::startTask(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_SERV) << "Start task" << _id;
|
||||||
|
|
||||||
|
auto res = QueuedCoreAdaptor::sendTaskStart(_id, _token);
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const bool val) {
|
||||||
|
output = {{"code", val ? 200 : 500}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantHash QueuedTcpServerResponseHelperTask::stopTask(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_SERV) << "Stop task" << _id;
|
||||||
|
|
||||||
|
auto res = QueuedCoreAdaptor::sendTaskStop(_id, _token);
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const bool val) {
|
||||||
|
output = {{"code", val ? 200 : 500}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ getDefinitions(const QVariantHash &_data);
|
|||||||
QVariantHash getTask(const long long _id, const QVariantHash &_data);
|
QVariantHash getTask(const long long _id, const QVariantHash &_data);
|
||||||
QVariantHash getTasks(const QVariantHash &_data, const QString &_token);
|
QVariantHash getTasks(const QVariantHash &_data, const QString &_token);
|
||||||
QVariantHash startOrStopTask(const long long _id, const QString &_token);
|
QVariantHash startOrStopTask(const long long _id, const QString &_token);
|
||||||
|
QVariantHash startTask(const long long _id, const QString &_token);
|
||||||
|
QVariantHash stopTask(const long long _id, const QString &_token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,19 +25,40 @@ QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
|||||||
qCDebug(LOG_SERV) << "Add user" << _user << "with data" << _data;
|
qCDebug(LOG_SERV) << "Add user" << _user << "with data" << _data;
|
||||||
|
|
||||||
// try define if user exists first
|
// try define if user exists first
|
||||||
auto userId = QueuedCoreAdaptor::getUserId(_user);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(_user);
|
||||||
|
long long userId = -1;
|
||||||
|
Result::match(userIdRes, [&userId](const long long val) { userId = val; },
|
||||||
|
[&userId](const QueuedError &) {});
|
||||||
|
|
||||||
auto defs = getDefinitions(_data);
|
auto defs = getDefinitions(_data);
|
||||||
defs.name = _user;
|
defs.name = _user;
|
||||||
|
|
||||||
|
QVariantHash output;
|
||||||
if (userId > 0) {
|
if (userId > 0) {
|
||||||
// edit existing user
|
// edit existing user
|
||||||
bool status = QueuedCoreAdaptor::sendUserEdit(userId, defs, _token);
|
auto res = QueuedCoreAdaptor::sendUserEdit(userId, defs, _token);
|
||||||
return {{"code", status ? 200 : 400}};
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const bool val) {
|
||||||
|
output = {{"code", val ? 200 : 500}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// add new user
|
// add new user
|
||||||
auto id = QueuedCoreAdaptor::sendUserAdd(defs, _token);
|
auto res = QueuedCoreAdaptor::sendUserAdd(defs, _token);
|
||||||
return {{"code", id > 0 ? 200 : 400}, {"id", id}};
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output](const long long val) {
|
||||||
|
output = {{"code", val ? 200 : 500}, {"id", val}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +69,10 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
|||||||
|
|
||||||
QueuedUser::QueuedUserDefinitions defs;
|
QueuedUser::QueuedUserDefinitions defs;
|
||||||
defs.email = _data["email"].toString();
|
defs.email = _data["email"].toString();
|
||||||
defs.password = QueuedUser::hashFromPassword(_data["password"].toString());
|
auto res = QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
||||||
|
Result::match(
|
||||||
|
res, [&defs](const QString &val) { defs.password = val; },
|
||||||
|
[](const QueuedError &) {});
|
||||||
defs.permissions = _data["permissions"].toUInt();
|
defs.permissions = _data["permissions"].toUInt();
|
||||||
// limits
|
// limits
|
||||||
QueuedLimits::Limits limits;
|
QueuedLimits::Limits limits;
|
||||||
@ -77,10 +101,17 @@ QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
|||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
// some conversion magic
|
// some conversion magic
|
||||||
QVariantList outputReport;
|
QVariantList outputReport;
|
||||||
auto report = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
auto res = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
||||||
for (auto &user : report)
|
Result::match(
|
||||||
outputReport.append(user);
|
res,
|
||||||
output["report"] = outputReport;
|
[&output, &outputReport](const QList<QVariantHash> &val) {
|
||||||
|
for (auto &user : val)
|
||||||
|
outputReport += user;
|
||||||
|
output = {{"code", 200}, {"report", outputReport}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -92,15 +123,35 @@ QueuedTcpServerResponseHelperUser::getUser(const QString &_user,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get user data for" << _user << _data;
|
qCDebug(LOG_SERV) << "Get user data for" << _user << _data;
|
||||||
|
|
||||||
auto userId = QueuedCoreAdaptor::getUserId(_user);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(_user);
|
||||||
|
long long userId = -1;
|
||||||
|
Result::match(userIdRes, [&userId](const long long val) { userId = val; },
|
||||||
|
[](const QueuedError &) {});
|
||||||
|
if (userId == -1)
|
||||||
|
return {{"code", 500}};
|
||||||
|
|
||||||
auto property = _data["property"].toString();
|
auto property = _data["property"].toString();
|
||||||
|
|
||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
if (property.isEmpty())
|
if (property.isEmpty()) {
|
||||||
output["properties"] = QueuedCoreAdaptor::getUser(userId);
|
auto res = QueuedCoreAdaptor::getUser(userId);
|
||||||
else
|
Result::match(
|
||||||
output["properties"] = QVariantHash(
|
res,
|
||||||
{{property, QueuedCoreAdaptor::getUser(userId, property)}});
|
[&output](const QVariantHash &val) { output["properties"] = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
auto res = QueuedCoreAdaptor::getUser(userId, property);
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&output, &property](const QVariant &val) {
|
||||||
|
output["properties"] = {{property, val}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -120,10 +171,17 @@ QueuedTcpServerResponseHelperUser::getUsers(const QVariantHash &_data,
|
|||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
// some conversion magic
|
// some conversion magic
|
||||||
QVariantList outputReport;
|
QVariantList outputReport;
|
||||||
auto report = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
auto res = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
||||||
for (auto &user : report)
|
Result::match(
|
||||||
outputReport.append(user);
|
res,
|
||||||
output["report"] = outputReport;
|
[&output, &outputReport](const QList<QVariantHash> &val) {
|
||||||
|
for (auto &user : val)
|
||||||
|
outputReport += user;
|
||||||
|
output = {{"code", 200}, {"report", outputReport}};
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
|
});
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedConfig.h
|
* @file QueuedConfig.h
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -39,75 +39,75 @@ namespace QueuedConfig
|
|||||||
/**
|
/**
|
||||||
* @brief DBus service name for library and application
|
* @brief DBus service name for library and application
|
||||||
*/
|
*/
|
||||||
const char DBUS_SERVICE[] = DBUS_SERVICE_NAME;
|
static const char DBUS_SERVICE[] = DBUS_SERVICE_NAME;
|
||||||
/**
|
/**
|
||||||
* @brief DBus object path for application
|
* @brief DBus object path for application
|
||||||
*/
|
*/
|
||||||
const char DBUS_APPLICATION_PATH[] = "/application";
|
static const char DBUS_APPLICATION_PATH[] = "/application";
|
||||||
/**
|
/**
|
||||||
* @brief DBus object path for library
|
* @brief DBus object path for library
|
||||||
*/
|
*/
|
||||||
const char DBUS_OBJECT_PATH[] = "/queued";
|
static const char DBUS_OBJECT_PATH[] = "/queued";
|
||||||
/**
|
/**
|
||||||
* @brief DBus properties path for properties library
|
* @brief DBus properties path for properties library
|
||||||
*/
|
*/
|
||||||
const char DBUS_PROPERTY_PATH[] = "/property";
|
static const char DBUS_PROPERTY_PATH[] = "/property";
|
||||||
/**
|
/**
|
||||||
* @brief DBus properties path for reports library
|
* @brief DBus properties path for reports library
|
||||||
*/
|
*/
|
||||||
const char DBUS_REPORTS_PATH[] = "/report";
|
static const char DBUS_REPORTS_PATH[] = "/report";
|
||||||
|
|
||||||
// path configuration
|
// path configuration
|
||||||
// common paths
|
// common paths
|
||||||
/**
|
/**
|
||||||
* @brief installation directory for executables
|
* @brief installation directory for executables
|
||||||
*/
|
*/
|
||||||
const char BIN_INSTALL_DIR[] = "@BIN_INSTALL_DIR@";
|
static const char BIN_INSTALL_DIR[] = "@BIN_INSTALL_DIR@";
|
||||||
/**
|
/**
|
||||||
* @brief installation directory for data
|
* @brief installation directory for data
|
||||||
*/
|
*/
|
||||||
const char DATA_INSTALL_DIR[] = "@DATA_INSTALL_DIR@";
|
static const char DATA_INSTALL_DIR[] = "@DATA_INSTALL_DIR@";
|
||||||
/**
|
/**
|
||||||
* @brief installation directory for headers
|
* @brief installation directory for headers
|
||||||
*/
|
*/
|
||||||
const char INCLUDE_INSTALL_DIR[] = "@INCLUDE_INSTALL_DIR@";
|
static const char INCLUDE_INSTALL_DIR[] = "@INCLUDE_INSTALL_DIR@";
|
||||||
/**
|
/**
|
||||||
* @brief installation directory for libraries
|
* @brief installation directory for libraries
|
||||||
*/
|
*/
|
||||||
const char LIB_INSTALL_DIR[] = "@LIB_INSTALL_DIR@";
|
static const char LIB_INSTALL_DIR[] = "@LIB_INSTALL_DIR@";
|
||||||
/**
|
/**
|
||||||
* @brief the same as CMAKE_INSTALL_PREFIX
|
* @brief the same as CMAKE_INSTALL_PREFIX
|
||||||
*/
|
*/
|
||||||
const char ROOT_INSTALL_DIR[] = "@CMAKE_INSTALL_PREFIX@";
|
static const char ROOT_INSTALL_DIR[] = "@CMAKE_INSTALL_PREFIX@";
|
||||||
// application specific
|
// application specific
|
||||||
/**
|
/**
|
||||||
* @brief path to queued home directory
|
* @brief path to queued home directory
|
||||||
*/
|
*/
|
||||||
const char HOME_PATH[] = "queued";
|
static const char HOME_PATH[] = "queued";
|
||||||
/**
|
/**
|
||||||
* @brief path to plugins inside @ref HOME_PATH
|
* @brief path to plugins inside @ref HOME_PATH
|
||||||
*/
|
*/
|
||||||
const char PLUGIN_PATH[] = "plugins";
|
static const char PLUGIN_PATH[] = "plugins";
|
||||||
|
|
||||||
// internal configuration
|
// internal configuration
|
||||||
/**
|
/**
|
||||||
* @brief version of internal storage
|
* @brief version of internal storage
|
||||||
*/
|
*/
|
||||||
const int DATABASE_VERSION = 1;
|
static const int DATABASE_VERSION = 1;
|
||||||
/**
|
/**
|
||||||
* @brief header name for token
|
* @brief header name for token
|
||||||
*/
|
*/
|
||||||
const char WEBAPI_TOKEN_HEADER[] = "x-queued-token";
|
static const char WEBAPI_TOKEN_HEADER[] = "x-queued-token";
|
||||||
/**
|
/**
|
||||||
* @brief supported web server API versions
|
* @brief supported web server API versions
|
||||||
*/
|
*/
|
||||||
const int WEBAPI_VERSIONS[] = {1};
|
static const int WEBAPI_VERSIONS[] = {1};
|
||||||
|
|
||||||
// cgroups configuration
|
// cgroups configuration
|
||||||
/**
|
/**
|
||||||
* @brief path to root directory of cgroups
|
* @brief path to root directory of cgroups
|
||||||
*/
|
*/
|
||||||
const char CG_FS_PATH[] = "/sys/fs/cgroup";
|
static const char CG_FS_PATH[] = "/sys/fs/cgroup";
|
||||||
|
|
||||||
// plugin interfaces
|
// plugin interfaces
|
||||||
/**
|
/**
|
||||||
@ -119,7 +119,7 @@ const char CG_FS_PATH[] = "/sys/fs/cgroup";
|
|||||||
/**
|
/**
|
||||||
* @brief plugin interface name
|
* @brief plugin interface name
|
||||||
*/
|
*/
|
||||||
const char PLUGIN_INTERFACE[] = PLUGIN_INTERFACE_NAME;
|
static const char PLUGIN_INTERFACE[] = PLUGIN_INTERFACE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,3 +5,4 @@ install (FILES "QueuedConfig.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued
|
|||||||
install (FILES "QueuedLibraries.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued")
|
install (FILES "QueuedLibraries.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued")
|
||||||
install (FILES "QueuedMacros.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued")
|
install (FILES "QueuedMacros.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued")
|
||||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/QueuedPaths.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued")
|
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/QueuedPaths.cmake" DESTINATION "${LIB_INSTALL_DIR}/cmake/Queued")
|
||||||
|
install (FILES "${PROJECT_TRDPARTY_DIR}/result/result.hpp" DESTINATION "${INCLUDE_INSTALL_DIR}/${SUBPROJECT}/result")
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "QueuedPropertyInterface.h"
|
#include "QueuedPropertyInterface.h"
|
||||||
#include "QueuedReportInterface.h"
|
#include "QueuedReportInterface.h"
|
||||||
#include "QueuedReportManager.h"
|
#include "QueuedReportManager.h"
|
||||||
|
#include "QueuedResult.h"
|
||||||
#include "QueuedSettings.h"
|
#include "QueuedSettings.h"
|
||||||
#include "QueuedStaticConfig.h"
|
#include "QueuedStaticConfig.h"
|
||||||
#include "QueuedSystemInfo.h"
|
#include "QueuedSystemInfo.h"
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "QueuedEnums.h"
|
#include "QueuedEnums.h"
|
||||||
#include "QueuedLimits.h"
|
#include "QueuedLimits.h"
|
||||||
|
#include "QueuedResult.h"
|
||||||
#include "QueuedStaticConfig.h"
|
#include "QueuedStaticConfig.h"
|
||||||
|
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successfully addition
|
* @return true on successfully addition
|
||||||
*/
|
*/
|
||||||
bool addPlugin(const QString &_plugin, const QString &_token);
|
QueuedResult<bool> addPlugin(const QString &_plugin, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief add new task
|
* @brief add new task
|
||||||
* @param _command
|
* @param _command
|
||||||
@ -86,10 +87,10 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
long long addTask(const QString &_command, const QStringList &_arguments,
|
QueuedResult<long long>
|
||||||
const QString &_workingDirectory, const long long _userId,
|
addTask(const QString &_command, const QStringList &_arguments,
|
||||||
const QueuedLimits::Limits &_limits,
|
const QString &_workingDirectory, const long long _userId,
|
||||||
const QString &_token);
|
const QueuedLimits::Limits &_limits, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief add new user
|
* @brief add new user
|
||||||
* @param _name
|
* @param _name
|
||||||
@ -106,17 +107,18 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return user ID or -1 if no user created
|
* @return user ID or -1 if no user created
|
||||||
*/
|
*/
|
||||||
long long addUser(const QString &_name, const QString &_email,
|
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
||||||
const QString &_password, const uint _permissions,
|
const QString &_password,
|
||||||
const QueuedLimits::Limits &_limits,
|
const uint _permissions,
|
||||||
const QString &_token);
|
const QueuedLimits::Limits &_limits,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief try to authorize by given token
|
* @brief try to authorize by given token
|
||||||
* @param _token
|
* @param _token
|
||||||
* token ID
|
* token ID
|
||||||
* @return true if token is valid
|
* @return true if token is valid
|
||||||
*/
|
*/
|
||||||
bool authorization(const QString &_token);
|
QueuedResult<bool> authorization(const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief authorize and create new token for user
|
* @brief authorize and create new token for user
|
||||||
* @param _name
|
* @param _name
|
||||||
@ -125,7 +127,8 @@ public:
|
|||||||
* user password
|
* user password
|
||||||
* @return token. It will be empty if authorization error occurs
|
* @return token. It will be empty if authorization error occurs
|
||||||
*/
|
*/
|
||||||
QString authorization(const QString &_name, const QString &_password);
|
QueuedResult<QString> authorization(const QString &_name,
|
||||||
|
const QString &_password);
|
||||||
/**
|
/**
|
||||||
* @brief edit advanced settings
|
* @brief edit advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -136,8 +139,8 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful option edition
|
* @return true on successful option edition
|
||||||
*/
|
*/
|
||||||
bool editOption(const QString &_key, const QVariant &_value,
|
QueuedResult<bool> editOption(const QString &_key, const QVariant &_value,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit task
|
* @brief edit task
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -150,8 +153,9 @@ public:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
bool editTask(const long long _id, const QVariantHash &_taskData,
|
QueuedResult<bool> editTask(const long long _id,
|
||||||
const QString &_token);
|
const QVariantHash &_taskData,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -164,8 +168,9 @@ public:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
bool editUser(const long long _id, const QVariantHash &_userData,
|
QueuedResult<bool> editUser(const long long _id,
|
||||||
const QString &_token);
|
const QVariantHash &_userData,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user permissions
|
* @brief edit user permissions
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -178,16 +183,24 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful user permission edition
|
* @return true on successful user permission edition
|
||||||
*/
|
*/
|
||||||
bool editUserPermission(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedEnums::Permission &_permission,
|
editUserPermission(const long long _id,
|
||||||
const bool _add, const QString &_token);
|
const QueuedEnums::Permission &_permission,
|
||||||
|
const bool _add, const QString &_token);
|
||||||
|
/**
|
||||||
|
* @brief hash password
|
||||||
|
* @param _password
|
||||||
|
* user password as plain text
|
||||||
|
* @return hashed password with applied salt
|
||||||
|
*/
|
||||||
|
QueuedResult<QString> hashFromPassword(const QString &_password);
|
||||||
/**
|
/**
|
||||||
* @brief get value from advanced settings
|
* @brief get value from advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
* key string
|
* key string
|
||||||
* @return option value or empty QVariant
|
* @return option value or empty QVariant
|
||||||
*/
|
*/
|
||||||
QVariant option(const QString &_key);
|
QueuedResult<QVariant> option(const QString &_key);
|
||||||
/**
|
/**
|
||||||
* @brief usage report
|
* @brief usage report
|
||||||
* @param _from
|
* @param _from
|
||||||
@ -198,9 +211,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return performance table
|
* @return performance table
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> performanceReport(const QDateTime &_from,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QDateTime &_to,
|
performanceReport(const QDateTime &_from, const QDateTime &_to,
|
||||||
const QString &_token) const;
|
const QString &_token) const;
|
||||||
/**
|
/**
|
||||||
* @brief get plugin settings
|
* @brief get plugin settings
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -216,7 +229,8 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful plugin removal
|
* @return true on successful plugin removal
|
||||||
*/
|
*/
|
||||||
bool removePlugin(const QString &_plugin, const QString &_token);
|
QueuedResult<bool> removePlugin(const QString &_plugin,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief force start task
|
* @brief force start task
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -225,7 +239,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful task start
|
* @return true on successful task start
|
||||||
*/
|
*/
|
||||||
bool startTask(const long long _id, const QString &_token);
|
QueuedResult<bool> startTask(const long long _id, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief force stop task
|
* @brief force stop task
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -234,7 +248,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful task stop
|
* @return true on successful task stop
|
||||||
*/
|
*/
|
||||||
bool stopTask(const long long _id, const QString &_token);
|
QueuedResult<bool> stopTask(const long long _id, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief get task by ID
|
* @brief get task by ID
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -254,9 +268,10 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of tasks in database format
|
* @return list of tasks in database format
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> taskReport(const long long _user,
|
QueuedResult<QList<QVariantHash>> taskReport(const long long _user,
|
||||||
const QDateTime &_from, const QDateTime &_to,
|
const QDateTime &_from,
|
||||||
const QString &_token) const;
|
const QDateTime &_to,
|
||||||
|
const QString &_token) const;
|
||||||
/**
|
/**
|
||||||
* @brief get user by ID
|
* @brief get user by ID
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -281,9 +296,10 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of users in database format
|
* @return list of users in database format
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> userReport(const QDateTime &_lastLogged,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QueuedEnums::Permission _permission,
|
userReport(const QDateTime &_lastLogged,
|
||||||
const QString &_token) const;
|
const QueuedEnums::Permission _permission,
|
||||||
|
const QString &_token) const;
|
||||||
// control methods
|
// control methods
|
||||||
/**
|
/**
|
||||||
* @brief deinit subclasses
|
* @brief deinit subclasses
|
||||||
@ -394,7 +410,7 @@ private:
|
|||||||
* @param _args
|
* @param _args
|
||||||
* class constructor arguments
|
* class constructor arguments
|
||||||
*/
|
*/
|
||||||
template<class T, typename... Args> T *initObject(T *_dest, Args... _args)
|
template <class T, typename... Args> T *initObject(T *_dest, Args... _args)
|
||||||
{
|
{
|
||||||
return _dest ? _dest : new T(this, _args...);
|
return _dest ? _dest : new T(this, _args...);
|
||||||
};
|
};
|
||||||
@ -432,11 +448,11 @@ private:
|
|||||||
* task defined limits
|
* task defined limits
|
||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
long long addTaskPrivate(const QString &_command,
|
QueuedResult<long long> addTaskPrivate(const QString &_command,
|
||||||
const QStringList &_arguments,
|
const QStringList &_arguments,
|
||||||
const QString &_workingDirectory,
|
const QString &_workingDirectory,
|
||||||
const long long _userId,
|
const long long _userId,
|
||||||
const QueuedLimits::Limits &_limits);
|
const QueuedLimits::Limits &_limits);
|
||||||
/**
|
/**
|
||||||
* @brief add new user
|
* @brief add new user
|
||||||
* @param _name
|
* @param _name
|
||||||
@ -451,9 +467,11 @@ private:
|
|||||||
* user limits
|
* user limits
|
||||||
* @return user ID or -1 if no user found
|
* @return user ID or -1 if no user found
|
||||||
*/
|
*/
|
||||||
long long addUserPrivate(const QString &_name, const QString &_email,
|
QueuedResult<long long> addUserPrivate(const QString &_name,
|
||||||
const QString &_password, const uint _permissions,
|
const QString &_email,
|
||||||
const QueuedLimits::Limits &_limits);
|
const QString &_password,
|
||||||
|
const uint _permissions,
|
||||||
|
const QueuedLimits::Limits &_limits);
|
||||||
/**
|
/**
|
||||||
* @brief edit advanced settings
|
* @brief edit advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -462,7 +480,8 @@ private:
|
|||||||
* advanced settings value
|
* advanced settings value
|
||||||
* @return true on successful option edition
|
* @return true on successful option edition
|
||||||
*/
|
*/
|
||||||
bool editOptionPrivate(const QString &_key, const QVariant &_value);
|
QueuedResult<bool> editOptionPrivate(const QString &_key,
|
||||||
|
const QVariant &_value);
|
||||||
/**
|
/**
|
||||||
* @brief edit plugin list
|
* @brief edit plugin list
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -471,7 +490,8 @@ private:
|
|||||||
* true if it requires add plugin
|
* true if it requires add plugin
|
||||||
* @return true on successful action
|
* @return true on successful action
|
||||||
*/
|
*/
|
||||||
bool editPluginPrivate(const QString &_plugin, const bool _add);
|
QueuedResult<bool> editPluginPrivate(const QString &_plugin,
|
||||||
|
const bool _add);
|
||||||
/**
|
/**
|
||||||
* @brief edit task
|
* @brief edit task
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -482,7 +502,8 @@ private:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
bool editTaskPrivate(const long long _id, const QVariantHash &_taskData);
|
QueuedResult<bool> editTaskPrivate(const long long _id,
|
||||||
|
const QVariantHash &_taskData);
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -493,7 +514,8 @@ private:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
bool editUserPrivate(const long long _id, const QVariantHash &_userData);
|
QueuedResult<bool> editUserPrivate(const long long _id,
|
||||||
|
const QVariantHash &_userData);
|
||||||
/**
|
/**
|
||||||
* @brief edit user permissions
|
* @brief edit user permissions
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -504,9 +526,10 @@ private:
|
|||||||
* indicates whether it should be added or removed
|
* indicates whether it should be added or removed
|
||||||
* @return true on successful user permission edition
|
* @return true on successful user permission edition
|
||||||
*/
|
*/
|
||||||
bool editUserPermissionPrivate(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedEnums::Permission &_permission,
|
editUserPermissionPrivate(const long long _id,
|
||||||
const bool _add);
|
const QueuedEnums::Permission &_permission,
|
||||||
|
const bool _add);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#ifndef QUEUEDCOREADAPTOR_H
|
#ifndef QUEUEDCOREADAPTOR_H
|
||||||
#define QUEUEDCOREADAPTOR_H
|
#define QUEUEDCOREADAPTOR_H
|
||||||
|
|
||||||
#include <QDBusArgument>
|
#include <QDBusConnection>
|
||||||
#include <QVariant>
|
#include <QDBusReply>
|
||||||
|
|
||||||
#include "QueuedProcess.h"
|
#include "QueuedProcess.h"
|
||||||
#include "QueuedStaticConfig.h"
|
#include "QueuedStaticConfig.h"
|
||||||
@ -45,7 +45,7 @@ namespace QueuedCoreAdaptor
|
|||||||
* token ID
|
* token ID
|
||||||
* @return true if token is valid
|
* @return true if token is valid
|
||||||
*/
|
*/
|
||||||
bool auth(const QString &_token);
|
QueuedResult<bool> auth(const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send auth method
|
* @brief send auth method
|
||||||
* @param _name
|
* @param _name
|
||||||
@ -54,7 +54,7 @@ bool auth(const QString &_token);
|
|||||||
* user password
|
* user password
|
||||||
* @return generated token ID or empty string in case of invalid password
|
* @return generated token ID or empty string in case of invalid password
|
||||||
*/
|
*/
|
||||||
QString auth(const QString &_name, const QString &_password);
|
QueuedResult<QString> auth(const QString &_name, const QString &_password);
|
||||||
/**
|
/**
|
||||||
* @brief send OptionEdit
|
* @brief send OptionEdit
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -65,8 +65,15 @@ QString auth(const QString &_name, const QString &_password);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful option edition
|
* @return true on successful option edition
|
||||||
*/
|
*/
|
||||||
bool sendOptionEdit(const QString &_key, const QVariant &_value,
|
QueuedResult<bool> sendOptionEdit(const QString &_key, const QVariant &_value,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
|
/**
|
||||||
|
* @brief send PasswordHash
|
||||||
|
* @param _password
|
||||||
|
* user password
|
||||||
|
* @return hashed password with applied salt
|
||||||
|
*/
|
||||||
|
QueuedResult<QString> sendPasswordHash(const QString &_password);
|
||||||
/**
|
/**
|
||||||
* @brief send PluginAdd
|
* @brief send PluginAdd
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -75,7 +82,7 @@ bool sendOptionEdit(const QString &_key, const QVariant &_value,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful plugin addition
|
* @return true on successful plugin addition
|
||||||
*/
|
*/
|
||||||
bool sendPluginAdd(const QString &_plugin, const QString &_token);
|
QueuedResult<bool> sendPluginAdd(const QString &_plugin, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send PluginRemove
|
* @brief send PluginRemove
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -84,7 +91,8 @@ bool sendPluginAdd(const QString &_plugin, const QString &_token);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful plugin removal
|
* @return true on successful plugin removal
|
||||||
*/
|
*/
|
||||||
bool sendPluginRemove(const QString &_plugin, const QString &_token);
|
QueuedResult<bool> sendPluginRemove(const QString &_plugin,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send TaskAdd
|
* @brief send TaskAdd
|
||||||
* @param _definitions
|
* @param _definitions
|
||||||
@ -93,7 +101,7 @@ bool sendPluginRemove(const QString &_plugin, const QString &_token);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return task ID or {0, -1} if no task added
|
* @return task ID or {0, -1} if no task added
|
||||||
*/
|
*/
|
||||||
long long
|
QueuedResult<long long>
|
||||||
sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
@ -106,9 +114,10 @@ sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
bool sendTaskEdit(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
sendTaskEdit(const long long _id,
|
||||||
const QString &_token);
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send TaskStart
|
* @brief send TaskStart
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -117,7 +126,7 @@ bool sendTaskEdit(const long long _id,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task start
|
* @return true on successful task start
|
||||||
*/
|
*/
|
||||||
bool sendTaskStart(const long long _id, const QString &_token);
|
QueuedResult<bool> sendTaskStart(const long long _id, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send TaskStop
|
* @brief send TaskStop
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -126,7 +135,7 @@ bool sendTaskStart(const long long _id, const QString &_token);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task stop
|
* @return true on successful task stop
|
||||||
*/
|
*/
|
||||||
bool sendTaskStop(const long long _id, const QString &_token);
|
QueuedResult<bool> sendTaskStop(const long long _id, const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send UserAdd
|
* @brief send UserAdd
|
||||||
* @param _definitions
|
* @param _definitions
|
||||||
@ -135,8 +144,9 @@ bool sendTaskStop(const long long _id, const QString &_token);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return user ID or -1 if no user added
|
* @return user ID or -1 if no user added
|
||||||
*/
|
*/
|
||||||
long long sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedResult<long long>
|
||||||
const QString &_token);
|
sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send UserEdit
|
* @brief send UserEdit
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -147,9 +157,10 @@ long long sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
bool sendUserEdit(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
sendUserEdit(const long long _id,
|
||||||
const QString &_token);
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send UserPermissionsAdd
|
* @brief send UserPermissionsAdd
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -160,9 +171,10 @@ bool sendUserEdit(const long long _id,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission addition
|
* @return true on successful permission addition
|
||||||
*/
|
*/
|
||||||
bool sendUserPermissionAdd(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedEnums::Permission _permission,
|
sendUserPermissionAdd(const long long _id,
|
||||||
const QString &_token);
|
const QueuedEnums::Permission _permission,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief send sendUserPermissionRemove
|
* @brief send sendUserPermissionRemove
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -173,9 +185,10 @@ bool sendUserPermissionAdd(const long long _id,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission removal
|
* @return true on successful permission removal
|
||||||
*/
|
*/
|
||||||
bool sendUserPermissionRemove(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedEnums::Permission _permission,
|
sendUserPermissionRemove(const long long _id,
|
||||||
const QString &_token);
|
const QueuedEnums::Permission _permission,
|
||||||
|
const QString &_token);
|
||||||
// specific methods for properties
|
// specific methods for properties
|
||||||
/**
|
/**
|
||||||
* @brief get option
|
* @brief get option
|
||||||
@ -183,14 +196,14 @@ bool sendUserPermissionRemove(const long long _id,
|
|||||||
* option name
|
* option name
|
||||||
* @return option value
|
* @return option value
|
||||||
*/
|
*/
|
||||||
QVariant getOption(const QString &_property);
|
QueuedResult<QVariant> getOption(const QString &_property);
|
||||||
/**
|
/**
|
||||||
* @brief get option
|
* @brief get option
|
||||||
* @param _property
|
* @param _property
|
||||||
* option name
|
* option name
|
||||||
* @return option value
|
* @return option value
|
||||||
*/
|
*/
|
||||||
QVariant getOption(const QueuedConfig::QueuedSettings _property);
|
QueuedResult<QVariant> getOption(const QueuedConfig::QueuedSettings _property);
|
||||||
/**
|
/**
|
||||||
* @brief performance report
|
* @brief performance report
|
||||||
* @param _from
|
* @param _from
|
||||||
@ -201,24 +214,21 @@ QVariant getOption(const QueuedConfig::QueuedSettings _property);
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of user with used resources
|
* @return list of user with used resources
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> getPerformance(const QDateTime &_from, const QDateTime &_to,
|
QueuedResult<QList<QVariantHash>> getPerformance(const QDateTime &_from,
|
||||||
const QString &_token);
|
const QDateTime &_to,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief server status
|
* @brief server status
|
||||||
* @return server status information
|
* @return server status information
|
||||||
*/
|
*/
|
||||||
QHash<QString, QHash<QString, QString>> getStatus();
|
QueuedResult<QueuedStatusMap> getStatus();
|
||||||
/**
|
/**
|
||||||
* @brief get all task properties
|
* @brief get all task properties
|
||||||
* @param _id
|
* @param _id
|
||||||
* task ID
|
* task ID
|
||||||
* @return task properties
|
* @return task properties
|
||||||
*/
|
*/
|
||||||
QVariantHash getTask(const long long _id);
|
QueuedResult<QVariantHash> getTask(const long long _id);
|
||||||
/**
|
|
||||||
* @return server status information
|
|
||||||
*/
|
|
||||||
QHash<QString, QHash<QString, QString>> getStatus();
|
|
||||||
/**
|
/**
|
||||||
* @brief get task property
|
* @brief get task property
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -227,7 +237,7 @@ QHash<QString, QHash<QString, QString>> getStatus();
|
|||||||
* task property name
|
* task property name
|
||||||
* @return task property value
|
* @return task property value
|
||||||
*/
|
*/
|
||||||
QVariant getTask(const long long _id, const QString &_property);
|
QueuedResult<QVariant> getTask(const long long _id, const QString &_property);
|
||||||
/**
|
/**
|
||||||
* @brief get tasks list
|
* @brief get tasks list
|
||||||
* @param _user
|
* @param _user
|
||||||
@ -240,15 +250,17 @@ QVariant getTask(const long long _id, const QString &_property);
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of task in database representation
|
* @return list of task in database representation
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> getTasks(const long long _user, const QDateTime &_from,
|
QueuedResult<QList<QVariantHash>> getTasks(const long long _user,
|
||||||
const QDateTime &_to, const QString &_token);
|
const QDateTime &_from,
|
||||||
|
const QDateTime &_to,
|
||||||
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief get user properties
|
* @brief get user properties
|
||||||
* @param _id
|
* @param _id
|
||||||
* user id
|
* user id
|
||||||
* @return user properties
|
* @return user properties
|
||||||
*/
|
*/
|
||||||
QVariantHash getUser(const long long _id);
|
QueuedResult<QVariantHash> getUser(const long long _id);
|
||||||
/**
|
/**
|
||||||
* @brief get user property
|
* @brief get user property
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -257,7 +269,7 @@ QVariantHash getUser(const long long _id);
|
|||||||
* user property name
|
* user property name
|
||||||
* @return user property value
|
* @return user property value
|
||||||
*/
|
*/
|
||||||
QVariant getUser(const long long _id, const QString &_property);
|
QueuedResult<QVariant> getUser(const long long _id, const QString &_property);
|
||||||
/**
|
/**
|
||||||
* @brief get user ID
|
* @brief get user ID
|
||||||
* @param _name
|
* @param _name
|
||||||
@ -265,7 +277,7 @@ QVariant getUser(const long long _id, const QString &_property);
|
|||||||
* @return user ID or {0, -1} if no user found. If _name is numeric value it
|
* @return user ID or {0, -1} if no user found. If _name is numeric value it
|
||||||
* returns converted one
|
* returns converted one
|
||||||
*/
|
*/
|
||||||
long long getUserId(const QString &_name);
|
QueuedResult<long long> getUserId(const QString &_name);
|
||||||
/**
|
/**
|
||||||
* @brief get users list
|
* @brief get users list
|
||||||
* @param _lastLogged
|
* @param _lastLogged
|
||||||
@ -276,10 +288,49 @@ long long getUserId(const QString &_name);
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of users in database representation
|
* @return list of users in database representation
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> getUsers(const QDateTime &_lastLogged,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QueuedEnums::Permission _permission,
|
getUsers(const QDateTime &_lastLogged,
|
||||||
const QString &_token);
|
const QueuedEnums::Permission _permission, const QString &_token);
|
||||||
// common methods
|
// common methods
|
||||||
|
/**
|
||||||
|
* @brief additional method to avoid conversion from QueuedResult to
|
||||||
|
* QDBusVariant
|
||||||
|
* @tparam T
|
||||||
|
* QueuedResult payload class
|
||||||
|
* @param _data
|
||||||
|
* input data
|
||||||
|
* @return converted data to QDBusVariant
|
||||||
|
*/
|
||||||
|
template <class T> QDBusVariant toDBusVariant(const QueuedResult<T> &_data)
|
||||||
|
{
|
||||||
|
return QDBusVariant(QVariant::fromValue<QueuedResult<T>>(_data));
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief additional method to avoid conversion from QDBusVariant to
|
||||||
|
* QueuedResult
|
||||||
|
* @tparam T
|
||||||
|
* QueuedResult payload class
|
||||||
|
* @param _data
|
||||||
|
* input data
|
||||||
|
* @return converted data to QueuedResult
|
||||||
|
*/
|
||||||
|
template <class T> QueuedResult<T> toResult(const QDBusVariant &_data)
|
||||||
|
{
|
||||||
|
return qdbus_cast<QueuedResult<T>>(_data.variant().value<QDBusArgument>());
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief additional method to avoid conversion from QVariant to
|
||||||
|
* QueuedResult
|
||||||
|
* @tparam T
|
||||||
|
* QueuedResult payload class
|
||||||
|
* @param _data
|
||||||
|
* input data
|
||||||
|
* @return converted data to QueuedResult
|
||||||
|
*/
|
||||||
|
template <class T> QueuedResult<T> toResult(const QVariant &_data)
|
||||||
|
{
|
||||||
|
return qdbus_cast<QueuedResult<T>>(_data.value<QDBusArgument>());
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* @brief common DBus request
|
* @brief common DBus request
|
||||||
* @param _service
|
* @param _service
|
||||||
@ -294,16 +345,27 @@ QList<QVariantHash> getUsers(const QDateTime &_lastLogged,
|
|||||||
* command arguments
|
* command arguments
|
||||||
* @return reply object from DBus request
|
* @return reply object from DBus request
|
||||||
*/
|
*/
|
||||||
QVariantList sendRequest(const QString &_service, const QString &_path,
|
template <typename T>
|
||||||
const QString &_interface, const QString &_cmd,
|
QueuedResult<T> sendRequest(const QString &_service, const QString &_path,
|
||||||
const QVariantList &_args);
|
const QString &_interface, const QString &_cmd,
|
||||||
/**
|
const QVariantList &_args)
|
||||||
* @brief additional method to avoid conversion from DBus type to native ones
|
{
|
||||||
* @param _data
|
QDBusConnection bus = QDBusConnection::systemBus();
|
||||||
* source data
|
QDBusMessage request
|
||||||
* @return converted value
|
= QDBusMessage::createMethodCall(_service, _path, _interface, _cmd);
|
||||||
*/
|
if (!_args.isEmpty())
|
||||||
QVariant toNativeType(const QVariant &_data);
|
request.setArguments(_args);
|
||||||
|
|
||||||
|
QDBusReply<QDBusVariant> dbusResponse
|
||||||
|
= bus.call(request, QDBus::BlockWithGui);
|
||||||
|
|
||||||
|
if (dbusResponse.isValid()) {
|
||||||
|
auto response = dbusResponse.value();
|
||||||
|
return toResult<T>(response);
|
||||||
|
} else {
|
||||||
|
return QueuedError(dbusResponse.error().message().toStdString());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public slots:
|
|||||||
* user password
|
* user password
|
||||||
* @return generated token ID or empty string in case of invalid password
|
* @return generated token ID or empty string in case of invalid password
|
||||||
*/
|
*/
|
||||||
QString Auth(const QString &name, const QString &password);
|
QDBusVariant Auth(const QString &name, const QString &password);
|
||||||
/**
|
/**
|
||||||
* @brief edit option
|
* @brief edit option
|
||||||
* @param key
|
* @param key
|
||||||
@ -72,8 +72,15 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful option edition
|
* @return true on successful option edition
|
||||||
*/
|
*/
|
||||||
bool OptionEdit(const QString &key, const QDBusVariant &value,
|
QDBusVariant OptionEdit(const QString &key, const QDBusVariant &value,
|
||||||
const QString &token);
|
const QString &token);
|
||||||
|
/**
|
||||||
|
* @brief get password hash
|
||||||
|
* @param password
|
||||||
|
* user password as plain text
|
||||||
|
* @return hashed password
|
||||||
|
*/
|
||||||
|
QDBusVariant PasswordHash(const QString &password);
|
||||||
/**
|
/**
|
||||||
* @brief add plugin
|
* @brief add plugin
|
||||||
* @param plugin
|
* @param plugin
|
||||||
@ -82,7 +89,7 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful plugin addition
|
* @return true on successful plugin addition
|
||||||
*/
|
*/
|
||||||
bool PluginAdd(const QString &plugin, const QString &token);
|
QDBusVariant PluginAdd(const QString &plugin, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief remove plugin
|
* @brief remove plugin
|
||||||
* @param plugin
|
* @param plugin
|
||||||
@ -91,7 +98,7 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful plugin removal
|
* @return true on successful plugin removal
|
||||||
*/
|
*/
|
||||||
bool PluginRemove(const QString &plugin, const QString &token);
|
QDBusVariant PluginRemove(const QString &plugin, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief add new task
|
* @brief add new task
|
||||||
* @param command
|
* @param command
|
||||||
@ -116,11 +123,11 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
qlonglong TaskAdd(const QString &command, const QStringList &arguments,
|
QDBusVariant TaskAdd(const QString &command, const QStringList &arguments,
|
||||||
const QString &workingDirectory, const qlonglong user,
|
const QString &workingDirectory, const qlonglong user,
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong storage, const QString &token);
|
const qlonglong storage, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief edit task
|
* @brief edit task
|
||||||
* @param id
|
* @param id
|
||||||
@ -153,13 +160,13 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
bool TaskEdit(const qlonglong id, const QString &command,
|
QDBusVariant TaskEdit(const qlonglong id, const QString &command,
|
||||||
const QStringList &arguments, const QString &directory,
|
const QStringList &arguments,
|
||||||
const uint nice, const uint uid, const uint gid,
|
const QString &directory, const uint nice,
|
||||||
const qlonglong user, const qlonglong cpu,
|
const uint uid, const uint gid, const qlonglong user,
|
||||||
const qlonglong gpu, const qlonglong memory,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong gpumemory, const qlonglong storage,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const QString &token);
|
const qlonglong storage, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief force start task
|
* @brief force start task
|
||||||
* @param id
|
* @param id
|
||||||
@ -168,7 +175,7 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task start
|
* @return true on successful task start
|
||||||
*/
|
*/
|
||||||
bool TaskStart(const qlonglong id, const QString &token);
|
QDBusVariant TaskStart(const qlonglong id, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief force stop task
|
* @brief force stop task
|
||||||
* @param id
|
* @param id
|
||||||
@ -177,14 +184,14 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task stop
|
* @return true on successful task stop
|
||||||
*/
|
*/
|
||||||
bool TaskStop(const qlonglong id, const QString &token);
|
QDBusVariant TaskStop(const qlonglong id, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief try auth by token
|
* @brief try auth by token
|
||||||
* @param token
|
* @param token
|
||||||
* token ID
|
* token ID
|
||||||
* @return true if token is valid
|
* @return true if token is valid
|
||||||
*/
|
*/
|
||||||
bool TryAuth(const QString &token);
|
QDBusVariant TryAuth(const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief add new user
|
* @brief add new user
|
||||||
* @param name
|
* @param name
|
||||||
@ -209,11 +216,11 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return user ID or -1 if no user found
|
* @return user ID or -1 if no user found
|
||||||
*/
|
*/
|
||||||
qlonglong UserAdd(const QString &name, const QString &email,
|
QDBusVariant UserAdd(const QString &name, const QString &email,
|
||||||
const QString &password, const uint permissions,
|
const QString &password, const uint permissions,
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong storage, const QString &token);
|
const qlonglong storage, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
* @param id
|
* @param id
|
||||||
@ -238,11 +245,11 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
bool UserEdit(const qlonglong id, const QString &name,
|
QDBusVariant UserEdit(const qlonglong id, const QString &name,
|
||||||
const QString &password, const QString &email,
|
const QString &password, const QString &email,
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong storage, const QString &token);
|
const qlonglong storage, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief add permission to user
|
* @brief add permission to user
|
||||||
* @param id
|
* @param id
|
||||||
@ -253,8 +260,8 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission addition
|
* @return true on successful permission addition
|
||||||
*/
|
*/
|
||||||
bool UserPermissionAdd(const qlonglong id, const uint permission,
|
QDBusVariant UserPermissionAdd(const qlonglong id, const uint permission,
|
||||||
const QString &token);
|
const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief remove permission from user
|
* @brief remove permission from user
|
||||||
* @param id
|
* @param id
|
||||||
@ -265,8 +272,8 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission removal
|
* @return true on successful permission removal
|
||||||
*/
|
*/
|
||||||
bool UserPermissionRemove(const qlonglong id, const uint permission,
|
QDBusVariant UserPermissionRemove(const qlonglong id, const uint permission,
|
||||||
const QString &token);
|
const QString &token);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
@ -37,19 +37,19 @@ namespace QueuedDB
|
|||||||
/**
|
/**
|
||||||
* @brief settings table name
|
* @brief settings table name
|
||||||
*/
|
*/
|
||||||
const char SETTINGS_TABLE[] = "settings";
|
static const char SETTINGS_TABLE[] = "settings";
|
||||||
/**
|
/**
|
||||||
* @brief tasks table name
|
* @brief tasks table name
|
||||||
*/
|
*/
|
||||||
const char TASKS_TABLE[] = "tasks";
|
static const char TASKS_TABLE[] = "tasks";
|
||||||
/**
|
/**
|
||||||
* @brief tokens table name
|
* @brief tokens table name
|
||||||
*/
|
*/
|
||||||
const char TOKENS_TABLE[] = "tokens";
|
static const char TOKENS_TABLE[] = "tokens";
|
||||||
/**
|
/**
|
||||||
* @brief users table name
|
* @brief users table name
|
||||||
*/
|
*/
|
||||||
const char USERS_TABLE[] = "users";
|
static const char USERS_TABLE[] = "users";
|
||||||
/**
|
/**
|
||||||
* @struct QueuedDBField
|
* @struct QueuedDBField
|
||||||
* @brief describes database column
|
* @brief describes database column
|
||||||
@ -76,7 +76,7 @@ typedef QHash<QString, QHash<QString, QueuedDBField>> QueuedDBSchema;
|
|||||||
/**
|
/**
|
||||||
* @brief database schema
|
* @brief database schema
|
||||||
*/
|
*/
|
||||||
const QueuedDBSchema DBSchema = {
|
static const QueuedDBSchema DBSchema = {
|
||||||
{SETTINGS_TABLE,
|
{SETTINGS_TABLE,
|
||||||
{{"_id",
|
{{"_id",
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
||||||
|
@ -62,11 +62,12 @@ namespace QueuedDebug
|
|||||||
/**
|
/**
|
||||||
* @brief default log format
|
* @brief default log format
|
||||||
*/
|
*/
|
||||||
const char LOG_FORMAT[] = "[%{time "
|
static const char LOG_FORMAT[]
|
||||||
"process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
|
= "[%{time "
|
||||||
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
|
"process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
|
||||||
"fatal}FF%{endif}][%{category}][%{function}] "
|
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
|
||||||
"%{message}";
|
"fatal}FF%{endif}][%{category}][%{function}] "
|
||||||
|
"%{message}";
|
||||||
/**
|
/**
|
||||||
* @brief method to apply log format
|
* @brief method to apply log format
|
||||||
*/
|
*/
|
||||||
|
@ -56,7 +56,7 @@ enum class Permission {
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(Permissions, Permission)
|
Q_DECLARE_FLAGS(Permissions, Permission)
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Permissions)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Permissions)
|
||||||
const QHash<QString, Permission> PermissionMap = {
|
static const QHash<QString, Permission> PermissionMap = {
|
||||||
{"superadmin", Permission::SuperAdmin},
|
{"superadmin", Permission::SuperAdmin},
|
||||||
{"admin", Permission::Admin},
|
{"admin", Permission::Admin},
|
||||||
{"job", Permission::Job},
|
{"job", Permission::Job},
|
||||||
@ -71,7 +71,7 @@ const QHash<QString, Permission> PermissionMap = {
|
|||||||
inline Permission stringToPermission(const QString &_permission)
|
inline Permission stringToPermission(const QString &_permission)
|
||||||
{
|
{
|
||||||
return PermissionMap.contains(_permission.toLower())
|
return PermissionMap.contains(_permission.toLower())
|
||||||
? PermissionMap[_permission.toLower()]
|
? PermissionMap.value(_permission.toLower())
|
||||||
: Permission::Invalid;
|
: Permission::Invalid;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -83,6 +83,23 @@ inline Permission stringToPermission(const QString &_permission)
|
|||||||
* send SIGKILL on exit
|
* send SIGKILL on exit
|
||||||
*/
|
*/
|
||||||
enum class ExitAction { Terminate = 1 << 1, Kill = 1 << 2 };
|
enum class ExitAction { Terminate = 1 << 1, Kill = 1 << 2 };
|
||||||
|
/**
|
||||||
|
* @enum ReturnStatus
|
||||||
|
* @brief DBus response status
|
||||||
|
* @var ReturnStatus::OK
|
||||||
|
* no errors in report
|
||||||
|
* @var ReturnStatus::Error
|
||||||
|
* generic error occurs
|
||||||
|
* @var ReturnStatus::InsufficientPermissions
|
||||||
|
* insufficient user permissions
|
||||||
|
*/
|
||||||
|
enum class ReturnStatus {
|
||||||
|
Error = 1 << 1,
|
||||||
|
InvalidArgument = 1 << 2,
|
||||||
|
InsufficientPermissions = 1 << 3,
|
||||||
|
InvalidToken = 1 << 4,
|
||||||
|
InvalidPassword = 1 << 5
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public slots:
|
|||||||
* user name
|
* user name
|
||||||
* @return user ID or -1 if no user found
|
* @return user ID or -1 if no user found
|
||||||
*/
|
*/
|
||||||
qlonglong UserIdByName(const QString &name);
|
QDBusVariant UserIdByName(const QString &name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
204
sources/queued/include/queued/QueuedResult.h
Normal file
204
sources/queued/include/queued/QueuedResult.h
Normal file
@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Queued team
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
*
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file QueuedResult.h
|
||||||
|
* Header of Queued library
|
||||||
|
* @author Queued team
|
||||||
|
* @copyright MIT
|
||||||
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QUEUEDRESULT_H
|
||||||
|
#define QUEUEDRESULT_H
|
||||||
|
|
||||||
|
#include <QDBusArgument>
|
||||||
|
|
||||||
|
#include <result/result.hpp>
|
||||||
|
|
||||||
|
namespace QueuedEnums
|
||||||
|
{
|
||||||
|
enum class ReturnStatus;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef QueuedError
|
||||||
|
* custom result error implementation
|
||||||
|
*/
|
||||||
|
typedef Result::Error<QueuedEnums::ReturnStatus> QueuedError;
|
||||||
|
/**
|
||||||
|
* @brief DBus marshalling method
|
||||||
|
* @param _argument
|
||||||
|
* output DBus argument
|
||||||
|
* @param _arg
|
||||||
|
* input error class
|
||||||
|
* @return appended argument body
|
||||||
|
*/
|
||||||
|
inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
||||||
|
const QueuedError &_arg)
|
||||||
|
{
|
||||||
|
_argument.beginStructure();
|
||||||
|
_argument << QString(_arg.message().c_str());
|
||||||
|
_argument << static_cast<long long>(_arg.code());
|
||||||
|
_argument.endStructure();
|
||||||
|
|
||||||
|
return _argument;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief DBus un-marshalling method
|
||||||
|
* @param _argument
|
||||||
|
* input DBus argument
|
||||||
|
* @param _arg
|
||||||
|
* output object
|
||||||
|
* @return source DBus argument
|
||||||
|
*/
|
||||||
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
||||||
|
QueuedError &_arg)
|
||||||
|
{
|
||||||
|
QString message;
|
||||||
|
long long code;
|
||||||
|
|
||||||
|
_argument.beginStructure();
|
||||||
|
_argument >> message;
|
||||||
|
_argument >> code;
|
||||||
|
_argument.endStructure();
|
||||||
|
|
||||||
|
_arg = QueuedError(message.toStdString(),
|
||||||
|
static_cast<QueuedEnums::ReturnStatus>(code));
|
||||||
|
return _argument;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @typedef QueuedStatusMap
|
||||||
|
* status report representation
|
||||||
|
*/
|
||||||
|
typedef QHash<QString, QHash<QString, QString>> QueuedStatusMap;
|
||||||
|
/**
|
||||||
|
* @typedef QueuedResult
|
||||||
|
* @tparam T
|
||||||
|
* result value payload class
|
||||||
|
* custom Result<T, E> implementation
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
using QueuedResult = Result::Result<T, QueuedEnums::ReturnStatus>;
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<bool>)
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<long long>)
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<QString>)
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<QStringList>)
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<QVariant>)
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<QList<QVariantHash>>)
|
||||||
|
Q_DECLARE_METATYPE(QueuedResult<QueuedStatusMap>)
|
||||||
|
/**
|
||||||
|
* @brief DBus marshalling method
|
||||||
|
* @param _argument
|
||||||
|
* output DBus argument
|
||||||
|
* @param _arg
|
||||||
|
* input variant object
|
||||||
|
* @return appended argument body
|
||||||
|
*/
|
||||||
|
inline QDBusArgument &operator<<(QDBusArgument &_argument, const QVariant &_arg)
|
||||||
|
{
|
||||||
|
return _argument << QDBusVariant(_arg.isValid() ? _arg : "");
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief DBus un-marshalling method
|
||||||
|
* @param _argument
|
||||||
|
* input DBus argument
|
||||||
|
* @param _arg
|
||||||
|
* output variant object
|
||||||
|
* @return source DBus argument
|
||||||
|
*/
|
||||||
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
||||||
|
QVariant &_arg)
|
||||||
|
{
|
||||||
|
QDBusVariant variant;
|
||||||
|
|
||||||
|
_argument >> variant;
|
||||||
|
_arg = variant.variant();
|
||||||
|
|
||||||
|
return _argument;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief DBus marshalling method
|
||||||
|
* @tparam T
|
||||||
|
* result value payload class
|
||||||
|
* @param _argument
|
||||||
|
* output DBus argument
|
||||||
|
* @param _arg
|
||||||
|
* input result object
|
||||||
|
* @return appended argument body
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
||||||
|
const QueuedResult<T> &_arg)
|
||||||
|
{
|
||||||
|
// HACK we are using explicit cast to QString here to make sure of valid
|
||||||
|
// marshalling
|
||||||
|
_argument.beginStructure();
|
||||||
|
switch (_arg.type()) {
|
||||||
|
case Result::Content::Value:
|
||||||
|
_argument << QString("v");
|
||||||
|
_argument << _arg.get();
|
||||||
|
_argument << QueuedError();
|
||||||
|
break;
|
||||||
|
case Result::Content::Error:
|
||||||
|
_argument << QString("e");
|
||||||
|
_argument << T();
|
||||||
|
_argument << _arg.error();
|
||||||
|
break;
|
||||||
|
case Result::Content::Empty:
|
||||||
|
_argument << QString("n");
|
||||||
|
_argument << T();
|
||||||
|
_argument << QueuedError();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_argument.endStructure();
|
||||||
|
|
||||||
|
return _argument;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief DBus un-marshalling method
|
||||||
|
* @tparam T
|
||||||
|
* result value payload class
|
||||||
|
* @param _argument
|
||||||
|
* input DBus argument
|
||||||
|
* @param _arg
|
||||||
|
* output result object
|
||||||
|
* @return source DBus argument
|
||||||
|
*/
|
||||||
|
template <class T>
|
||||||
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
||||||
|
QueuedResult<T> &_arg)
|
||||||
|
{
|
||||||
|
QString type;
|
||||||
|
T value;
|
||||||
|
QueuedError error;
|
||||||
|
|
||||||
|
_argument.beginStructure();
|
||||||
|
_argument >> type;
|
||||||
|
_argument >> value;
|
||||||
|
_argument >> error;
|
||||||
|
_argument.endStructure();
|
||||||
|
|
||||||
|
if (type == "v")
|
||||||
|
_arg = value;
|
||||||
|
else if (type == "e")
|
||||||
|
_arg = error;
|
||||||
|
else if (type == "n")
|
||||||
|
_arg = QueuedResult<T>();
|
||||||
|
return _argument;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* QUEUEDRESULT_H */
|
@ -44,10 +44,13 @@ namespace QueuedConfig
|
|||||||
* administrator user name
|
* administrator user name
|
||||||
* @var QueuedAdminSetup::password
|
* @var QueuedAdminSetup::password
|
||||||
* administrator user password
|
* administrator user password
|
||||||
|
* @var QueuedAdminSetup::salt
|
||||||
|
* user passwords salt
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
QString name;
|
QString name;
|
||||||
QString password;
|
QString password;
|
||||||
|
QString salt;
|
||||||
} QueuedAdminSetup;
|
} QueuedAdminSetup;
|
||||||
/**
|
/**
|
||||||
* @struct QueuedDBSetup
|
* @struct QueuedDBSetup
|
||||||
@ -80,6 +83,8 @@ typedef struct {
|
|||||||
* unknown key
|
* unknown key
|
||||||
* @var QueuedSettings::DatabaseInterval
|
* @var QueuedSettings::DatabaseInterval
|
||||||
* database actions interval in msecs
|
* database actions interval in msecs
|
||||||
|
* @var QueuedSettings::DatabaseVersion
|
||||||
|
* internal field to control current database version
|
||||||
* @var QueuedSettings::DefaultLimits
|
* @var QueuedSettings::DefaultLimits
|
||||||
* default limits value
|
* default limits value
|
||||||
* @var QueuedSettings::KeepTasks
|
* @var QueuedSettings::KeepTasks
|
||||||
@ -88,14 +93,10 @@ typedef struct {
|
|||||||
* keep users last logged in msecs
|
* keep users last logged in msecs
|
||||||
* @var QueuedSettings::OnExitAction
|
* @var QueuedSettings::OnExitAction
|
||||||
* on queued exit action enum
|
* on queued exit action enum
|
||||||
* @var QueuedSettings::TokenExpiration
|
|
||||||
* token expiration value in days
|
|
||||||
* @var QueuedSettings::DatabaseVersion
|
|
||||||
* internal field to control current database version
|
|
||||||
* @var QueuedSettings::ProcessCommandLine
|
|
||||||
* control process command line
|
|
||||||
* @var QueuedSettings::Plugins
|
* @var QueuedSettings::Plugins
|
||||||
* plugin list
|
* plugin list
|
||||||
|
* @var QueuedSettings::ProcessCommandLine
|
||||||
|
* control process command line
|
||||||
* @var QueuedSettings::ServerAddress
|
* @var QueuedSettings::ServerAddress
|
||||||
* queued server bind address
|
* queued server bind address
|
||||||
* @var QueuedSettings::ServerMaxConnections
|
* @var QueuedSettings::ServerMaxConnections
|
||||||
@ -104,22 +105,24 @@ typedef struct {
|
|||||||
* queued server bind port
|
* queued server bind port
|
||||||
* @var QueuedSettings::ServerTimeout
|
* @var QueuedSettings::ServerTimeout
|
||||||
* server thread timeout
|
* server thread timeout
|
||||||
|
* @var QueuedSettings::TokenExpiration
|
||||||
|
* token expiration value in days
|
||||||
*/
|
*/
|
||||||
enum class QueuedSettings {
|
enum class QueuedSettings {
|
||||||
Invalid,
|
Invalid,
|
||||||
DatabaseInterval,
|
DatabaseInterval,
|
||||||
|
DatabaseVersion,
|
||||||
DefaultLimits,
|
DefaultLimits,
|
||||||
KeepTasks,
|
KeepTasks,
|
||||||
KeepUsers,
|
KeepUsers,
|
||||||
OnExitAction,
|
OnExitAction,
|
||||||
TokenExpiration,
|
|
||||||
DatabaseVersion,
|
|
||||||
ProcessCommandLine,
|
|
||||||
Plugins,
|
Plugins,
|
||||||
|
ProcessCommandLine,
|
||||||
ServerAddress,
|
ServerAddress,
|
||||||
ServerMaxConnections,
|
ServerMaxConnections,
|
||||||
ServerPort,
|
ServerPort,
|
||||||
ServerTimeout
|
ServerTimeout,
|
||||||
|
TokenExpiration
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @struct QueuedSettingsField
|
* @struct QueuedSettingsField
|
||||||
@ -141,25 +144,25 @@ typedef QHash<QString, QueuedSettingsField> QueuedSettingsDefaultMap;
|
|||||||
/**
|
/**
|
||||||
* @brief default settings map
|
* @brief default settings map
|
||||||
*/
|
*/
|
||||||
const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
static const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
||||||
{"", {QueuedSettings::Invalid, QVariant()}},
|
{"", {QueuedSettings::Invalid, QVariant()}},
|
||||||
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}},
|
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}},
|
||||||
|
{"DatabaseVersion",
|
||||||
|
{QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION}},
|
||||||
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0"}},
|
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0"}},
|
||||||
{"KeepTasks", {QueuedSettings::KeepTasks, 0}},
|
{"KeepTasks", {QueuedSettings::KeepTasks, 0}},
|
||||||
{"KeepUsers", {QueuedSettings::KeepUsers, 0}},
|
{"KeepUsers", {QueuedSettings::KeepUsers, 0}},
|
||||||
{"OnExitAction", {QueuedSettings::OnExitAction, 2}},
|
{"OnExitAction", {QueuedSettings::OnExitAction, 2}},
|
||||||
{"TokenExpiration", {QueuedSettings::TokenExpiration, 30}},
|
{"Plugins", {QueuedSettings::Plugins, ""}},
|
||||||
{"DatabaseVersion",
|
|
||||||
{QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION}},
|
|
||||||
{"ProcessCommandLine",
|
{"ProcessCommandLine",
|
||||||
{QueuedSettings::ProcessCommandLine,
|
{QueuedSettings::ProcessCommandLine,
|
||||||
"systemd-run\n--scope\n--unit={name}\n--uid={uid}\n--gid={gid}"
|
"systemd-run\n--scope\n--unit={name}\n--uid={uid}\n--gid={gid}"
|
||||||
"\n-p\nCPUQuota={cpu}%\n-p\nMemoryHigh={memory}\n{application}"}},
|
"\n-p\nCPUQuota={cpu}%\n-p\nMemoryHigh={memory}\n{application}"}},
|
||||||
{"Plugins", {QueuedSettings::Plugins, ""}},
|
|
||||||
{"ServerAddress", {QueuedSettings::ServerAddress, ""}},
|
{"ServerAddress", {QueuedSettings::ServerAddress, ""}},
|
||||||
{"ServerMaxConnections", {QueuedSettings::ServerMaxConnections, 30}},
|
{"ServerMaxConnections", {QueuedSettings::ServerMaxConnections, 30}},
|
||||||
{"ServerPort", {QueuedSettings::ServerPort, 8080}},
|
{"ServerPort", {QueuedSettings::ServerPort, 8080}},
|
||||||
{"ServerTimeout", {QueuedSettings::ServerTimeout, -1}},
|
{"ServerTimeout", {QueuedSettings::ServerTimeout, -1}},
|
||||||
|
{"TokenExpiration", {QueuedSettings::TokenExpiration, 30}},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,9 +98,12 @@ public:
|
|||||||
* @brief generates SHA512 hash from given password
|
* @brief generates SHA512 hash from given password
|
||||||
* @param _password
|
* @param _password
|
||||||
* password as string
|
* password as string
|
||||||
|
* @param _salt
|
||||||
|
* password salt if any
|
||||||
* @return SHA512 of password
|
* @return SHA512 of password
|
||||||
*/
|
*/
|
||||||
static QString hashFromPassword(const QString &_password);
|
static QString hashFromPassword(const QString &_password,
|
||||||
|
const QString &_salt);
|
||||||
/**
|
/**
|
||||||
* @brief test user permissions
|
* @brief test user permissions
|
||||||
* @param _permission
|
* @param _permission
|
||||||
@ -117,9 +120,11 @@ public:
|
|||||||
* @brief check if password is valid
|
* @brief check if password is valid
|
||||||
* @param _password
|
* @param _password
|
||||||
* password as string
|
* password as string
|
||||||
|
* @param _salt
|
||||||
|
* password salt if any
|
||||||
* @return true if password matches stored hash
|
* @return true if password matches stored hash
|
||||||
*/
|
*/
|
||||||
bool isPasswordValid(const QString &_password) const;
|
bool isPasswordValid(const QString &_password, const QString &_salt) const;
|
||||||
/**
|
/**
|
||||||
* @brief remove permissions from user
|
* @brief remove permissions from user
|
||||||
* @param _permission
|
* @param _permission
|
||||||
|
@ -39,6 +39,7 @@ class QueuedTokenManager;
|
|||||||
class QueuedUserManager : public QObject
|
class QueuedUserManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString salt READ salt WRITE setSalt)
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(
|
||||||
long long tokenExpiration READ tokenExpiration WRITE setTokenExpiration)
|
long long tokenExpiration READ tokenExpiration WRITE setTokenExpiration)
|
||||||
|
|
||||||
@ -144,11 +145,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
QueuedUser *user(const QString &_name, const bool _isToken);
|
QueuedUser *user(const QString &_name, const bool _isToken);
|
||||||
// properties
|
// properties
|
||||||
|
/**
|
||||||
|
* @brief password salt if any
|
||||||
|
* @return password salt if any or empty string
|
||||||
|
*/
|
||||||
|
QString salt() const;
|
||||||
/**
|
/**
|
||||||
* @brief token expiration
|
* @brief token expiration
|
||||||
* @return token expiration in days
|
* @return token expiration in days
|
||||||
*/
|
*/
|
||||||
long long tokenExpiration() const;
|
long long tokenExpiration() const;
|
||||||
|
/**
|
||||||
|
* @brief set password salt
|
||||||
|
* @param _salt
|
||||||
|
* new password salt
|
||||||
|
*/
|
||||||
|
void setSalt(const QString &_salt);
|
||||||
/**
|
/**
|
||||||
* @brief set token expiration
|
* @brief set token expiration
|
||||||
* @param _expiry
|
* @param _expiry
|
||||||
@ -167,6 +179,10 @@ signals:
|
|||||||
void userLoggedIn(const long long _id, const QDateTime &_time);
|
void userLoggedIn(const long long _id, const QDateTime &_time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief password salt
|
||||||
|
*/
|
||||||
|
QString m_salt;
|
||||||
/**
|
/**
|
||||||
* @brief token expiration in days
|
* @brief token expiration in days
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,7 @@ file (GLOB_RECURSE SUBPROJECT_HEADERS "*.h" "${PROJECT_LIBRARY_DIR}/*h")
|
|||||||
include_directories ("${PROJECT_LIBRARY_DIR}/include"
|
include_directories ("${PROJECT_LIBRARY_DIR}/include"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
"${CMAKE_BINARY_DIR}"
|
"${CMAKE_BINARY_DIR}"
|
||||||
|
"${PROJECT_TRDPARTY_DIR}"
|
||||||
"${Qt_INCLUDE}")
|
"${Qt_INCLUDE}")
|
||||||
|
|
||||||
qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}")
|
qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}")
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedAdvancedSettings.cpp
|
* @file QueuedAdvancedSettings.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedControlGroupsAdaptor.cpp
|
* @file QueuedControlGroupsAdaptor.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedCore.cpp
|
* @file QueuedCore.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -25,8 +25,11 @@
|
|||||||
|
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
#include "../../3rdparty/result/result.hpp"
|
||||||
#include <queued/QueuedDatabaseSchema.h>
|
#include <queued/QueuedDatabaseSchema.h>
|
||||||
|
#include <queued/QueuedStaticConfig.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,14 +59,16 @@ QueuedCore::~QueuedCore()
|
|||||||
/**
|
/**
|
||||||
* @fn addPlugin
|
* @fn addPlugin
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::addPlugin(const QString &_plugin, const QString &_token)
|
QueuedResult<bool> QueuedCore::addPlugin(const QString &_plugin,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add plugin";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add plugin";
|
||||||
return false;
|
return QueuedError("Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return editPluginPrivate(_plugin, true);
|
return editPluginPrivate(_plugin, true);
|
||||||
@ -73,7 +78,7 @@ bool QueuedCore::addPlugin(const QString &_plugin, const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @addTask
|
* @addTask
|
||||||
*/
|
*/
|
||||||
long long
|
QueuedResult<long long>
|
||||||
QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
||||||
const QString &_workingDirectory, const long long _userId,
|
const QString &_workingDirectory, const long long _userId,
|
||||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
const QueuedLimits::Limits &_limits, const QString &_token)
|
||||||
@ -84,7 +89,8 @@ QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return false;
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
long long actualUserId = (_userId == -1) ? userAuthId : _userId;
|
long long actualUserId = (_userId == -1) ? userAuthId : _userId;
|
||||||
@ -96,13 +102,17 @@ QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
|||||||
// it means that user places task as own one
|
// it means that user places task as own one
|
||||||
if (!isUser) {
|
if (!isUser) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
||||||
return -1;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// user tries to place task as another one
|
// user tries to place task as another one
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
||||||
return -1;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,10 +124,10 @@ QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
|||||||
/**
|
/**
|
||||||
* @fn addUser
|
* @fn addUser
|
||||||
*/
|
*/
|
||||||
long long QueuedCore::addUser(const QString &_name, const QString &_email,
|
QueuedResult<long long>
|
||||||
const QString &_password, const uint _permissions,
|
QueuedCore::addUser(const QString &_name, const QString &_email,
|
||||||
const QueuedLimits::Limits &_limits,
|
const QString &_password, const uint _permissions,
|
||||||
const QString &_token)
|
const QueuedLimits::Limits &_limits, const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
||||||
<< "and permissions" << _permissions;
|
<< "and permissions" << _permissions;
|
||||||
@ -126,14 +136,16 @@ long long QueuedCore::addUser(const QString &_name, const QString &_email,
|
|||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add user";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add user";
|
||||||
return -1;
|
return QueuedError("Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if already exists
|
// check if already exists
|
||||||
auto userObj = user(_name);
|
auto userObj = user(_name);
|
||||||
if (userObj) {
|
if (userObj) {
|
||||||
qCWarning(LOG_LIB) << "User" << _name << "already exists";
|
qCWarning(LOG_LIB) << "User" << _name << "already exists";
|
||||||
return -1;
|
return QueuedError("User already exists",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
return addUserPrivate(_name, _email, _password, _permissions, _limits);
|
return addUserPrivate(_name, _email, _password, _permissions, _limits);
|
||||||
@ -143,7 +155,7 @@ long long QueuedCore::addUser(const QString &_name, const QString &_email,
|
|||||||
/**
|
/**
|
||||||
* @fn authorization
|
* @fn authorization
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::authorization(const QString &_token)
|
QueuedResult<bool> QueuedCore::authorization(const QString &_token)
|
||||||
{
|
{
|
||||||
bool status = false;
|
bool status = false;
|
||||||
m_users->checkToken(_token, &status);
|
m_users->checkToken(_token, &status);
|
||||||
@ -155,30 +167,33 @@ bool QueuedCore::authorization(const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn authorization
|
* @fn authorization
|
||||||
*/
|
*/
|
||||||
QString QueuedCore::authorization(const QString &_name,
|
QueuedResult<QString> QueuedCore::authorization(const QString &_name,
|
||||||
const QString &_password)
|
const QString &_password)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Authorize user" << _name;
|
qCDebug(LOG_LIB) << "Authorize user" << _name;
|
||||||
|
|
||||||
QString token = m_users->authorize(_name, _password);
|
QString token = m_users->authorize(_name, _password);
|
||||||
if (!token.isEmpty()) {
|
if (token.isEmpty()) {
|
||||||
|
return QueuedError("Invalid username or password",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidPassword);
|
||||||
|
} else {
|
||||||
QVariantHash payload
|
QVariantHash payload
|
||||||
= {{"token", token},
|
= {{"token", token},
|
||||||
{"user", _name},
|
{"user", _name},
|
||||||
{"validUntil",
|
{"validUntil",
|
||||||
m_users->checkToken(token).toString(Qt::ISODateWithMs)}};
|
m_users->checkToken(token).toString(Qt::ISODateWithMs)}};
|
||||||
m_database->add(QueuedDB::TOKENS_TABLE, payload);
|
m_database->add(QueuedDB::TOKENS_TABLE, payload);
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn editOption
|
* @fn editOption
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editOption(const QString &_key, const QVariant &_value,
|
QueuedResult<bool> QueuedCore::editOption(const QString &_key,
|
||||||
const QString &_token)
|
const QVariant &_value,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
||||||
|
|
||||||
@ -186,7 +201,8 @@ bool QueuedCore::editOption(const QString &_key, const QVariant &_value,
|
|||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit options";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit options";
|
||||||
return false;
|
return QueuedError("Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return editOptionPrivate(_key, _value);
|
return editOptionPrivate(_key, _value);
|
||||||
@ -196,22 +212,25 @@ bool QueuedCore::editOption(const QString &_key, const QVariant &_value,
|
|||||||
/**
|
/**
|
||||||
* @fn editTask
|
* @fn editTask
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
QueuedResult<bool> QueuedCore::editTask(const long long _id,
|
||||||
const QString &_token)
|
const QVariantHash &_taskData,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
||||||
|
|
||||||
auto task = m_processes->process(_id);
|
auto task = m_processes->process(_id);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
||||||
return false;
|
return QueuedError("Task does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return false;
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
@ -220,13 +239,17 @@ bool QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
|||||||
// it means that user edits own task
|
// it means that user edits own task
|
||||||
if (!isUser) {
|
if (!isUser) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// user tries to edit random task
|
// user tries to edit random task
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// only admin can edit run/stopped task
|
// only admin can edit run/stopped task
|
||||||
@ -234,7 +257,9 @@ bool QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
|||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB)
|
qCInfo(LOG_LIB)
|
||||||
<< "User" << _token << "not allowed to edit run/exited task";
|
<< "User" << _token << "not allowed to edit run/exited task";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,29 +275,34 @@ bool QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
|||||||
/**
|
/**
|
||||||
* @fn editUser
|
* @fn editUser
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editUser(const long long _id, const QVariantHash &_userData,
|
QueuedResult<bool> QueuedCore::editUser(const long long _id,
|
||||||
const QString &_token)
|
const QVariantHash &_userData,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
||||||
|
|
||||||
auto userObj = user(_id);
|
auto userObj = user(_id);
|
||||||
if (!userObj) {
|
if (!userObj) {
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
||||||
return false;
|
return QueuedError("User does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return false;
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (userAuthId != _id) {
|
if (userAuthId != _id) {
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit user";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit user";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,37 +318,42 @@ bool QueuedCore::editUser(const long long _id, const QVariantHash &_userData,
|
|||||||
/**
|
/**
|
||||||
* @fn editUserPermission
|
* @fn editUserPermission
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editUserPermission(const long long _id,
|
QueuedResult<bool>
|
||||||
const QueuedEnums::Permission &_permission,
|
QueuedCore::editUserPermission(const long long _id,
|
||||||
const bool _add, const QString &_token)
|
const QueuedEnums::Permission &_permission,
|
||||||
|
const bool _add, const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission)
|
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission)
|
||||||
<< "for user" << _id << "add" << _add;
|
<< "for user" << _id << "add" << _add;
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
|
||||||
if (!authUser) {
|
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
long long userAuthId = authUser->index();
|
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (userAuthId != _id) {
|
if (!isAdmin) {
|
||||||
if (!isAdmin) {
|
qCInfo(LOG_LIB) << "User" << _token
|
||||||
qCInfo(LOG_LIB)
|
<< "not allowed to edit permissions";
|
||||||
<< "User" << _token << "not allowed to edit permissions";
|
return QueuedError("Not allowed",
|
||||||
return false;
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return editUserPermissionPrivate(_id, _permission, _add);
|
return editUserPermissionPrivate(_id, _permission, _add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn hashFromPassword
|
||||||
|
*/
|
||||||
|
QueuedResult<QString> QueuedCore::hashFromPassword(const QString &_password)
|
||||||
|
{
|
||||||
|
return _password.isEmpty() ? ""
|
||||||
|
: QueuedUser::hashFromPassword(
|
||||||
|
_password, m_settings->admin().salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn option
|
* @fn option
|
||||||
*/
|
*/
|
||||||
QVariant QueuedCore::option(const QString &_key)
|
QueuedResult<QVariant> QueuedCore::option(const QString &_key)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Look for option" << _key;
|
qCDebug(LOG_LIB) << "Look for option" << _key;
|
||||||
|
|
||||||
@ -329,9 +364,9 @@ QVariant QueuedCore::option(const QString &_key)
|
|||||||
/**
|
/**
|
||||||
* @fn performanceReport
|
* @fn performanceReport
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> QueuedCore::performanceReport(const QDateTime &_from,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QDateTime &_to,
|
QueuedCore::performanceReport(const QDateTime &_from, const QDateTime &_to,
|
||||||
const QString &_token) const
|
const QString &_token) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get performance report for" << _from << _to;
|
qCDebug(LOG_LIB) << "Get performance report for" << _from << _to;
|
||||||
|
|
||||||
@ -339,7 +374,8 @@ QList<QVariantHash> QueuedCore::performanceReport(const QDateTime &_from,
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QList<QVariantHash>();
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
||||||
@ -382,14 +418,16 @@ QVariantHash QueuedCore::pluginSettings(const QString &_plugin)
|
|||||||
/**
|
/**
|
||||||
* @fn removePlugin
|
* @fn removePlugin
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::removePlugin(const QString &_plugin, const QString &_token)
|
QueuedResult<bool> QueuedCore::removePlugin(const QString &_plugin,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to remove plugin";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to remove plugin";
|
||||||
return false;
|
return QueuedError("Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return editPluginPrivate(_plugin, false);
|
return editPluginPrivate(_plugin, false);
|
||||||
@ -399,7 +437,8 @@ bool QueuedCore::removePlugin(const QString &_plugin, const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn startTask
|
* @fn startTask
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::startTask(const long long _id, const QString &_token)
|
QueuedResult<bool> QueuedCore::startTask(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
||||||
|
|
||||||
@ -407,14 +446,17 @@ bool QueuedCore::startTask(const long long _id, const QString &_token)
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return false;
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (userAuthId != _id) {
|
if (userAuthId != _id) {
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to start tasks";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to start tasks";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,21 +469,24 @@ bool QueuedCore::startTask(const long long _id, const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn stopTask
|
* @fn stopTask
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::stopTask(const long long _id, const QString &_token)
|
QueuedResult<bool> QueuedCore::stopTask(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
||||||
|
|
||||||
auto task = m_processes->process(_id);
|
auto task = m_processes->process(_id);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
||||||
return false;
|
return QueuedError("Task does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return false;
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
@ -450,13 +495,17 @@ bool QueuedCore::stopTask(const long long _id, const QString &_token)
|
|||||||
// it means that user edits own task
|
// it means that user edits own task
|
||||||
if (!isUser) {
|
if (!isUser) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// user tries to edit random task
|
// user tries to edit random task
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
||||||
return false;
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,10 +529,9 @@ const QueuedProcess *QueuedCore::task(const long long _id) const
|
|||||||
/**
|
/**
|
||||||
* @fn taskReport
|
* @fn taskReport
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> QueuedCore::taskReport(const long long _user,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QDateTime &_from,
|
QueuedCore::taskReport(const long long _user, const QDateTime &_from,
|
||||||
const QDateTime &_to,
|
const QDateTime &_to, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get tasks table by" << _user << _from << _to;
|
qCDebug(LOG_LIB) << "Get tasks table by" << _user << _from << _to;
|
||||||
|
|
||||||
@ -491,7 +539,8 @@ QList<QVariantHash> QueuedCore::taskReport(const long long _user,
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QList<QVariantHash>();
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
||||||
@ -502,7 +551,9 @@ QList<QVariantHash> QueuedCore::taskReport(const long long _user,
|
|||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB)
|
qCInfo(LOG_LIB)
|
||||||
<< "User" << _token << "not allowed to get task report";
|
<< "User" << _token << "not allowed to get task report";
|
||||||
return QList<QVariantHash>();
|
return QueuedError(
|
||||||
|
"Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +586,7 @@ const QueuedUser *QueuedCore::user(const QString &_name) const
|
|||||||
/**
|
/**
|
||||||
* @fn userReport
|
* @fn userReport
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash>
|
QueuedResult<QList<QVariantHash>>
|
||||||
QueuedCore::userReport(const QDateTime &_lastLogged,
|
QueuedCore::userReport(const QDateTime &_lastLogged,
|
||||||
const QueuedEnums::Permission _permission,
|
const QueuedEnums::Permission _permission,
|
||||||
const QString &_token) const
|
const QString &_token) const
|
||||||
@ -547,7 +598,8 @@ QueuedCore::userReport(const QDateTime &_lastLogged,
|
|||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to get user report";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to get user report";
|
||||||
return QList<QVariantHash>();
|
return QueuedError("Not allowed",
|
||||||
|
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_reports->users(_lastLogged, _permission);
|
return m_reports->users(_lastLogged, _permission);
|
||||||
@ -617,7 +669,7 @@ void QueuedCore::updateSettings(const QueuedConfig::QueuedSettings _id,
|
|||||||
qCDebug(LOG_LIB) << "Received update for" << static_cast<int>(_id) << _key
|
qCDebug(LOG_LIB) << "Received update for" << static_cast<int>(_id) << _key
|
||||||
<< "with value" << _value;
|
<< "with value" << _value;
|
||||||
|
|
||||||
// FIXME propbably there is a better way to change settings
|
// FIXME probably there is a better way to change settings
|
||||||
switch (_id) {
|
switch (_id) {
|
||||||
case QueuedConfig::QueuedSettings::Invalid:
|
case QueuedConfig::QueuedSettings::Invalid:
|
||||||
// check if it is plugin settings
|
// check if it is plugin settings
|
||||||
@ -827,7 +879,7 @@ void QueuedCore::initSettings(const QString &_configuration)
|
|||||||
m_settings->readConfiguration();
|
m_settings->readConfiguration();
|
||||||
// init database now
|
// init database now
|
||||||
auto dbSetup = m_settings->db();
|
auto dbSetup = m_settings->db();
|
||||||
m_database = initObject(m_database, dbSetup.path, dbSetup.driver);
|
m_database = initObject(m_database, dbSetup.path, dbSetup.driver);
|
||||||
m_database->close();
|
m_database->close();
|
||||||
bool status = m_database->open(dbSetup.hostname, dbSetup.port,
|
bool status = m_database->open(dbSetup.hostname, dbSetup.port,
|
||||||
dbSetup.username, dbSetup.password);
|
dbSetup.username, dbSetup.password);
|
||||||
@ -870,6 +922,7 @@ void QueuedCore::initUsers()
|
|||||||
.toLongLong();
|
.toLongLong();
|
||||||
|
|
||||||
m_users = initObject(m_users);
|
m_users = initObject(m_users);
|
||||||
|
m_users->setSalt(m_settings->admin().salt);
|
||||||
m_users->setTokenExpiration(expiry);
|
m_users->setTokenExpiration(expiry);
|
||||||
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
|
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
|
||||||
auto dbTokens = m_database->get(
|
auto dbTokens = m_database->get(
|
||||||
@ -888,11 +941,10 @@ void QueuedCore::initUsers()
|
|||||||
/**
|
/**
|
||||||
* @addTaskPrivate
|
* @addTaskPrivate
|
||||||
*/
|
*/
|
||||||
long long QueuedCore::addTaskPrivate(const QString &_command,
|
QueuedResult<long long> QueuedCore::addTaskPrivate(
|
||||||
const QStringList &_arguments,
|
const QString &_command, const QStringList &_arguments,
|
||||||
const QString &_workingDirectory,
|
const QString &_workingDirectory, const long long _userId,
|
||||||
const long long _userId,
|
const QueuedLimits::Limits &_limits)
|
||||||
const QueuedLimits::Limits &_limits)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
||||||
<< "from user" << _userId;
|
<< "from user" << _userId;
|
||||||
@ -902,7 +954,8 @@ long long QueuedCore::addTaskPrivate(const QString &_command,
|
|||||||
auto userObj = user(_userId);
|
auto userObj = user(_userId);
|
||||||
if (!userObj) {
|
if (!userObj) {
|
||||||
qCWarning(LOG_LIB) << "Could not find task user" << _userId;
|
qCWarning(LOG_LIB) << "Could not find task user" << _userId;
|
||||||
return false;
|
return QueuedError("Invalid token",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
}
|
}
|
||||||
auto taskLimits = QueuedLimits::minimalLimits(
|
auto taskLimits = QueuedLimits::minimalLimits(
|
||||||
_limits, userObj->nativeLimits(),
|
_limits, userObj->nativeLimits(),
|
||||||
@ -920,7 +973,7 @@ long long QueuedCore::addTaskPrivate(const QString &_command,
|
|||||||
auto id = m_database->add(QueuedDB::TASKS_TABLE, properties);
|
auto id = m_database->add(QueuedDB::TASKS_TABLE, properties);
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
qCWarning(LOG_LIB) << "Could not add task" << _command;
|
qCWarning(LOG_LIB) << "Could not add task" << _command;
|
||||||
return id;
|
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to child object
|
// add to child object
|
||||||
@ -936,11 +989,10 @@ long long QueuedCore::addTaskPrivate(const QString &_command,
|
|||||||
/**
|
/**
|
||||||
* @fn addUserPrivate
|
* @fn addUserPrivate
|
||||||
*/
|
*/
|
||||||
long long QueuedCore::addUserPrivate(const QString &_name,
|
QueuedResult<long long>
|
||||||
const QString &_email,
|
QueuedCore::addUserPrivate(const QString &_name, const QString &_email,
|
||||||
const QString &_password,
|
const QString &_password, const uint _permissions,
|
||||||
const uint _permissions,
|
const QueuedLimits::Limits &_limits)
|
||||||
const QueuedLimits::Limits &_limits)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
||||||
<< "and permissions" << _permissions;
|
<< "and permissions" << _permissions;
|
||||||
@ -953,7 +1005,7 @@ long long QueuedCore::addUserPrivate(const QString &_name,
|
|||||||
auto id = m_database->add(QueuedDB::USERS_TABLE, properties);
|
auto id = m_database->add(QueuedDB::USERS_TABLE, properties);
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
qCWarning(LOG_LIB) << "Could not add user" << _name;
|
qCWarning(LOG_LIB) << "Could not add user" << _name;
|
||||||
return id;
|
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to child object
|
// add to child object
|
||||||
@ -969,7 +1021,8 @@ long long QueuedCore::addUserPrivate(const QString &_name,
|
|||||||
/**
|
/**
|
||||||
* @fn editOptionPrivate
|
* @fn editOptionPrivate
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editOptionPrivate(const QString &_key, const QVariant &_value)
|
QueuedResult<bool> QueuedCore::editOptionPrivate(const QString &_key,
|
||||||
|
const QVariant &_value)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
||||||
|
|
||||||
@ -1009,7 +1062,8 @@ bool QueuedCore::editOptionPrivate(const QString &_key, const QVariant &_value)
|
|||||||
/**
|
/**
|
||||||
* @fn editPluginPrivate
|
* @fn editPluginPrivate
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add)
|
QueuedResult<bool> QueuedCore::editPluginPrivate(const QString &_plugin,
|
||||||
|
const bool _add)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit plugin" << _plugin << "add" << _add;
|
qCDebug(LOG_LIB) << "Edit plugin" << _plugin << "add" << _add;
|
||||||
|
|
||||||
@ -1018,19 +1072,25 @@ bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add)
|
|||||||
.toString()
|
.toString()
|
||||||
.split('\n');
|
.split('\n');
|
||||||
|
|
||||||
bool status = false;
|
QueuedResult<bool> r;
|
||||||
if (_add && !pluginList.contains(_plugin)) {
|
if (_add && !pluginList.contains(_plugin)) {
|
||||||
status = m_plugins->loadPlugin(_plugin, pluginSettings(_plugin));
|
if (m_plugins->loadPlugin(_plugin, pluginSettings(_plugin))) {
|
||||||
pluginList.append(_plugin);
|
pluginList.append(_plugin);
|
||||||
|
r = true;
|
||||||
|
}
|
||||||
} else if (!_add && pluginList.contains(_plugin)) {
|
} else if (!_add && pluginList.contains(_plugin)) {
|
||||||
status = m_plugins->unloadPlugin(_plugin);
|
if (m_plugins->unloadPlugin(_plugin)) {
|
||||||
pluginList.removeAll(_plugin);
|
pluginList.removeAll(_plugin);
|
||||||
|
r = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(LOG_LIB) << "Plugin" << _plugin
|
qCDebug(LOG_LIB) << "Plugin" << _plugin
|
||||||
<< "not loaded or already loaded";
|
<< "not loaded or already loaded";
|
||||||
|
r = QueuedError("Plugin is not loaded or already loaded",
|
||||||
|
QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status) {
|
if (r.type() == Result::Content::Value) {
|
||||||
editOptionPrivate(m_advancedSettings->internalId(
|
editOptionPrivate(m_advancedSettings->internalId(
|
||||||
QueuedConfig::QueuedSettings::Plugins),
|
QueuedConfig::QueuedSettings::Plugins),
|
||||||
pluginList.join('\n'));
|
pluginList.join('\n'));
|
||||||
@ -1043,22 +1103,23 @@ bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn editTaskPrivate
|
* @fn editTaskPrivate
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editTaskPrivate(const long long _id,
|
QueuedResult<bool> QueuedCore::editTaskPrivate(const long long _id,
|
||||||
const QVariantHash &_taskData)
|
const QVariantHash &_taskData)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
||||||
|
|
||||||
auto task = m_processes->process(_id);
|
auto task = m_processes->process(_id);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
||||||
return false;
|
return QueuedError("Task does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// modify record in database first
|
// modify record in database first
|
||||||
@ -1066,7 +1127,7 @@ bool QueuedCore::editTaskPrivate(const long long _id,
|
|||||||
if (!status) {
|
if (!status) {
|
||||||
qCWarning(LOG_LIB) << "Could not modify task record" << _id
|
qCWarning(LOG_LIB) << "Could not modify task record" << _id
|
||||||
<< "in database, do not edit it in memory";
|
<< "in database, do not edit it in memory";
|
||||||
return false;
|
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// modify values stored in memory
|
// modify values stored in memory
|
||||||
@ -1083,15 +1144,16 @@ bool QueuedCore::editTaskPrivate(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn editUserPrivate
|
* @fn editUserPrivate
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editUserPrivate(const long long _id,
|
QueuedResult<bool> QueuedCore::editUserPrivate(const long long _id,
|
||||||
const QVariantHash &_userData)
|
const QVariantHash &_userData)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
||||||
|
|
||||||
auto userObj = m_users->user(_id);
|
auto userObj = m_users->user(_id);
|
||||||
if (!userObj) {
|
if (!userObj) {
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
||||||
return false;
|
return QueuedError("User does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
};
|
};
|
||||||
|
|
||||||
// modify record in database first
|
// modify record in database first
|
||||||
@ -1099,7 +1161,7 @@ bool QueuedCore::editUserPrivate(const long long _id,
|
|||||||
if (!status) {
|
if (!status) {
|
||||||
qCWarning(LOG_LIB) << "Could not modify user record" << _id
|
qCWarning(LOG_LIB) << "Could not modify user record" << _id
|
||||||
<< "in database, do not edit it in memory";
|
<< "in database, do not edit it in memory";
|
||||||
return false;
|
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// modify values stored in memory
|
// modify values stored in memory
|
||||||
@ -1116,7 +1178,7 @@ bool QueuedCore::editUserPrivate(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn editUserPermissionPrivate
|
* @fn editUserPermissionPrivate
|
||||||
*/
|
*/
|
||||||
bool QueuedCore::editUserPermissionPrivate(
|
QueuedResult<bool> QueuedCore::editUserPermissionPrivate(
|
||||||
const long long _id, const QueuedEnums::Permission &_permission,
|
const long long _id, const QueuedEnums::Permission &_permission,
|
||||||
const bool _add)
|
const bool _add)
|
||||||
{
|
{
|
||||||
@ -1126,14 +1188,15 @@ bool QueuedCore::editUserPermissionPrivate(
|
|||||||
auto userObj = m_users->user(_id);
|
auto userObj = m_users->user(_id);
|
||||||
if (!userObj) {
|
if (!userObj) {
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
||||||
return false;
|
return QueuedError("User does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit runtime permissions to get value
|
// edit runtime permissions to get value
|
||||||
auto perms = _add ? userObj->addPermission(_permission)
|
auto perms = _add ? userObj->addPermission(_permission)
|
||||||
: userObj->removePermission(_permission);
|
: userObj->removePermission(_permission);
|
||||||
auto permissions = static_cast<uint>(perms);
|
auto permissions = static_cast<uint>(perms);
|
||||||
qCInfo(LOG_LIB) << "New user permissions" << perms << permissions;
|
qCInfo(LOG_LIB) << "New user permissions" << perms;
|
||||||
|
|
||||||
// modify in database now
|
// modify in database now
|
||||||
QVariantHash payload = {{"permissions", permissions}};
|
QVariantHash payload = {{"permissions", permissions}};
|
||||||
@ -1146,7 +1209,7 @@ bool QueuedCore::editUserPermissionPrivate(
|
|||||||
userObj->removePermission(_permission);
|
userObj->removePermission(_permission);
|
||||||
else
|
else
|
||||||
userObj->addPermission(_permission);
|
userObj->addPermission(_permission);
|
||||||
return false;
|
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -16,104 +16,105 @@
|
|||||||
* @file QueuedCoreAdaptor.cpp
|
* @file QueuedCoreAdaptor.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
#include <QDBusConnection>
|
|
||||||
#include <QDBusMessage>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn auth
|
* @fn auth
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::auth(const QString &_token)
|
QueuedResult<bool> QueuedCoreAdaptor::auth(const QString &_token)
|
||||||
{
|
{
|
||||||
QVariantList args = {_token};
|
QVariantList args = {_token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "TryAuth", args)
|
QueuedConfig::DBUS_SERVICE, "TryAuth", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn auth
|
* @fn auth
|
||||||
*/
|
*/
|
||||||
QString QueuedCoreAdaptor::auth(const QString &_name, const QString &_password)
|
QueuedResult<QString> QueuedCoreAdaptor::auth(const QString &_name,
|
||||||
|
const QString &_password)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Auth user" << _name;
|
qCDebug(LOG_DBUS) << "Auth user" << _name;
|
||||||
|
|
||||||
QVariantList args = {_name, _password};
|
QVariantList args = {_name, _password};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QString>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Auth", args)
|
QueuedConfig::DBUS_SERVICE, "Auth", args);
|
||||||
.first()
|
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendOptionEdit
|
* @fn sendOptionEdit
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendOptionEdit(const QString &_key,
|
QueuedResult<bool> QueuedCoreAdaptor::sendOptionEdit(const QString &_key,
|
||||||
const QVariant &_value,
|
const QVariant &_value,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit option" << _key << "to" << _value;
|
qCDebug(LOG_DBUS) << "Edit option" << _key << "to" << _value;
|
||||||
|
|
||||||
QVariantList args
|
QVariantList args
|
||||||
= {_key, QVariant::fromValue(QDBusVariant(_value)), _token};
|
= {_key, QVariant::fromValue(QDBusVariant(_value)), _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "OptionEdit", args)
|
QueuedConfig::DBUS_SERVICE, "OptionEdit", args);
|
||||||
.first()
|
}
|
||||||
.toBool();
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn sendPasswordHash
|
||||||
|
*/
|
||||||
|
QueuedResult<QString>
|
||||||
|
QueuedCoreAdaptor::sendPasswordHash(const QString &_password)
|
||||||
|
{
|
||||||
|
QVariantList args = {_password};
|
||||||
|
return sendRequest<QString>(QueuedConfig::DBUS_SERVICE,
|
||||||
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
|
QueuedConfig::DBUS_SERVICE, "Auth", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendPluginAdd
|
* @fn sendPluginAdd
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendPluginAdd(const QString &_plugin,
|
QueuedResult<bool> QueuedCoreAdaptor::sendPluginAdd(const QString &_plugin,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add plugin" << _plugin;
|
qCDebug(LOG_DBUS) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
QVariantList args = {_plugin, _token};
|
QVariantList args = {_plugin, _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "PluginAdd", args)
|
QueuedConfig::DBUS_SERVICE, "PluginAdd", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendPluginRemove
|
* @fn sendPluginRemove
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendPluginRemove(const QString &_plugin,
|
QueuedResult<bool> QueuedCoreAdaptor::sendPluginRemove(const QString &_plugin,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Remove plugin" << _plugin;
|
qCDebug(LOG_DBUS) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
QVariantList args = {_plugin, _token};
|
QVariantList args = {_plugin, _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "PluginRemove", args)
|
QueuedConfig::DBUS_SERVICE, "PluginRemove", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendTaskAdd
|
* @fn sendTaskAdd
|
||||||
*/
|
*/
|
||||||
long long QueuedCoreAdaptor::sendTaskAdd(
|
QueuedResult<long long> QueuedCoreAdaptor::sendTaskAdd(
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
@ -130,18 +131,16 @@ long long QueuedCoreAdaptor::sendTaskAdd(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskAdd", args)
|
QueuedConfig::DBUS_SERVICE, "TaskAdd", args);
|
||||||
.first()
|
|
||||||
.toLongLong();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendTaskEdit
|
* @fn sendTaskEdit
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendTaskEdit(
|
QueuedResult<bool> QueuedCoreAdaptor::sendTaskEdit(
|
||||||
const long long _id,
|
const long long _id,
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
@ -163,51 +162,46 @@ bool QueuedCoreAdaptor::sendTaskEdit(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskEdit", args)
|
QueuedConfig::DBUS_SERVICE, "TaskEdit", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendTaskStart
|
* @fn sendTaskStart
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendTaskStart(const long long _id,
|
QueuedResult<bool> QueuedCoreAdaptor::sendTaskStart(const long long _id,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Start task" << _id;
|
qCDebug(LOG_DBUS) << "Start task" << _id;
|
||||||
|
|
||||||
QVariantList args = {_id, _token};
|
QVariantList args = {_id, _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskStart", args)
|
QueuedConfig::DBUS_SERVICE, "TaskStart", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendTaskStop
|
* @fn sendTaskStop
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendTaskStop(const long long _id, const QString &_token)
|
QueuedResult<bool> QueuedCoreAdaptor::sendTaskStop(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Stop task" << _id;
|
qCDebug(LOG_DBUS) << "Stop task" << _id;
|
||||||
|
|
||||||
QVariantList args = {_id, _token};
|
QVariantList args = {_id, _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskStop", args)
|
QueuedConfig::DBUS_SERVICE, "TaskStop", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendUserAdd
|
* @fn sendUserAdd
|
||||||
*/
|
*/
|
||||||
long long QueuedCoreAdaptor::sendUserAdd(
|
QueuedResult<long long> QueuedCoreAdaptor::sendUserAdd(
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
@ -224,18 +218,16 @@ long long QueuedCoreAdaptor::sendUserAdd(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "UserAdd", args)
|
QueuedConfig::DBUS_SERVICE, "UserAdd", args);
|
||||||
.first()
|
|
||||||
.toLongLong();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendUserEdit
|
* @fn sendUserEdit
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendUserEdit(
|
QueuedResult<bool> QueuedCoreAdaptor::sendUserEdit(
|
||||||
const long long _id, const QueuedUser::QueuedUserDefinitions &_definitions,
|
const long long _id, const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
@ -252,18 +244,16 @@ bool QueuedCoreAdaptor::sendUserEdit(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "UserEdit", args)
|
QueuedConfig::DBUS_SERVICE, "UserEdit", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendUserPermissionAdd
|
* @fn sendUserPermissionAdd
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendUserPermissionAdd(
|
QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionAdd(
|
||||||
const long long _id, const QueuedEnums::Permission _permission,
|
const long long _id, const QueuedEnums::Permission _permission,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
@ -271,18 +261,16 @@ bool QueuedCoreAdaptor::sendUserPermissionAdd(
|
|||||||
<< "to" << _id;
|
<< "to" << _id;
|
||||||
|
|
||||||
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "UserPermissionAdd", args)
|
QueuedConfig::DBUS_SERVICE, "UserPermissionAdd", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendUserPermissionRemove
|
* @fn sendUserPermissionRemove
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreAdaptor::sendUserPermissionRemove(
|
QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionRemove(
|
||||||
const long long _id, const QueuedEnums::Permission _permission,
|
const long long _id, const QueuedEnums::Permission _permission,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
@ -290,33 +278,30 @@ bool QueuedCoreAdaptor::sendUserPermissionRemove(
|
|||||||
<< "from" << _id;
|
<< "from" << _id;
|
||||||
|
|
||||||
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "UserPermissionRemove", args)
|
QueuedConfig::DBUS_SERVICE, "UserPermissionRemove", args);
|
||||||
.first()
|
|
||||||
.toBool();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getOption
|
* @fn getOption
|
||||||
*/
|
*/
|
||||||
QVariant QueuedCoreAdaptor::getOption(const QString &_property)
|
QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get option" << _property;
|
qCDebug(LOG_DBUS) << "Get option" << _property;
|
||||||
|
|
||||||
QVariantList args = {_property};
|
QVariantList args = {_property};
|
||||||
return toNativeType(sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Option", args)
|
QueuedConfig::DBUS_SERVICE, "Option", args);
|
||||||
.first());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getOption
|
* @fn getOption
|
||||||
*/
|
*/
|
||||||
QVariant
|
QueuedResult<QVariant>
|
||||||
QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property)
|
QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property);
|
qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property);
|
||||||
@ -328,110 +313,122 @@ QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property)
|
|||||||
/**
|
/**
|
||||||
* @fn getPerformance
|
* @fn getPerformance
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> QueuedCoreAdaptor::getPerformance(const QDateTime &_from,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QDateTime &_to,
|
QueuedCoreAdaptor::getPerformance(const QDateTime &_from, const QDateTime &_to,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get performance report for" << _from << _to;
|
qCDebug(LOG_DBUS) << "Get performance report for" << _from << _to;
|
||||||
|
|
||||||
QVariantList args = {_from.toString(Qt::ISODateWithMs),
|
QVariantList args = {_from.toString(Qt::ISODateWithMs),
|
||||||
_to.toString(Qt::ISODateWithMs), _token};
|
_to.toString(Qt::ISODateWithMs), _token};
|
||||||
return qdbus_cast<QList<QVariantHash>>(toNativeType(
|
return sendRequest<QList<QVariantHash>>(
|
||||||
sendRequest(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Performance", args)
|
QueuedConfig::DBUS_SERVICE, "Performance", args);
|
||||||
.first()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getStatus
|
* @fn getStatus
|
||||||
*/
|
*/
|
||||||
QHash<QString, QHash<QString, QString>> QueuedCoreAdaptor::getStatus()
|
QueuedResult<QueuedStatusMap> QueuedCoreAdaptor::getStatus()
|
||||||
{
|
{
|
||||||
return qdbus_cast<QHash<QString, QHash<QString, QString>>>(toNativeType(
|
return sendRequest<QueuedStatusMap>(
|
||||||
sendRequest(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Status", {})
|
QueuedConfig::DBUS_SERVICE, "Status", {});
|
||||||
.first()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getTask
|
* @fn getTask
|
||||||
*/
|
*/
|
||||||
QVariantHash QueuedCoreAdaptor::getTask(const long long _id)
|
QueuedResult<QVariantHash> QueuedCoreAdaptor::getTask(const long long _id)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get task properties" << _id;
|
qCDebug(LOG_DBUS) << "Get task properties" << _id;
|
||||||
|
|
||||||
return qdbus_cast<QVariantHash>(getTask(_id, ""));
|
auto res = getTask(_id, "");
|
||||||
|
|
||||||
|
QueuedResult<QVariantHash> output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output = toResult<QVariantHash>(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) { output = err; });
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getTask
|
* @fn getTask
|
||||||
*/
|
*/
|
||||||
QVariant QueuedCoreAdaptor::getTask(const long long _id,
|
QueuedResult<QVariant> QueuedCoreAdaptor::getTask(const long long _id,
|
||||||
const QString &_property)
|
const QString &_property)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get task property" << _id << _property;
|
qCDebug(LOG_DBUS) << "Get task property" << _id << _property;
|
||||||
|
|
||||||
QVariantList args = {_id, _property};
|
QVariantList args = {_id, _property};
|
||||||
return toNativeType(sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Task", args)
|
QueuedConfig::DBUS_SERVICE, "Task", args);
|
||||||
.first());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getTasks
|
* @fn getTasks
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> QueuedCoreAdaptor::getTasks(const long long _user,
|
QueuedResult<QList<QVariantHash>>
|
||||||
const QDateTime &_from,
|
QueuedCoreAdaptor::getTasks(const long long _user, const QDateTime &_from,
|
||||||
const QDateTime &_to,
|
const QDateTime &_to, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get tasks list for" << _user << _from << _to;
|
qCDebug(LOG_DBUS) << "Get tasks list for" << _user << _from << _to;
|
||||||
|
|
||||||
QVariantList args = {_user, _from.toString(Qt::ISODateWithMs),
|
QVariantList args = {_user, _from.toString(Qt::ISODateWithMs),
|
||||||
_to.toString(Qt::ISODateWithMs), _token};
|
_to.toString(Qt::ISODateWithMs), _token};
|
||||||
return qdbus_cast<QList<QVariantHash>>(toNativeType(
|
return sendRequest<QList<QVariantHash>>(
|
||||||
sendRequest(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Tasks", args)
|
QueuedConfig::DBUS_SERVICE, "Tasks", args);
|
||||||
.first()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getUser
|
* @fn getUser
|
||||||
*/
|
*/
|
||||||
QVariantHash QueuedCoreAdaptor::getUser(const long long _id)
|
QueuedResult<QVariantHash> QueuedCoreAdaptor::getUser(const long long _id)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get user property" << _id;
|
qCDebug(LOG_DBUS) << "Get user property" << _id;
|
||||||
|
|
||||||
return qdbus_cast<QVariantHash>(getUser(_id, ""));
|
auto res = getUser(_id, "");
|
||||||
|
|
||||||
|
QueuedResult<QVariantHash> output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output = toResult<QVariantHash>(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) { output = err; });
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getUser
|
* @fn getUser
|
||||||
*/
|
*/
|
||||||
QVariant QueuedCoreAdaptor::getUser(const long long _id,
|
QueuedResult<QVariant> QueuedCoreAdaptor::getUser(const long long _id,
|
||||||
const QString &_property)
|
const QString &_property)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get user property" << _id << _property;
|
qCDebug(LOG_DBUS) << "Get user property" << _id << _property;
|
||||||
|
|
||||||
QVariantList args = {_id, _property};
|
QVariantList args = {_id, _property};
|
||||||
return toNativeType(sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "User", args)
|
QueuedConfig::DBUS_SERVICE, "User", args);
|
||||||
.first());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getUserId
|
* @fn getUserId
|
||||||
*/
|
*/
|
||||||
long long QueuedCoreAdaptor::getUserId(const QString &_name)
|
QueuedResult<long long> QueuedCoreAdaptor::getUserId(const QString &_name)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get user ID for" << _name;
|
qCDebug(LOG_DBUS) << "Get user ID for" << _name;
|
||||||
|
|
||||||
@ -441,18 +438,16 @@ long long QueuedCoreAdaptor::getUserId(const QString &_name)
|
|||||||
return stringToLong;
|
return stringToLong;
|
||||||
|
|
||||||
QVariantList args = {_name};
|
QVariantList args = {_name};
|
||||||
return sendRequest(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<long long>(
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "UserIdByName", args)
|
QueuedConfig::DBUS_SERVICE, "UserIdByName", args);
|
||||||
.first()
|
|
||||||
.toLongLong();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getUsers
|
* @fn getUsers
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash>
|
QueuedResult<QList<QVariantHash>>
|
||||||
QueuedCoreAdaptor::getUsers(const QDateTime &_lastLogged,
|
QueuedCoreAdaptor::getUsers(const QDateTime &_lastLogged,
|
||||||
const QueuedEnums::Permission _permission,
|
const QueuedEnums::Permission _permission,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
@ -462,47 +457,7 @@ QueuedCoreAdaptor::getUsers(const QDateTime &_lastLogged,
|
|||||||
|
|
||||||
QVariantList args = {_lastLogged.toString(Qt::ISODateWithMs),
|
QVariantList args = {_lastLogged.toString(Qt::ISODateWithMs),
|
||||||
static_cast<uint>(_permission), _token};
|
static_cast<uint>(_permission), _token};
|
||||||
return qdbus_cast<QList<QVariantHash>>(toNativeType(
|
return sendRequest<QList<QVariantHash>>(
|
||||||
sendRequest(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Users", args)
|
QueuedConfig::DBUS_SERVICE, "Users", args);
|
||||||
.first()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fn sendRequest
|
|
||||||
*/
|
|
||||||
QVariantList QueuedCoreAdaptor::sendRequest(const QString &_service,
|
|
||||||
const QString &_path,
|
|
||||||
const QString &_interface,
|
|
||||||
const QString &_cmd,
|
|
||||||
const QVariantList &_args)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_DBUS) << "Send request to service" << _service << "by interface"
|
|
||||||
<< _interface << "to" << _path << "command" << _cmd
|
|
||||||
<< "with args" << _args;
|
|
||||||
|
|
||||||
QDBusConnection bus = QDBusConnection::systemBus();
|
|
||||||
QDBusMessage request
|
|
||||||
= QDBusMessage::createMethodCall(_service, _path, _interface, _cmd);
|
|
||||||
if (!_args.isEmpty())
|
|
||||||
request.setArguments(_args);
|
|
||||||
|
|
||||||
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
|
|
||||||
QVariantList arguments = response.arguments();
|
|
||||||
|
|
||||||
QString error = response.errorMessage();
|
|
||||||
if (!error.isEmpty())
|
|
||||||
qCWarning(LOG_DBUS) << "Error message" << error;
|
|
||||||
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fn toNativeType
|
|
||||||
*/
|
|
||||||
QVariant QueuedCoreAdaptor::toNativeType(const QVariant &_data)
|
|
||||||
{
|
|
||||||
return _data.value<QDBusVariant>().variant();
|
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,15 @@
|
|||||||
* @file QueuedCoreInterface.cpp
|
* @file QueuedCoreInterface.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
#include <QDBusMetaType>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class QueuedCoreInterface
|
* @class QueuedCoreInterface
|
||||||
@ -35,6 +37,15 @@ QueuedCoreInterface::QueuedCoreInterface(QueuedCore *parent)
|
|||||||
, m_core(parent)
|
, m_core(parent)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
qRegisterMetaType<QueuedResult<bool>>("QueuedResult<bool>");
|
||||||
|
qDBusRegisterMetaType<QueuedResult<bool>>();
|
||||||
|
|
||||||
|
qRegisterMetaType<QueuedResult<long long>>("QueuedResult<long long>");
|
||||||
|
qDBusRegisterMetaType<QueuedResult<long long>>();
|
||||||
|
|
||||||
|
qRegisterMetaType<QueuedResult<QString>>("QueuedResult<QString>");
|
||||||
|
qDBusRegisterMetaType<QueuedResult<QString>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -50,54 +61,68 @@ QueuedCoreInterface::~QueuedCoreInterface()
|
|||||||
/**
|
/**
|
||||||
* @fn Auth
|
* @fn Auth
|
||||||
*/
|
*/
|
||||||
QString QueuedCoreInterface::Auth(const QString &name, const QString &password)
|
QDBusVariant QueuedCoreInterface::Auth(const QString &name,
|
||||||
|
const QString &password)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Authorize user" << name;
|
qCDebug(LOG_DBUS) << "Authorize user" << name;
|
||||||
|
|
||||||
return m_core->authorization(name, password);
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
m_core->authorization(name, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn OptionEdit
|
* @fn OptionEdit
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::OptionEdit(const QString &key,
|
QDBusVariant QueuedCoreInterface::OptionEdit(const QString &key,
|
||||||
const QDBusVariant &value,
|
const QDBusVariant &value,
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant();
|
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant();
|
||||||
|
|
||||||
return m_core->editOption(key, value.variant(), token);
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
m_core->editOption(key, value.variant(), token));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn PasswordHash
|
||||||
|
*/
|
||||||
|
QDBusVariant QueuedCoreInterface::PasswordHash(const QString &password)
|
||||||
|
{
|
||||||
|
return QueuedCoreAdaptor::toDBusVariant(m_core->hashFromPassword(password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn PluginAdd
|
* @fn PluginAdd
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::PluginAdd(const QString &plugin, const QString &token)
|
QDBusVariant QueuedCoreInterface::PluginAdd(const QString &plugin,
|
||||||
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add plugin" << plugin;
|
qCDebug(LOG_DBUS) << "Add plugin" << plugin;
|
||||||
|
|
||||||
return m_core->addPlugin(plugin, token);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->addPlugin(plugin, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn PluginRemove
|
* @fn PluginRemove
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::PluginRemove(const QString &plugin,
|
QDBusVariant QueuedCoreInterface::PluginRemove(const QString &plugin,
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Remove plugin" << plugin;
|
qCDebug(LOG_DBUS) << "Remove plugin" << plugin;
|
||||||
|
|
||||||
return m_core->removePlugin(plugin, token);
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
m_core->removePlugin(plugin, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TaskAdd
|
* @fn TaskAdd
|
||||||
*/
|
*/
|
||||||
qlonglong QueuedCoreInterface::TaskAdd(
|
QDBusVariant QueuedCoreInterface::TaskAdd(
|
||||||
const QString &command, const QStringList &arguments,
|
const QString &command, const QStringList &arguments,
|
||||||
const QString &workingDirectory, const qlonglong user, const qlonglong cpu,
|
const QString &workingDirectory, const qlonglong user, const qlonglong cpu,
|
||||||
const qlonglong gpu, const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong gpu, const qlonglong memory, const qlonglong gpumemory,
|
||||||
@ -106,16 +131,16 @@ qlonglong QueuedCoreInterface::TaskAdd(
|
|||||||
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments
|
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments
|
||||||
<< workingDirectory << "from user" << user;
|
<< workingDirectory << "from user" << user;
|
||||||
|
|
||||||
return m_core->addTask(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->addTask(
|
||||||
command, arguments, workingDirectory, user,
|
command, arguments, workingDirectory, user,
|
||||||
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token);
|
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TaskEdit
|
* @fn TaskEdit
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::TaskEdit(
|
QDBusVariant QueuedCoreInterface::TaskEdit(
|
||||||
const qlonglong id, const QString &command, const QStringList &arguments,
|
const qlonglong id, const QString &command, const QStringList &arguments,
|
||||||
const QString &directory, const uint nice, const uint uid, const uint gid,
|
const QString &directory, const uint nice, const uint uid, const uint gid,
|
||||||
const qlonglong user, const qlonglong cpu, const qlonglong gpu,
|
const qlonglong user, const qlonglong cpu, const qlonglong gpu,
|
||||||
@ -129,7 +154,9 @@ bool QueuedCoreInterface::TaskEdit(
|
|||||||
auto task = m_core->task(id);
|
auto task = m_core->task(id);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
||||||
return false;
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(
|
||||||
|
QueuedError("Task does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// build payload
|
// build payload
|
||||||
@ -162,45 +189,47 @@ bool QueuedCoreInterface::TaskEdit(
|
|||||||
limits.storage = storage;
|
limits.storage = storage;
|
||||||
data["limits"] = limits.toString();
|
data["limits"] = limits.toString();
|
||||||
|
|
||||||
return m_core->editTask(id, data, token);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->editTask(id, data, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TaskStart
|
* @fn TaskStart
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::TaskStart(const qlonglong id, const QString &token)
|
QDBusVariant QueuedCoreInterface::TaskStart(const qlonglong id,
|
||||||
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Force start task" << id;
|
qCDebug(LOG_DBUS) << "Force start task" << id;
|
||||||
|
|
||||||
return m_core->startTask(id, token);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->startTask(id, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TaskStop
|
* @fn TaskStop
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::TaskStop(const qlonglong id, const QString &token)
|
QDBusVariant QueuedCoreInterface::TaskStop(const qlonglong id,
|
||||||
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Force stop task" << id;
|
qCDebug(LOG_DBUS) << "Force stop task" << id;
|
||||||
|
|
||||||
return m_core->stopTask(id, token);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->stopTask(id, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TryAuth
|
* @fn TryAuth
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::TryAuth(const QString &token)
|
QDBusVariant QueuedCoreInterface::TryAuth(const QString &token)
|
||||||
{
|
{
|
||||||
return m_core->authorization(token);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->authorization(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn UserAdd
|
* @fn UserAdd
|
||||||
*/
|
*/
|
||||||
qlonglong
|
QDBusVariant
|
||||||
QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
||||||
const QString &password, const uint permissions,
|
const QString &password, const uint permissions,
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
@ -210,22 +239,21 @@ QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
|||||||
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email
|
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email
|
||||||
<< permissions;
|
<< permissions;
|
||||||
|
|
||||||
return m_core->addUser(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->addUser(
|
||||||
name, email, password, permissions,
|
name, email, password, permissions,
|
||||||
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token);
|
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn UserEdit
|
* @fn UserEdit
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
QDBusVariant
|
||||||
const QString &password,
|
QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||||
const QString &email, const qlonglong cpu,
|
const QString &password, const QString &email,
|
||||||
const qlonglong gpu, const qlonglong memory,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong gpumemory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong storage,
|
const qlonglong storage, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit user" << id << name << email << cpu << gpu
|
qCDebug(LOG_DBUS) << "Edit user" << id << name << email << cpu << gpu
|
||||||
<< memory << gpumemory << storage;
|
<< memory << gpumemory << storage;
|
||||||
@ -234,7 +262,9 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
|||||||
auto user = m_core->user(id);
|
auto user = m_core->user(id);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
||||||
return false;
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(
|
||||||
|
QueuedError("User does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// build payload
|
// build payload
|
||||||
@ -259,33 +289,33 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
|||||||
limits.storage = storage;
|
limits.storage = storage;
|
||||||
data["limits"] = limits.toString();
|
data["limits"] = limits.toString();
|
||||||
|
|
||||||
return m_core->editUser(id, data, token);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->editUser(id, data, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn UserPermissionAdd
|
* @fn UserPermissionAdd
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
QDBusVariant QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
||||||
const uint permission,
|
const uint permission,
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id;
|
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id;
|
||||||
|
|
||||||
return m_core->editUserPermission(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->editUserPermission(
|
||||||
id, static_cast<QueuedEnums::Permission>(permission), true, token);
|
id, static_cast<QueuedEnums::Permission>(permission), true, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn UserPermissionRemove
|
* @fn UserPermissionRemove
|
||||||
*/
|
*/
|
||||||
bool QueuedCoreInterface::UserPermissionRemove(const qlonglong id,
|
QDBusVariant QueuedCoreInterface::UserPermissionRemove(const qlonglong id,
|
||||||
const uint permission,
|
const uint permission,
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id;
|
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id;
|
||||||
|
|
||||||
return m_core->editUserPermission(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->editUserPermission(
|
||||||
id, static_cast<QueuedEnums::Permission>(permission), false, token);
|
id, static_cast<QueuedEnums::Permission>(permission), false, token));
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedDatabase.cpp
|
* @file QueuedDatabase.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedDatabaseManager.cpp
|
* @file QueuedDatabaseManager.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedDebug.cpp
|
* @file QueuedDebug.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedLimits.cpp
|
* @file QueuedLimits.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedPluginManager.cpp
|
* @file QueuedPluginManager.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedProcess.cpp
|
* @file QueuedProcess.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedProcessManager.cpp
|
* @file QueuedProcessManager.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,13 +16,14 @@
|
|||||||
* @file QueuedPropertyInterface.cpp
|
* @file QueuedPropertyInterface.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
#include <QDBusMetaType>
|
||||||
#include <QMetaProperty>
|
#include <QMetaProperty>
|
||||||
|
|
||||||
|
|
||||||
@ -37,6 +38,9 @@ QueuedPropertyInterface::QueuedPropertyInterface(QueuedCore *parent)
|
|||||||
, m_core(parent)
|
, m_core(parent)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
qRegisterMetaType<QueuedResult<QVariant>>("QueuedResult<QVariant>");
|
||||||
|
qDBusRegisterMetaType<QueuedResult<QVariant>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -56,8 +60,7 @@ QDBusVariant QueuedPropertyInterface::Option(const QString &property)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get property" << property;
|
qCDebug(LOG_DBUS) << "Get property" << property;
|
||||||
|
|
||||||
auto response = m_core->option(property);
|
return QueuedCoreAdaptor::toDBusVariant(m_core->option(property));
|
||||||
return QDBusVariant(response.isValid() ? response : "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,17 +75,21 @@ QDBusVariant QueuedPropertyInterface::Task(const long long id,
|
|||||||
auto task = m_core->task(id);
|
auto task = m_core->task(id);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
||||||
return QDBusVariant("");
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(
|
||||||
|
QueuedError("Task does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.isEmpty()) {
|
if (property.isEmpty()) {
|
||||||
auto response = QVariant::fromValue<QVariantHash>(getProperties(task));
|
auto response = QVariant::fromValue<QVariantHash>(getProperties(task));
|
||||||
return QDBusVariant(response);
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
QueuedResult<QVariant>(response));
|
||||||
} else {
|
} else {
|
||||||
auto response = task->property(qPrintable(property));
|
auto response = task->property(qPrintable(property));
|
||||||
if (response.type() == QVariant::DateTime)
|
if (response.type() == QVariant::DateTime)
|
||||||
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
||||||
return QDBusVariant(response.isValid() ? response : "");
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
QueuedResult<QVariant>(response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,17 +105,21 @@ QDBusVariant QueuedPropertyInterface::User(const long long id,
|
|||||||
auto user = m_core->user(id);
|
auto user = m_core->user(id);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
||||||
return QDBusVariant("");
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(
|
||||||
|
QueuedError("User does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.isEmpty()) {
|
if (property.isEmpty()) {
|
||||||
auto response = QVariant::fromValue<QVariantHash>(getProperties(user));
|
auto response = QVariant::fromValue<QVariantHash>(getProperties(user));
|
||||||
return QDBusVariant(response);
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
QueuedResult<QVariant>(response));
|
||||||
} else {
|
} else {
|
||||||
auto response = user->property(qPrintable(property));
|
auto response = user->property(qPrintable(property));
|
||||||
if (response.type() == QVariant::DateTime)
|
if (response.type() == QVariant::DateTime)
|
||||||
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
||||||
return QDBusVariant(response.isValid() ? response : "");
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
QueuedResult<QVariant>(response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,17 +127,20 @@ QDBusVariant QueuedPropertyInterface::User(const long long id,
|
|||||||
/**
|
/**
|
||||||
* @fn UserIdByName
|
* @fn UserIdByName
|
||||||
*/
|
*/
|
||||||
qlonglong QueuedPropertyInterface::UserIdByName(const QString &name)
|
QDBusVariant QueuedPropertyInterface::UserIdByName(const QString &name)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Look for user ID" << name;
|
qCDebug(LOG_DBUS) << "Look for user ID" << name;
|
||||||
|
|
||||||
auto user = m_core->user(name);
|
auto user = m_core->user(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find user" << name;
|
qCWarning(LOG_DBUS) << "Could not find user" << name;
|
||||||
return -1;
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<long long>(
|
||||||
|
QueuedError("User does not exist",
|
||||||
|
QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return user->index();
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
|
QueuedResult<long long>(user->index()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedReportInterface.cpp
|
* @file QueuedReportInterface.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -38,16 +38,16 @@ QueuedReportInterface::QueuedReportInterface(QueuedCore *parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
// QList<QVariantHash>
|
|
||||||
qRegisterMetaType<QList<QVariantHash>>("QList<QVariantHash>");
|
|
||||||
qDBusRegisterMetaType<QList<QVariantHash>>();
|
|
||||||
// QHash<QString, QString>
|
|
||||||
qRegisterMetaType<QHash<QString, QString>>("QHash<QString, QString>");
|
qRegisterMetaType<QHash<QString, QString>>("QHash<QString, QString>");
|
||||||
qDBusRegisterMetaType<QHash<QString, QString>>();
|
qDBusRegisterMetaType<QHash<QString, QString>>();
|
||||||
// QHash<QString, QHash<QString, QString>>
|
|
||||||
qRegisterMetaType<QHash<QString, QHash<QString, QString>>>(
|
qRegisterMetaType<QueuedResult<QList<QVariantHash>>>(
|
||||||
"QHash<QString, QHash<QString, QString>>");
|
"QueuedResult<QList<QVariantHash>>");
|
||||||
qDBusRegisterMetaType<QHash<QString, QHash<QString, QString>>>();
|
qDBusRegisterMetaType<QueuedResult<QList<QVariantHash>>>();
|
||||||
|
|
||||||
|
qRegisterMetaType<QueuedResult<QueuedStatusMap>>(
|
||||||
|
"QueuedResult<QueuedStatusMap>");
|
||||||
|
qDBusRegisterMetaType<QueuedResult<QueuedStatusMap>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,10 +69,9 @@ QDBusVariant QueuedReportInterface::Performance(const QString &from,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Performance report for" << from << to;
|
qCDebug(LOG_DBUS) << "Performance report for" << from << to;
|
||||||
|
|
||||||
return QDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->performanceReport(
|
||||||
QVariant::fromValue<QList<QVariantHash>>(m_core->performanceReport(
|
QDateTime::fromString(from, Qt::ISODateWithMs),
|
||||||
QDateTime::fromString(from, Qt::ISODateWithMs),
|
QDateTime::fromString(to, Qt::ISODateWithMs), token));
|
||||||
QDateTime::fromString(to, Qt::ISODateWithMs), token)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,11 +80,11 @@ QDBusVariant QueuedReportInterface::Performance(const QString &from,
|
|||||||
*/
|
*/
|
||||||
QDBusVariant QueuedReportInterface::Status()
|
QDBusVariant QueuedReportInterface::Status()
|
||||||
{
|
{
|
||||||
auto metadata = QueuedDebug::getBuildMetaData();
|
QueuedResult<QueuedStatusMap> metadata = QueuedDebug::getBuildMetaData();
|
||||||
// append metadata here
|
// append metadata here
|
||||||
|
|
||||||
return QDBusVariant(
|
return QDBusVariant(
|
||||||
QVariant::fromValue<QHash<QString, QHash<QString, QString>>>(metadata));
|
QVariant::fromValue<QueuedResult<QueuedStatusMap>>(metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -99,10 +98,9 @@ QDBusVariant QueuedReportInterface::Tasks(const qlonglong user,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Search for tasks" << user << from << to;
|
qCDebug(LOG_DBUS) << "Search for tasks" << user << from << to;
|
||||||
|
|
||||||
return QDBusVariant(QVariant::fromValue<QList<QVariantHash>>(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->taskReport(
|
||||||
m_core->taskReport(user, QDateTime::fromString(from, Qt::ISODateWithMs),
|
user, QDateTime::fromString(from, Qt::ISODateWithMs),
|
||||||
QDateTime::fromString(to, Qt::ISODateWithMs),
|
QDateTime::fromString(to, Qt::ISODateWithMs), token));
|
||||||
token)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -115,9 +113,9 @@ QDBusVariant QueuedReportInterface::Users(const QString &lastLogged,
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Search for users" << lastLogged << permission;
|
qCDebug(LOG_DBUS) << "Search for users" << lastLogged << permission;
|
||||||
|
|
||||||
return QDBusVariant(QVariant::fromValue<QList<QVariantHash>>(
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
m_core->userReport(QDateTime::fromString(lastLogged, Qt::ISODateWithMs),
|
m_core->userReport(QDateTime::fromString(lastLogged, Qt::ISODateWithMs),
|
||||||
permission < 1 ? QueuedEnums::Permission::Invalid
|
permission < 1 ? QueuedEnums::Permission::Invalid
|
||||||
: QueuedEnums::Permission(permission),
|
: QueuedEnums::Permission(permission),
|
||||||
token)));
|
token));
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedReportManager.cpp
|
* @file QueuedReportManager.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedSettings.cpp
|
* @file QueuedSettings.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <queued/QueuedStaticConfig.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,6 +122,7 @@ void QueuedSettings::readConfiguration()
|
|||||||
settings.beginGroup("Administrator");
|
settings.beginGroup("Administrator");
|
||||||
m_cfgAdmin.name = settings.value("Username", "root").toString();
|
m_cfgAdmin.name = settings.value("Username", "root").toString();
|
||||||
m_cfgAdmin.password = settings.value("Password").toString();
|
m_cfgAdmin.password = settings.value("Password").toString();
|
||||||
|
m_cfgAdmin.salt = settings.value("Salt").toString();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
// database related settings
|
// database related settings
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedSystemInfo.cpp
|
* @file QueuedSystemInfo.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedTokenManager.cpp
|
* @file QueuedTokenManager.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedUser.cpp
|
* @file QueuedUser.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -77,9 +77,10 @@ QueuedUser::addPermission(const QueuedEnums::Permission _permission)
|
|||||||
/**
|
/**
|
||||||
* @fn hashFromPassword
|
* @fn hashFromPassword
|
||||||
*/
|
*/
|
||||||
QString QueuedUser::hashFromPassword(const QString &_password)
|
QString QueuedUser::hashFromPassword(const QString &_password,
|
||||||
|
const QString &_salt)
|
||||||
{
|
{
|
||||||
return QCryptographicHash::hash(_password.toUtf8(),
|
return QCryptographicHash::hash(_salt.toUtf8() + _password.toUtf8(),
|
||||||
QCryptographicHash::Sha512)
|
QCryptographicHash::Sha512)
|
||||||
.toHex();
|
.toHex();
|
||||||
}
|
}
|
||||||
@ -120,9 +121,11 @@ QPair<uint, uint> QueuedUser::ids()
|
|||||||
/**
|
/**
|
||||||
* @fn isPasswordValid
|
* @fn isPasswordValid
|
||||||
*/
|
*/
|
||||||
bool QueuedUser::isPasswordValid(const QString &_password) const
|
bool QueuedUser::isPasswordValid(const QString &_password,
|
||||||
|
const QString &_salt) const
|
||||||
{
|
{
|
||||||
return (m_definitions.password.toUtf8() == hashFromPassword(_password));
|
return (m_definitions.password.toUtf8()
|
||||||
|
== hashFromPassword(_password, _salt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* @file QueuedUserManager.cpp
|
* @file QueuedUserManager.cpp
|
||||||
* Source code of queued library
|
* Source code of queued library
|
||||||
* @author Queued team
|
* @author Queued team
|
||||||
* @copyright GPLv3
|
* @copyright MIT
|
||||||
* @bug https://github.com/arcan1s/queued/issues
|
* @bug https://github.com/arcan1s/queued/issues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ QString QueuedUserManager::authorize(const QString &_user,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool status = userObj->isPasswordValid(_password);
|
bool status = userObj->isPasswordValid(_password, salt());
|
||||||
if (!status) {
|
if (!status) {
|
||||||
qCInfo(LOG_LIB) << "User password invalid for" << _user;
|
qCInfo(LOG_LIB) << "User password invalid for" << _user;
|
||||||
return "";
|
return "";
|
||||||
@ -243,6 +243,15 @@ QueuedUser *QueuedUserManager::user(const QString &_name, const bool _isToken)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @salt
|
||||||
|
*/
|
||||||
|
QString QueuedUserManager::salt() const
|
||||||
|
{
|
||||||
|
return m_salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @fn tokenExpiration
|
* @fn tokenExpiration
|
||||||
*/
|
*/
|
||||||
@ -252,6 +261,15 @@ long long QueuedUserManager::tokenExpiration() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn setSalt
|
||||||
|
*/
|
||||||
|
void QueuedUserManager::setSalt(const QString &_salt)
|
||||||
|
{
|
||||||
|
m_salt = _salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn setTokenExpiration
|
* @fn setTokenExpiration
|
||||||
*/
|
*/
|
||||||
|
@ -23,11 +23,25 @@
|
|||||||
#include "QueuedctlUser.h"
|
#include "QueuedctlUser.h"
|
||||||
|
|
||||||
|
|
||||||
QString QueuedctlAuth::auth(const QString &_user)
|
QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user,
|
||||||
|
const QString &_cache)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Auth as user" << _user;
|
qCDebug(LOG_APP) << "Auth as user" << _user;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::auth(_user, QueuedctlUser::getPassword());
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
|
||||||
|
auto res = QueuedCoreAdaptor::auth(_user, QueuedctlUser::getPassword());
|
||||||
|
Result::match(res,
|
||||||
|
[&output, &_user, &_cache](const QString &val) {
|
||||||
|
setToken(val, _user, _cache);
|
||||||
|
output.status = true;
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.status = false;
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -40,8 +54,7 @@ QString QueuedctlAuth::getToken(const QString &_cache, const QString &_user)
|
|||||||
if (tryAuth(tokenId)) {
|
if (tryAuth(tokenId)) {
|
||||||
return tokenId;
|
return tokenId;
|
||||||
} else {
|
} else {
|
||||||
tokenId = auth(_user);
|
auth(_user, _cache);
|
||||||
setToken(tokenId, _user, _cache);
|
|
||||||
return getToken(_cache, _user);
|
return getToken(_cache, _user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,5 +96,7 @@ bool QueuedctlAuth::tryAuth(const QString &_token)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Try auth with" << _token;
|
qCDebug(LOG_APP) << "Try auth with" << _token;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::auth(_token);
|
auto res = QueuedCoreAdaptor::auth(_token);
|
||||||
|
|
||||||
|
return ((res.type() == Result::Content::Value) && res.get());
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,13 @@
|
|||||||
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
|
|
||||||
namespace QueuedctlAuth
|
namespace QueuedctlAuth
|
||||||
{
|
{
|
||||||
QString auth(const QString &_user);
|
QueuedctlCommon::QueuedctlResult auth(const QString &_user,
|
||||||
|
const QString &_cache);
|
||||||
QString getToken(const QString &_cache, const QString &_user);
|
QString getToken(const QString &_cache, const QString &_user);
|
||||||
void parser(QCommandLineParser &_parser);
|
void parser(QCommandLineParser &_parser);
|
||||||
void setToken(const QString &_token, const QString &_user,
|
void setToken(const QString &_token, const QString &_user,
|
||||||
|
@ -221,173 +221,147 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case QueuedctlArgument::Auth: {
|
case QueuedctlArgument::Auth: {
|
||||||
QString token = QueuedctlAuth::auth(_user);
|
result = QueuedctlAuth::auth(_user, _cache);
|
||||||
result.status = !token.isEmpty();
|
|
||||||
if (result.status)
|
|
||||||
QueuedctlAuth::setToken(token, _user, _cache);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::OptionGet: {
|
case QueuedctlArgument::OptionGet: {
|
||||||
QVariant value = QueuedctlOption::getOption(args.at(1));
|
result = QueuedctlOption::getOption(args.at(1));
|
||||||
result.status = value.isValid();
|
|
||||||
result.output = value.toString();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::OptionSet: {
|
case QueuedctlArgument::OptionSet: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status
|
result = QueuedctlOption::editOption(args.at(1), args.at(2), token);
|
||||||
= QueuedctlOption::editOption(args.at(1), args.at(2), token);
|
|
||||||
if (result.status)
|
|
||||||
result.output
|
|
||||||
= QString("Option %1 set to %2").arg(args.at(1), args.at(2));
|
|
||||||
else
|
|
||||||
result.output = QString("Could not set option %1 to %2")
|
|
||||||
.arg(args.at(1), args.at(2));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::PermissionAdd: {
|
case QueuedctlArgument::PermissionAdd: {
|
||||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||||
|
long long userId = -1;
|
||||||
|
Result::match(userIdRes,
|
||||||
|
[&userId](const long long val) { userId = val; },
|
||||||
|
[&result](const QueuedError &err) {
|
||||||
|
result.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
if (userId == -1)
|
||||||
|
break;
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status
|
result = QueuedctlPermissions::addPermission(userId, args.at(2), token);
|
||||||
= QueuedctlPermissions::addPermission(userId, args.at(2), token);
|
|
||||||
if (result.status)
|
|
||||||
result.output = QString("Add permission %2 to user %1")
|
|
||||||
.arg(args.at(1))
|
|
||||||
.arg(args.at(2));
|
|
||||||
else
|
|
||||||
result.output = QString("Could not add permission %2 to user %1")
|
|
||||||
.arg(args.at(1))
|
|
||||||
.arg(args.at(2));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::PermissionRemove: {
|
case QueuedctlArgument::PermissionRemove: {
|
||||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||||
|
long long userId = -1;
|
||||||
|
Result::match(userIdRes,
|
||||||
|
[&userId](const long long val) { userId = val; },
|
||||||
|
[&result](const QueuedError &err) {
|
||||||
|
result.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
if (userId == -1)
|
||||||
|
break;
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status
|
result
|
||||||
= QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
= QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
||||||
if (result.status)
|
|
||||||
result.output = QString("Remove permission %2 from user %1")
|
|
||||||
.arg(args.at(1))
|
|
||||||
.arg(args.at(2));
|
|
||||||
else
|
|
||||||
result.output
|
|
||||||
= QString("Could not remove permission %2 from user %1")
|
|
||||||
.arg(args.at(1))
|
|
||||||
.arg(args.at(2));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::PluginAdd: {
|
case QueuedctlArgument::PluginAdd: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status = QueuedctlPlugins::addPlugin(args.at(1), token);
|
result = QueuedctlPlugins::addPlugin(args.at(1), token);
|
||||||
if (result.status)
|
|
||||||
result.output = QString("Add plugin %1").arg(args.at(1));
|
|
||||||
else
|
|
||||||
result.output = QString("Could not add plugin %1").arg(args.at(1));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::PluginList: {
|
case QueuedctlArgument::PluginList: {
|
||||||
result.status = true;
|
result = QueuedctlPlugins::listPlugins();
|
||||||
result.output = QueuedctlPlugins::listPlugins().join('\n');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::PluginRemove: {
|
case QueuedctlArgument::PluginRemove: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status = QueuedctlPlugins::removePlugin(args.at(1), token);
|
result = QueuedctlPlugins::removePlugin(args.at(1), token);
|
||||||
if (result.status)
|
|
||||||
result.output = QString("Remove plugin %1").arg(args.at(1));
|
|
||||||
else
|
|
||||||
result.output
|
|
||||||
= QString("Could not remove plugin %1").arg(args.at(1));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::Report: {
|
case QueuedctlArgument::Report: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status = true;
|
result = QueuedctlUser::getReport(_parser, token);
|
||||||
result.output
|
|
||||||
= hashListToString(QueuedctlUser::getReport(_parser, token));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::Status: {
|
case QueuedctlArgument::Status: {
|
||||||
auto status = QueuedCoreAdaptor::getStatus();
|
auto res = QueuedCoreAdaptor::getStatus();
|
||||||
result.status = !status.isEmpty();
|
Result::match(res,
|
||||||
result.output = hashHashToString(status);
|
[&result](const QueuedStatusMap &val) {
|
||||||
|
result.status = true;
|
||||||
|
result.output = hashHashToString(val);
|
||||||
|
},
|
||||||
|
[&result](const QueuedError &err) {
|
||||||
|
result.output = err.message().c_str();
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskAdd: {
|
case QueuedctlArgument::TaskAdd: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
auto definitions = QueuedctlTask::getDefinitions(_parser, false);
|
auto definitions = QueuedctlTask::getDefinitions(_parser, false);
|
||||||
long long taskId = QueuedctlTask::addTask(definitions, token);
|
result = QueuedctlTask::addTask(definitions, token);
|
||||||
result.status = (taskId > 0);
|
|
||||||
if (result.status)
|
|
||||||
result.output = QString("Task %1 added").arg(taskId);
|
|
||||||
else
|
|
||||||
result.output = "Could not add task";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskGet: {
|
case QueuedctlArgument::TaskGet: {
|
||||||
QVariant value
|
result = QueuedctlTask::getTask(args.at(1).toLongLong(), args.at(2));
|
||||||
= QueuedctlTask::getTask(args.at(1).toLongLong(), args.at(2));
|
|
||||||
result.status = value.isValid();
|
|
||||||
result.output = args.at(2).isEmpty() ? hashToString(value.toHash())
|
|
||||||
: value.toString();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskList: {
|
case QueuedctlArgument::TaskList: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status = true;
|
result = QueuedctlTask::getTasks(_parser, token);
|
||||||
result.output
|
|
||||||
= hashListToString(QueuedctlTask::getTasks(_parser, token));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskSet: {
|
case QueuedctlArgument::TaskSet: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
auto definitions = QueuedctlTask::getDefinitions(_parser, true);
|
auto definitions = QueuedctlTask::getDefinitions(_parser, true);
|
||||||
result.status = QueuedctlTask::setTask(args.at(1).toLongLong(),
|
result = QueuedctlTask::setTask(args.at(1).toLongLong(), definitions,
|
||||||
definitions, token);
|
token);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskStart: {
|
case QueuedctlArgument::TaskStart: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status
|
result = QueuedctlTask::startTask(args.at(1).toLongLong(), token);
|
||||||
= QueuedctlTask::startTask(args.at(1).toLongLong(), token);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskStop: {
|
case QueuedctlArgument::TaskStop: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status = QueuedctlTask::stopTask(args.at(1).toLongLong(), token);
|
result = QueuedctlTask::stopTask(args.at(1).toLongLong(), token);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::UserAdd: {
|
case QueuedctlArgument::UserAdd: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
auto definitions = QueuedctlUser::getDefinitions(_parser, false);
|
auto definitions = QueuedctlUser::getDefinitions(_parser, false);
|
||||||
long long userId = QueuedctlUser::addUser(definitions, token);
|
result = QueuedctlUser::addUser(definitions, token);
|
||||||
result.status = (userId > 0);
|
|
||||||
if (result.status)
|
|
||||||
result.output = QString("User %1 added").arg(userId);
|
|
||||||
else
|
|
||||||
result.output = "Could not add user";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::UserGet: {
|
case QueuedctlArgument::UserGet: {
|
||||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||||
QVariant value = QueuedctlUser::getUser(userId, args.at(2));
|
long long userId = -1;
|
||||||
result.status = value.isValid();
|
Result::match(userIdRes,
|
||||||
result.output = args.at(2).isEmpty() ? hashToString(value.toHash())
|
[&userId](const long long val) { userId = val; },
|
||||||
: value.toString();
|
[&result](const QueuedError &err) {
|
||||||
|
result.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
if (userId == -1)
|
||||||
|
break;
|
||||||
|
result = QueuedctlUser::getUser(userId, args.at(2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::UserList: {
|
case QueuedctlArgument::UserList: {
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
result.status = true;
|
result = QueuedctlUser::getUsers(_parser, token);
|
||||||
result.output
|
|
||||||
= hashListToString(QueuedctlUser::getUsers(_parser, token));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::UserSet: {
|
case QueuedctlArgument::UserSet: {
|
||||||
auto userId = QueuedCoreAdaptor::getUserId(args.at(1));
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1));
|
||||||
|
long long userId = -1;
|
||||||
|
Result::match(userIdRes,
|
||||||
|
[&userId](const long long val) { userId = val; },
|
||||||
|
[&result](const QueuedError &err) {
|
||||||
|
result.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
if (userId == -1)
|
||||||
|
break;
|
||||||
QString token = QueuedctlAuth::getToken(_cache, _user);
|
QString token = QueuedctlAuth::getToken(_cache, _user);
|
||||||
auto definitions = QueuedctlUser::getDefinitions(_parser, true);
|
auto definitions = QueuedctlUser::getDefinitions(_parser, true);
|
||||||
result.status = QueuedctlUser::setUser(userId, definitions, token);
|
result = QueuedctlUser::setUser(userId, definitions, token);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::Invalid: {
|
case QueuedctlArgument::Invalid: {
|
||||||
|
@ -15,24 +15,45 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "QueuedctlOption.h"
|
#include "QueuedctlOption.h"
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlOption::editOption(const QString &_option, const QVariant &_value,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token)
|
QueuedctlOption::editOption(const QString &_option, const QVariant &_value,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Edit option" << _option << "to" << _value;
|
qCDebug(LOG_APP) << "Edit option" << _option << "to" << _value;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendOptionEdit(_option, _value, _token);
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
auto res = QueuedCoreAdaptor::sendOptionEdit(_option, _value, _token);
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant QueuedctlOption::getOption(const QString &_option)
|
QueuedctlCommon::QueuedctlResult
|
||||||
|
QueuedctlOption::getOption(const QString &_option)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get option" << _option;
|
qCDebug(LOG_APP) << "Get option" << _option;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::getOption(_option);
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
auto res = QueuedCoreAdaptor::getOption(_option);
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output.status = val.isValid();
|
||||||
|
output.output = val.toString();
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,12 +19,15 @@
|
|||||||
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
|
|
||||||
namespace QueuedctlOption
|
namespace QueuedctlOption
|
||||||
{
|
{
|
||||||
bool editOption(const QString &_option, const QVariant &_value,
|
QueuedctlCommon::QueuedctlResult editOption(const QString &_option,
|
||||||
const QString &_token);
|
const QVariant &_value,
|
||||||
QVariant getOption(const QString &_option);
|
const QString &_token);
|
||||||
|
QueuedctlCommon::QueuedctlResult getOption(const QString &_option);
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
@ -15,34 +15,54 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "QueuedctlPermissions.h"
|
#include "QueuedctlPermissions.h"
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlPermissions::addPermission(const long long _id,
|
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(
|
||||||
const QString &_permission,
|
const long long _id, const QString &_permission, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add permission" << _permission << "to" << _id;
|
qCDebug(LOG_APP) << "Add permission" << _permission << "to" << _id;
|
||||||
|
|
||||||
auto permission = QueuedEnums::stringToPermission(_permission);
|
auto permission = QueuedEnums::stringToPermission(_permission);
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
|
||||||
return (permission != QueuedEnums::Permission::Invalid)
|
if (permission == QueuedEnums::Permission::Invalid) {
|
||||||
&& QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
output.output = "Invalid permission";
|
||||||
|
} else {
|
||||||
|
auto res
|
||||||
|
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlPermissions::removePermission(const long long _id,
|
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
||||||
const QString &_permission,
|
const long long _id, const QString &_permission, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Remove permission" << _permission << "to" << _id;
|
qCDebug(LOG_APP) << "Remove permission" << _permission << "to" << _id;
|
||||||
|
|
||||||
auto permission = QueuedEnums::stringToPermission(_permission);
|
auto permission = QueuedEnums::stringToPermission(_permission);
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
|
||||||
return (permission != QueuedEnums::Permission::Invalid)
|
if (permission == QueuedEnums::Permission::Invalid) {
|
||||||
&& QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission,
|
output.output = "Invalid permission";
|
||||||
_token);
|
} else {
|
||||||
|
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission,
|
||||||
|
_token);
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,13 +19,17 @@
|
|||||||
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
|
|
||||||
namespace QueuedctlPermissions
|
namespace QueuedctlPermissions
|
||||||
{
|
{
|
||||||
bool addPermission(const long long _id, const QString &_permission,
|
QueuedctlCommon::QueuedctlResult addPermission(const long long _id,
|
||||||
const QString &_token);
|
const QString &_permission,
|
||||||
bool removePermission(const long long _id, const QString &_permission,
|
const QString &_token);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult removePermission(const long long _id,
|
||||||
|
const QString &_permission,
|
||||||
|
const QString &_token);
|
||||||
void parser(QCommandLineParser &_parser);
|
void parser(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,32 +15,61 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "QueuedctlPlugins.h"
|
#include "QueuedctlPlugins.h"
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
QueuedctlCommon::QueuedctlResult
|
||||||
|
QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add plugin" << _plugin;
|
qCDebug(LOG_APP) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendPluginAdd(_plugin, _token);
|
auto res = QueuedCoreAdaptor::sendPluginAdd(_plugin, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList QueuedctlPlugins::listPlugins()
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
||||||
{
|
{
|
||||||
return QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins)
|
auto res
|
||||||
.toString()
|
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins);
|
||||||
.split('\n');
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output.status = val.isValid();
|
||||||
|
output.output = val.toString();
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlPlugins::removePlugin(const QString &_plugin,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token)
|
QueuedctlPlugins::removePlugin(const QString &_plugin, const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Remove plugin" << _plugin;
|
qCDebug(LOG_APP) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendPluginRemove(_plugin, _token);
|
auto res = QueuedCoreAdaptor::sendPluginRemove(_plugin, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,12 +19,16 @@
|
|||||||
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
|
|
||||||
namespace QueuedctlPlugins
|
namespace QueuedctlPlugins
|
||||||
{
|
{
|
||||||
bool addPlugin(const QString &_plugin, const QString &_token);
|
QueuedctlCommon::QueuedctlResult addPlugin(const QString &_plugin,
|
||||||
QStringList listPlugins();
|
const QString &_token);
|
||||||
bool removePlugin(const QString &_plugin, const QString &_token);
|
QueuedctlCommon::QueuedctlResult listPlugins();
|
||||||
|
QueuedctlCommon::QueuedctlResult removePlugin(const QString &_plugin,
|
||||||
|
const QString &_token);
|
||||||
void parser(QCommandLineParser &_parser);
|
void parser(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "QueuedctlTask.h"
|
#include "QueuedctlTask.h"
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@ -25,13 +26,25 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long long QueuedctlTask::addTask(
|
QueuedctlCommon::QueuedctlResult QueuedctlTask::addTask(
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add task" << _definitions.command;
|
qCDebug(LOG_APP) << "Add task" << _definitions.command;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendTaskAdd(_definitions, _token);
|
auto res = QueuedCoreAdaptor::sendTaskAdd(_definitions, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const long long val) {
|
||||||
|
output.status = (val > 0);
|
||||||
|
output.output = QString::number(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -52,10 +65,15 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
|||||||
});
|
});
|
||||||
|
|
||||||
definitions.nice = _parser.value("nice").toUInt();
|
definitions.nice = _parser.value("nice").toUInt();
|
||||||
definitions.user
|
if (_parser.value("task-user").isEmpty()) {
|
||||||
= _parser.value("task-user").isEmpty()
|
definitions.user = 0;
|
||||||
? 0
|
} else {
|
||||||
: QueuedCoreAdaptor::getUserId(_parser.value("task-user"));
|
auto res = QueuedCoreAdaptor::getUserId(_parser.value("task-user"));
|
||||||
|
Result::match(
|
||||||
|
res,
|
||||||
|
[&definitions](const long long val) { definitions.user = val; },
|
||||||
|
[&definitions](const QueuedError &) { definitions.user = 0; });
|
||||||
|
}
|
||||||
definitions.workingDirectory
|
definitions.workingDirectory
|
||||||
= QFileInfo(_parser.value("directory")).absoluteFilePath();
|
= QFileInfo(_parser.value("directory")).absoluteFilePath();
|
||||||
// limits now
|
// limits now
|
||||||
@ -87,30 +105,67 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant QueuedctlTask::getTask(const long long _id, const QString &_property)
|
QueuedctlCommon::QueuedctlResult
|
||||||
|
QueuedctlTask::getTask(const long long _id, const QString &_property)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get property" << _property << "from task" << _id;
|
qCDebug(LOG_APP) << "Get property" << _property << "from task" << _id;
|
||||||
|
|
||||||
if (_property.isEmpty())
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
return QueuedCoreAdaptor::getTask(_id);
|
|
||||||
else
|
if (_property.isEmpty()) {
|
||||||
return QueuedCoreAdaptor::getTask(_id, _property);
|
auto res = QueuedCoreAdaptor::getTask(_id);
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariantHash &val) {
|
||||||
|
output.status = true;
|
||||||
|
output.output = QueuedctlCommon::hashToString(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
auto res = QueuedCoreAdaptor::getTask(_id, _property);
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output.status = val.isValid();
|
||||||
|
output.output = val.toString();
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<QVariantHash> QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token)
|
QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
long long user
|
long long userId = -1;
|
||||||
= _parser.value("task-user").isEmpty()
|
if (!_parser.value("task-user").isEmpty()) {
|
||||||
? -1
|
auto res = QueuedCoreAdaptor::getUserId(_parser.value("task-user"));
|
||||||
: QueuedCoreAdaptor::getUserId(_parser.value("task-user"));
|
Result::match(res, [&userId](const long long val) { userId = val; },
|
||||||
|
[&userId](const QueuedError &) {});
|
||||||
|
}
|
||||||
QDateTime stop
|
QDateTime stop
|
||||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||||
QDateTime start
|
QDateTime start
|
||||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||||
|
|
||||||
return QueuedCoreAdaptor::getTasks(user, start, stop, _token);
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
|
||||||
|
auto res = QueuedCoreAdaptor::getTasks(userId, start, stop, _token);
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QList<QVariantHash> &val) {
|
||||||
|
output.status = true;
|
||||||
|
output.output = QueuedctlCommon::hashListToString(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,28 +300,54 @@ void QueuedctlTask::parserStart(QCommandLineParser &_parser)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlTask::setTask(
|
QueuedctlCommon::QueuedctlResult QueuedctlTask::setTask(
|
||||||
const long long _id,
|
const long long _id,
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Edit task" << _id;
|
qCDebug(LOG_APP) << "Edit task" << _id;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendTaskEdit(_id, _definitions, _token);
|
auto res = QueuedCoreAdaptor::sendTaskEdit(_id, _definitions, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlTask::startTask(const long long _id, const QString &_token)
|
QueuedctlCommon::QueuedctlResult QueuedctlTask::startTask(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Start task" << _id;
|
qCDebug(LOG_APP) << "Start task" << _id;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendTaskStart(_id, _token);
|
auto res = QueuedCoreAdaptor::sendTaskStart(_id, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlTask::stopTask(const long long _id, const QString &_token)
|
QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Stop task" << _id;
|
qCDebug(LOG_APP) << "Stop task" << _id;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendTaskStop(_id, _token);
|
auto res = QueuedCoreAdaptor::sendTaskStart(_id, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -21,26 +21,33 @@
|
|||||||
|
|
||||||
#include <queued/QueuedProcess.h>
|
#include <queued/QueuedProcess.h>
|
||||||
|
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
|
|
||||||
namespace QueuedctlTask
|
namespace QueuedctlTask
|
||||||
{
|
{
|
||||||
long long addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token);
|
addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
|
const QString &_token);
|
||||||
QueuedProcess::QueuedProcessDefinitions
|
QueuedProcess::QueuedProcessDefinitions
|
||||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll);
|
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll);
|
||||||
QVariant getTask(const long long _id, const QString &_property);
|
QueuedctlCommon::QueuedctlResult getTask(const long long _id,
|
||||||
QList<QVariantHash> getTasks(const QCommandLineParser &_parser,
|
const QString &_property);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult getTasks(const QCommandLineParser &_parser,
|
||||||
|
const QString &_token);
|
||||||
void parserAdd(QCommandLineParser &_parser);
|
void parserAdd(QCommandLineParser &_parser);
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserList(QCommandLineParser &_parser);
|
void parserList(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
void parserStart(QCommandLineParser &_parser);
|
void parserStart(QCommandLineParser &_parser);
|
||||||
bool setTask(const long long _id,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
setTask(const long long _id,
|
||||||
const QString &_token);
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
bool startTask(const long long _id, const QString &_token);
|
const QString &_token);
|
||||||
bool stopTask(const long long _id, const QString &_token);
|
QueuedctlCommon::QueuedctlResult startTask(const long long _id,
|
||||||
|
const QString &_token);
|
||||||
|
QueuedctlCommon::QueuedctlResult stopTask(const long long _id,
|
||||||
|
const QString &_token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "QueuedctlUser.h"
|
#include "QueuedctlUser.h"
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <queued/QueuedUser.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
@ -26,18 +28,31 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long long
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add user" << _definitions.name;
|
qCDebug(LOG_APP) << "Add user" << _definitions.name;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendUserAdd(_definitions, _token);
|
auto res = QueuedCoreAdaptor::sendUserAdd(_definitions, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const long long val) {
|
||||||
|
output.status = (val > 0);
|
||||||
|
output.output = QString::number(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<QVariantHash> QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token)
|
QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get usage report";
|
qCDebug(LOG_APP) << "Get usage report";
|
||||||
|
|
||||||
@ -46,7 +61,19 @@ QList<QVariantHash> QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
|||||||
QDateTime start
|
QDateTime start
|
||||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||||
|
|
||||||
return QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
auto res = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QList<QVariantHash> &val) {
|
||||||
|
output.status = true;
|
||||||
|
output.output = QueuedctlCommon::hashListToString(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,15 +86,16 @@ QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
|||||||
|
|
||||||
QueuedUser::QueuedUserDefinitions definitions;
|
QueuedUser::QueuedUserDefinitions definitions;
|
||||||
|
|
||||||
definitions.email = _parser.value("email");
|
// define password first
|
||||||
definitions.password = _parser.isSet("stdin-password")
|
definitions.password = _parser.isSet("stdin-password")
|
||||||
? getPassword()
|
? getPassword()
|
||||||
: _parser.value("password");
|
: _parser.value("password");
|
||||||
// transform to hash
|
auto res = QueuedCoreAdaptor::sendPasswordHash(definitions.password);
|
||||||
definitions.password
|
Result::match(
|
||||||
= definitions.password.isEmpty()
|
res, [&definitions](const QString &val) { definitions.password = val; },
|
||||||
? ""
|
[](const QueuedError &) {});
|
||||||
: QueuedUser::hashFromPassword(definitions.password);
|
|
||||||
|
definitions.email = _parser.value("email");
|
||||||
// limits now
|
// limits now
|
||||||
QueuedLimits::Limits limits(
|
QueuedLimits::Limits limits(
|
||||||
_parser.value("limit-cpu").toLongLong(),
|
_parser.value("limit-cpu").toLongLong(),
|
||||||
@ -107,19 +135,42 @@ QString QueuedctlUser::getPassword()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant QueuedctlUser::getUser(const long long _id, const QString &_property)
|
QueuedctlCommon::QueuedctlResult
|
||||||
|
QueuedctlUser::getUser(const long long _id, const QString &_property)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get property" << _property << "from user" << _id;
|
qCDebug(LOG_APP) << "Get property" << _property << "from user" << _id;
|
||||||
|
|
||||||
if (_property.isEmpty())
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
return QueuedCoreAdaptor::getUser(_id);
|
|
||||||
else
|
if (_property.isEmpty()) {
|
||||||
return QueuedCoreAdaptor::getUser(_id, _property);
|
auto res = QueuedCoreAdaptor::getUser(_id);
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariantHash &val) {
|
||||||
|
output.status = true;
|
||||||
|
output.output = QueuedctlCommon::hashToString(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
auto res = QueuedCoreAdaptor::getUser(_id, _property);
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QVariant &val) {
|
||||||
|
output.status = val.isValid();
|
||||||
|
output.output = val.toString();
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<QVariantHash> QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token)
|
QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
QDateTime lastLogin = QDateTime::fromString(_parser.value("last-logged"),
|
QDateTime lastLogin = QDateTime::fromString(_parser.value("last-logged"),
|
||||||
Qt::ISODateWithMs);
|
Qt::ISODateWithMs);
|
||||||
@ -128,7 +179,19 @@ QList<QVariantHash> QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
|||||||
? QueuedEnums::Permission::Invalid
|
? QueuedEnums::Permission::Invalid
|
||||||
: QueuedEnums::Permission(_parser.value("access").toInt());
|
: QueuedEnums::Permission(_parser.value("access").toInt());
|
||||||
|
|
||||||
return QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
auto res = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res,
|
||||||
|
[&output](const QList<QVariantHash> &val) {
|
||||||
|
output.status = true;
|
||||||
|
output.output = QueuedctlCommon::hashListToString(val);
|
||||||
|
},
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -253,11 +316,20 @@ void QueuedctlUser::parserSet(QCommandLineParser &_parser)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QueuedctlUser::setUser(
|
QueuedctlCommon::QueuedctlResult
|
||||||
const long long _id, const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedctlUser::setUser(const long long _id,
|
||||||
const QString &_token)
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Edit user" << _id;
|
qCDebug(LOG_APP) << "Edit user" << _id;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::sendUserEdit(_id, _definitions, _token);
|
auto res = QueuedCoreAdaptor::sendUserEdit(_id, _definitions, _token);
|
||||||
|
|
||||||
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
Result::match(res, [&output](const bool val) { output.status = val; },
|
||||||
|
[&output](const QueuedError &err) {
|
||||||
|
output.output = err.message().c_str();
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -21,27 +21,32 @@
|
|||||||
|
|
||||||
#include <queued/QueuedUser.h>
|
#include <queued/QueuedUser.h>
|
||||||
|
|
||||||
|
#include "QueuedctlCommon.h"
|
||||||
|
|
||||||
|
|
||||||
namespace QueuedctlUser
|
namespace QueuedctlUser
|
||||||
{
|
{
|
||||||
long long addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QString &_token);
|
addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
QList<QVariantHash> getReport(const QCommandLineParser &_parser,
|
const QString &_token);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult getReport(const QCommandLineParser &_parser,
|
||||||
|
const QString &_token);
|
||||||
QueuedUser::QueuedUserDefinitions
|
QueuedUser::QueuedUserDefinitions
|
||||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll);
|
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll);
|
||||||
QString getPassword();
|
QString getPassword();
|
||||||
QVariant getUser(const long long _id, const QString &_property);
|
QueuedctlCommon::QueuedctlResult getUser(const long long _id,
|
||||||
QList<QVariantHash> getUsers(const QCommandLineParser &_parser,
|
const QString &_property);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult getUsers(const QCommandLineParser &_parser,
|
||||||
|
const QString &_token);
|
||||||
void parserAdd(QCommandLineParser &_parser);
|
void parserAdd(QCommandLineParser &_parser);
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserList(QCommandLineParser &_parser);
|
void parserList(QCommandLineParser &_parser);
|
||||||
void parserReport(QCommandLineParser &_parser);
|
void parserReport(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
bool setUser(const long long _id,
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
setUser(const long long _id,
|
||||||
const QString &_token);
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
|
const QString &_token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
|
|
||||||
// information
|
// information
|
||||||
const char NAME[] = "Queued";
|
static const char NAME[] = "Queued";
|
||||||
const char VERSION[] = "@PROJECT_VERSION@";
|
static const char VERSION[] = "@PROJECT_VERSION@";
|
||||||
const char COMMIT_SHA[] = "@PROJECT_COMMIT_SHA@";
|
static const char COMMIT_SHA[] = "@PROJECT_COMMIT_SHA@";
|
||||||
const char AUTHOR[] = "@PROJECT_AUTHOR@";
|
static const char AUTHOR[] = "@PROJECT_AUTHOR@";
|
||||||
const char EMAIL[] = "@PROJECT_CONTACT@";
|
static const char EMAIL[] = "@PROJECT_CONTACT@";
|
||||||
const char LICENSE[] = "@PROJECT_LICENSE@";
|
static const char LICENSE[] = "@PROJECT_LICENSE@";
|
||||||
const char TRDPARTY_LICENSE[] = "";
|
static const char TRDPARTY_LICENSE[] = "";
|
||||||
const char SPECIAL_THANKS[] = "";
|
static const char SPECIAL_THANKS[] = "";
|
||||||
|
|
||||||
// configuration
|
// configuration
|
||||||
// use define here instead of normal const definition for moc
|
// use define here instead of normal const definition for moc
|
||||||
@ -20,43 +20,46 @@ const char SPECIAL_THANKS[] = "";
|
|||||||
#cmakedefine BUILD_TESTING
|
#cmakedefine BUILD_TESTING
|
||||||
|
|
||||||
// links
|
// links
|
||||||
const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
|
static const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
|
||||||
const char REPOSITORY[] = "https://github.com/arcan1s/queued";
|
static const char REPOSITORY[] = "https://github.com/arcan1s/queued";
|
||||||
const char RELEASES[] = "https://github.com/arcan1s/queued/releases/tag/V.";
|
static const char RELEASES[]
|
||||||
const char VERSION_API[]
|
= "https://github.com/arcan1s/queued/releases/tag/V.";
|
||||||
|
static const char VERSION_API[]
|
||||||
= "https://api.github.com/repos/arcan1s/queued/releases";
|
= "https://api.github.com/repos/arcan1s/queued/releases";
|
||||||
const char BUGTRACKER[] = "https://github.com/arcan1s/queued/issues";
|
static const char BUGTRACKER[] = "https://github.com/arcan1s/queued/issues";
|
||||||
const char BUGTRACKER_API[] = "https://arcanis.me/repos/arcan1s/queued/issues";
|
static const char BUGTRACKER_API[]
|
||||||
|
= "https://arcanis.me/repos/arcan1s/queued/issues";
|
||||||
|
|
||||||
// build information
|
// build information
|
||||||
const char BUILD_DATE[] = "@CURRENT_DATE@";
|
static const char BUILD_DATE[] = "@CURRENT_DATE@";
|
||||||
|
|
||||||
// cmake properties
|
// cmake properties
|
||||||
const char CMAKE_BUILD_TYPE[] = "@CMAKE_BUILD_TYPE@";
|
static const char CMAKE_BUILD_TYPE[] = "@CMAKE_BUILD_TYPE@";
|
||||||
const char CMAKE_CXX_COMPILER[] = "@CMAKE_CXX_COMPILER@";
|
static const char CMAKE_CXX_COMPILER[] = "@CMAKE_CXX_COMPILER@";
|
||||||
const char CMAKE_CXX_FLAGS[] = "@CMAKE_CXX_FLAGS@";
|
static const char CMAKE_CXX_FLAGS[] = "@CMAKE_CXX_FLAGS@";
|
||||||
const char CMAKE_CXX_FLAGS_DEBUG[] = "@CMAKE_CXX_FLAGS_DEBUG@";
|
static const char CMAKE_CXX_FLAGS_DEBUG[] = "@CMAKE_CXX_FLAGS_DEBUG@";
|
||||||
const char CMAKE_CXX_FLAGS_RELEASE[] = "@CMAKE_CXX_FLAGS_RELEASE@";
|
static const char CMAKE_CXX_FLAGS_RELEASE[] = "@CMAKE_CXX_FLAGS_RELEASE@";
|
||||||
const char CMAKE_CXX_FLAGS_OPTIMIZATION[] = "@CMAKE_CXX_FLAGS_OPTIMIZATION@";
|
static const char CMAKE_CXX_FLAGS_OPTIMIZATION[]
|
||||||
const char CMAKE_DEFINITIONS[] = "@CMAKE_DEFINITIONS@";
|
= "@CMAKE_CXX_FLAGS_OPTIMIZATION@";
|
||||||
const char CMAKE_INSTALL_PREFIX[] = "@CMAKE_INSTALL_PREFIX@";
|
static const char CMAKE_DEFINITIONS[] = "@CMAKE_DEFINITIONS@";
|
||||||
const char CMAKE_MODULE_LINKER_FLAGS[] = "@CMAKE_MODULE_LINKER_FLAGS@";
|
static const char CMAKE_INSTALL_PREFIX[] = "@CMAKE_INSTALL_PREFIX@";
|
||||||
const char CMAKE_SHARED_LINKER_FLAGS[] = "@CMAKE_SHARED_LINKER_FLAGS@";
|
static const char CMAKE_MODULE_LINKER_FLAGS[] = "@CMAKE_MODULE_LINKER_FLAGS@";
|
||||||
|
static const char CMAKE_SHARED_LINKER_FLAGS[] = "@CMAKE_SHARED_LINKER_FLAGS@";
|
||||||
// components
|
// components
|
||||||
const char BUILD_DEB_PACKAGE[] = "@BUILD_DEB_PACKAGE@";
|
static const char BUILD_DEB_PACKAGE[] = "@BUILD_DEB_PACKAGE@";
|
||||||
const char BUILD_RPM_PACKAGE[] = "@BUILD_RPM_PACKAGE@";
|
static const char BUILD_RPM_PACKAGE[] = "@BUILD_RPM_PACKAGE@";
|
||||||
const char CLANGFORMAT_EXECUTABLE[] = "@CLANGFORMAT_EXECUTABLE@";
|
static const char CLANGFORMAT_EXECUTABLE[] = "@CLANGFORMAT_EXECUTABLE@";
|
||||||
const char COVERITY_COMMENT[] = "@COVERITY_COMMENT@";
|
static const char COVERITY_COMMENT[] = "@COVERITY_COMMENT@";
|
||||||
const char COVERITY_DIRECTORY[] = "@COVERITY_DIRECTORY@";
|
static const char COVERITY_DIRECTORY[] = "@COVERITY_DIRECTORY@";
|
||||||
const char COVERITY_EMAIL[] = "@COVERITY_EMAIL@";
|
static const char COVERITY_EMAIL[] = "@COVERITY_EMAIL@";
|
||||||
const char COVERITY_EXECUTABLE[] = "@COVERITY_EXECUTABLE@";
|
static const char COVERITY_EXECUTABLE[] = "@COVERITY_EXECUTABLE@";
|
||||||
const char COVERITY_URL[] = "@COVERITY_URL@";
|
static const char COVERITY_URL[] = "@COVERITY_URL@";
|
||||||
const char CPPCHECK_EXECUTABLE[] = "@CPPCHECK_EXECUTABLE@";
|
static const char CPPCHECK_EXECUTABLE[] = "@CPPCHECK_EXECUTABLE@";
|
||||||
// additional functions
|
// additional functions
|
||||||
const char PROP_DOCS[] = "@BUILD_DOCS@";
|
static const char PROP_DOCS[] = "@BUILD_DOCS@";
|
||||||
const char PROP_FUTURE[] = "@BUILD_FUTURE@";
|
static const char PROP_FUTURE[] = "@BUILD_FUTURE@";
|
||||||
const char PROP_LOAD[] = "@BUILD_LOAD@";
|
static const char PROP_LOAD[] = "@BUILD_LOAD@";
|
||||||
const char PROP_TEST[] = "@BUILD_TESTING@";
|
static const char PROP_TEST[] = "@BUILD_TESTING@";
|
||||||
|
|
||||||
|
|
||||||
#endif /* VERSION_H */
|
#endif /* VERSION_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user