GitLab: Support unsecure http as well

Change-Id: Idfb4faf1cbfbfd6c2914b057e6c76461de0ceeff
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Stenger
2022-06-03 10:21:00 +02:00
parent 6674e5f267
commit fdb413c9a7
8 changed files with 36 additions and 16 deletions

View File

@@ -221,17 +221,22 @@ void GitLabDialog::handleUser(const User &user)
m_currentUserId = user.id;
if (!user.error.message.isEmpty()) {
// TODO
if (user.error.code == 1) {
m_ui.mainLabel->setText(tr("Not logged in."));
if (user.error.code == 1) {
m_ui.detailsLabel->setText(tr("Insufficient access token."));
m_ui.detailsLabel->setToolTip(user.error.message + QLatin1Char('\n')
+ tr("Permission scope read_api or api needed."));
} else if (user.error.code >= 300 && user.error.code < 400) {
m_ui.detailsLabel->setText(tr("Check settings for misconfiguration."));
m_ui.detailsLabel->setToolTip(user.error.message);
} else {
m_ui.detailsLabel->setText({});
m_ui.detailsLabel->setToolTip({});
}
updatePageButtons();
m_ui.treeViewTitle->setText(tr("Projects (%1)").arg(0));
return;
}
}
if (user.id != -1) {
if (user.bot) {

View File

@@ -84,6 +84,10 @@ GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
m_port.setDefaultValue(GitLabServer::defaultPort);
m_port.setEnabled(m == Edit);
m_port.setLabelText(tr("Port:"));
m_secure.setLabelText(tr("HTTPS:"));
m_secure.setLabelPlacement(Utils::BoolAspect::LabelPlacement::InExtraLabel);
m_secure.setDefaultValue(true);
m_secure.setEnabled(m == Edit);
using namespace Utils::Layouting;
const Break nl;
@@ -93,7 +97,8 @@ GitLabServerWidget::GitLabServerWidget(Mode m, QWidget *parent)
m_host,
m_description,
m_token,
m_port
m_port,
m_secure
},
Stretch()
}.attachTo(this, m == Edit);
@@ -107,6 +112,7 @@ GitLabServer GitLabServerWidget::gitLabServer() const
result.description = m_description.value();
result.token = m_token.value();
result.port = m_port.value();
result.secure = m_secure.value();
return result;
}
@@ -117,6 +123,7 @@ void GitLabServerWidget::setGitLabServer(const GitLabServer &server)
m_description.setValue(server.description);
m_token.setValue(server.token);
m_port.setValue(server.port);
m_secure.setValue(server.secure);
}
GitLabOptionsWidget::GitLabOptionsWidget(QWidget *parent)

View File

@@ -56,6 +56,7 @@ private:
Utils::StringAspect m_description;
Utils::StringAspect m_token;
Utils::IntegerAspect m_port;
Utils::BoolAspect m_secure;
};
class GitLabOptionsWidget : public QWidget

View File

@@ -46,12 +46,13 @@ GitLabServer::GitLabServer()
}
GitLabServer::GitLabServer(const Utils::Id &id, const QString &host, const QString &description,
const QString &token, unsigned short port)
const QString &token, unsigned short port, bool secure)
: id(id)
, host(host)
, description(description)
, token(token)
, port(port)
, secure(secure)
{
}
@@ -59,8 +60,8 @@ bool GitLabServer::operator==(const GitLabServer &other) const
{
if (port && other.port && port != other.port)
return false;
return id == other.id && host == other.host && description == other.description
&& token == other.token ;
return secure == other.secure && id == other.id && host == other.host
&& description == other.description && token == other.token ;
}
bool GitLabServer::operator!=(const GitLabServer &other) const
@@ -76,12 +77,13 @@ QJsonObject GitLabServer::toJson() const
result.insert("description", description);
result.insert("port", port);
result.insert("token", token);
result.insert("secure", secure);
return result;
}
GitLabServer GitLabServer::fromJson(const QJsonObject &json)
{
GitLabServer invalid{Utils::Id(), "", "", "", 0};
GitLabServer invalid{Utils::Id(), "", "", "", 0, true};
const QJsonValue id = json.value("id");
if (id == QJsonValue::Undefined)
return invalid;
@@ -97,15 +99,16 @@ GitLabServer GitLabServer::fromJson(const QJsonObject &json)
const QJsonValue port = json.value("port");
if (port == QJsonValue::Undefined)
return invalid;
const bool secure = json.value("secure").toBool(true);
return {Utils::Id::fromString(id.toString()), host.toString(), description.toString(),
token.toString(), (unsigned short)port.toInt()};
token.toString(), (unsigned short)port.toInt(), secure};
}
QStringList GitLabServer::curlArguments() const
{
// credentials from .netrc (?), no progress
QStringList args = { "-nsS" };
if (!validateCert)
if (secure && !validateCert)
args << "-k";
return args;
}

View File

@@ -42,7 +42,7 @@ public:
GitLabServer(); // TODO different protocol handling e.g. for clone / push?
GitLabServer(const Utils::Id &id, const QString &host, const QString &description,
const QString &token, unsigned short port);;
const QString &token, unsigned short port, bool secure);
bool operator==(const GitLabServer &other) const;
bool operator!=(const GitLabServer &other) const;
QJsonObject toJson() const;
@@ -56,6 +56,7 @@ public:
QString token;
unsigned short port = 0;
bool secure = true;
bool validateCert = true; // TODO
};

View File

@@ -233,7 +233,8 @@ void GitLabProjectSettingsWidget::onConnectionChecked(const Project &project,
bool linkable = false;
if (!project.error.message.isEmpty()) {
m_infoLabel->setType(Utils::InfoLabel::Error);
m_infoLabel->setText(project.error.message);
m_infoLabel->setText(tr("Check settings for misconfiguration.")
+ " (" + project.error.message + ')');
} else {
if (project.accessLevel != -1) {
m_infoLabel->setType(Utils::InfoLabel::Ok);

View File

@@ -111,8 +111,8 @@ QueryRunner::QueryRunner(const Query &query, const Utils::Id &id, QObject *paren
args << "-i";
if (!server.token.isEmpty())
args << "--header" << "PRIVATE-TOKEN: " + server.token;
QString url = "https://" + server.host;
if (server.port != GitLabServer::defaultPort)
QString url = (server.secure ? "https://" : "http://") + server.host;
if (server.port && (server.port != (server.secure ? GitLabServer::defaultPort : 80)))
url.append(':' + QString::number(server.port));
url += query.toString();
args << url;

View File

@@ -93,6 +93,8 @@ static std::pair<Error, QJsonObject> preHandleSingle(const QByteArray &json)
const QJsonDocument doc = QJsonDocument::fromJson(json, &error);
if (error.error != QJsonParseError::NoError) {
if (!json.isEmpty() && json.at(0) == '<') // we likely got an HTML response
result.code = 399;
result.message = error.errorString();
} else if (!doc.isObject()) {
result.message = "Not an Object";