mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
implement support of new commands to clients
This commit is contained in:
parent
5f229b8ade
commit
4f9e3d6639
@ -84,6 +84,8 @@ QueuedTcpServerResponseHelper::pathToEnum(const QString &_path)
|
||||
return RequestPath::Option;
|
||||
else if (_path == "permissions")
|
||||
return RequestPath::Permissions;
|
||||
else if (_path == "plugin")
|
||||
return RequestPath::Plugin;
|
||||
else if (_path == "plugins")
|
||||
return RequestPath::Plugins;
|
||||
else if (_path == "reports")
|
||||
|
@ -27,6 +27,7 @@ enum class RequestPath {
|
||||
Auth,
|
||||
Option,
|
||||
Permissions,
|
||||
Plugin,
|
||||
Plugins,
|
||||
Reports,
|
||||
Status,
|
||||
|
@ -68,6 +68,13 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Plugin:
|
||||
if (_type == "GET")
|
||||
output
|
||||
= QueuedTcpServerResponseHelperPlugins::getPlugin(_arg, _token);
|
||||
else
|
||||
output = {{"code", 405}};
|
||||
break;
|
||||
case QueuedTcpServerResponseHelper::RequestPath::Plugins:
|
||||
if (_type == "DELETE")
|
||||
output = QueuedTcpServerResponseHelperPlugins::removePlugin(_arg,
|
||||
|
@ -30,7 +30,8 @@ QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
[&output](const QVariant &val) {
|
||||
output = {{"code", 200}, {"token", val}};
|
||||
QVariantHash opt = {{"_option", val}};
|
||||
output = {{"code", 200}, {"properties", opt}};
|
||||
},
|
||||
[&output](const QueuedError &) {
|
||||
output = {{"code", 404}, {"message", "Option not found"}};
|
||||
|
@ -40,6 +40,29 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
||||
}
|
||||
|
||||
|
||||
QVariantHash
|
||||
QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_SERV) << "Get plugin" << _name;
|
||||
|
||||
auto res = QueuedCoreAdaptor::getPlugin(_name, _token);
|
||||
|
||||
QVariantHash output;
|
||||
res.match(
|
||||
[&output](const QueuedPluginSpecification::Plugin &val) {
|
||||
auto dump = QueuedPluginSpecification::dumpSpecification(val);
|
||||
QVariantList plugins = {dump};
|
||||
output = {{"code", 200}, {"plugins", plugins}};
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||
{
|
||||
auto res = QueuedCoreAdaptor::getOption(
|
||||
|
@ -23,6 +23,7 @@
|
||||
namespace QueuedTcpServerResponseHelperPlugins
|
||||
{
|
||||
QVariantHash addPlugin(const QString &_name, const QString &_token);
|
||||
QVariantHash getPlugin(const QString &_name, const QString &_token);
|
||||
QVariantHash listPlugins();
|
||||
QVariantHash removePlugin(const QString &_name, const QString &_token);
|
||||
};
|
||||
|
@ -40,6 +40,10 @@ namespace QueuedLimits
|
||||
{
|
||||
struct Limits;
|
||||
}
|
||||
namespace QueuedPluginSpecification
|
||||
{
|
||||
struct Plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief aggregator of queued classes
|
||||
@ -228,8 +232,8 @@ public:
|
||||
* user auth token
|
||||
* @return dictionary of PluginSpecification representation
|
||||
*/
|
||||
QueuedResult<QVariantHash> plugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
||||
plugin(const QString &_plugin, const QString &_token);
|
||||
/**
|
||||
* @brief get plugin settings
|
||||
* @param _plugin
|
||||
|
@ -204,6 +204,16 @@ sendUserPermissionRemove(const long long _id,
|
||||
*/
|
||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
||||
getPlugin(const QString &_plugin, const QString &_token);
|
||||
/**
|
||||
* @brief get plugin options
|
||||
* @param _plugin
|
||||
* plugin name
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return plugin options dictionary
|
||||
*/
|
||||
QueuedResult<QVariantHash> getPluginOptions(const QString &_plugin,
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief get option
|
||||
* @param _property
|
||||
|
@ -24,6 +24,7 @@
|
||||
#ifndef QUEUEDPLUGINSPECIFICATION_H
|
||||
#define QUEUEDPLUGINSPECIFICATION_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
|
||||
|
||||
@ -51,6 +52,50 @@ struct PluginOption {
|
||||
QString name;
|
||||
QString type;
|
||||
};
|
||||
/**
|
||||
* @brief DBus marshalling method
|
||||
* @param _argument
|
||||
* output DBus argument
|
||||
* @param _arg
|
||||
* input variant object
|
||||
* @return appended argument body
|
||||
*/
|
||||
inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
||||
const PluginOption &_arg)
|
||||
{
|
||||
_argument.beginStructure();
|
||||
_argument << QDBusVariant(_arg.defaultValue.isValid() ? _arg.defaultValue
|
||||
: "");
|
||||
_argument << _arg.description;
|
||||
_argument << _arg.name;
|
||||
_argument << _arg.type;
|
||||
_argument.endStructure();
|
||||
|
||||
return _argument;
|
||||
};
|
||||
/**
|
||||
* @brief DBus un-marshalling method
|
||||
* @param _argument
|
||||
* input DBus argument
|
||||
* @param _arg
|
||||
* output variant object
|
||||
* @return source DBus argument
|
||||
*/
|
||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
||||
PluginOption &_arg)
|
||||
{
|
||||
QDBusVariant variant;
|
||||
|
||||
_argument.beginStructure();
|
||||
_argument >> variant;
|
||||
_arg.defaultValue = variant.variant();
|
||||
_argument >> _arg.description;
|
||||
_argument >> _arg.name;
|
||||
_argument >> _arg.type;
|
||||
_argument.endStructure();
|
||||
|
||||
return _argument;
|
||||
};
|
||||
/**
|
||||
* @struct Plugin
|
||||
* @brief plugin specification structure
|
||||
@ -72,6 +117,47 @@ struct Plugin {
|
||||
QString license;
|
||||
QList<PluginOption> options;
|
||||
};
|
||||
/**
|
||||
* @brief DBus marshalling method
|
||||
* @param _argument
|
||||
* output DBus argument
|
||||
* @param _arg
|
||||
* input variant object
|
||||
* @return appended argument body
|
||||
*/
|
||||
inline QDBusArgument &operator<<(QDBusArgument &_argument, const Plugin &_arg)
|
||||
{
|
||||
_argument.beginStructure();
|
||||
_argument << _arg.author;
|
||||
_argument << _arg.description;
|
||||
_argument << _arg.homepage;
|
||||
_argument << _arg.license;
|
||||
_argument << _arg.options;
|
||||
_argument.endStructure();
|
||||
|
||||
return _argument;
|
||||
};
|
||||
/**
|
||||
* @brief DBus un-marshalling method
|
||||
* @param _argument
|
||||
* input DBus argument
|
||||
* @param _arg
|
||||
* output variant object
|
||||
* @return source DBus argument
|
||||
*/
|
||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
||||
Plugin &_arg)
|
||||
{
|
||||
_argument.beginStructure();
|
||||
_argument >> _arg.author;
|
||||
_argument >> _arg.description;
|
||||
_argument >> _arg.homepage;
|
||||
_argument >> _arg.license;
|
||||
_argument >> _arg.options;
|
||||
_argument.endStructure();
|
||||
|
||||
return _argument;
|
||||
};
|
||||
/**
|
||||
* @brief dump specification to map
|
||||
* @param _plugin
|
||||
|
@ -62,6 +62,15 @@ public slots:
|
||||
* @return plugin properties
|
||||
*/
|
||||
QDBusVariant Plugin(const QString &plugin, const QString &token);
|
||||
/**
|
||||
* @brief get plugin options
|
||||
* @param plugin
|
||||
* plugin name
|
||||
* @param token
|
||||
* user auth token
|
||||
* @return list of plugin options and their values
|
||||
*/
|
||||
QDBusVariant PluginOptions(const QString &plugin, const QString &token);
|
||||
/**
|
||||
* @brief get advanced option
|
||||
* @param property
|
||||
|
@ -28,12 +28,15 @@
|
||||
|
||||
#include <result/result.hpp>
|
||||
|
||||
#include "QueuedPluginSpecification.h"
|
||||
|
||||
|
||||
namespace QueuedEnums
|
||||
{
|
||||
enum class ReturnStatus;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef QueuedError
|
||||
* custom result error implementation
|
||||
@ -100,7 +103,11 @@ Q_DECLARE_METATYPE(QueuedResult<QStringList>)
|
||||
Q_DECLARE_METATYPE(QueuedResult<QVariant>)
|
||||
Q_DECLARE_METATYPE(QueuedResult<QList<QVariantHash>>)
|
||||
Q_DECLARE_METATYPE(QueuedResult<QVariantHash>)
|
||||
Q_DECLARE_METATYPE(QueuedResult<QueuedPluginSpecification::Plugin>)
|
||||
Q_DECLARE_METATYPE(QueuedResult<QueuedPluginSpecification::PluginOption>)
|
||||
Q_DECLARE_METATYPE(QueuedResult<QueuedStatusMap>)
|
||||
Q_DECLARE_METATYPE(QueuedPluginSpecification::Plugin)
|
||||
Q_DECLARE_METATYPE(QueuedPluginSpecification::PluginOption)
|
||||
/**
|
||||
* @brief DBus marshalling method
|
||||
* @param _argument
|
||||
|
@ -231,8 +231,8 @@ public:
|
||||
* user auth token
|
||||
* @return dictionary of PluginSpecification representation
|
||||
*/
|
||||
QueuedResult<QVariantHash> plugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
||||
plugin(const QString &_plugin, const QString &_token);
|
||||
/**
|
||||
* @brief get plugin settings
|
||||
* @param _plugin
|
||||
|
@ -211,8 +211,8 @@ QueuedCore::performanceReport(const QDateTime &_from, const QDateTime &_to,
|
||||
/**
|
||||
* @fn plugin
|
||||
*/
|
||||
QueuedResult<QVariantHash> QueuedCore::plugin(const QString &_plugin,
|
||||
const QString &_token)
|
||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
||||
QueuedCore::plugin(const QString &_plugin, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Get data for plugin" << _plugin;
|
||||
|
||||
|
@ -297,18 +297,26 @@ QueuedCoreAdaptor::getPlugin(const QString &_plugin, const QString &_token)
|
||||
|
||||
QVariantList args = {_plugin, _token};
|
||||
|
||||
auto result = sendRequest<QVariantHash>(
|
||||
return sendRequest<QueuedPluginSpecification::Plugin>(
|
||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||
QueuedConfig::DBUS_SERVICE, "Plugin", args);
|
||||
}
|
||||
|
||||
QueuedResult<QueuedPluginSpecification::Plugin> output;
|
||||
result.match(
|
||||
[&output](const QVariantHash &res) {
|
||||
output = QueuedPluginSpecification::readSpecification(res);
|
||||
},
|
||||
[&output](const QueuedError &err) { output = err; });
|
||||
|
||||
return output;
|
||||
/**
|
||||
* @fn getPluginOptions
|
||||
*/
|
||||
QueuedResult<QVariantHash>
|
||||
QueuedCoreAdaptor::getPluginOptions(const QString &_plugin,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Get options for plugin" << _plugin;
|
||||
|
||||
QVariantList args = {_plugin, _token};
|
||||
|
||||
return sendRequest<QVariantHash>(
|
||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||
QueuedConfig::DBUS_SERVICE, "PluginOptions", args);
|
||||
}
|
||||
|
||||
|
||||
|
@ -386,19 +386,15 @@ QueuedResult<QList<QVariantHash>> QueuedCorePrivate::performanceReport(
|
||||
/**
|
||||
* @fn plugin
|
||||
*/
|
||||
QueuedResult<QVariantHash> QueuedCorePrivate::plugin(const QString &_plugin,
|
||||
const QString &_token)
|
||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
||||
QueuedCorePrivate::plugin(const QString &_plugin, const QString &_token)
|
||||
{
|
||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||
if (!isAdmin)
|
||||
return QueuedError("Not allowed",
|
||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||
|
||||
auto spec = m_plugins->loadSpecification(_plugin);
|
||||
auto map = QueuedPluginSpecification::dumpSpecification(spec);
|
||||
// do something if we need
|
||||
|
||||
return map;
|
||||
return m_plugins->loadSpecification(_plugin);
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,6 +44,18 @@ QueuedPropertyInterface::QueuedPropertyInterface(QueuedCore *parent)
|
||||
|
||||
qRegisterMetaType<QueuedResult<QVariantHash>>("QueuedResult<QVariantHash>");
|
||||
qDBusRegisterMetaType<QueuedResult<QVariantHash>>();
|
||||
|
||||
qRegisterMetaType<QueuedPluginSpecification::PluginOption>(
|
||||
"QueuedPluginSpecification::PluginOption");
|
||||
qDBusRegisterMetaType<QueuedPluginSpecification::PluginOption>();
|
||||
|
||||
qRegisterMetaType<QueuedPluginSpecification::Plugin>(
|
||||
"QueuedPluginSpecification::Plugin");
|
||||
qDBusRegisterMetaType<QueuedPluginSpecification::Plugin>();
|
||||
|
||||
qRegisterMetaType<QueuedResult<QueuedPluginSpecification::Plugin>>(
|
||||
"QueuedResult<QueuedPluginSpecification::Plugin>");
|
||||
qDBusRegisterMetaType<QueuedResult<QueuedPluginSpecification::Plugin>>();
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +80,19 @@ QDBusVariant QueuedPropertyInterface::Plugin(const QString &plugin,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn PluginOptions
|
||||
*/
|
||||
QDBusVariant QueuedPropertyInterface::PluginOptions(const QString &plugin,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Get plugin options" << plugin;
|
||||
|
||||
return QueuedCoreAdaptor::toDBusVariant(
|
||||
m_core->pluginSettings(plugin, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn Option
|
||||
*/
|
||||
|
@ -149,7 +149,9 @@ void QueuedctlCommon::preprocess(const QStringList &_args,
|
||||
QueuedctlPermissions::parser(_parser);
|
||||
break;
|
||||
case QueuedctlArgument::PluginAdd:
|
||||
case QueuedctlArgument::PluginOptions:
|
||||
case QueuedctlArgument::PluginRemove:
|
||||
case QueuedctlArgument::PluginSpecification:
|
||||
QueuedctlPlugins::parser(_parser);
|
||||
break;
|
||||
case QueuedctlArgument::PluginList:
|
||||
@ -269,10 +271,18 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
result = QueuedctlPlugins::listPlugins();
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::PluginOptions: {
|
||||
result = QueuedctlPlugins::getPluginOptions(args.at(1), token);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::PluginRemove: {
|
||||
result = QueuedctlPlugins::removePlugin(args.at(1), token);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::PluginSpecification: {
|
||||
result = QueuedctlPlugins::getPlugin(args.at(1), token);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::Report: {
|
||||
result = QueuedctlUser::getReport(_parser, token);
|
||||
break;
|
||||
|
@ -32,7 +32,9 @@ enum class QueuedctlArgument {
|
||||
PermissionRemove,
|
||||
PluginAdd,
|
||||
PluginList,
|
||||
PluginOptions,
|
||||
PluginRemove,
|
||||
PluginSpecification,
|
||||
Report,
|
||||
Status,
|
||||
TaskAdd,
|
||||
@ -63,9 +65,13 @@ const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments = {
|
||||
{QueuedctlArgument::PermissionAdd, "Sets user permission.", 3}},
|
||||
{"perm-remove",
|
||||
{QueuedctlArgument::PermissionRemove, "Removes user permission.", 3}},
|
||||
{"plugin",
|
||||
{QueuedctlArgument::PluginSpecification, "Get plugin description.", 2}},
|
||||
{"plugin-add", {QueuedctlArgument::PluginAdd, "Adds plugin to load.", 2}},
|
||||
{"plugin-list",
|
||||
{QueuedctlArgument::PluginList, "Shows enabled plugins.", 1}},
|
||||
{"plugin-options",
|
||||
{QueuedctlArgument::PluginOptions, "Get plugin options.", 2}},
|
||||
{"plugin-remove",
|
||||
{QueuedctlArgument::PluginRemove, "Removes plugin to load.", 2}},
|
||||
{"report", {QueuedctlArgument::Report, "Shows usage report.", 1}},
|
||||
|
@ -45,9 +45,9 @@ QueuedctlOption::getOption(const QString &_option, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
auto res = QueuedCoreAdaptor::getOption(_option, _token);
|
||||
res.match(
|
||||
[&output](const QVariant &val) {
|
||||
[&output, &_option](const QVariant &val) {
|
||||
output.status = val.isValid();
|
||||
output.output = val.toString();
|
||||
output.output = QString("%1: %2").arg(_option, val.toString());
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
|
@ -37,6 +37,63 @@ QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlPlugins::getPlugin(const QString &_plugin, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get plugin" << _plugin;
|
||||
|
||||
auto res = QueuedCoreAdaptor::getPlugin(_plugin, _token);
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match(
|
||||
[&output](const QueuedPluginSpecification::Plugin &val) {
|
||||
QStringList text;
|
||||
text += QString("Author: %1").arg(val.author);
|
||||
text += QString("Description: %1").arg(val.description);
|
||||
text += QString("Homepage: %1").arg(val.homepage);
|
||||
text += QString("License: %1").arg(val.license);
|
||||
text += QString("Options:");
|
||||
for (auto &opt : val.options) {
|
||||
text += QString(" %1").arg(opt.name);
|
||||
text += QString(" description: %1").arg(opt.description);
|
||||
text += QString(" type: %1").arg(opt.type);
|
||||
text += QString(" default: %1")
|
||||
.arg(opt.defaultValue.toString());
|
||||
}
|
||||
|
||||
output.status = true;
|
||||
output.output = text.join('\n');
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get plugin options" << _plugin;
|
||||
|
||||
auto res = QueuedCoreAdaptor::getPluginOptions(_plugin, _token);
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match(
|
||||
[&output](const QVariantHash &val) {
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
||||
{
|
||||
auto res = QueuedCoreAdaptor::getOption(
|
||||
|
@ -26,6 +26,10 @@ namespace QueuedctlPlugins
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult addPlugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getPlugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getPluginOptions(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult listPlugins();
|
||||
QueuedctlCommon::QueuedctlResult removePlugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
|
Loading…
Reference in New Issue
Block a user