forked from qt-creator/qt-creator
PublicKeyDeploymentDialog: Don't use SshRemoteProcessRunner
Use QtcProcess with a path on device instead. Get rid of SshKeyDeployer, inline its functionality inside PublicKeyDeploymentDialog. Change-Id: I01b9fecb06b459f93e8eefaf889ef0dea9f69f1d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -39,7 +39,6 @@ add_qtc_plugin(RemoteLinux
|
|||||||
remotelinuxsignaloperation.cpp remotelinuxsignaloperation.h
|
remotelinuxsignaloperation.cpp remotelinuxsignaloperation.h
|
||||||
remotelinuxx11forwardingaspect.cpp remotelinuxx11forwardingaspect.h
|
remotelinuxx11forwardingaspect.cpp remotelinuxx11forwardingaspect.h
|
||||||
rsyncdeploystep.cpp rsyncdeploystep.h
|
rsyncdeploystep.cpp rsyncdeploystep.h
|
||||||
sshkeydeployer.cpp sshkeydeployer.h
|
|
||||||
sshprocessinterface.h
|
sshprocessinterface.h
|
||||||
tarpackagecreationstep.cpp tarpackagecreationstep.h
|
tarpackagecreationstep.cpp tarpackagecreationstep.h
|
||||||
uploadandinstalltarpackagestep.cpp uploadandinstalltarpackagestep.h
|
uploadandinstalltarpackagestep.cpp uploadandinstalltarpackagestep.h
|
||||||
|
|||||||
@@ -25,11 +25,9 @@
|
|||||||
|
|
||||||
#include "publickeydeploymentdialog.h"
|
#include "publickeydeploymentdialog.h"
|
||||||
|
|
||||||
#include "sshkeydeployer.h"
|
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <projectexplorer/devicesupport/idevice.h>
|
#include <projectexplorer/devicesupport/idevice.h>
|
||||||
#include <ssh/sshconnection.h>
|
#include <ssh/sshconnection.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
@@ -37,11 +35,12 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class PublicKeyDeploymentDialogPrivate
|
class PublicKeyDeploymentDialogPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SshKeyDeployer keyDeployer;
|
QtcProcess m_process;
|
||||||
bool done;
|
bool m_done;
|
||||||
};
|
};
|
||||||
} // namespace Internal;
|
} // namespace Internal;
|
||||||
|
|
||||||
@@ -68,16 +67,38 @@ PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(const IDevice::ConstPtr &de
|
|||||||
setMinimumDuration(0);
|
setMinimumDuration(0);
|
||||||
setMaximum(1);
|
setMaximum(1);
|
||||||
|
|
||||||
d->done = false;
|
d->m_done = false;
|
||||||
setLabelText(tr("Deploying..."));
|
setLabelText(tr("Deploying..."));
|
||||||
setValue(0);
|
setValue(0);
|
||||||
connect(this, &PublicKeyDeploymentDialog::canceled,
|
connect(this, &PublicKeyDeploymentDialog::canceled, this,
|
||||||
this, &PublicKeyDeploymentDialog::handleCanceled);
|
[this] { d->m_done ? accept() : reject(); });
|
||||||
connect(&d->keyDeployer, &SshKeyDeployer::error,
|
connect(&d->m_process, &QtcProcess::done, this, [this] {
|
||||||
this, &PublicKeyDeploymentDialog::handleDeploymentError);
|
const bool succeeded = d->m_process.error() == QProcess::UnknownError;
|
||||||
connect(&d->keyDeployer, &SshKeyDeployer::finishedSuccessfully,
|
QString finalMessage;
|
||||||
this, &PublicKeyDeploymentDialog::handleDeploymentSuccess);
|
if (!succeeded) {
|
||||||
d->keyDeployer.deployPublicKey(deviceConfig->sshParameters(), publicKeyFileName);
|
QString errorMessage = d->m_process.errorString();
|
||||||
|
if (errorMessage.isEmpty())
|
||||||
|
errorMessage = d->m_process.stdErr();
|
||||||
|
if (errorMessage.endsWith('\n'))
|
||||||
|
errorMessage.chop(1);
|
||||||
|
finalMessage = tr("Key deployment failed.");
|
||||||
|
if (!errorMessage.isEmpty())
|
||||||
|
finalMessage += '\n' + errorMessage;
|
||||||
|
}
|
||||||
|
handleDeploymentDone(succeeded, finalMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
FileReader reader;
|
||||||
|
if (!reader.fetch(publicKeyFileName)) {
|
||||||
|
handleDeploymentDone(false, tr("Public key error: %1").arg(reader.errorString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString command = "test -d .ssh || mkdir -p ~/.ssh && chmod 0700 .ssh && echo '"
|
||||||
|
+ QString::fromLocal8Bit(reader.data())
|
||||||
|
+ "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
|
||||||
|
d->m_process.setCommand({deviceConfig->mapToGlobalPath("/bin/sh"), {"-c", command}});
|
||||||
|
d->m_process.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
|
PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
|
||||||
@@ -85,43 +106,20 @@ PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PublicKeyDeploymentDialog::handleDeploymentSuccess()
|
void PublicKeyDeploymentDialog::handleDeploymentDone(bool succeeded, const QString &errorMessage)
|
||||||
{
|
{
|
||||||
handleDeploymentFinished(QString());
|
QString buttonText = succeeded ? tr("Deployment finished successfully.") : errorMessage;
|
||||||
setValue(1);
|
const QString textColor = creatorTheme()->color(
|
||||||
d->done = true;
|
succeeded ? Theme::TextColorNormal : Theme::TextColorError).name();
|
||||||
}
|
|
||||||
|
|
||||||
void PublicKeyDeploymentDialog::handleDeploymentError(const QString &errorMsg)
|
|
||||||
{
|
|
||||||
handleDeploymentFinished(errorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PublicKeyDeploymentDialog::handleDeploymentFinished(const QString &errorMsg)
|
|
||||||
{
|
|
||||||
QString buttonText;
|
|
||||||
QString textColor;
|
|
||||||
if (errorMsg.isEmpty()) {
|
|
||||||
buttonText = tr("Deployment finished successfully.");
|
|
||||||
textColor = Utils::creatorTheme()->color(Utils::Theme::TextColorNormal).name();
|
|
||||||
} else {
|
|
||||||
buttonText = errorMsg;
|
|
||||||
textColor = Utils::creatorTheme()->color(Utils::Theme::TextColorError).name();
|
|
||||||
}
|
|
||||||
setLabelText(QString::fromLatin1("<font color=\"%1\">%2</font>")
|
setLabelText(QString::fromLatin1("<font color=\"%1\">%2</font>")
|
||||||
.arg(textColor)
|
.arg(textColor, buttonText.replace("\n", "<br/>")));
|
||||||
.arg(buttonText.replace("\n", "<br/>")));
|
|
||||||
setCancelButtonText(tr("Close"));
|
setCancelButtonText(tr("Close"));
|
||||||
}
|
|
||||||
|
|
||||||
void PublicKeyDeploymentDialog::handleCanceled()
|
if (!succeeded)
|
||||||
{
|
return;
|
||||||
disconnect(&d->keyDeployer, nullptr, this, nullptr);
|
|
||||||
d->keyDeployer.stopDeployment();
|
setValue(1);
|
||||||
if (d->done)
|
d->m_done = true;
|
||||||
accept();
|
|
||||||
else
|
|
||||||
reject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RemoteLinux
|
} // namespace RemoteLinux
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ public:
|
|||||||
~PublicKeyDeploymentDialog() override;
|
~PublicKeyDeploymentDialog() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleDeploymentFinished(const QString &errorMsg);
|
void handleDeploymentDone(bool succeeded, const QString &errorMessage);
|
||||||
void handleDeploymentError(const QString &errorMsg);
|
|
||||||
void handleDeploymentSuccess();
|
|
||||||
void handleCanceled();
|
|
||||||
|
|
||||||
Internal::PublicKeyDeploymentDialogPrivate * const d;
|
Internal::PublicKeyDeploymentDialogPrivate * const d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ Project {
|
|||||||
"remotelinuxx11forwardingaspect.h",
|
"remotelinuxx11forwardingaspect.h",
|
||||||
"rsyncdeploystep.cpp",
|
"rsyncdeploystep.cpp",
|
||||||
"rsyncdeploystep.h",
|
"rsyncdeploystep.h",
|
||||||
"sshkeydeployer.cpp",
|
|
||||||
"sshkeydeployer.h",
|
|
||||||
"sshprocessinterface.h",
|
"sshprocessinterface.h",
|
||||||
"tarpackagecreationstep.cpp",
|
"tarpackagecreationstep.cpp",
|
||||||
"tarpackagecreationstep.h",
|
"tarpackagecreationstep.h",
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "sshkeydeployer.h"
|
|
||||||
|
|
||||||
#include <ssh/sshremoteprocessrunner.h>
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
|
|
||||||
using namespace QSsh;
|
|
||||||
using namespace Utils;
|
|
||||||
|
|
||||||
namespace RemoteLinux {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class SshKeyDeployerPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SshRemoteProcessRunner deployProcess;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
|
|
||||||
SshKeyDeployer::SshKeyDeployer(QObject *parent)
|
|
||||||
: QObject(parent), d(new Internal::SshKeyDeployerPrivate)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SshKeyDeployer::~SshKeyDeployer()
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshKeyDeployer::deployPublicKey(const SshConnectionParameters &sshParams,
|
|
||||||
const FilePath &keyFilePath)
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
FileReader reader;
|
|
||||||
if (!reader.fetch(keyFilePath)) {
|
|
||||||
emit error(tr("Public key error: %1").arg(reader.errorString()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(&d->deployProcess, &SshRemoteProcessRunner::connectionError,
|
|
||||||
this, &SshKeyDeployer::handleConnectionFailure);
|
|
||||||
connect(&d->deployProcess, &SshRemoteProcessRunner::finished,
|
|
||||||
this, &SshKeyDeployer::handleKeyUploadFinished);
|
|
||||||
const QString command = "test -d .ssh "
|
|
||||||
"|| mkdir -p ~/.ssh && chmod 0700 .ssh && echo '"
|
|
||||||
+ QString::fromLocal8Bit(reader.data())
|
|
||||||
+ "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
|
|
||||||
d->deployProcess.run(command, sshParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshKeyDeployer::handleConnectionFailure()
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
emit error(tr("Connection failed: %1").arg(d->deployProcess.lastConnectionErrorString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshKeyDeployer::handleKeyUploadFinished()
|
|
||||||
{
|
|
||||||
const int exitCode = d->deployProcess.exitCode();
|
|
||||||
const QString errorMsg = d->deployProcess.errorString();
|
|
||||||
cleanup();
|
|
||||||
if (errorMsg.isEmpty() && exitCode == 0) {
|
|
||||||
emit finishedSuccessfully();
|
|
||||||
} else {
|
|
||||||
emit error(tr("Key deployment failed: %1.").arg(errorMsg.isEmpty()
|
|
||||||
? QString::fromUtf8(d->deployProcess.readAllStandardError())
|
|
||||||
: errorMsg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshKeyDeployer::stopDeployment()
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SshKeyDeployer::cleanup()
|
|
||||||
{
|
|
||||||
disconnect(&d->deployProcess, nullptr, this, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace RemoteLinux
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "remotelinux_export.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace QSsh { class SshConnectionParameters; }
|
|
||||||
namespace Utils { class FilePath; }
|
|
||||||
|
|
||||||
namespace RemoteLinux {
|
|
||||||
namespace Internal { class SshKeyDeployerPrivate; }
|
|
||||||
|
|
||||||
class REMOTELINUX_EXPORT SshKeyDeployer : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_DISABLE_COPY(SshKeyDeployer)
|
|
||||||
public:
|
|
||||||
explicit SshKeyDeployer(QObject *parent = nullptr);
|
|
||||||
~SshKeyDeployer() override;
|
|
||||||
|
|
||||||
void deployPublicKey(const QSsh::SshConnectionParameters &sshParams,
|
|
||||||
const Utils::FilePath &keyFilePath);
|
|
||||||
void stopDeployment();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void error(const QString &errorMsg);
|
|
||||||
void finishedSuccessfully();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void handleConnectionFailure();
|
|
||||||
void handleKeyUploadFinished();
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
Internal::SshKeyDeployerPrivate * const d;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace RemoteLinux
|
|
||||||
Reference in New Issue
Block a user