mirror of
https://github.com/logos-co/logos-view-module-runtime.git
synced 2026-08-31 13:01:08 +00:00
fix: Pass per-spawn auth token to ui-host via private socket
This commit is contained in:
+43
-2
@@ -3,6 +3,9 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
#include <QPointer>
|
||||
#include <QUuid>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -16,12 +19,18 @@ ViewModuleHost::~ViewModuleHost()
|
||||
stop();
|
||||
}
|
||||
|
||||
bool ViewModuleHost::spawn(const QString& moduleName, const QString& pluginPath)
|
||||
bool ViewModuleHost::spawn(const QString& moduleName, const QString& pluginPath,
|
||||
const QString& authToken)
|
||||
{
|
||||
if (m_process) {
|
||||
qWarning() << "ViewModuleHost: process already running for" << m_moduleName;
|
||||
return false;
|
||||
}
|
||||
if (authToken.isEmpty()) {
|
||||
qWarning() << "ViewModuleHost: refusing to spawn ui-host for" << moduleName
|
||||
<< "with an empty auth token";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_moduleName = moduleName;
|
||||
m_stdoutBuffer.clear();
|
||||
@@ -42,6 +51,33 @@ bool ViewModuleHost::spawn(const QString& moduleName, const QString& pluginPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString tokenSocketName = m_socketName + QStringLiteral("_token");
|
||||
QLocalServer::removeServer(tokenSocketName);
|
||||
m_tokenServer = new QLocalServer(this);
|
||||
m_tokenServer->setSocketOptions(QLocalServer::UserAccessOption);
|
||||
if (!m_tokenServer->listen(tokenSocketName)) {
|
||||
qWarning() << "ViewModuleHost: failed to listen on token socket for"
|
||||
<< moduleName << ":" << m_tokenServer->errorString();
|
||||
delete m_tokenServer;
|
||||
m_tokenServer = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
QPointer<QLocalServer> serverGuard(m_tokenServer);
|
||||
const QString tokenToSend = authToken;
|
||||
connect(m_tokenServer, &QLocalServer::newConnection, this,
|
||||
[serverGuard, tokenToSend]() {
|
||||
if (!serverGuard) return;
|
||||
QLocalSocket* sock = serverGuard->nextPendingConnection();
|
||||
if (!sock) return;
|
||||
sock->write(tokenToSend.toUtf8());
|
||||
sock->flush();
|
||||
sock->waitForBytesWritten(2000);
|
||||
sock->disconnectFromServer();
|
||||
sock->deleteLater();
|
||||
serverGuard->close();
|
||||
});
|
||||
|
||||
QProcess* process = new QProcess(this);
|
||||
m_process = process;
|
||||
|
||||
@@ -81,13 +117,18 @@ bool ViewModuleHost::spawn(const QString& moduleName, const QString& pluginPath)
|
||||
<< "--path" << pluginPath
|
||||
<< "--socket" << m_socketName;
|
||||
|
||||
qDebug() << "ViewModuleHost: spawning" << uiHostPath << args;
|
||||
qDebug() << "ViewModuleHost: spawning" << uiHostPath << "for" << moduleName;
|
||||
m_process->start(uiHostPath, args);
|
||||
|
||||
if (!process->waitForStarted(5000)) {
|
||||
qWarning() << "ViewModuleHost: failed to start ui-host for" << moduleName;
|
||||
m_process = nullptr;
|
||||
delete process;
|
||||
if (m_tokenServer) {
|
||||
m_tokenServer->close();
|
||||
m_tokenServer->deleteLater();
|
||||
m_tokenServer = nullptr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user