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