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