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>
|
2020-06-06 07:21:02 +00:00
|
|
|
#include <Parsers/parseIdentifierOrStringLiteral.h>
|
2021-06-15 19:55:21 +00:00
|
|
|
#include <common/range.h>
|
2019-11-29 17:22:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2020-05-07 02:45:27 +00:00
|
|
|
using EntityType = IAccessEntity::Type;
|
2020-06-06 07:21:02 +00:00
|
|
|
using EntityTypeInfo = IAccessEntity::TypeInfo;
|
2020-05-07 02:45:27 +00:00
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
bool parseEntityType(IParserBase::Pos & pos, Expected & expected, EntityType & type)
|
|
|
|
{
|
2021-06-15 19:55:21 +00:00
|
|
|
for (auto i : collections::range(EntityType::MAX))
|
2020-06-06 07:21:02 +00:00
|
|
|
{
|
|
|
|
const auto & type_info = EntityTypeInfo::get(i);
|
|
|
|
if (ParserKeyword{type_info.plural_name.c_str()}.ignore(pos, expected)
|
|
|
|
|| (!type_info.plural_alias.empty() && ParserKeyword{type_info.plural_alias.c_str()}.ignore(pos, expected)))
|
|
|
|
{
|
|
|
|
type = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool parseOnDBAndTableName(IParserBase::Pos & pos, Expected & expected, String & database, bool & any_database, String & table, bool & any_table)
|
2019-11-29 17:22:56 +00:00
|
|
|
{
|
|
|
|
return IParserBase::wrapParseImpl(pos, [&]
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
return ParserKeyword{"ON"}.ignore(pos, expected)
|
|
|
|
&& parseDatabaseAndTableNameOrAsterisks(pos, expected, database, any_database, table, any_table);
|
2019-11-29 17:22:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
EntityType type;
|
|
|
|
bool all = false;
|
2020-05-08 12:50:45 +00:00
|
|
|
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-06-06 07:21:02 +00:00
|
|
|
if (parseEntityType(pos, expected, type))
|
2020-05-12 23:36:39 +00:00
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
all = true;
|
2020-05-12 23:36:39 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2020-06-06 07:21:02 +00:00
|
|
|
else if (ParserKeyword{"CURRENT QUOTA"}.ignore(pos, expected) || ParserKeyword{"QUOTA"}.ignore(pos, expected))
|
2020-05-08 12:50:45 +00:00
|
|
|
{
|
|
|
|
type = EntityType::QUOTA;
|
|
|
|
current_quota = true;
|
|
|
|
}
|
|
|
|
else
|
2019-11-29 17:22:56 +00:00
|
|
|
return false;
|
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
String short_name;
|
|
|
|
std::optional<std::pair<String, String>> database_and_table_name;
|
2020-05-08 12:50:45 +00:00
|
|
|
if (type == EntityType::ROW_POLICY)
|
2020-06-06 07:21:02 +00:00
|
|
|
{
|
|
|
|
String database, table_name;
|
|
|
|
bool any_database, any_table;
|
|
|
|
if (parseOnDBAndTableName(pos, expected, database, any_database, table_name, any_table))
|
|
|
|
{
|
|
|
|
if (any_database)
|
|
|
|
all = true;
|
|
|
|
else
|
|
|
|
database_and_table_name.emplace(database, table_name);
|
|
|
|
}
|
|
|
|
else if (parseIdentifierOrStringLiteral(pos, expected, short_name))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
all = true;
|
|
|
|
}
|
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-06-06 07:21:02 +00:00
|
|
|
query->type = type;
|
|
|
|
query->all = all;
|
2020-05-08 12:50:45 +00:00
|
|
|
query->current_quota = current_quota;
|
2020-05-12 23:36:39 +00:00
|
|
|
query->current_roles = current_roles;
|
|
|
|
query->enabled_roles = enabled_roles;
|
2020-06-06 07:21:02 +00:00
|
|
|
query->short_name = std::move(short_name);
|
|
|
|
query->database_and_table_name = std::move(database_and_table_name);
|
2020-05-07 02:45:27 +00:00
|
|
|
|
2019-11-29 17:22:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|