From f57775c830113f88b7f1882efa941bd88b4c8106 Mon Sep 17 00:00:00 2001 From: Konrad Kujawa Date: Fri, 12 May 2023 13:55:46 +0200 Subject: [PATCH] Remove QGrpcUserPasswordCredentials Remove QGrpcUserPasswordCredentials, as they are unused after introducing QGrpcMetadata. [ChangeLog] Removed QGrpcUserPasswordCredentials. Now user and password credentials can be added by using QGrpcMetadata. Task-number: QTBUG-111037 Change-Id: I8e998bae9882f238c4498f41e9f0d0a2894b49a7 Reviewed-by: Qt CI Bot Reviewed-by: Alexey Edelev --- src/grpc/CMakeLists.txt | 2 - src/grpc/qabstractgrpcchannel.h | 1 - src/grpc/qgrpccalloptions.cpp | 25 +-------- src/grpc/qgrpccalloptions.h | 3 - src/grpc/qgrpcchannel.cpp | 1 - src/grpc/qgrpcchannel_p.h | 1 - src/grpc/qgrpcchanneloptions.cpp | 26 +-------- src/grpc/qgrpcchanneloptions.h | 3 - src/grpc/qgrpccredentials.cpp | 68 ----------------------- src/grpc/qgrpccredentials.h | 34 ------------ src/grpc/qgrpchttp2channel.cpp | 6 +- src/grpc/qgrpcuserpasswordcredentials.cpp | 63 --------------------- src/grpc/qgrpcuserpasswordcredentials.h | 30 ---------- 13 files changed, 4 insertions(+), 259 deletions(-) delete mode 100644 src/grpc/qgrpccredentials.cpp delete mode 100644 src/grpc/qgrpccredentials.h delete mode 100644 src/grpc/qgrpcuserpasswordcredentials.cpp delete mode 100644 src/grpc/qgrpcuserpasswordcredentials.h diff --git a/src/grpc/CMakeLists.txt b/src/grpc/CMakeLists.txt index 99481513..7527a06a 100644 --- a/src/grpc/CMakeLists.txt +++ b/src/grpc/CMakeLists.txt @@ -10,8 +10,6 @@ qt_internal_add_module(Grpc qabstractgrpcchannel.h qabstractgrpcchannel_p.h qabstractgrpcchannel.cpp qgrpchttp2channel.h qgrpchttp2channel.cpp qabstractgrpcclient.h qabstractgrpcclient.cpp - qgrpccredentials.h qgrpccredentials.cpp - qgrpcuserpasswordcredentials.h qgrpcuserpasswordcredentials.cpp qgrpccalloptions.h qgrpccalloptions.cpp qgrpcchanneloptions.h qgrpcchanneloptions.cpp qgrpcmetadata.h diff --git a/src/grpc/qabstractgrpcchannel.h b/src/grpc/qabstractgrpcchannel.h index e84d9cc0..b4717159 100644 --- a/src/grpc/qabstractgrpcchannel.h +++ b/src/grpc/qabstractgrpcchannel.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/src/grpc/qgrpccalloptions.cpp b/src/grpc/qgrpccalloptions.cpp index 5eae93fc..2d5a423c 100644 --- a/src/grpc/qgrpccalloptions.cpp +++ b/src/grpc/qgrpccalloptions.cpp @@ -21,13 +21,10 @@ using namespace Qt::StringLiterals; struct QGrpcCallOptionsPrivate { public: - QGrpcCallOptionsPrivate() : credentials(nullptr) { } - std::optional host; std::optional deadline; - std::shared_ptr credentials; - std::optional maxRetryAttempts; QGrpcMetadata metadata; + std::optional maxRetryAttempts; }; /*! @@ -69,16 +66,6 @@ QGrpcCallOptions &QGrpcCallOptions::withDeadline(std::chrono::milliseconds deadl return *this; } -/*! - Sets call credentials with \a credentials and returns updated QGrpcCallOptions object. -*/ -QGrpcCallOptions &QGrpcCallOptions::withCredentials( - std::shared_ptr credentials) -{ - dPtr->credentials = credentials; - return *this; -} - /*! Sets maximum retry attempts value with \a maxRetryAttempts and returns updated QGrpcCallOptions object. */ @@ -107,16 +94,6 @@ std::optional QGrpcCallOptions::deadline() const return dPtr->deadline; } -/*! - Returns credentials for a call. - - If value was not set returns empty std::optional. -*/ -std::optional QGrpcCallOptions::credentials() const -{ - return dPtr->credentials ? (*dPtr->credentials)() : std::optional(); -} - /*! Returns maximum retry attempts value for a call. diff --git a/src/grpc/qgrpccalloptions.h b/src/grpc/qgrpccalloptions.h index 21552303..0175e234 100644 --- a/src/grpc/qgrpccalloptions.h +++ b/src/grpc/qgrpccalloptions.h @@ -5,7 +5,6 @@ #define QGRPCALLOPTIONS_H #include -#include #include #include @@ -27,12 +26,10 @@ public: QGrpcCallOptions &operator=(const QGrpcCallOptions &other); QGrpcCallOptions &withDeadline(std::chrono::milliseconds deadline); - QGrpcCallOptions &withCredentials(std::shared_ptr credentials); QGrpcCallOptions &withMaxRetryAttempts(qint64 maxRetryAttempts); QGrpcCallOptions &withMetadata(const QGrpcMetadata &metadata); std::optional deadline() const; - std::optional credentials() const; std::optional maxRetryAttempts() const; QGrpcMetadata metadata() const; diff --git a/src/grpc/qgrpcchannel.cpp b/src/grpc/qgrpcchannel.cpp index 470277d1..a343dc2f 100644 --- a/src/grpc/qgrpcchannel.cpp +++ b/src/grpc/qgrpcchannel.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include diff --git a/src/grpc/qgrpcchannel_p.h b/src/grpc/qgrpcchannel_p.h index ecf5780e..dbbb3924 100644 --- a/src/grpc/qgrpcchannel_p.h +++ b/src/grpc/qgrpcchannel_p.h @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/src/grpc/qgrpcchanneloptions.cpp b/src/grpc/qgrpcchanneloptions.cpp index abcf7bdd..abff5461 100644 --- a/src/grpc/qgrpcchanneloptions.cpp +++ b/src/grpc/qgrpcchanneloptions.cpp @@ -21,13 +21,12 @@ using namespace Qt::StringLiterals; struct QGrpcChannelOptionsPrivate { public: - QGrpcChannelOptionsPrivate(const QUrl &_host) : host(_host), credentials(nullptr) { } + QGrpcChannelOptionsPrivate(const QUrl &_host) : host(_host) { } QUrl host; std::optional deadline; - std::shared_ptr credentials; - std::optional credentialList; QGrpcMetadata metadata; + std::optional credentialList; #if QT_CONFIG(ssl) std::optional sslConfiguration; #endif @@ -82,16 +81,6 @@ QGrpcChannelOptions &QGrpcChannelOptions::withDeadline(std::chrono::milliseconds return *this; } -/*! - Sets channel credentials with \a credentials and returns updated QGrpcChannelOptions object. -*/ -QGrpcChannelOptions &QGrpcChannelOptions::withCredentials( - std::shared_ptr credentials) -{ - dPtr->credentials = credentials; - return *this; -} - /*! Sets channel credential list with \a credentialList and returns updated QGrpcChannelOptions object. */ @@ -128,17 +117,6 @@ QUrl QGrpcChannelOptions::host() const return dPtr->host; } -/*! - Returns credentials for the channel. - - If value was not set returns empty std::optional. -*/ -std::optional QGrpcChannelOptions::credentials() const -{ - return dPtr->credentials ? dPtr->credentials->channelCredentials() - : std::optional(); -} - /*! Returns credential list for the channel. diff --git a/src/grpc/qgrpcchanneloptions.h b/src/grpc/qgrpcchanneloptions.h index 341357c5..3e04a924 100644 --- a/src/grpc/qgrpcchanneloptions.h +++ b/src/grpc/qgrpcchanneloptions.h @@ -5,7 +5,6 @@ #define QGRPCHANNELOPTIONS_H #include -#include #include #include @@ -33,13 +32,11 @@ public: QGrpcChannelOptions &withHost(const QUrl &host); QGrpcChannelOptions &withDeadline(std::chrono::milliseconds deadline); - QGrpcChannelOptions &withCredentials(std::shared_ptr credentials); QGrpcChannelOptions &withCredentialList(const QStringList &credentialList); QGrpcChannelOptions &withMetadata(const QGrpcMetadata &metadata); QUrl host() const; std::optional deadline() const; - std::optional credentials() const; std::optional credentialList() const; QGrpcMetadata metadata() const; diff --git a/src/grpc/qgrpccredentials.cpp b/src/grpc/qgrpccredentials.cpp deleted file mode 100644 index e008ed44..00000000 --- a/src/grpc/qgrpccredentials.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// Copyright (C) 2019 Alexey Edelev -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include - -QT_BEGIN_NAMESPACE - -/*! - \typealias QGrpcCredentialMap - \relates QGrpcCallCredentials - \relates QGrpcChannelCredentials - - Alias for \c{QMap}. - This is the key-value map of credentials, such as user-password credentials - or session parameters. -*/ - -/*! - \class QGrpcCallCredentials - \inmodule QtGrpc - - \brief The QGrpcCallCredentials is the base class for gRPC call credentials. - - You may inherrit this class to create your own credentials implementation, - that will be used for each method call. - Classes inheriting from QGrpcCallCredentials must reimplement - \c{QGrpcCredentialMap operator()} and return a credentials map - for the call. -*/ - -/*! - \fn virtual QGrpcCredentialMap QGrpcCallCredentials::operator()() const = 0 - - This pure virtual operator returns a key-value map of the credentials for RPC calls. - - This operator is called to obtain the QGrpcCredentialMap for the call. -*/ - -/*! - \class QGrpcChannelCredentials - \inmodule QtGrpc - - \brief The QGrpcChannelCredentials is the base class for gRPC - channel credentials. - - Channel credentials are used by the channel when establishing - an initial connection. - For example Ssl credentials or some session tokens. - Classes inheriting this class should reimplement - \c{QGrpcCredentialMap channelCredentials() const}, - that returns session parameters for the specific channel. -*/ - -/*! - \fn virtual QGrpcCredentialMap QGrpcChannelCredentials::channelCredentials() const = 0 - - This pure virtual function shall return a key-value map of session parameters - for the specific channel. - - This function is called to obtain the QGrpcCredentialMap for the channel. -*/ - -QGrpcCallCredentials::~QGrpcCallCredentials() = default; - -QGrpcChannelCredentials::~QGrpcChannelCredentials() = default; - -QT_END_NAMESPACE diff --git a/src/grpc/qgrpccredentials.h b/src/grpc/qgrpccredentials.h deleted file mode 100644 index 71bd01b4..00000000 --- a/src/grpc/qgrpccredentials.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// Copyright (C) 2019 Alexey Edelev -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef QGRPCCREDENTIALS_H -#define QGRPCCREDENTIALS_H - -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -using QGrpcCredentialMap = QMap; - -class Q_GRPC_EXPORT QGrpcCallCredentials -{ -public: - virtual ~QGrpcCallCredentials(); - virtual QGrpcCredentialMap operator()() const = 0; -}; - -class Q_GRPC_EXPORT QGrpcChannelCredentials -{ -public: - virtual ~QGrpcChannelCredentials(); - virtual QGrpcCredentialMap channelCredentials() const = 0; -}; - -QT_END_NAMESPACE - -#endif // QGRPCCREDENTIALS_H diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index 6b5b771d..6e5e74fb 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -130,10 +129,7 @@ struct QGrpcHttp2ChannelPrivate #if QT_CONFIG(ssl) request.setSslConfiguration(sslConfig); #endif - if (const auto credentials = callOptions.credentials()) { - for (const auto &[key, value] : credentials->toStdMap()) - request.setRawHeader(key, value.toString().toUtf8()); - } + addMetadataToRequest(&request, channelOptions.metadata(), callOptions.metadata()); request.setAttribute(QNetworkRequest::Http2DirectAttribute, true); diff --git a/src/grpc/qgrpcuserpasswordcredentials.cpp b/src/grpc/qgrpcuserpasswordcredentials.cpp deleted file mode 100644 index bd1facf0..00000000 --- a/src/grpc/qgrpcuserpasswordcredentials.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// Copyright (C) 2019 Alexey Edelev -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "qgrpcuserpasswordcredentials.h" - -QT_BEGIN_NAMESPACE - -namespace { -constexpr char defaultUserFieldName[] = "user-name"; -constexpr char defaultPasswordFieldName[] = "user-password"; -} - -/*! - \class QGrpcUserPasswordCredentials - \inmodule QtGrpc - - \brief The QGrpcUserPasswordCredentials class is a reference - implementation of simple user-password call authentication. -*/ - -/*! - QGrpcUserPasswordCredentials constructs QGrpcUserPasswordCredentials with \a userName - and \a password with default UserFieldName and PasswordFieldName header keys. - The \c userNameField defaults to \c{"user-name"}, - the \c passwordField defaults to \c{"user-password"}. -*/ -QGrpcUserPasswordCredentials::QGrpcUserPasswordCredentials(const QString &userName, - const QString &password) - : QGrpcUserPasswordCredentials(defaultUserFieldName, userName, defaultPasswordFieldName, - password) -{ -} - -/*! - QGrpcUserPasswordCredentials constructs QGrpcUserPasswordCredentials with \a userName and \a password - credentials with manually specified \a userNameField and \a passwordField header keys. -*/ -QGrpcUserPasswordCredentials::QGrpcUserPasswordCredentials(const QByteArray &userNameField, - const QString &userName, - const QByteArray &passwordField, - const QString &password) - : m_map(QGrpcCredentialMap{ { userNameField, QVariant::fromValue(userName) }, - { passwordField, QVariant::fromValue(password) } }) -{ -} - -QGrpcUserPasswordCredentials::QGrpcUserPasswordCredentials() = default; - -/*! - Destroys the QGrpcUserPasswordCredentials object. -*/ -QGrpcUserPasswordCredentials::~QGrpcUserPasswordCredentials() = default; - -/*! - Returns the stored credentials map. -*/ -QGrpcCredentialMap QGrpcUserPasswordCredentials::operator()() const -{ - return m_map; -} - -QT_END_NAMESPACE diff --git a/src/grpc/qgrpcuserpasswordcredentials.h b/src/grpc/qgrpcuserpasswordcredentials.h deleted file mode 100644 index c01301ec..00000000 --- a/src/grpc/qgrpcuserpasswordcredentials.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// Copyright (C) 2019 Alexey Edelev -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef QGRPCUSERPASSWORDCREDENTIALS_H -#define QGRPCUSERPASSWORDCREDENTIALS_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class Q_GRPC_EXPORT QGrpcUserPasswordCredentials final : public QGrpcCallCredentials -{ -public: - explicit QGrpcUserPasswordCredentials(const QString &userName, const QString &password); - explicit QGrpcUserPasswordCredentials(const QByteArray &userNameField, const QString &userName, - const QByteArray &passwordField, const QString &password); - - ~QGrpcUserPasswordCredentials() override; - QGrpcCredentialMap operator()() const override; - -private: - QGrpcUserPasswordCredentials(); - QGrpcCredentialMap m_map; -}; - -QT_END_NAMESPACE - -#endif // QGRPCUSERPASSWORDCREDENTIALS_H