diff options
author | Robert Griebl <robert.griebl@qt.io> | 2022-09-16 14:03:06 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2022-09-27 14:50:28 +0200 |
commit | 1f095b170878b3fce11c7924d237adbc778678a8 (patch) | |
tree | 91d8fd6dd36b697a4ef8b5248db681189627e984 | |
parent | 78c0f56f1022b5e94e7bac9a5de48b51783a4938 (diff) | |
download | qtapplicationmanager-1f095b170878b3fce11c7924d237adbc778678a8.tar.gz |
Remove the outdated package-uploader tool from this repo
In case the qtauto-deployment-server repo will be updated in the
future, this tool will move to that repo.
Change-Id: I93109a8f08bfd6cab6d96242115099eba48231b6
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/tools/uploader/CMakeLists.txt | 14 | ||||
-rw-r--r-- | src/tools/uploader/uploader.cpp | 155 |
3 files changed, 0 insertions, 171 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a850f505..ad23bb40 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,6 +49,4 @@ if(NOT QT_FEATURE_cross_compile OR QT_FEATURE_am_tools_only) if (QT_FEATURE_am_installer) add_subdirectory(tools/packager) endif() - - add_subdirectory(tools/uploader) endif() diff --git a/src/tools/uploader/CMakeLists.txt b/src/tools/uploader/CMakeLists.txt deleted file mode 100644 index 1ad6c511..00000000 --- a/src/tools/uploader/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ - -qt_get_tool_target_name(target_name package-uploader) -qt_internal_add_tool(${target_name} - USER_FACING - EXCEPTIONS - TOOLS_TARGET AppManMainPrivate - SOURCES - uploader.cpp - LIBRARIES - Qt::Network - Qt::AppManCommonPrivate - DEFINES - AM_COMPILING_APPMAN -) diff --git a/src/tools/uploader/uploader.cpp b/src/tools/uploader/uploader.cpp deleted file mode 100644 index 1d8d59a5..00000000 --- a/src/tools/uploader/uploader.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// Copyright (C) 2019 Luxoft Sweden AB -// Copyright (C) 2018 Pelagicore AG -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include <QtAppManCommon/global.h> -#include <QCommandLineParser> -#include <QCoreApplication> -#include <QDebug> -#include <QFile> -#include <QHttpMultiPart> -#include <QHttpPart> -#include <QNetworkAccessManager> -#include <QNetworkRequest> -#include <QNetworkReply> -#include <QJsonDocument> -#include <QString> -#include <QMap> - -const QString descriptionParameter = qSL("description"); -const QString summaryParameter = qSL("summary"); -const QString shortDescriptionParameter = qSL("short-description"); -const QString categoryParameter = qSL("category"); -const QString vendorParameter = qSL("vendor"); -const QString usernameParameter = qSL("username"); -const QString passwordParameter = qSL("password"); - -const QString applicationName = qSL("Deployment Server remote upload tool"); - -const QString serverReplyOk = qSL("ok"); -const QString serverReplyStatus = qSL("status"); -const QString invalidServerReply = qSL("Invalid server reply"); - - -QString getCurrentUsername() -{ - QString username = QString::fromLatin1(qgetenv("USER")); // For Linux/QNX/macOS - if (username.isEmpty()) - username = QString::fromLatin1(qgetenv("USERNAME")); // For windows - return username; -} - -QString makeBasicAuth(const QString& username,const QString& password) -{ - QString header = qSL("Basic "); - QString base64data = username + qSL(":") + password; - //Encode string in base64, and convert it back to string. - //toUtf8 is used, because password can be non-ascii - //fromLatin1 is used, because base64 is latin1 by definition. - base64data = QString::fromLatin1(base64data.toUtf8().toBase64()); - header = header + base64data; - return header; -} - -Q_NORETURN void printErrorAndExit(const QString &errorMessage, int exitCode) -{ - fprintf(stderr, "%s\n", qPrintable(errorMessage)); - exit(exitCode); -} - -Q_NORETURN void printErrorAndExit(const QString &errorPrefix, const QString &errorMessage, int exitCode) -{ - fprintf(stderr, "%s: %s\n", qPrintable(errorPrefix), qPrintable(errorMessage)); - exit(exitCode); -} - -int main(int argc, char *argv[]) -{ - QCoreApplication::setApplicationName(applicationName); - QCoreApplication::setOrganizationName(qSL("QtProject")); - QCoreApplication::setOrganizationDomain(qSL("qt-project.org")); - QCoreApplication::setApplicationVersion(qSL(AM_VERSION)); - QCoreApplication a(argc, argv); - - QCommandLineParser clp; - clp.setApplicationDescription(qSL("\n") + QCoreApplication::applicationName()); - clp.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions); - clp.addHelpOption(); - clp.addVersionOption(); - clp.addOption({{usernameParameter, qSL("u")}, qSL("User for uploading package. Defaults to current user"), usernameParameter, getCurrentUsername()}); - clp.addOption({{passwordParameter, qSL("p")}, qSL("Password for uploading package"), passwordParameter}); - clp.addOption({{categoryParameter, qSL("c")}, qSL("Category name or id for the package"), categoryParameter}); - clp.addOption({vendorParameter, qSL("Vendor name or id for the package"), vendorParameter}); - clp.addOption({summaryParameter, qSL("Short description"), qSL("Description string")}); - clp.addOption({descriptionParameter, qSL("Long description"), qSL("Description string")}); - clp.addOption({{qSL("url"), qSL("s")}, qSL("Server base url (with port)"), qSL("url"), qSL("http://localhost:8080")}); - clp.addPositionalArgument(qSL("package"), qSL("The file name of uploaded package")); - clp.process(a); - if (!clp.parse(QCoreApplication::arguments())) - printErrorAndExit(clp.errorText(), 1); - - if (clp.positionalArguments().isEmpty()) - clp.showHelp(2); - - QString username; - QString password; - username = clp.value(usernameParameter); - if (clp.isSet(passwordParameter)) - password = clp.value(passwordParameter); - - // Fill in the parameter map - QMap<QString, QString> parametersList; - if (clp.isSet(descriptionParameter)) - parametersList.insert(descriptionParameter, clp.value(descriptionParameter)); - if (clp.isSet(summaryParameter)) - parametersList.insert(shortDescriptionParameter, clp.value(summaryParameter)); - if (clp.isSet(categoryParameter)) - parametersList.insert(categoryParameter, clp.value(categoryParameter)); - if (clp.isSet(vendorParameter)) - parametersList.insert(vendorParameter, clp.value(vendorParameter)); - - QNetworkAccessManager am; - QNetworkRequest request(QUrl(clp.value(qSL("url")) + qSL("/upload"))); - // Setting this header is done to avoid two accesses to the server, first one - // unauthenticated, second one authenticated, so authentication is forced by - // adding a header - request.setRawHeader("Authorization", makeBasicAuth(username, password).toLatin1()); - QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); - - // Sending parameters to server - for (auto parameter = parametersList.cbegin(); parameter != parametersList.cend(); ++parameter) { - QHttpPart requestParameters; - QString dispositionHeader = qSL("form-data; name=\"") + parameter.key() + qSL("\""); - requestParameters.setHeader(QNetworkRequest::ContentDispositionHeader, dispositionHeader); - requestParameters.setBody(parameter.value().toUtf8()); - multipart->append(requestParameters); - } - - // Sending file to server - QHttpPart packagePart; - packagePart.setHeader(QNetworkRequest::ContentTypeHeader, qSL("application/octet-stream")); - packagePart.setHeader(QNetworkRequest::ContentDispositionHeader, qSL("form-data; name=\"package\";filename=\"package.appkg\"")); - QFile *packageFile = new QFile(clp.positionalArguments().constFirst()); - if (!packageFile->open(QIODevice::ReadOnly)) - printErrorAndExit(packageFile->errorString(), 3); - packagePart.setBodyDevice(packageFile); - multipart->append(packagePart); - packageFile->setParent(multipart); - - QNetworkReply *reply = am.post(request, multipart); - multipart->setParent(reply); - QEventLoop eventLoop; // QNetworkAcessManager does not work without event loop. At all. - QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit())); - eventLoop.exec(); - if (reply->error() != QNetworkReply::NoError) - printErrorAndExit(qSL("Network error"), reply->errorString(), 4); - QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); - if (document.isNull()) // Invalid reply - printErrorAndExit(invalidServerReply, 5); - if (!document[serverReplyStatus].isString()) // Invalid reply - printErrorAndExit(invalidServerReply, 5); - if (document[serverReplyStatus].toString() != serverReplyOk) - printErrorAndExit(qSL("Error uploading package"), document[serverReplyStatus].toString(), 6); - return 0; -} |