mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-22 09:59:55 +00:00
massive fixes in logic
This commit is contained in:
@ -137,22 +137,21 @@ typedef QHash<QString, QueuedSettingsField> QueuedSettingsDefaultMap;
|
||||
* @ingroup QueuedCfg
|
||||
* @brief default settings map
|
||||
*/
|
||||
const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
||||
{"", {QueuedSettings::Invalid, QVariant()}},
|
||||
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}},
|
||||
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\x010\x010\x010\x010"}},
|
||||
{"KeepTasks", {QueuedSettings::KeepTasks, 0}},
|
||||
{"KeepUsers", {QueuedSettings::KeepUsers, 0}},
|
||||
{"OnExitAction", {QueuedSettings::OnExitAction, 2}},
|
||||
{"TokenExpiration", {QueuedSettings::TokenExpiration, 30}},
|
||||
{"DatabaseVersion",
|
||||
{QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION}},
|
||||
{"ProcessCommandLine",
|
||||
{QueuedSettings::ProcessCommandLine,
|
||||
"systemd-run\x01--scope\x01--unit={name}\x01--uid={uid}\x01--gid={gid}"
|
||||
"\x01-p\x01CPUQuota={cpu}%\x01-p\x01MemoryHigh={memory}\x01{"
|
||||
"application}"}},
|
||||
{"Plugins", {QueuedSettings::Plugins, ""}}};
|
||||
const QueuedSettingsDefaultMap QueuedSettingsDefaults
|
||||
= {{"", {QueuedSettings::Invalid, QVariant()}},
|
||||
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000}},
|
||||
{"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}},
|
||||
{"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, ""}}};
|
||||
};
|
||||
|
||||
#endif /* QUEUEDCONFIGURATION_H */
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "QueuedConfiguration.h"
|
||||
#include "QueuedEnums.h"
|
||||
#include "QueuedLimits.h"
|
||||
#include "QueuedUserManager.h"
|
||||
|
||||
|
||||
class QueuedAdvancedSettings;
|
||||
@ -41,6 +40,8 @@ class QueuedProcessManager;
|
||||
class QueuedReportManager;
|
||||
class QueuedSettings;
|
||||
class QueuedTokenManager;
|
||||
class QueuedUser;
|
||||
class QueuedUserManager;
|
||||
|
||||
/**
|
||||
* @brief aggregator of queued classes
|
||||
@ -63,12 +64,11 @@ public:
|
||||
* @brief add plugin to autoload and load it now
|
||||
* @param _plugin
|
||||
* plugin name
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successfully addition
|
||||
*/
|
||||
bool addPlugin(const QString &_plugin,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
bool addPlugin(const QString &_plugin, const QString &_token);
|
||||
/**
|
||||
* @brief add new task
|
||||
* @param _command
|
||||
@ -83,14 +83,14 @@ public:
|
||||
* task owner user ID
|
||||
* @param _limits
|
||||
* task defined limits
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successfully addition
|
||||
*/
|
||||
bool addTask(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const uint _nice,
|
||||
const long long _userId, const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief add new user
|
||||
* @param _name
|
||||
@ -103,65 +103,62 @@ public:
|
||||
* user permissions
|
||||
* @param _limits
|
||||
* user limits
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successfully addition
|
||||
*/
|
||||
bool addUser(const QString &_name, const QString &_email,
|
||||
const QString &_password, const uint _permissions,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
const QueuedLimits::Limits &_limits, const QString &_token);
|
||||
/**
|
||||
* @brief authorize and create new token for user
|
||||
* @param _name
|
||||
* user name
|
||||
* @param _password
|
||||
* user password
|
||||
* @return authorization structure. Token field will be empty in case if no
|
||||
* authorization occurs
|
||||
* @return token. It will be empty if authorization error occurs
|
||||
*/
|
||||
QueuedUserManager::QueuedUserAuthorization
|
||||
authorization(const QString &_name, const QString &_password);
|
||||
QString authorization(const QString &_name, const QString &_password);
|
||||
/**
|
||||
* @brief edit advanced settings
|
||||
* @param _key
|
||||
* advanced settings key
|
||||
* @param _value
|
||||
* advanced settings value
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successful option edition
|
||||
*/
|
||||
bool editOption(const QString &_key, const QVariant &_value,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief edit task
|
||||
* @param _id
|
||||
* task ID to edit
|
||||
* @param _taskData
|
||||
* task data to edit
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @remark _taskData should contain only fields defined in schema, any other
|
||||
* 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 QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief edit user
|
||||
* @param _id
|
||||
* user ID to edit
|
||||
* @param _userData
|
||||
* user data to edit
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @remark _userData should contain only fields defined in schema, any other
|
||||
* 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 QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief edit user permissions
|
||||
* @param _id
|
||||
@ -170,15 +167,13 @@ public:
|
||||
* permission to add or remove
|
||||
* @param _add
|
||||
* indicates whether it should be added or removed
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successful user permission edition
|
||||
*/
|
||||
bool
|
||||
editUserPermission(const long long _id,
|
||||
const QueuedEnums::Permission &_permission,
|
||||
const bool _add,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
bool editUserPermission(const long long _id,
|
||||
const QueuedEnums::Permission &_permission,
|
||||
const bool _add, const QString &_token);
|
||||
/**
|
||||
* @brief get value from advanced settings
|
||||
* @param _key
|
||||
@ -197,32 +192,29 @@ public:
|
||||
* @brief remove plugin from autoload and unload it now
|
||||
* @param _plugin
|
||||
* plugin name
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successful plugin removal
|
||||
*/
|
||||
bool removePlugin(const QString &_plugin,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
bool removePlugin(const QString &_plugin, const QString &_token);
|
||||
/**
|
||||
* @brief force start task
|
||||
* @param _id
|
||||
* task ID
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successful task start
|
||||
*/
|
||||
bool startTask(const long long _id,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
bool startTask(const long long _id, const QString &_token);
|
||||
/**
|
||||
* @brief force stop task
|
||||
* @param _id
|
||||
* task ID
|
||||
* @param _auth
|
||||
* user auth structure
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return true on successful task stop
|
||||
*/
|
||||
bool stopTask(const long long _id,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
bool stopTask(const long long _id, const QString &_token);
|
||||
/**
|
||||
* @brief get task by ID
|
||||
* @param _id
|
||||
|
@ -68,26 +68,21 @@ public slots:
|
||||
* option key to edit
|
||||
* @param value
|
||||
* option value to edit
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful option edition
|
||||
*/
|
||||
bool OptionEdit(const QString &key, const QDBusVariant &value,
|
||||
const QString &whoAmI, const QString &token);
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief add plugin
|
||||
* @param plugin
|
||||
* plugin name
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful plugin addition
|
||||
*/
|
||||
bool PluginAdd(const QString &plugin, const QString &whoAmI,
|
||||
const QString &token);
|
||||
bool PluginAdd(const QString &plugin, const QString &token);
|
||||
/**
|
||||
* @brief remove plugin
|
||||
* @param plugin
|
||||
@ -98,8 +93,7 @@ public slots:
|
||||
* auth user token
|
||||
* @return true on successful plugin removal
|
||||
*/
|
||||
bool PluginRemove(const QString &plugin, const QString &whoAmI,
|
||||
const QString &token);
|
||||
bool PluginRemove(const QString &plugin, const QString &token);
|
||||
/**
|
||||
* @brief add new task
|
||||
* @param command
|
||||
@ -132,8 +126,7 @@ public slots:
|
||||
const QString &workingDirectory, const uint nice,
|
||||
const long long user, const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token);
|
||||
const QString &storage, const QString &token);
|
||||
/**
|
||||
* @brief edit task
|
||||
* @param id
|
||||
@ -175,8 +168,7 @@ public slots:
|
||||
const uint nice, const uint uid, const uint gid,
|
||||
const uint state, const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token);
|
||||
const QString &storage, const QString &token);
|
||||
/**
|
||||
* @brief force start task
|
||||
* @param id
|
||||
@ -187,8 +179,7 @@ public slots:
|
||||
* auth user token
|
||||
* @return true on successful task start
|
||||
*/
|
||||
bool TaskStart(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token);
|
||||
bool TaskStart(const qlonglong id, const QString &token);
|
||||
/**
|
||||
* @brief force stop task
|
||||
* @param id
|
||||
@ -199,8 +190,7 @@ public slots:
|
||||
* auth user token
|
||||
* @return true on successful task stop
|
||||
*/
|
||||
bool TaskStop(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token);
|
||||
bool TaskStop(const qlonglong id, const QString &token);
|
||||
/**
|
||||
* @brief add new user
|
||||
* @param name
|
||||
@ -231,8 +221,7 @@ public slots:
|
||||
const QString &password, const uint permissions,
|
||||
const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token);
|
||||
const QString &storage, const QString &token);
|
||||
/**
|
||||
* @brief edit user
|
||||
* @param id
|
||||
@ -263,8 +252,7 @@ public slots:
|
||||
const QString &password, const QString &email,
|
||||
const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token);
|
||||
const QString &storage, const QString &token);
|
||||
/**
|
||||
* @brief add permission to user
|
||||
* @param id
|
||||
@ -278,7 +266,7 @@ public slots:
|
||||
* @return true on successful permission addition
|
||||
*/
|
||||
bool UserPermissionAdd(const qlonglong id, const uint permission,
|
||||
const QString &whoAmI, const QString &token);
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief remove permission from user
|
||||
* @param id
|
||||
@ -292,7 +280,7 @@ public slots:
|
||||
* @return true on successful permission removal
|
||||
*/
|
||||
bool UserPermissionRemove(const qlonglong id, const uint permission,
|
||||
const QString &whoAmI, const QString &token);
|
||||
const QString &token);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -102,7 +102,6 @@ const QueuedDBSchema DBSchema = {
|
||||
{"nice", {"nice", "INT", QVariant::UInt, false}},
|
||||
{"uid", {"uid", "INT", QVariant::UInt, false}},
|
||||
{"gid", {"gid", "INT", QVariant::UInt, false}},
|
||||
{"state", {"state", "INT", QVariant::UInt, true}},
|
||||
{"limits", {"limits", "TEXT", QVariant::String, false}},
|
||||
{"startTime", {"startTime", "INT", QVariant::LongLong, true}},
|
||||
{"endTime", {"endTime", "INT", QVariant::LongLong, true}}}},
|
||||
@ -111,6 +110,7 @@ const QueuedDBSchema DBSchema = {
|
||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
||||
true}},
|
||||
{"token", {"token", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
||||
{"user", {"user", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
||||
{"validUntil",
|
||||
{"validUntil", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}}}},
|
||||
{USERS_TABLE,
|
||||
|
@ -55,22 +55,6 @@ enum class Permission {
|
||||
};
|
||||
Q_DECLARE_FLAGS(Permissions, Permission)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Permissions)
|
||||
/**
|
||||
* @ingroup QueuedEnums
|
||||
* @enum ProcessState
|
||||
* @brief process state description
|
||||
* @var ProcessState::NotRunning
|
||||
* process is not running yet
|
||||
* @var ProcessState::Running
|
||||
* process running at the moment
|
||||
* @var ProcessState::Exited
|
||||
* process exit
|
||||
*/
|
||||
enum class ProcessState {
|
||||
NotRunning = 1 << 1,
|
||||
Running = 1 << 2,
|
||||
Exited = 1 << 3
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
@ -63,7 +63,7 @@ struct Limits {
|
||||
*/
|
||||
QString toString() const
|
||||
{
|
||||
return QString("%1\x01%2\x01%3\x01%4\x01%5")
|
||||
return QString("%1\n%2\n%3\n%4\n%5")
|
||||
.arg(cpu)
|
||||
.arg(gpu)
|
||||
.arg(memory)
|
||||
@ -87,7 +87,7 @@ struct Limits {
|
||||
*/
|
||||
Limits(const QString &_stringLimits)
|
||||
{
|
||||
QStringList limits = _stringLimits.split(QChar('\x01'));
|
||||
QStringList limits = _stringLimits.split(QChar('\n'));
|
||||
while (limits.count() < 5)
|
||||
limits.append(QString("0"));
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <QDateTime>
|
||||
#include <QProcess>
|
||||
|
||||
#include "QueuedEnums.h"
|
||||
#include "QueuedLimits.h"
|
||||
|
||||
|
||||
@ -49,7 +48,6 @@ class QueuedProcess : public QProcess
|
||||
Q_PROPERTY(QueuedLimits::Limits nativeLimtis READ nativeLimits)
|
||||
Q_PROPERTY(uint nice READ nice WRITE setNice)
|
||||
Q_PROPERTY(QString processLine READ processLine WRITE setProcessLine)
|
||||
Q_PROPERTY(QueuedEnums::ProcessState pstate READ pstate WRITE setPState)
|
||||
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime)
|
||||
Q_PROPERTY(uint uid READ uid WRITE setUid)
|
||||
Q_PROPERTY(long long user READ user WRITE setUser)
|
||||
@ -79,8 +77,6 @@ public:
|
||||
* task owner ID
|
||||
* @var limits
|
||||
* task limits
|
||||
* @var state
|
||||
* current task state
|
||||
*/
|
||||
typedef struct {
|
||||
QString command;
|
||||
@ -93,7 +89,6 @@ public:
|
||||
QDateTime endTime;
|
||||
long long user;
|
||||
QString limits;
|
||||
QueuedEnums::ProcessState state;
|
||||
} QueuedProcessDefinitions;
|
||||
|
||||
/**
|
||||
@ -168,11 +163,6 @@ public:
|
||||
* @return process line as is in configuration
|
||||
*/
|
||||
QString processLine() const;
|
||||
/**
|
||||
* @brief process state
|
||||
* @return process defined state
|
||||
*/
|
||||
QueuedEnums::ProcessState pstate() const;
|
||||
/**
|
||||
* @brief process start time
|
||||
* @return process start time
|
||||
@ -239,12 +229,6 @@ public:
|
||||
* 4. {application} will be replaced to application line and arguments
|
||||
*/
|
||||
void setProcessLine(const QString &_processLine);
|
||||
/**
|
||||
* @brief set process state
|
||||
* @param _limits
|
||||
* new process state
|
||||
*/
|
||||
void setPState(const QueuedEnums::ProcessState _state);
|
||||
/**
|
||||
* @brief set start time
|
||||
* @param _time
|
||||
|
@ -36,6 +36,22 @@ class QueuedTokenManager : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @struct QueuedTokenDefinitions
|
||||
* @brief structure to define token
|
||||
* @var token
|
||||
* token ID
|
||||
* @var user
|
||||
* token owner user
|
||||
* @var validUntil
|
||||
* valid until
|
||||
*/
|
||||
typedef struct {
|
||||
QString token;
|
||||
QString user;
|
||||
QDateTime validUntil;
|
||||
} QueuedTokenDefinitions;
|
||||
|
||||
/**
|
||||
* @brief QueuedTokenManager class constructor
|
||||
* @param parent
|
||||
@ -50,22 +66,31 @@ public:
|
||||
* @brief check if token is valid
|
||||
* @param _token
|
||||
* token ID
|
||||
* @return true if token is valid otherwise return false
|
||||
* @return token user if token is valid otherwise return false
|
||||
*/
|
||||
bool isTokenValid(const QString &_token) const;
|
||||
QString isTokenValid(const QString &_token) const;
|
||||
/**
|
||||
* @brief upload tokens from database
|
||||
* @param _value
|
||||
* @brief load token
|
||||
* @param _definitions
|
||||
* token definitions
|
||||
*/
|
||||
void
|
||||
loadToken(const QueuedTokenManager::QueuedTokenDefinitions &_definitions);
|
||||
/**
|
||||
* @brief upload tokens from database
|
||||
* @param _value
|
||||
* tokens from database
|
||||
*/
|
||||
*/
|
||||
void loadTokens(const QList<QVariantHash> &_values);
|
||||
/**
|
||||
* @brief register new token
|
||||
* @param _user
|
||||
* token user
|
||||
* @param _validUntil
|
||||
* token valid until
|
||||
* @return new generated token
|
||||
*/
|
||||
QString registerToken(const QDateTime _validUntil);
|
||||
QString registerToken(const QString &_user, const QDateTime &_validUntil);
|
||||
/**
|
||||
* @brief token expiration
|
||||
* @param _token
|
||||
@ -90,20 +115,12 @@ signals:
|
||||
* token ID
|
||||
*/
|
||||
void tokenExpired(const QString &_token);
|
||||
/**
|
||||
* @brief signal which will be emitted on newly created token
|
||||
* @param _token
|
||||
* token ID
|
||||
* @param _validUntil
|
||||
* token valid until
|
||||
*/
|
||||
void tokenRegistered(const QString &_token, const QDateTime &_validUntil);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief token storage
|
||||
*/
|
||||
QHash<QString, QDateTime> m_tokens;
|
||||
QHash<QString, QueuedTokenDefinitions> m_tokens;
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,20 +43,6 @@ class QueuedUserManager : public QObject
|
||||
long long tokenExpiration READ tokenExpiration WRITE setTokenExpiration)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @struct UserAuthorization
|
||||
* user authorization structure
|
||||
* @remark only
|
||||
* @var token
|
||||
* authorization token
|
||||
* @var user
|
||||
* username, token owner
|
||||
*/
|
||||
typedef struct {
|
||||
QString token;
|
||||
QString user;
|
||||
} QueuedUserAuthorization;
|
||||
|
||||
/**
|
||||
* @brief QueuedUserManager class constructor
|
||||
* @param parent
|
||||
@ -86,16 +72,6 @@ public:
|
||||
*/
|
||||
QueuedUser *add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const long long _id);
|
||||
/**
|
||||
* @brief build user auth structure
|
||||
* @param _user
|
||||
* user name
|
||||
* @param _token
|
||||
* user token
|
||||
* @return generated structure
|
||||
*/
|
||||
static QueuedUserAuthorization auth(const QString &_user,
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief authorize user
|
||||
* @param _user
|
||||
@ -107,13 +83,13 @@ public:
|
||||
QString authorize(const QString &_user, const QString &_password);
|
||||
/**
|
||||
* @brief authorize user for service
|
||||
* @param _auth
|
||||
* user authorization structure
|
||||
* @param _token
|
||||
* user token
|
||||
* @param _service
|
||||
* service to authorize
|
||||
* @return true if user allowed to do it otherwise return false
|
||||
*/
|
||||
bool authorize(const QueuedUserAuthorization &_auth,
|
||||
bool authorize(const QString &_token,
|
||||
const QueuedEnums::Permission _service);
|
||||
/**
|
||||
* @brief check token expiration
|
||||
@ -154,9 +130,11 @@ public:
|
||||
* @brief user by name
|
||||
* @param _name
|
||||
* user name for search
|
||||
* @param _isToken
|
||||
* is passed name token or not
|
||||
* @return user by name or nullptr if no user found
|
||||
*/
|
||||
QueuedUser *user(const QString &_name);
|
||||
QueuedUser *user(const QString &_name, const bool _isToken);
|
||||
// properties
|
||||
/**
|
||||
* @brief token expiration
|
||||
|
@ -56,15 +56,13 @@ QueuedCore::~QueuedCore()
|
||||
/**
|
||||
* @fn addPlugin
|
||||
*/
|
||||
bool QueuedCore::addPlugin(
|
||||
const QString &_plugin,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::addPlugin(const QString &_plugin, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
||||
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user << "not allowed to add plugin";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add plugin";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -75,38 +73,36 @@ bool QueuedCore::addPlugin(
|
||||
/**
|
||||
* @addTask
|
||||
*/
|
||||
bool QueuedCore::addTask(
|
||||
const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const uint _nice, const long long _userId,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const uint _nice,
|
||||
const long long _userId,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
||||
<< "from user" << _userId;
|
||||
|
||||
auto authUser = m_users->user(_auth.user);
|
||||
auto authUser = m_users->user(_token, true);
|
||||
if (!authUser) {
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _auth.user;
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||
return false;
|
||||
}
|
||||
long long userAuthId = authUser->index();
|
||||
long long actualUserId = (_userId == -1) ? userAuthId : _userId;
|
||||
|
||||
// check permissions
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isUser = m_users->authorize(_auth, QueuedEnums::Permission::JobOwner);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
bool isUser = m_users->authorize(_token, QueuedEnums::Permission::JobOwner);
|
||||
if (userAuthId == actualUserId) {
|
||||
// it means that user places task as own one
|
||||
if (!isUser) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to add task";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// user tries to place task as another one
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to add task";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -119,23 +115,23 @@ bool QueuedCore::addTask(
|
||||
/**
|
||||
* @fn addUser
|
||||
*/
|
||||
bool QueuedCore::addUser(
|
||||
const QString &_name, const QString &_email, const QString &_password,
|
||||
const uint _permissions, const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool 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;
|
||||
|
||||
// check permissions
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user << "not allowed to add user";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add user";
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if already exists
|
||||
auto user = m_users->user(_name);
|
||||
auto user = m_users->user(_name, false);
|
||||
if (user) {
|
||||
qCWarning(LOG_LIB) << "User" << _name << "already exists";
|
||||
return false;
|
||||
@ -148,41 +144,36 @@ bool QueuedCore::addUser(
|
||||
/**
|
||||
* @fn authorization
|
||||
*/
|
||||
QueuedUserManager::QueuedUserAuthorization
|
||||
QueuedCore::authorization(const QString &_name, const QString &_password)
|
||||
QString QueuedCore::authorization(const QString &_name,
|
||||
const QString &_password)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Authorize user" << _name;
|
||||
|
||||
QString token = m_users->authorize(_name, _password);
|
||||
QueuedUserManager::QueuedUserAuthorization auth;
|
||||
auth.user = _name;
|
||||
auth.token = token;
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
QVariantHash payload = {
|
||||
{"token", token},
|
||||
{"user", _name},
|
||||
{"validUntil", m_users->checkToken(token).toString(Qt::ISODate)}};
|
||||
m_database->add(QueuedDB::TOKENS_TABLE, payload);
|
||||
}
|
||||
|
||||
return auth;
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn editOption
|
||||
*/
|
||||
bool QueuedCore::editOption(
|
||||
const QString &_key, const QVariant &_value,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::editOption(const QString &_key, const QVariant &_value,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
||||
|
||||
// check permissions
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to edit options";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit options";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -193,9 +184,8 @@ bool QueuedCore::editOption(
|
||||
/**
|
||||
* @fn editTask
|
||||
*/
|
||||
bool QueuedCore::editTask(
|
||||
const long long _id, const QVariantHash &_taskData,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
||||
|
||||
@ -206,33 +196,31 @@ bool QueuedCore::editTask(
|
||||
}
|
||||
|
||||
// check permissions
|
||||
auto authUser = m_users->user(_auth.user);
|
||||
auto authUser = m_users->user(_token, true);
|
||||
if (!authUser) {
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _auth.user;
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||
return false;
|
||||
}
|
||||
long long userAuthId = authUser->index();
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isUser = m_users->authorize(_auth, QueuedEnums::Permission::JobOwner);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
bool isUser = m_users->authorize(_token, QueuedEnums::Permission::JobOwner);
|
||||
if (userAuthId == task->user()) {
|
||||
// it means that user edits own task
|
||||
if (!isUser) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to edit task";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// user tries to edit random task
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to edit task";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// only admin can edit run/stopped task
|
||||
if (task->pstate() != QueuedEnums::ProcessState::NotRunning) {
|
||||
if (!task->startTime().isNull()) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
qCInfo(LOG_LIB) << "User" << _token
|
||||
<< "not allowed to edit run/exited task";
|
||||
return false;
|
||||
}
|
||||
@ -250,9 +238,8 @@ bool QueuedCore::editTask(
|
||||
/**
|
||||
* @fn editUser
|
||||
*/
|
||||
bool QueuedCore::editUser(
|
||||
const long long _id, const QVariantHash &_userData,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::editUser(const long long _id, const QVariantHash &_userData,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
||||
|
||||
@ -263,17 +250,16 @@ bool QueuedCore::editUser(
|
||||
}
|
||||
|
||||
// check permissions
|
||||
auto authUser = m_users->user(_auth.user);
|
||||
auto authUser = m_users->user(_token, true);
|
||||
if (!authUser) {
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _auth.user;
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||
return false;
|
||||
}
|
||||
long long userAuthId = authUser->index();
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (userAuthId != _id) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to edit user";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit user";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -290,24 +276,24 @@ bool QueuedCore::editUser(
|
||||
/**
|
||||
* @fn editUserPermission
|
||||
*/
|
||||
bool QueuedCore::editUserPermission(
|
||||
const long long _id, const QueuedEnums::Permission &_permission,
|
||||
const bool _add, const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
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(_auth.user);
|
||||
auto authUser = m_users->user(_token, true);
|
||||
if (!authUser) {
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _auth.user;
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||
return false;
|
||||
}
|
||||
long long userAuthId = authUser->index();
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (userAuthId != _id) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
qCInfo(LOG_LIB) << "User" << _token
|
||||
<< "not allowed to edit permissions";
|
||||
return false;
|
||||
}
|
||||
@ -351,16 +337,13 @@ QVariantHash QueuedCore::pluginSettings(const QString &_plugin)
|
||||
/**
|
||||
* @fn removePlugin
|
||||
*/
|
||||
bool QueuedCore::removePlugin(
|
||||
const QString &_plugin,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::removePlugin(const QString &_plugin, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
||||
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to remove plugin";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to remove plugin";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -371,24 +354,21 @@ bool QueuedCore::removePlugin(
|
||||
/**
|
||||
* @fn startTask
|
||||
*/
|
||||
bool QueuedCore::startTask(
|
||||
const long long _id,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::startTask(const long long _id, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
||||
|
||||
// check permissions
|
||||
auto authUser = m_users->user(_auth.user);
|
||||
auto authUser = m_users->user(_token, true);
|
||||
if (!authUser) {
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _auth.user;
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||
return false;
|
||||
}
|
||||
long long userAuthId = authUser->index();
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (userAuthId != _id) {
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to start tasks";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to start tasks";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -402,9 +382,7 @@ bool QueuedCore::startTask(
|
||||
/**
|
||||
* @fn stopTask
|
||||
*/
|
||||
bool QueuedCore::stopTask(
|
||||
const long long _id,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
bool QueuedCore::stopTask(const long long _id, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
||||
|
||||
@ -415,26 +393,24 @@ bool QueuedCore::stopTask(
|
||||
}
|
||||
|
||||
// check permissions
|
||||
auto authUser = m_users->user(_auth.user);
|
||||
auto authUser = m_users->user(_token, true);
|
||||
if (!authUser) {
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _auth.user;
|
||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||
return false;
|
||||
}
|
||||
long long userAuthId = authUser->index();
|
||||
bool isAdmin = m_users->authorize(_auth, QueuedEnums::Permission::Admin);
|
||||
bool isUser = m_users->authorize(_auth, QueuedEnums::Permission::JobOwner);
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
bool isUser = m_users->authorize(_token, QueuedEnums::Permission::JobOwner);
|
||||
if (userAuthId == task->user()) {
|
||||
// it means that user edits own task
|
||||
if (!isUser) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to stop task";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// user tries to edit random task
|
||||
if (!isAdmin) {
|
||||
qCInfo(LOG_LIB) << "User" << _auth.user
|
||||
<< "not allowed to stop task";
|
||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -682,7 +658,7 @@ void QueuedCore::initPlugins()
|
||||
QStringList pluginList
|
||||
= m_advancedSettings->get(QueuedCfg::QueuedSettings::Plugins)
|
||||
.toString()
|
||||
.split('\x01');
|
||||
.split('\n');
|
||||
|
||||
m_plugins = new QueuedPluginManager(this);
|
||||
for (auto &plugin : pluginList)
|
||||
@ -704,10 +680,8 @@ void QueuedCore::initProcesses()
|
||||
.toString();
|
||||
|
||||
m_processes = new QueuedProcessManager(this, processLine, onExitAction);
|
||||
auto dbProcesses = m_database->get(
|
||||
QueuedDB::TASKS_TABLE,
|
||||
QString("WHERE state != %1")
|
||||
.arg(static_cast<int>(QueuedEnums::ProcessState::Exited)));
|
||||
auto dbProcesses = m_database->get(QueuedDB::TASKS_TABLE,
|
||||
QString("WHERE endTime IS NULL"));
|
||||
m_processes->loadProcesses(dbProcesses);
|
||||
|
||||
m_connections
|
||||
@ -813,14 +787,15 @@ bool QueuedCore::addTaskPrivate(const QString &_command,
|
||||
QueuedLimits::Limits(
|
||||
m_advancedSettings->get(QueuedCfg::QueuedSettings::DefaultLimits)
|
||||
.toString()));
|
||||
QVariantHash properties = {{"user", _userId},
|
||||
{"command", _command},
|
||||
{"commandArguments", _arguments},
|
||||
{"workDirectory", _workingDirectory},
|
||||
{"nice", _nice},
|
||||
{"uid", ids.first},
|
||||
{"gid", ids.second},
|
||||
{"limits", taskLimits.toString()}};
|
||||
QVariantHash properties
|
||||
= {{"user", _userId},
|
||||
{"command", _command},
|
||||
{"commandArguments", _arguments},
|
||||
{"workDirectory", _workingDirectory},
|
||||
{"nice", _nice},
|
||||
{"uid", ids.first},
|
||||
{"gid", ids.second},
|
||||
{"limits", taskLimits.toString()}};
|
||||
auto id = m_database->add(QueuedDB::TASKS_TABLE, properties);
|
||||
if (id == -1) {
|
||||
qCWarning(LOG_LIB) << "Could not add task" << _command;
|
||||
@ -903,7 +878,7 @@ bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add)
|
||||
QStringList pluginList
|
||||
= m_advancedSettings->get(QueuedCfg::QueuedSettings::Plugins)
|
||||
.toString()
|
||||
.split('\x01');
|
||||
.split('\n');
|
||||
|
||||
bool status = false;
|
||||
if (_add && !pluginList.contains(_plugin))
|
||||
|
@ -54,7 +54,7 @@ QString QueuedCoreInterface::Auth(const QString &name, const QString &password)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Authorize user" << name;
|
||||
|
||||
return m_core->authorization(name, password).token;
|
||||
return m_core->authorization(name, password);
|
||||
}
|
||||
|
||||
|
||||
@ -63,26 +63,22 @@ QString QueuedCoreInterface::Auth(const QString &name, const QString &password)
|
||||
*/
|
||||
bool QueuedCoreInterface::OptionEdit(const QString &key,
|
||||
const QDBusVariant &value,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant() << "auth by"
|
||||
<< whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant();
|
||||
|
||||
return m_core->editOption(key, value.variant(),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->editOption(key, value.variant(), token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn PluginAdd
|
||||
*/
|
||||
bool QueuedCoreInterface::PluginAdd(const QString &plugin,
|
||||
const QString &whoAmI, const QString &token)
|
||||
bool QueuedCoreInterface::PluginAdd(const QString &plugin, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add plugin" << plugin << "auth by" << whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Add plugin" << plugin;
|
||||
|
||||
return m_core->addPlugin(plugin, QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->addPlugin(plugin, token);
|
||||
}
|
||||
|
||||
|
||||
@ -90,12 +86,11 @@ bool QueuedCoreInterface::PluginAdd(const QString &plugin,
|
||||
* @fn PluginRemove
|
||||
*/
|
||||
bool QueuedCoreInterface::PluginRemove(const QString &plugin,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Remove plugin" << plugin << "auth by" << whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Remove plugin" << plugin;
|
||||
|
||||
return m_core->removePlugin(plugin, QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->removePlugin(plugin, token);
|
||||
}
|
||||
|
||||
|
||||
@ -106,35 +101,35 @@ bool QueuedCoreInterface::TaskAdd(
|
||||
const QString &command, const QStringList &arguments,
|
||||
const QString &workingDirectory, const uint nice, const long long user,
|
||||
const long long cpu, const long long gpu, const QString &memory,
|
||||
const QString &gpumemory, const QString &storage, const QString &whoAmI,
|
||||
const QString &token)
|
||||
const QString &gpumemory, const QString &storage, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments
|
||||
<< workingDirectory << nice << "from user" << user
|
||||
<< "auth by" << whoAmI;
|
||||
<< workingDirectory << nice << "from user" << user;
|
||||
|
||||
return m_core->addTask(
|
||||
command, arguments, workingDirectory, nice, user,
|
||||
QueuedLimits::Limits(cpu, gpu, QueuedLimits::convertMemory(memory),
|
||||
QueuedLimits::convertMemory(gpumemory),
|
||||
QueuedLimits::convertMemory(storage)),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskEdit
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskEdit(
|
||||
const qlonglong id, const QString &command, const QStringList &arguments,
|
||||
const QString &directory, const uint nice, const uint uid, const uint gid,
|
||||
const uint state, const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory, const QString &storage,
|
||||
const QString &whoAmI, const QString &token)
|
||||
bool QueuedCoreInterface::TaskEdit(const qlonglong id, const QString &command,
|
||||
const QStringList &arguments,
|
||||
const QString &directory, const uint nice,
|
||||
const uint uid, const uint gid,
|
||||
const uint state, const long long cpu,
|
||||
const long long gpu, const QString &memory,
|
||||
const QString &gpumemory,
|
||||
const QString &storage, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Edit task" << id << command << arguments << directory
|
||||
<< nice << uid << gid << state << cpu << gpu << memory
|
||||
<< gpumemory << storage << "auth by" << whoAmI;
|
||||
<< gpumemory << storage;
|
||||
|
||||
auto task = m_core->task(id);
|
||||
if (!task) {
|
||||
@ -172,31 +167,29 @@ bool QueuedCoreInterface::TaskEdit(
|
||||
limits.storage = QueuedLimits::convertMemory(storage);
|
||||
data[QString("limits")] = limits.toString();
|
||||
|
||||
return m_core->editTask(id, data, QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->editTask(id, data, token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskStart
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskStart(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token)
|
||||
bool QueuedCoreInterface::TaskStart(const qlonglong id, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Force start task" << id << "auth by" << whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Force start task" << id;
|
||||
|
||||
return m_core->startTask(id, QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->startTask(id, token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskStop
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskStop(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token)
|
||||
bool QueuedCoreInterface::TaskStop(const qlonglong id, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Force stop task" << id << "auth by" << whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Force stop task" << id;
|
||||
|
||||
return m_core->stopTask(id, QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->stopTask(id, token);
|
||||
}
|
||||
|
||||
|
||||
@ -208,18 +201,17 @@ bool QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
||||
const uint permissions, const long long cpu,
|
||||
const long long gpu, const QString &memory,
|
||||
const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token)
|
||||
const QString &storage, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email
|
||||
<< permissions << "auth by" << whoAmI;
|
||||
<< permissions;
|
||||
|
||||
return m_core->addUser(
|
||||
name, email, password, permissions,
|
||||
QueuedLimits::Limits(cpu, gpu, QueuedLimits::convertMemory(memory),
|
||||
QueuedLimits::convertMemory(gpumemory),
|
||||
QueuedLimits::convertMemory(storage)),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
token);
|
||||
}
|
||||
|
||||
|
||||
@ -231,11 +223,10 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||
const QString &email, const long long cpu,
|
||||
const long long gpu, const QString &memory,
|
||||
const QString &gpumemory,
|
||||
const QString &storage,
|
||||
const QString &whoAmI, const QString &token)
|
||||
const QString &storage, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Edit user" << id << name << email << cpu << gpu
|
||||
<< memory << gpumemory << storage << "auth by" << whoAmI;
|
||||
<< memory << gpumemory << storage;
|
||||
|
||||
// get user object first to match limits
|
||||
auto user = m_core->user(id);
|
||||
@ -266,7 +257,7 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||
limits.storage = QueuedLimits::convertMemory(storage);
|
||||
data[QString("limits")] = limits.toString();
|
||||
|
||||
return m_core->editUser(id, data, QueuedUserManager::auth(whoAmI, token));
|
||||
return m_core->editUser(id, data, token);
|
||||
}
|
||||
|
||||
|
||||
@ -275,15 +266,12 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||
*/
|
||||
bool QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
||||
const uint permission,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id
|
||||
<< "auth by" << whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id;
|
||||
|
||||
return m_core->editUserPermission(
|
||||
id, static_cast<QueuedEnums::Permission>(permission), true,
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
id, static_cast<QueuedEnums::Permission>(permission), true, token);
|
||||
}
|
||||
|
||||
|
||||
@ -292,13 +280,10 @@ bool QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
||||
*/
|
||||
bool QueuedCoreInterface::UserPermissionRemove(const qlonglong id,
|
||||
const uint permission,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id
|
||||
<< "auth by" << whoAmI;
|
||||
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id;
|
||||
|
||||
return m_core->editUserPermission(
|
||||
id, static_cast<QueuedEnums::Permission>(permission), false,
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
id, static_cast<QueuedEnums::Permission>(permission), false, token);
|
||||
}
|
||||
|
@ -41,14 +41,12 @@ QueuedProcess::QueuedProcess(QObject *parent,
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
qRegisterMetaType<QueuedLimits::Limits>("QueuedLimits::Limits");
|
||||
|
||||
// update QProcess related values as well
|
||||
// TODO configuration
|
||||
setCommand(m_definitions.command);
|
||||
setCommandArguments(m_definitions.arguments);
|
||||
setWorkDirectory(m_definitions.workingDirectory);
|
||||
|
||||
setStandardErrorFile(QString("%1-err.log").arg(name()), QIODevice::Append);
|
||||
setStandardOutputFile(QString("%1-out.log").arg(name()), QIODevice::Append);
|
||||
}
|
||||
|
||||
|
||||
@ -91,14 +89,14 @@ void QueuedProcess::updateArguments()
|
||||
0, 'f', 0));
|
||||
|
||||
// command line
|
||||
QString commandLine = command() + "\x01" + commandArguments().join('\x01');
|
||||
QString commandLine = command() + "\n" + commandArguments().join('\n');
|
||||
application.replace("{application}", commandLine);
|
||||
|
||||
QStringList arguments = application.split('\x01');
|
||||
QStringList arguments = application.split('\n');
|
||||
|
||||
// set QProcess properties
|
||||
setProgram(arguments.takeFirst());
|
||||
setCommandArguments(arguments);
|
||||
setArguments(arguments);
|
||||
}
|
||||
|
||||
|
||||
@ -192,15 +190,6 @@ QString QueuedProcess::processLine() const
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn pstate
|
||||
*/
|
||||
QueuedEnums::ProcessState QueuedProcess::pstate() const
|
||||
{
|
||||
return m_definitions.state;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn startTime
|
||||
*/
|
||||
@ -319,17 +308,6 @@ void QueuedProcess::setProcessLine(const QString &_processLine)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setPState
|
||||
*/
|
||||
void QueuedProcess::setPState(const QueuedEnums::ProcessState _state)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set process state to" << static_cast<int>(_state);
|
||||
|
||||
m_definitions.state = _state;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setStartTime
|
||||
*/
|
||||
@ -372,6 +350,12 @@ void QueuedProcess::setWorkDirectory(const QString &_workDirectory)
|
||||
qCDebug(LOG_LIB) << "Set working directory to" << _workDirectory;
|
||||
|
||||
m_definitions.workingDirectory = _workDirectory;
|
||||
setStandardErrorFile(
|
||||
QString("%1/%2-err.log").arg(_workDirectory).arg(name()),
|
||||
QIODevice::Append);
|
||||
setStandardOutputFile(
|
||||
QString("%1/%2-out.log").arg(_workDirectory).arg(name()),
|
||||
QIODevice::Append);
|
||||
setWorkingDirectory(_workDirectory);
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,9 @@ QueuedProcessManager::QueuedProcessManager(QObject *parent,
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
qRegisterMetaType<QueuedProcessManager::OnExitAction>(
|
||||
"QueuedProcessManager::OnExitAction");
|
||||
|
||||
setOnExitAction(onExit);
|
||||
setProcessLine(processLine);
|
||||
}
|
||||
@ -47,7 +50,7 @@ QueuedProcessManager::~QueuedProcessManager()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
QList<long long> indices = m_processes.keys();
|
||||
QList<long long> indices = processes().keys();
|
||||
for (auto index : indices)
|
||||
remove(index);
|
||||
}
|
||||
@ -66,7 +69,7 @@ QueuedProcess *QueuedProcessManager::add(const QVariantHash &_properties,
|
||||
// parameters
|
||||
defs.command = _properties[QString("command")].toString();
|
||||
defs.arguments = _properties[QString("commandArguments")].toString().split(
|
||||
QChar('\x01'));
|
||||
QChar('\n'));
|
||||
defs.workingDirectory = _properties[QString("workDirectory")].toString();
|
||||
defs.nice = _properties[QString("nice")].toUInt();
|
||||
defs.limits = _properties[QString("limits")].toString();
|
||||
@ -94,10 +97,11 @@ QueuedProcess *QueuedProcessManager::add(
|
||||
qCDebug(LOG_LIB) << "Add new process" << _definitions.command
|
||||
<< "with index" << _index;
|
||||
|
||||
if (m_processes.contains(_index))
|
||||
return m_processes[_index];
|
||||
if (processes().contains(_index))
|
||||
return process(_index);
|
||||
|
||||
QueuedProcess *process = new QueuedProcess(this, _definitions, _index);
|
||||
process->setProcessLine(processLine());
|
||||
m_processes[_index] = process;
|
||||
// connect to signal
|
||||
m_connections[_index] = connect(
|
||||
@ -107,6 +111,8 @@ QueuedProcess *QueuedProcessManager::add(
|
||||
return taskFinished(exitCode, exitStatus, _index);
|
||||
});
|
||||
|
||||
// check if we can start new task
|
||||
start();
|
||||
return process;
|
||||
}
|
||||
|
||||
@ -150,7 +156,7 @@ void QueuedProcessManager::remove(const long long _index)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Remove process by index" << _index;
|
||||
|
||||
if (!m_processes.contains(_index))
|
||||
if (!processes().contains(_index))
|
||||
return;
|
||||
|
||||
QueuedProcess *pr = m_processes.take(_index);
|
||||
@ -188,6 +194,9 @@ void QueuedProcessManager::start()
|
||||
|
||||
auto tasks = processes().values();
|
||||
for (auto pr : tasks) {
|
||||
// check task state
|
||||
if (pr->state() != QProcess::ProcessState::NotRunning)
|
||||
continue;
|
||||
// check limits first
|
||||
if (((1.0 - weightedCpu)
|
||||
< QueuedSystemInfo::cpuWeight(pr->nativeLimits().cpu))
|
||||
@ -222,8 +231,10 @@ void QueuedProcessManager::start(const long long _index)
|
||||
return;
|
||||
}
|
||||
|
||||
QDateTime start = QDateTime::currentDateTimeUtc();
|
||||
pr->start();
|
||||
emit(taskStartTimeReceived(_index, QDateTime::currentDateTimeUtc()));
|
||||
pr->setStartTime(start);
|
||||
emit(taskStartTimeReceived(_index, start));
|
||||
}
|
||||
|
||||
|
||||
@ -288,7 +299,7 @@ void QueuedProcessManager::setProcessLine(const QString _processLine)
|
||||
qCDebug(LOG_LIB) << "Set process line to" << _processLine;
|
||||
|
||||
m_processLine = _processLine;
|
||||
for (auto process : m_processes.values())
|
||||
for (auto process : processes().values())
|
||||
process->setProcessLine(processLine());
|
||||
}
|
||||
|
||||
@ -302,35 +313,35 @@ QueuedLimits::Limits QueuedProcessManager::usedLimits()
|
||||
long long cpu = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
return process->state() == QProcess::ProcessState::Running
|
||||
? value + process->nativeLimits().cpu
|
||||
: value;
|
||||
});
|
||||
long long gpu = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
return process->state() == QProcess::ProcessState::Running
|
||||
? value + process->nativeLimits().gpu
|
||||
: value;
|
||||
});
|
||||
long long memory = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
return process->state() == QProcess::ProcessState::Running
|
||||
? value + process->nativeLimits().memory
|
||||
: value;
|
||||
});
|
||||
long long gpumemory = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
return process->state() == QProcess::ProcessState::Running
|
||||
? value + process->nativeLimits().gpumemory
|
||||
: value;
|
||||
});
|
||||
long long storage = std::accumulate(
|
||||
tasks.cbegin(), tasks.cend(), 0,
|
||||
[](long long value, QueuedProcess *process) {
|
||||
return process->pstate() == QueuedEnums::ProcessState::Running
|
||||
return process->state() == QProcess::ProcessState::Running
|
||||
? value + process->nativeLimits().storage
|
||||
: value;
|
||||
});
|
||||
@ -352,7 +363,7 @@ void QueuedProcessManager::taskFinished(const int _exitCode,
|
||||
auto pr = process(_index);
|
||||
if (pr) {
|
||||
auto endTime = QDateTime::currentDateTimeUtc();
|
||||
pr->setEndTime(endTime);
|
||||
remove(_index);
|
||||
emit(taskStopTimeReceived(_index, endTime));
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,10 @@ QueuedSettings::QueuedSettings(QObject *parent, const QString path)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
qRegisterMetaType<QueuedCfg::QueuedAdminSetup>(
|
||||
"QueuedCfg::QueuedAdminSetup");
|
||||
qRegisterMetaType<QueuedCfg::QueuedDBSetup>("QueuedCfg::QueuedDBSetup");
|
||||
|
||||
readConfiguration();
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <QTimer>
|
||||
#include <QUuid>
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -52,12 +53,38 @@ QueuedTokenManager::~QueuedTokenManager()
|
||||
/**
|
||||
* @fn isTokenValid
|
||||
*/
|
||||
bool QueuedTokenManager::isTokenValid(const QString &_token) const
|
||||
QString QueuedTokenManager::isTokenValid(const QString &_token) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Check token on validity" << _token;
|
||||
|
||||
return m_tokens.contains(_token)
|
||||
&& (tokenExpiration(_token) > QDateTime::currentDateTimeUtc());
|
||||
if (m_tokens.contains(_token)
|
||||
&& (tokenExpiration(_token) > QDateTime::currentDateTimeUtc()))
|
||||
return m_tokens[_token].user;
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief loadToken
|
||||
*/
|
||||
void QueuedTokenManager::loadToken(
|
||||
const QueuedTokenManager::QueuedTokenDefinitions &_definitions)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add toen for user" << _definitions.user
|
||||
<< "valud until" << _definitions.validUntil;
|
||||
|
||||
m_tokens[_definitions.token] = _definitions;
|
||||
|
||||
// register expiry timer
|
||||
std::chrono::milliseconds duration(
|
||||
_definitions.validUntil.toMSecsSinceEpoch()
|
||||
- QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
timer.setInterval(duration);
|
||||
connect(&timer, &QTimer::timeout,
|
||||
[this, _definitions]() { return expireToken(_definitions.token); });
|
||||
}
|
||||
|
||||
|
||||
@ -71,17 +98,8 @@ void QueuedTokenManager::loadTokens(const QList<QVariantHash> &_values)
|
||||
for (auto &token : _values) {
|
||||
QDateTime validUntil = QDateTime::fromString(
|
||||
token[QString("validUntil")].toString(), Qt::ISODate);
|
||||
QString tokenId = token[QString("token")].toString();
|
||||
m_tokens[tokenId] = validUntil;
|
||||
// create timer
|
||||
std::chrono::milliseconds duration(
|
||||
validUntil.toMSecsSinceEpoch()
|
||||
- QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
timer.setInterval(duration);
|
||||
connect(&timer, &QTimer::timeout,
|
||||
[this, tokenId]() { return expireToken(tokenId); });
|
||||
loadToken({token[QString("token")].toString(),
|
||||
token[QString("user")].toString(), validUntil});
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +107,8 @@ void QueuedTokenManager::loadTokens(const QList<QVariantHash> &_values)
|
||||
/**
|
||||
* @fn registerToken
|
||||
*/
|
||||
QString QueuedTokenManager::registerToken(const QDateTime _validUntil)
|
||||
QString QueuedTokenManager::registerToken(const QString &_user,
|
||||
const QDateTime &_validUntil)
|
||||
{
|
||||
// generate from uuid
|
||||
QString token
|
||||
@ -98,8 +117,7 @@ QString QueuedTokenManager::registerToken(const QDateTime _validUntil)
|
||||
<< _validUntil;
|
||||
|
||||
// append to internal storage
|
||||
m_tokens[token] = _validUntil;
|
||||
emit(tokenRegistered(token, _validUntil));
|
||||
loadToken({token, _user, _validUntil});
|
||||
|
||||
// and return requester
|
||||
return token;
|
||||
@ -111,7 +129,7 @@ QString QueuedTokenManager::registerToken(const QDateTime _validUntil)
|
||||
*/
|
||||
QDateTime QueuedTokenManager::tokenExpiration(const QString &_token) const
|
||||
{
|
||||
return m_tokens[_token];
|
||||
return m_tokens[_token].validUntil;
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,6 +44,8 @@ QueuedUser::QueuedUser(QObject *parent,
|
||||
, m_index(index)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
qRegisterMetaType<QueuedLimits::Limits>("QueuedLimits::Limits");
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,22 +93,6 @@ QueuedUserManager::add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn auth
|
||||
*/
|
||||
QueuedUserManager::QueuedUserAuthorization
|
||||
QueuedUserManager::auth(const QString &_user, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Generate auth structure for user" << _user;
|
||||
|
||||
QueuedUserAuthorization authObj;
|
||||
authObj.user = _user;
|
||||
authObj.token = _token;
|
||||
|
||||
return authObj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn authorize
|
||||
*/
|
||||
@ -117,7 +101,7 @@ QString QueuedUserManager::authorize(const QString &_user,
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Authorize user" << _user;
|
||||
|
||||
auto userObj = user(_user);
|
||||
auto userObj = user(_user, false);
|
||||
if (!userObj) {
|
||||
qCInfo(LOG_LIB) << "No user found" << _user;
|
||||
return QString();
|
||||
@ -132,28 +116,27 @@ QString QueuedUserManager::authorize(const QString &_user,
|
||||
auto time = QDateTime::currentDateTimeUtc();
|
||||
QDateTime expiry = time.addDays(tokenExpiration());
|
||||
emit(userLoggedIn(userObj->index(), time));
|
||||
return m_tokens->registerToken(expiry);
|
||||
return m_tokens->registerToken(_user, expiry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn authorize
|
||||
*/
|
||||
bool QueuedUserManager::authorize(const QueuedUserAuthorization &_auth,
|
||||
bool QueuedUserManager::authorize(const QString &_token,
|
||||
const QueuedEnums::Permission _service)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Authorize user" << _auth.user << "for"
|
||||
<< static_cast<int>(_service);
|
||||
qCDebug(LOG_LIB) << "Authorize user for" << static_cast<int>(_service);
|
||||
|
||||
bool status = m_tokens->isTokenValid(_auth.token);
|
||||
if (!status) {
|
||||
qCInfo(LOG_LIB) << "Token invalid for user" << _auth.user;
|
||||
QString username = m_tokens->isTokenValid(_token);
|
||||
if (username.isEmpty()) {
|
||||
qCInfo(LOG_LIB) << "Token" << _token << "invalid";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto userObj = user(_auth.user);
|
||||
auto userObj = user(username, false);
|
||||
if (!userObj) {
|
||||
qCInfo(LOG_LIB) << "No user found" << _auth.user;
|
||||
qCInfo(LOG_LIB) << "No user found" << username;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -167,8 +150,10 @@ bool QueuedUserManager::authorize(const QueuedUserAuthorization &_auth,
|
||||
QDateTime QueuedUserManager::checkToken(const QString &_token,
|
||||
bool *_valid) const
|
||||
{
|
||||
if (_valid)
|
||||
*_valid = m_tokens->isTokenValid(_token);
|
||||
if (_valid) {
|
||||
QString user = m_tokens->isTokenValid(_token);
|
||||
*_valid = !user.isEmpty();
|
||||
}
|
||||
|
||||
return m_tokens->tokenExpiration(_token);
|
||||
}
|
||||
@ -235,11 +220,14 @@ QueuedUser *QueuedUserManager::user(const long long _id)
|
||||
/**
|
||||
* @fn user
|
||||
*/
|
||||
QueuedUser *QueuedUserManager::user(const QString &_name)
|
||||
QueuedUser *QueuedUserManager::user(const QString &_name, const bool _isToken)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Look for user" << _name;
|
||||
qCDebug(LOG_LIB) << "Look for user" << _name << "is token" << _isToken;
|
||||
|
||||
return m_users.value(_name, nullptr);
|
||||
if (_isToken)
|
||||
return m_users.value(m_tokens->isTokenValid(_name), nullptr);
|
||||
else
|
||||
return m_users.value(_name, nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user