Fix clang-tidy warnings in Access folder

This commit is contained in:
Maksim Kita 2022-03-11 15:52:15 +00:00
parent b143aefd3f
commit e14cfd5dcd
30 changed files with 46 additions and 50 deletions

View File

@ -46,9 +46,9 @@ struct StringRef
constexpr StringRef(const char * data_, size_t size_) : data(data_), size(size_) {}
StringRef(const std::string & s) : data(s.data()), size(s.size()) {}
StringRef(const std::string & s) : data(s.data()), size(s.size()) {} /// NOLINT
constexpr explicit StringRef(std::string_view s) : data(s.data()), size(s.size()) {}
constexpr StringRef(const char * data_) : StringRef(std::string_view{data_}) {}
constexpr StringRef(const char * data_) : StringRef(std::string_view{data_}) {} /// NOLINT
constexpr StringRef() = default;
std::string toString() const { return std::string(data, size); }

View File

@ -15,7 +15,7 @@ class AccessRights
{
public:
AccessRights();
AccessRights(const AccessFlags & access);
explicit AccessRights(const AccessFlags & access);
~AccessRights();
AccessRights(const AccessRights & src);
AccessRights & operator =(const AccessRights & src);

View File

@ -15,17 +15,17 @@ using Strings = std::vector<String>;
class AccessFlags
{
public:
AccessFlags(AccessType type);
AccessFlags(AccessType type); /// NOLINT
/// The same as AccessFlags(AccessType::NONE).
AccessFlags() = default;
/// Constructs from a string like "SELECT".
AccessFlags(const std::string_view & keyword);
AccessFlags(const std::string_view & keyword); /// NOLINT
/// Constructs from a list of strings like "SELECT, UPDATE, INSERT".
AccessFlags(const std::vector<std::string_view> & keywords);
AccessFlags(const Strings & keywords);
AccessFlags(const std::vector<std::string_view> & keywords); /// NOLINT
AccessFlags(const Strings & keywords); /// NOLINT
AccessFlags(const AccessFlags & src) = default;
AccessFlags(AccessFlags && src) = default;
@ -109,7 +109,7 @@ private:
using Flags = std::bitset<SIZE>;
Flags flags;
AccessFlags(const Flags & flags_) : flags(flags_) {}
AccessFlags(const Flags & flags_) : flags(flags_) {} /// NOLINT
};
AccessFlags operator |(AccessType left, AccessType right);

View File

@ -26,7 +26,7 @@ struct AccessRightsElement
AccessRightsElement(AccessRightsElement &&) = default;
AccessRightsElement & operator=(AccessRightsElement &&) = default;
AccessRightsElement(AccessFlags access_flags_) : access_flags(access_flags_) {}
explicit AccessRightsElement(AccessFlags access_flags_) : access_flags(access_flags_) {}
AccessRightsElement(AccessFlags access_flags_, const std::string_view & database_);
AccessRightsElement(AccessFlags access_flags_, const std::string_view & database_, const std::string_view & table_);

View File

@ -18,7 +18,7 @@ public:
class IPSubnet
{
public:
IPSubnet() {}
IPSubnet() = default;
IPSubnet(const IPAddress & prefix_, const IPAddress & mask_) { set(prefix_, mask_); }
IPSubnet(const IPAddress & prefix_, size_t num_prefix_bits) { set(prefix_, num_prefix_bits); }
explicit IPSubnet(const IPAddress & address) { set(address); }
@ -43,9 +43,9 @@ public:
struct AnyHostTag {};
AllowedClientHosts() {}
AllowedClientHosts(AnyHostTag) { addAnyHost(); }
~AllowedClientHosts() {}
AllowedClientHosts() = default;
AllowedClientHosts(AnyHostTag) { addAnyHost(); } /// NOLINT
~AllowedClientHosts() = default;
AllowedClientHosts(const AllowedClientHosts & src) = default;
AllowedClientHosts & operator =(const AllowedClientHosts & src) = default;

View File

@ -54,7 +54,7 @@ class AuthenticationData
public:
using Digest = std::vector<uint8_t>;
AuthenticationData(AuthenticationType type_ = AuthenticationType::NO_PASSWORD) : type(type_) {}
explicit AuthenticationData(AuthenticationType type_ = AuthenticationType::NO_PASSWORD) : type(type_) {}
AuthenticationData(const AuthenticationData & src) = default;
AuthenticationData & operator =(const AuthenticationData & src) = default;
AuthenticationData(AuthenticationData && src) = default;

View File

@ -158,7 +158,7 @@ public:
private:
friend class AccessControl;
ContextAccess() {}
ContextAccess() {} /// NOLINT
ContextAccess(const AccessControl & access_control_, const Params & params_);
void initialize();

View File

@ -21,7 +21,6 @@ public:
protected:
[[noreturn]] static void throwNotReady();
protected:
bool is_ready = false;
String user_name;
};

View File

@ -60,8 +60,8 @@ public:
private:
friend class QuotaCache;
EnabledQuota(const Params & params_);
EnabledQuota() {}
explicit EnabledQuota(const Params & params_);
EnabledQuota() {} /// NOLINT
const String & getUserName() const { return params.user_name; }

View File

@ -41,7 +41,7 @@ public:
private:
friend class RoleCache;
EnabledRoles(const Params & params_);
explicit EnabledRoles(const Params & params_);
void setRolesInfo(const std::shared_ptr<const EnabledRolesInfo> & info_, scope_guard & notifications);

View File

@ -44,7 +44,7 @@ public:
private:
friend class RowPolicyCache;
EnabledRowPolicies(const Params & params_);
explicit EnabledRowPolicies(const Params & params_);
struct MixedFiltersKey
{

View File

@ -38,7 +38,7 @@ public:
private:
friend class SettingsProfilesCache;
EnabledSettings(const Params & params_);
explicit EnabledSettings(const Params & params_);
void setInfo(const std::shared_ptr<const SettingsProfilesInfo> & info_);
const Params params;

View File

@ -51,7 +51,6 @@ private:
using LDAPCaches = std::map<String, LDAPCache>; // server name -> cache
using LDAPParams = std::map<String, LDAPClient::Params>; // server name -> params
private:
mutable std::recursive_mutex mutex;
LDAPParams ldap_client_params_blueprint;
mutable LDAPCaches ldap_caches;

View File

@ -47,7 +47,6 @@ private:
void resetHandles() noexcept;
void initHandles();
private:
const Params params;
bool is_failed = false;

View File

@ -24,8 +24,8 @@ class ExternalAuthenticators;
class IAccessStorage
{
public:
IAccessStorage(const String & storage_name_) : storage_name(storage_name_) {}
virtual ~IAccessStorage() {}
explicit IAccessStorage(const String & storage_name_) : storage_name(storage_name_) {}
virtual ~IAccessStorage() = default;
/// Returns the name of this storage.
const String & getStorageName() const { return storage_name; }

View File

@ -37,7 +37,7 @@ public:
String getLDAPServerName() const;
public: // IAccessStorage implementations.
// IAccessStorage implementations.
virtual const char * getStorageType() const override;
virtual String getStorageParamsJSON() const override;
virtual bool isReadOnly() const override { return true; }
@ -54,7 +54,6 @@ private: // IAccessStorage implementations.
virtual scope_guard subscribeForChangesImpl(AccessEntityType type, const OnChangedHandler & handler) const override;
virtual std::optional<UUID> authenticateImpl(const Credentials & credentials, const Poco::Net::IPAddress & address, const ExternalAuthenticators & external_authenticators, bool throw_if_user_not_exists, bool allow_no_password, bool allow_plaintext_password) const override;
private:
void setConfiguration(AccessControl * access_control_, const Poco::Util::AbstractConfiguration & config, const String & prefix);
void processRoleChange(const UUID & id, const AccessEntityPtr & entity);

View File

@ -153,7 +153,7 @@ namespace
}
void LDAPClient::diag(const int rc, String text)
void LDAPClient::diag(int rc, String text)
{
std::scoped_lock lock(ldap_global_mutex);

View File

@ -133,12 +133,11 @@ public:
LDAPClient & operator= (LDAPClient &&) = delete;
protected:
MAYBE_NORETURN void diag(const int rc, String text = "");
MAYBE_NORETURN void diag(int rc, String text = "");
MAYBE_NORETURN bool openConnection();
void closeConnection() noexcept;
SearchResults search(const SearchParams & search_params);
protected:
const Params params;
#if USE_LDAP
LDAP * handle = nullptr;

View File

@ -15,7 +15,7 @@ class MemoryAccessStorage : public IAccessStorage
public:
static constexpr char STORAGE_TYPE[] = "memory";
MemoryAccessStorage(const String & storage_name_ = STORAGE_TYPE);
explicit MemoryAccessStorage(const String & storage_name_ = STORAGE_TYPE);
const char * getStorageType() const override { return STORAGE_TYPE; }

View File

@ -17,7 +17,7 @@ public:
using StoragePtr = std::shared_ptr<Storage>;
using ConstStoragePtr = std::shared_ptr<const Storage>;
MultipleAccessStorage(const String & storage_name_ = STORAGE_TYPE);
explicit MultipleAccessStorage(const String & storage_name_ = STORAGE_TYPE);
~MultipleAccessStorage() override;
const char * getStorageType() const override { return STORAGE_TYPE; }

View File

@ -19,7 +19,7 @@ struct RolesOrUsersSet;
class QuotaCache
{
public:
QuotaCache(const AccessControl & access_control_);
explicit QuotaCache(const AccessControl & access_control_);
~QuotaCache();
std::shared_ptr<const EnabledQuota> getEnabledQuota(

View File

@ -16,7 +16,7 @@ using RolePtr = std::shared_ptr<const Role>;
class RoleCache
{
public:
RoleCache(const AccessControl & access_control_);
explicit RoleCache(const AccessControl & access_control_);
~RoleCache();
std::shared_ptr<const EnabledRoles> getEnabledRoles(

View File

@ -26,13 +26,13 @@ struct RolesOrUsersSet
RolesOrUsersSet & operator =(RolesOrUsersSet && src) noexcept;
struct AllTag {};
RolesOrUsersSet(AllTag);
RolesOrUsersSet(AllTag); /// NOLINT
RolesOrUsersSet(const UUID & id);
RolesOrUsersSet(const std::vector<UUID> & ids_);
RolesOrUsersSet(const UUID & id); /// NOLINT
RolesOrUsersSet(const std::vector<UUID> & ids_); /// NOLINT
/// The constructor from AST requires the AccessControl if `ast.id_mode == false`.
RolesOrUsersSet(const ASTRolesOrUsersSet & ast);
RolesOrUsersSet(const ASTRolesOrUsersSet & ast); /// NOLINT
RolesOrUsersSet(const ASTRolesOrUsersSet & ast, const std::optional<UUID> & current_user_id);
RolesOrUsersSet(const ASTRolesOrUsersSet & ast, const AccessControl & access_control);
RolesOrUsersSet(const ASTRolesOrUsersSet & ast, const AccessControl & access_control, const std::optional<UUID> & current_user_id);

View File

@ -18,7 +18,7 @@ using RowPolicyPtr = std::shared_ptr<const RowPolicy>;
class RowPolicyCache
{
public:
RowPolicyCache(const AccessControl & access_control_);
explicit RowPolicyCache(const AccessControl & access_control_);
~RowPolicyCache();
std::shared_ptr<const EnabledRowPolicies> getEnabledRowPolicies(const UUID & user_id, const boost::container::flat_set<UUID> & enabled_roles);
@ -26,7 +26,7 @@ public:
private:
struct PolicyInfo
{
PolicyInfo(const RowPolicyPtr & policy_) { setPolicy(policy_); }
explicit PolicyInfo(const RowPolicyPtr & policy_) { setPolicy(policy_); }
void setPolicy(const RowPolicyPtr & policy_);
RowPolicyPtr policy;

View File

@ -51,7 +51,7 @@ class AccessControl;
class SettingsConstraints
{
public:
SettingsConstraints(const AccessControl & access_control_);
explicit SettingsConstraints(const AccessControl & access_control_);
SettingsConstraints(const SettingsConstraints & src);
SettingsConstraints & operator=(const SettingsConstraints & src);
SettingsConstraints(SettingsConstraints && src) noexcept;

View File

@ -15,7 +15,7 @@ struct SettingsConstraintsAndProfileIDs
std::vector<UUID> current_profiles;
std::vector<UUID> enabled_profiles;
SettingsConstraintsAndProfileIDs(const AccessControl & access_control_) : constraints(access_control_) {}
explicit SettingsConstraintsAndProfileIDs(const AccessControl & access_control_) : constraints(access_control_) {}
};
}

View File

@ -33,10 +33,10 @@ struct SettingsProfileElement
friend bool operator <=(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return !(rhs < lhs); }
friend bool operator >=(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return !(lhs < rhs); }
SettingsProfileElement() {}
SettingsProfileElement() = default;
/// The constructor from AST requires the AccessControl if `ast.id_mode == false`.
SettingsProfileElement(const ASTSettingsProfileElement & ast);
SettingsProfileElement(const ASTSettingsProfileElement & ast); /// NOLINT
SettingsProfileElement(const ASTSettingsProfileElement & ast, const AccessControl & access_control);
std::shared_ptr<ASTSettingsProfileElement> toAST() const;
std::shared_ptr<ASTSettingsProfileElement> toASTWithNames(const AccessControl & access_control) const;
@ -49,10 +49,10 @@ private:
class SettingsProfileElements : public std::vector<SettingsProfileElement>
{
public:
SettingsProfileElements() {}
SettingsProfileElements() = default;
/// The constructor from AST requires the AccessControl if `ast.id_mode == false`.
SettingsProfileElements(const ASTSettingsProfileElements & ast);
SettingsProfileElements(const ASTSettingsProfileElements & ast); /// NOLINT
SettingsProfileElements(const ASTSettingsProfileElements & ast, const AccessControl & access_control);
std::shared_ptr<ASTSettingsProfileElements> toAST() const;
std::shared_ptr<ASTSettingsProfileElements> toASTWithNames(const AccessControl & access_control) const;

View File

@ -18,7 +18,7 @@ struct SettingsProfilesInfo;
class SettingsProfilesCache
{
public:
SettingsProfilesCache(const AccessControl & access_control_);
explicit SettingsProfilesCache(const AccessControl & access_control_);
~SettingsProfilesCache();
void setDefaultProfileName(const String & default_profile_name);

View File

@ -29,7 +29,7 @@ struct SettingsProfilesInfo
/// Names of all the profiles in `profiles`.
std::unordered_map<UUID, String> names_of_profiles;
SettingsProfilesInfo(const AccessControl & access_control_) : constraints(access_control_), access_control(access_control_) {}
explicit SettingsProfilesInfo(const AccessControl & access_control_) : constraints(access_control_), access_control(access_control_) {}
std::shared_ptr<const SettingsConstraintsAndProfileIDs> getConstraintsAndProfileIDs(
const std::shared_ptr<const SettingsConstraintsAndProfileIDs> & previous = nullptr) const;

View File

@ -24,8 +24,9 @@ public:
using IsNoPasswordFunction = std::function<bool()>;
using IsPlaintextPasswordFunction = std::function<bool()>;
UsersConfigAccessStorage(const String & storage_name_ = STORAGE_TYPE, const CheckSettingNameFunction & check_setting_name_function_ = {}, const IsNoPasswordFunction & is_no_password_allowed_function_ ={}, const IsPlaintextPasswordFunction & is_plaintext_password_allowed_function_ = {});
UsersConfigAccessStorage(const CheckSettingNameFunction & check_setting_name_function_, const IsNoPasswordFunction & is_no_password_allowed_function_, const IsPlaintextPasswordFunction & is_plaintext_password_allowed_function_);
UsersConfigAccessStorage(const String & storage_name_ = STORAGE_TYPE, const CheckSettingNameFunction & check_setting_name_function_ = {}, const IsNoPasswordFunction & is_no_password_allowed_function_ ={}, const IsPlaintextPasswordFunction & is_plaintext_password_allowed_function_ = {}); /// NOLINT
UsersConfigAccessStorage(const CheckSettingNameFunction & check_setting_name_function_, const IsNoPasswordFunction & is_no_password_allowed_function_, const IsPlaintextPasswordFunction & is_plaintext_password_allowed_function_); /// NOLINT
~UsersConfigAccessStorage() override;
const char * getStorageType() const override { return STORAGE_TYPE; }