Axivion: delete Api token if server is removed

Fixes: QTCREATORBUG-31669
Change-Id: I646f604c5cf17d77fd7c8880164c27e7a6e61f10
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Mehdi Salem
2024-10-09 18:15:12 +02:00
committed by hjk
parent ca5583af2e
commit 9f37e0c44b
3 changed files with 50 additions and 12 deletions

View File

@@ -45,7 +45,6 @@
#include <memory>
constexpr char s_axivionTextMarkId[] = "AxivionTextMark";
constexpr char s_axivionKeychainService[] = "keychain.axivion.qtcreator";
using namespace Core;
using namespace ProjectExplorer;
@@ -114,17 +113,6 @@ static QString apiTokenDescription()
return "Automatically created by " + ua + " on " + user + "@" + QSysInfo::machineHostName();
}
static QString escapeKey(const QString &string)
{
QString escaped = string;
return escaped.replace('\\', "\\\\").replace('@', "\\@");
}
static QString credentialKey(const AxivionServer &server)
{
return escapeKey(server.username) + '@' + escapeKey(server.dashboard);
}
template <typename DtoType>
struct GetDtoStorage
{

View File

@@ -4,9 +4,12 @@
#include "axivionsettings.h"
#include "axiviontr.h"
#include "coreplugin/messagemanager.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/credentialquery.h>
#include <coreplugin/icore.h>
#include <solutions/tasking/tasktree.h>
#include <utils/algorithm.h>
#include <utils/id.h>
@@ -28,6 +31,7 @@
using namespace Core;
using namespace Utils;
using namespace Tasking;
namespace Axivion::Internal {
@@ -252,9 +256,37 @@ bool AxivionSettings::updateDashboardServers(const QList<AxivionServer> &other,
if (selected == oldDefault && m_allServers == other)
return false;
// collect dashserver items that have been removed,
// so we can delete the api tokens from the credentials store
const QStringList previousKeys = Utils::transform(m_allServers, &credentialKey);
const QStringList updatedKeys = Utils::transform(other, &credentialKey);
const QStringList keysToRemove = Utils::filtered(previousKeys, [updatedKeys](const QString &key) {
return !updatedKeys.contains(key);
});
m_defaultServerId.setValue(selected.toString(), BeQuiet);
m_allServers = other;
emit changed(); // should we be more detailed? (id)
const LoopList iterator(keysToRemove);
const auto onDeleteKeySetup = [iterator](CredentialQuery &query) {
MessageManager::writeSilently(Tr::tr("Axivion: Deleting Api token for %1 as respective "
"dashboard server was removed.").arg(*iterator));
query.setOperation(CredentialOperation::Delete);
query.setService(s_axivionKeychainService);
query.setKey(*iterator);
};
const Group recipe {
For (iterator) >> Do {
CredentialQueryTask(onDeleteKeySetup)
}
};
m_taskTreeRunner.start(recipe);
return true;
}
@@ -263,6 +295,17 @@ const QList<PathMapping> AxivionSettings::validPathMappings() const
return pathMappingSettings().validPathMappings();
}
static QString escapeKey(const QString &string)
{
QString escaped = string;
return escaped.replace('\\', "\\\\").replace('@', "\\@");
}
QString credentialKey(const AxivionServer &server)
{
return escapeKey(server.username) + '@' + escapeKey(server.dashboard);
}
// AxivionSettingsPage
// may allow some invalid, but does some minimal check for legality

View File

@@ -8,12 +8,16 @@
#include <QtGlobal>
#include <solutions/tasking/tasktreerunner.h>
QT_BEGIN_NAMESPACE
class QJsonObject;
QT_END_NAMESPACE
namespace Axivion::Internal {
constexpr char s_axivionKeychainService[] = "keychain.axivion.qtcreator";
class AxivionServer
{
public:
@@ -64,8 +68,11 @@ public:
private:
Utils::StringAspect m_defaultServerId{this};
QList<AxivionServer> m_allServers;
Tasking::TaskTreeRunner m_taskTreeRunner;
};
AxivionSettings &settings();
QString credentialKey(const AxivionServer &server);
} // Axivion::Internal