ClickHouse/src/Parsers/ParserShowGrantsQuery.cpp
Vitaly Baranov 9fe47df2e8 Support multiple users/roles in SHOW CREATE USER(ROLE, etc.) and SHOW GRANTS FOR commands.
Support syntax "SHOW CREATE USER ALL" and "SHOW GRANTS FOR ALL".
2020-06-15 22:07:47 +03:00

41 lines
1.1 KiB
C++

#include <Parsers/ParserShowGrantsQuery.h>
#include <Parsers/ParserRolesOrUsersSet.h>
#include <Parsers/ASTRolesOrUsersSet.h>
#include <Parsers/ASTShowGrantsQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/parseUserName.h>
namespace DB
{
bool ParserShowGrantsQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
if (!ParserKeyword{"SHOW GRANTS"}.ignore(pos, expected))
return false;
std::shared_ptr<ASTRolesOrUsersSet> for_roles;
if (ParserKeyword{"FOR"}.ignore(pos, expected))
{
ASTPtr for_roles_ast;
ParserRolesOrUsersSet for_roles_p;
for_roles_p.allowUserNames().allowRoleNames().allowAll().allowCurrentUser();
if (!for_roles_p.parse(pos, for_roles_ast, expected))
return false;
for_roles = typeid_cast<std::shared_ptr<ASTRolesOrUsersSet>>(for_roles_ast);
}
else
{
for_roles = std::make_shared<ASTRolesOrUsersSet>();
for_roles->current_user = true;
}
auto query = std::make_shared<ASTShowGrantsQuery>();
query->for_roles = std::move(for_roles);
node = query;
return true;
}
}