ClickHouse/src/Interpreters/InterpreterDropAccessEntityQuery.cpp

71 lines
2.2 KiB
C++
Raw Normal View History

2019-12-01 22:01:05 +00:00
#include <Interpreters/InterpreterDropAccessEntityQuery.h>
#include <Parsers/ASTDropAccessEntityQuery.h>
#include <Parsers/ASTRowPolicyName.h>
2019-12-01 22:01:05 +00:00
#include <Interpreters/Context.h>
2020-11-03 13:47:26 +00:00
#include <Interpreters/executeDDLQueryOnCluster.h>
2019-12-01 22:01:05 +00:00
#include <Access/AccessControlManager.h>
#include <Access/AccessFlags.h>
#include <Access/User.h>
#include <Access/Role.h>
2019-12-01 22:01:05 +00:00
#include <Access/Quota.h>
2019-11-29 17:22:56 +00:00
#include <Access/RowPolicy.h>
#include <Access/SettingsProfile.h>
2019-12-01 22:01:05 +00:00
namespace DB
{
namespace ErrorCodes
2019-12-01 22:01:05 +00:00
{
extern const int NOT_IMPLEMENTED;
}
2019-12-01 22:01:05 +00:00
using EntityType = IAccessEntity::Type;
BlockIO InterpreterDropAccessEntityQuery::execute()
{
auto & query = query_ptr->as<ASTDropAccessEntityQuery &>();
auto & access_control = getContext()->getAccessControlManager();
getContext()->checkAccess(getRequiredAccess());
if (!query.cluster.empty())
return executeDDLQueryOnCluster(query_ptr, getContext());
query.replaceEmptyDatabase(getContext()->getCurrentDatabase());
auto do_drop = [&](const Strings & names)
{
if (query.if_exists)
access_control.tryRemove(access_control.find(query.type, names));
else
access_control.remove(access_control.getIDs(query.type, names));
};
2019-12-01 22:01:05 +00:00
if (query.type == EntityType::ROW_POLICY)
do_drop(query.row_policy_names->toStrings());
else
do_drop(query.names);
return {};
2019-12-01 22:01:05 +00:00
}
AccessRightsElements InterpreterDropAccessEntityQuery::getRequiredAccess() const
{
const auto & query = query_ptr->as<const ASTDropAccessEntityQuery &>();
AccessRightsElements res;
switch (query.type)
{
case EntityType::USER: res.emplace_back(AccessType::DROP_USER); return res;
case EntityType::ROLE: res.emplace_back(AccessType::DROP_ROLE); return res;
case EntityType::SETTINGS_PROFILE: res.emplace_back(AccessType::DROP_SETTINGS_PROFILE); return res;
case EntityType::ROW_POLICY: res.emplace_back(AccessType::DROP_ROW_POLICY); return res;
case EntityType::QUOTA: res.emplace_back(AccessType::DROP_QUOTA); return res;
case EntityType::MAX: break;
}
throw Exception(
toString(query.type) + ": type is not supported by DROP query", ErrorCodes::NOT_IMPLEMENTED);
}
2019-12-01 22:01:05 +00:00
}