mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-16 23:29:56 +00:00
massive api changes: replace public method results to Result<T, E>
This commit is contained in:
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user