-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: user authz #3941
Merged
Merged
feat: user authz #3941
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "absl/strings/ascii.h" | ||
#include "absl/strings/match.h" | ||
#include "absl/types/span.h" | ||
#include "ast_node_converter.h" | ||
#include "base/fe_status.h" | ||
#include "node/sql_node.h" | ||
#include "udf/udf.h" | ||
|
@@ -725,6 +726,20 @@ base::Status ConvertStatement(const zetasql::ASTStatement* statement, node::Node | |
*output = create_user_node; | ||
break; | ||
} | ||
case zetasql::AST_GRANT_STATEMENT: { | ||
const zetasql::ASTGrantStatement* grant_stmt = statement->GetAsOrNull<zetasql::ASTGrantStatement>(); | ||
node::GrantNode* grant_node = nullptr; | ||
CHECK_STATUS(ConvertGrantStatement(grant_stmt, node_manager, &grant_node)) | ||
*output = grant_node; | ||
break; | ||
} | ||
case zetasql::AST_REVOKE_STATEMENT: { | ||
const zetasql::ASTRevokeStatement* revoke_stmt = statement->GetAsOrNull<zetasql::ASTRevokeStatement>(); | ||
node::RevokeNode* revoke_node = nullptr; | ||
CHECK_STATUS(ConvertRevokeStatement(revoke_stmt, node_manager, &revoke_node)) | ||
*output = revoke_node; | ||
break; | ||
} | ||
case zetasql::AST_ALTER_USER_STATEMENT: { | ||
const zetasql::ASTAlterUserStatement* alter_user_stmt = | ||
statement->GetAsOrNull<zetasql::ASTAlterUserStatement>(); | ||
|
@@ -2133,6 +2148,81 @@ base::Status ConvertAlterUserStatement(const zetasql::ASTAlterUserStatement* roo | |
return base::Status::OK(); | ||
} | ||
|
||
base::Status ConvertGrantStatement(const zetasql::ASTGrantStatement* root, node::NodeManager* node_manager, | ||
node::GrantNode** output) { | ||
CHECK_TRUE(root != nullptr, common::kSqlAstError, "not an ASTGrantStatement"); | ||
std::vector<std::string> target_path; | ||
CHECK_STATUS(AstPathExpressionToStringList(root->target_path(), target_path)); | ||
std::optional<std::string> target_type = std::nullopt; | ||
if (root->target_type() != nullptr) { | ||
target_type = root->target_type()->GetAsString(); | ||
} | ||
|
||
std::vector<std::string> privileges; | ||
std::vector<std::string> grantees; | ||
for (auto privilege : root->privileges()->privileges()) { | ||
if (privilege == nullptr) { | ||
continue; | ||
} | ||
|
||
auto privilege_action = privilege->privilege_action(); | ||
if (privilege_action != nullptr) { | ||
privileges.push_back(privilege_action->GetAsString()); | ||
} | ||
} | ||
|
||
for (auto grantee : root->grantee_list()->grantee_list()) { | ||
if (grantee == nullptr) { | ||
continue; | ||
} | ||
|
||
std::string grantee_str; | ||
CHECK_STATUS(AstStringLiteralToString(grantee, &grantee_str)); | ||
grantees.push_back(grantee_str); | ||
} | ||
*output = node_manager->MakeNode<node::GrantNode>(target_type, target_path.at(0), target_path.at(1), privileges, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in grant statements the target_path is required to have 2 elements: database and target |
||
root->privileges()->is_all_privileges(), grantees, | ||
root->with_grant_option()); | ||
return base::Status::OK(); | ||
} | ||
|
||
base::Status ConvertRevokeStatement(const zetasql::ASTRevokeStatement* root, node::NodeManager* node_manager, | ||
node::RevokeNode** output) { | ||
CHECK_TRUE(root != nullptr, common::kSqlAstError, "not an ASTRevokeStatement"); | ||
std::vector<std::string> target_path; | ||
CHECK_STATUS(AstPathExpressionToStringList(root->target_path(), target_path)); | ||
std::optional<std::string> target_type = std::nullopt; | ||
if (root->target_type() != nullptr) { | ||
target_type = root->target_type()->GetAsString(); | ||
} | ||
|
||
std::vector<std::string> privileges; | ||
std::vector<std::string> grantees; | ||
for (auto privilege : root->privileges()->privileges()) { | ||
if (privilege == nullptr) { | ||
continue; | ||
} | ||
|
||
auto privilege_action = privilege->privilege_action(); | ||
if (privilege_action != nullptr) { | ||
privileges.push_back(privilege_action->GetAsString()); | ||
} | ||
} | ||
|
||
for (auto grantee : root->grantee_list()->grantee_list()) { | ||
if (grantee == nullptr) { | ||
continue; | ||
} | ||
|
||
std::string grantee_str; | ||
CHECK_STATUS(AstStringLiteralToString(grantee, &grantee_str)); | ||
grantees.push_back(grantee_str); | ||
} | ||
*output = node_manager->MakeNode<node::RevokeNode>(target_type, target_path.at(0), target_path.at(1), privileges, | ||
root->privileges()->is_all_privileges(), grantees); | ||
return base::Status::OK(); | ||
} | ||
|
||
base::Status ConvertCreateIndexStatement(const zetasql::ASTCreateIndexStatement* root, node::NodeManager* node_manager, | ||
node::CreateIndexNode** output) { | ||
CHECK_TRUE(nullptr != root, common::kSqlAstError, "not an ASTCreateIndexStatement") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append new enums only