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 <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Konrad Kujawa 2023-05-12 13:55:46 +02:00
parent 7c91f00319
commit f57775c830
13 changed files with 4 additions and 259 deletions

View File

@ -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

View File

@ -9,7 +9,6 @@
#include <QtCore/QThread>
#include <QtCore/qbytearray.h>
#include <QtGrpc/qgrpccalloptions.h>
#include <QtGrpc/qgrpccredentials.h>
#include <QtGrpc/qgrpcstatus.h>
#include <QtGrpc/qtgrpcglobal.h>

View File

@ -21,13 +21,10 @@ using namespace Qt::StringLiterals;
struct QGrpcCallOptionsPrivate
{
public:
QGrpcCallOptionsPrivate() : credentials(nullptr) { }
std::optional<QUrl> host;
std::optional<std::chrono::milliseconds> deadline;
std::shared_ptr<QGrpcCallCredentials> credentials;
std::optional<qint64> maxRetryAttempts;
QGrpcMetadata metadata;
std::optional<qint64> 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<QGrpcCallCredentials> 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<std::chrono::milliseconds> QGrpcCallOptions::deadline() const
return dPtr->deadline;
}
/*!
Returns credentials for a call.
If value was not set returns empty std::optional.
*/
std::optional<QGrpcCredentialMap> QGrpcCallOptions::credentials() const
{
return dPtr->credentials ? (*dPtr->credentials)() : std::optional<QGrpcCredentialMap>();
}
/*!
Returns maximum retry attempts value for a call.

View File

@ -5,7 +5,6 @@
#define QGRPCALLOPTIONS_H
#include <QtCore/QUrl>
#include <QtGrpc/QGrpcCallCredentials>
#include <QtGrpc/qgrpcmetadata.h>
#include <QtGrpc/qtgrpcglobal.h>
@ -27,12 +26,10 @@ public:
QGrpcCallOptions &operator=(const QGrpcCallOptions &other);
QGrpcCallOptions &withDeadline(std::chrono::milliseconds deadline);
QGrpcCallOptions &withCredentials(std::shared_ptr<QGrpcCallCredentials> credentials);
QGrpcCallOptions &withMaxRetryAttempts(qint64 maxRetryAttempts);
QGrpcCallOptions &withMetadata(const QGrpcMetadata &metadata);
std::optional<std::chrono::milliseconds> deadline() const;
std::optional<QGrpcCredentialMap> credentials() const;
std::optional<qint64> maxRetryAttempts() const;
QGrpcMetadata metadata() const;

View File

@ -7,7 +7,6 @@
#include <QtCore/QThread>
#include <QtCore/qloggingcategory.h>
#include <QtGrpc/qabstractgrpcclient.h>
#include <QtGrpc/qgrpccredentials.h>
#include <QtProtobuf/QProtobufSerializer>
#include <qtgrpcglobal_p.h>

View File

@ -19,7 +19,6 @@
#include <QtGrpc/qabstractgrpcclient.h>
#include <QtGrpc/qgrpccallreply.h>
#include <QtGrpc/qgrpcchannel.h>
#include <QtGrpc/qgrpccredentials.h>
#include <QtGrpc/qgrpcstream.h>
#include <QtGrpc/private/qtgrpcglobal_p.h>

View File

@ -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<std::chrono::milliseconds> deadline;
std::shared_ptr<QGrpcChannelCredentials> credentials;
std::optional<QStringList> credentialList;
QGrpcMetadata metadata;
std::optional<QStringList> credentialList;
#if QT_CONFIG(ssl)
std::optional<QSslConfiguration> 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<QGrpcChannelCredentials> 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<QGrpcCredentialMap> QGrpcChannelOptions::credentials() const
{
return dPtr->credentials ? dPtr->credentials->channelCredentials()
: std::optional<QGrpcCredentialMap>();
}
/*!
Returns credential list for the channel.

View File

@ -5,7 +5,6 @@
#define QGRPCHANNELOPTIONS_H
#include <QtCore/QUrl>
#include <QtGrpc/QGrpcChannelCredentials>
#include <QtGrpc/qgrpcmetadata.h>
#include <QtGrpc/qtgrpcglobal.h>
@ -33,13 +32,11 @@ public:
QGrpcChannelOptions &withHost(const QUrl &host);
QGrpcChannelOptions &withDeadline(std::chrono::milliseconds deadline);
QGrpcChannelOptions &withCredentials(std::shared_ptr<QGrpcChannelCredentials> credentials);
QGrpcChannelOptions &withCredentialList(const QStringList &credentialList);
QGrpcChannelOptions &withMetadata(const QGrpcMetadata &metadata);
QUrl host() const;
std::optional<std::chrono::milliseconds> deadline() const;
std::optional<QGrpcCredentialMap> credentials() const;
std::optional<QStringList> credentialList() const;
QGrpcMetadata metadata() const;

View File

@ -1,68 +0,0 @@
// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2019 Alexey Edelev <semlanik@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGrpc/qgrpccredentials.h>
QT_BEGIN_NAMESPACE
/*!
\typealias QGrpcCredentialMap
\relates QGrpcCallCredentials
\relates QGrpcChannelCredentials
Alias for \c{QMap<QByteArray, QVariant>}.
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

View File

@ -1,34 +0,0 @@
// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2019 Alexey Edelev <semlanik@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QGRPCCREDENTIALS_H
#define QGRPCCREDENTIALS_H
#include <QtGrpc/qtgrpcglobal.h>
#include <QtCore/QByteArray>
#include <QtCore/QMap>
#include <QtCore/QVariant>
QT_BEGIN_NAMESPACE
using QGrpcCredentialMap = QMap<QByteArray, QVariant>;
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

View File

@ -8,7 +8,6 @@
#include <QtCore/QUrl>
#include <QtGrpc/qabstractgrpcclient.h>
#include <QtGrpc/qgrpccallreply.h>
#include <QtGrpc/qgrpccredentials.h>
#include <QtGrpc/qgrpcstream.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
@ -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);

View File

@ -1,63 +0,0 @@
// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2019 Alexey Edelev <semlanik@gmail.com>
// 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

View File

@ -1,30 +0,0 @@
// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2019 Alexey Edelev <semlanik@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef QGRPCUSERPASSWORDCREDENTIALS_H
#define QGRPCUSERPASSWORDCREDENTIALS_H
#include <QtGrpc/qgrpccredentials.h>
#include <QtGrpc/qtgrpcglobal.h>
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