added installation_uuid to apiPayload (#747)
Added installation_uuid to apiPayload
This commit is contained in:
parent
f0085f52eb
commit
d50e7dd3f4
8 changed files with 38 additions and 10 deletions
|
|
@ -9,7 +9,6 @@
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "vpnconnection.h"
|
#include "vpnconnection.h"
|
||||||
|
|
||||||
#include "core/controllers/apiController.h"
|
|
||||||
|
|
||||||
#include "ui/controllers/connectionController.h"
|
#include "ui/controllers/connectionController.h"
|
||||||
#include "ui/controllers/exportController.h"
|
#include "ui/controllers/exportController.h"
|
||||||
#include "ui/controllers/importController.h"
|
#include "ui/controllers/importController.h"
|
||||||
|
|
@ -125,7 +123,6 @@ private:
|
||||||
QScopedPointer<SettingsController> m_settingsController;
|
QScopedPointer<SettingsController> m_settingsController;
|
||||||
QScopedPointer<SitesController> m_sitesController;
|
QScopedPointer<SitesController> m_sitesController;
|
||||||
QScopedPointer<SystemController> m_systemController;
|
QScopedPointer<SystemController> m_systemController;
|
||||||
QScopedPointer<ApiController> m_apiController;
|
|
||||||
QScopedPointer<AppSplitTunnelingController> m_appSplitTunnelingController;
|
QScopedPointer<AppSplitTunnelingController> m_appSplitTunnelingController;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
#include "core/errorstrings.h"
|
|
||||||
#include "configurators/wireguard_configurator.h"
|
#include "configurators/wireguard_configurator.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -20,6 +19,7 @@ namespace
|
||||||
constexpr char certificate[] = "certificate";
|
constexpr char certificate[] = "certificate";
|
||||||
constexpr char publicKey[] = "public_key";
|
constexpr char publicKey[] = "public_key";
|
||||||
constexpr char protocol[] = "protocol";
|
constexpr char protocol[] = "protocol";
|
||||||
|
constexpr char uuid[] = "installation_uuid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,11 +64,11 @@ QJsonObject ApiController::fillApiPayload(const QString &protocol, const ApiCont
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode ApiController::updateServerConfigFromApi(QJsonObject &serverConfig)
|
ErrorCode ApiController::updateServerConfigFromApi(const QString &installationUuid, QJsonObject &serverConfig)
|
||||||
{
|
{
|
||||||
QFutureWatcher<ErrorCode> watcher;
|
QFutureWatcher<ErrorCode> watcher;
|
||||||
|
|
||||||
QFuture<ErrorCode> future = QtConcurrent::run([this, &serverConfig]() {
|
QFuture<ErrorCode> future = QtConcurrent::run([this, &serverConfig, &installationUuid]() {
|
||||||
auto containerConfig = serverConfig.value(config_key::containers).toArray();
|
auto containerConfig = serverConfig.value(config_key::containers).toArray();
|
||||||
|
|
||||||
if (serverConfig.value(config_key::configVersion).toInt()) {
|
if (serverConfig.value(config_key::configVersion).toInt()) {
|
||||||
|
|
@ -86,7 +86,10 @@ ErrorCode ApiController::updateServerConfigFromApi(QJsonObject &serverConfig)
|
||||||
|
|
||||||
auto apiPayloadData = generateApiPayloadData(protocol);
|
auto apiPayloadData = generateApiPayloadData(protocol);
|
||||||
|
|
||||||
QByteArray requestBody = QJsonDocument(fillApiPayload(protocol, apiPayloadData)).toJson();
|
auto apiPayload = fillApiPayload(protocol, apiPayloadData);
|
||||||
|
apiPayload[configKey::uuid] = installationUuid;
|
||||||
|
|
||||||
|
QByteArray requestBody = QJsonDocument(apiPayload).toJson();
|
||||||
|
|
||||||
QScopedPointer<QNetworkReply> reply;
|
QScopedPointer<QNetworkReply> reply;
|
||||||
reply.reset(manager.post(request, requestBody));
|
reply.reset(manager.post(request, requestBody));
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ public:
|
||||||
explicit ApiController(QObject *parent = nullptr);
|
explicit ApiController(QObject *parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
ErrorCode updateServerConfigFromApi(QJsonObject &serverConfig);
|
ErrorCode updateServerConfigFromApi(const QString &installationUuid, QJsonObject &serverConfig);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ApiPayloadData {
|
struct ApiPayloadData {
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,10 @@ QByteArray SecureQSettings::backupAppConfig() const
|
||||||
QJsonObject cfg;
|
QJsonObject cfg;
|
||||||
|
|
||||||
for (const QString &key : m_settings.allKeys()) {
|
for (const QString &key : m_settings.allKeys()) {
|
||||||
|
if (key == "Conf/installationUuid") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
cfg.insert(key, QJsonValue::fromVariant(value(key)));
|
cfg.insert(key, QJsonValue::fromVariant(value(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,6 +142,10 @@ bool SecureQSettings::restoreAppConfig(const QByteArray &json)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const QString &key : cfg.keys()) {
|
for (const QString &key : cfg.keys()) {
|
||||||
|
if (key == "Conf/installationUuid") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
setValue(key, cfg.value(key).toVariant());
|
setValue(key, cfg.value(key).toVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -361,7 +361,9 @@ QString Settings::secondaryDns() const
|
||||||
|
|
||||||
void Settings::clearSettings()
|
void Settings::clearSettings()
|
||||||
{
|
{
|
||||||
|
auto uuid = getInstallationUuid(false);
|
||||||
m_settings.clearSettings();
|
m_settings.clearSettings();
|
||||||
|
setInstallationUuid(uuid);
|
||||||
emit settingsCleared();
|
emit settingsCleared();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -423,6 +425,21 @@ void Settings::setAppsSplitTunnelingEnabled(bool enabled)
|
||||||
setValue("Conf/appsSplitTunnelingEnabled", enabled);
|
setValue("Conf/appsSplitTunnelingEnabled", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Settings::getInstallationUuid(const bool needCreate)
|
||||||
|
{
|
||||||
|
auto uuid = value("Conf/installationUuid", "").toString();
|
||||||
|
if (needCreate && uuid.isEmpty()) {
|
||||||
|
uuid = QUuid::createUuid().toString();
|
||||||
|
setInstallationUuid(uuid);
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setInstallationUuid(const QString &uuid)
|
||||||
|
{
|
||||||
|
setValue("Conf/installationUuid", uuid);
|
||||||
|
}
|
||||||
|
|
||||||
ServerCredentials Settings::defaultServerCredentials() const
|
ServerCredentials Settings::defaultServerCredentials() const
|
||||||
{
|
{
|
||||||
return serverCredentials(defaultServerIndex());
|
return serverCredentials(defaultServerIndex());
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,8 @@ public:
|
||||||
bool getAppsSplitTunnelingEnabled() const;
|
bool getAppsSplitTunnelingEnabled() const;
|
||||||
void setAppsSplitTunnelingEnabled(bool enabled);
|
void setAppsSplitTunnelingEnabled(bool enabled);
|
||||||
|
|
||||||
|
QString getInstallationUuid(const bool needCreate);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void saveLogsChanged(bool enabled);
|
void saveLogsChanged(bool enabled);
|
||||||
void screenshotsEnabledChanged(bool enabled);
|
void screenshotsEnabledChanged(bool enabled);
|
||||||
|
|
@ -224,6 +226,8 @@ private:
|
||||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||||
void setValue(const QString &key, const QVariant &value);
|
void setValue(const QString &key, const QVariant &value);
|
||||||
|
|
||||||
|
void setInstallationUuid(const QString &uuid);
|
||||||
|
|
||||||
mutable SecureQSettings m_settings;
|
mutable SecureQSettings m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ void ConnectionController::openConnection()
|
||||||
if (serverConfig.value(config_key::configVersion).toInt()
|
if (serverConfig.value(config_key::configVersion).toInt()
|
||||||
&& !m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) {
|
&& !m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) {
|
||||||
ApiController apiController;
|
ApiController apiController;
|
||||||
errorCode = apiController.updateServerConfigFromApi(serverConfig);
|
errorCode = apiController.updateServerConfigFromApi(m_settings->getInstallationUuid(true), serverConfig);
|
||||||
if (errorCode != ErrorCode::NoError) {
|
if (errorCode != ErrorCode::NoError) {
|
||||||
emit connectionErrorOccurred(errorString(errorCode));
|
emit connectionErrorOccurred(errorString(errorCode));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue