ClickHouse/src/Access/Credentials.cpp
Alexander Tokmakov 70d1adfe4b
Better formatting for exception messages (#45449)
* save format string for NetException

* format exceptions

* format exceptions 2

* format exceptions 3

* format exceptions 4

* format exceptions 5

* format exceptions 6

* fix

* format exceptions 7

* format exceptions 8

* Update MergeTreeIndexGin.cpp

* Update AggregateFunctionMap.cpp

* Update AggregateFunctionMap.cpp

* fix
2023-01-24 00:13:58 +03:00

101 lines
1.8 KiB
C++

#include <Access/Credentials.h>
#include <Common/Exception.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
Credentials::Credentials(const String & user_name_)
: user_name(user_name_)
{
}
const String & Credentials::getUserName() const
{
if (!isReady())
throwNotReady();
return user_name;
}
bool Credentials::isReady() const
{
return is_ready;
}
void Credentials::throwNotReady()
{
throw Exception(ErrorCodes::LOGICAL_ERROR, "Credentials are not ready");
}
AlwaysAllowCredentials::AlwaysAllowCredentials()
{
is_ready = true;
}
AlwaysAllowCredentials::AlwaysAllowCredentials(const String & user_name_)
: Credentials(user_name_)
{
is_ready = true;
}
void AlwaysAllowCredentials::setUserName(const String & user_name_)
{
user_name = user_name_;
}
SSLCertificateCredentials::SSLCertificateCredentials(const String & user_name_, const String & common_name_)
: Credentials(user_name_)
, common_name(common_name_)
{
is_ready = true;
}
const String & SSLCertificateCredentials::getCommonName() const
{
if (!isReady())
throwNotReady();
return common_name;
}
BasicCredentials::BasicCredentials()
{
is_ready = true;
}
BasicCredentials::BasicCredentials(const String & user_name_)
: Credentials(user_name_)
{
is_ready = true;
}
BasicCredentials::BasicCredentials(const String & user_name_, const String & password_)
: Credentials(user_name_)
, password(password_)
{
is_ready = true;
}
void BasicCredentials::setUserName(const String & user_name_)
{
user_name = user_name_;
}
void BasicCredentials::setPassword(const String & password_)
{
password = password_;
}
const String & BasicCredentials::getPassword() const
{
if (!isReady())
throwNotReady();
return password;
}
}