2020-05-07 02:45:27 +00:00
|
|
|
#include <Parsers/ParserShowAccessEntitiesQuery.h>
|
|
|
|
#include <Parsers/ASTShowAccessEntitiesQuery.h>
|
2019-11-29 17:22:56 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/parseDatabaseAndTableName.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2020-05-07 02:45:27 +00:00
|
|
|
using EntityType = IAccessEntity::Type;
|
|
|
|
|
2019-11-29 17:22:56 +00:00
|
|
|
bool parseONDatabaseAndTableName(IParserBase::Pos & pos, Expected & expected, String & database, String & table_name)
|
|
|
|
{
|
|
|
|
return IParserBase::wrapParseImpl(pos, [&]
|
|
|
|
{
|
|
|
|
database.clear();
|
|
|
|
table_name.clear();
|
|
|
|
return ParserKeyword{"ON"}.ignore(pos, expected) && parseDatabaseAndTableName(pos, expected, database, table_name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-07 02:45:27 +00:00
|
|
|
bool ParserShowAccessEntitiesQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2019-11-29 17:22:56 +00:00
|
|
|
{
|
2020-05-08 12:50:45 +00:00
|
|
|
if (!ParserKeyword{"SHOW"}.ignore(pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::optional<EntityType> type;
|
|
|
|
bool current_quota = false;
|
2020-05-12 23:36:39 +00:00
|
|
|
bool current_roles = false;
|
|
|
|
bool enabled_roles = false;
|
2020-05-08 12:50:45 +00:00
|
|
|
|
2020-05-12 23:36:39 +00:00
|
|
|
if (ParserKeyword{"USERS"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::USER;
|
|
|
|
}
|
|
|
|
else if (ParserKeyword{"ROLES"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::ROLE;
|
|
|
|
}
|
|
|
|
else if (ParserKeyword{"CURRENT ROLES"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::ROLE;
|
|
|
|
current_roles = true;
|
|
|
|
}
|
|
|
|
else if (ParserKeyword{"ENABLED ROLES"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::ROLE;
|
|
|
|
enabled_roles = true;
|
|
|
|
}
|
|
|
|
else if (ParserKeyword{"POLICIES"}.ignore(pos, expected) || ParserKeyword{"ROW POLICIES"}.ignore(pos, expected))
|
2020-05-08 12:50:45 +00:00
|
|
|
{
|
|
|
|
type = EntityType::ROW_POLICY;
|
|
|
|
}
|
|
|
|
else if (ParserKeyword{"QUOTAS"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::QUOTA;
|
|
|
|
}
|
|
|
|
else if (ParserKeyword{"QUOTA"}.ignore(pos, expected) || ParserKeyword{"CURRENT QUOTA"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::QUOTA;
|
|
|
|
current_quota = true;
|
|
|
|
}
|
2020-05-12 20:31:30 +00:00
|
|
|
else if (ParserKeyword{"PROFILES"}.ignore(pos, expected) || ParserKeyword{"SETTINGS PROFILES"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
type = EntityType::SETTINGS_PROFILE;
|
|
|
|
}
|
2020-05-08 12:50:45 +00:00
|
|
|
else
|
2019-11-29 17:22:56 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
String database, table_name;
|
2020-05-08 12:50:45 +00:00
|
|
|
if (type == EntityType::ROW_POLICY)
|
|
|
|
parseONDatabaseAndTableName(pos, expected, database, table_name);
|
2019-11-29 17:22:56 +00:00
|
|
|
|
2020-05-07 02:45:27 +00:00
|
|
|
auto query = std::make_shared<ASTShowAccessEntitiesQuery>();
|
|
|
|
node = query;
|
|
|
|
|
2020-05-08 12:50:45 +00:00
|
|
|
query->type = *type;
|
|
|
|
query->current_quota = current_quota;
|
2020-05-12 23:36:39 +00:00
|
|
|
query->current_roles = current_roles;
|
|
|
|
query->enabled_roles = enabled_roles;
|
2019-11-29 17:22:56 +00:00
|
|
|
query->database = std::move(database);
|
|
|
|
query->table_name = std::move(table_name);
|
2020-05-07 02:45:27 +00:00
|
|
|
|
2019-11-29 17:22:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|