Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 36 additions & 58 deletions go/vt/sqlparser/ast_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,11 +1069,13 @@ func (g *GrantProxy) SetExtra(extra any) {

// RevokePrivilege represents the REVOKE...ON...FROM statement.
type RevokePrivilege struct {
Privileges []Privilege
ObjectType GrantObjectType
PrivilegeLevel PrivilegeLevel
From []AccountName
Auth AuthInformation
Privileges []Privilege
ObjectType GrantObjectType
PrivilegeLevel PrivilegeLevel
From []AccountName
Auth AuthInformation
IfExists bool
IgnoreUnknownUser bool
}

var _ Statement = (*RevokePrivilege)(nil)
Expand All @@ -1085,6 +1087,9 @@ func (r *RevokePrivilege) iStatement() {}
// Format implements the interface Statement.
func (r *RevokePrivilege) Format(buf *TrackedBuffer) {
buf.Myprintf("revoke")
if r.IfExists {
buf.Myprintf(" if exists")
}
for i, privilege := range r.Privileges {
if i > 0 {
buf.Myprintf(",")
Expand All @@ -1109,6 +1114,9 @@ func (r *RevokePrivilege) Format(buf *TrackedBuffer) {
}
buf.Myprintf(" %s", user.String())
}
if r.IgnoreUnknownUser {
buf.Myprintf(" ignore unknown user")
}
}

// GetAuthInformation implements the AuthNode interface.
Expand Down Expand Up @@ -1136,59 +1144,13 @@ func (r *RevokePrivilege) SetExtra(extra any) {
r.Auth.Extra = extra
}

// RevokeAllPrivileges represents the REVOKE ALL statement.
type RevokeAllPrivileges struct {
From []AccountName
Auth AuthInformation
}

var _ Statement = (*RevokeAllPrivileges)(nil)
var _ AuthNode = (*RevokeAllPrivileges)(nil)

// iStatement implements the interface Statement.
func (r *RevokeAllPrivileges) iStatement() {}

// Format implements the interface Statement.
func (r *RevokeAllPrivileges) Format(buf *TrackedBuffer) {
buf.Myprintf("revoke all privileges, grant option from")
for i, user := range r.From {
if i > 0 {
buf.Myprintf(",")
}
buf.Myprintf(" %s", user.String())
}
}

// GetAuthInformation implements the AuthNode interface.
func (r *RevokeAllPrivileges) GetAuthInformation() AuthInformation {
return r.Auth
}

// SetAuthType implements the AuthNode interface.
func (r *RevokeAllPrivileges) SetAuthType(authType string) {
r.Auth.AuthType = authType
}

// SetAuthTargetType implements the AuthNode interface.
func (r *RevokeAllPrivileges) SetAuthTargetType(targetType string) {
r.Auth.TargetType = targetType
}

// SetAuthTargetNames implements the AuthNode interface.
func (r *RevokeAllPrivileges) SetAuthTargetNames(targetNames []string) {
r.Auth.TargetNames = targetNames
}

// SetExtra implements the AuthNode interface.
func (r *RevokeAllPrivileges) SetExtra(extra any) {
r.Auth.Extra = extra
}

// RevokeRole represents the REVOKE...FROM statement.
type RevokeRole struct {
Roles []AccountName
From []AccountName
Auth AuthInformation
Roles []AccountName
From []AccountName
Auth AuthInformation
IfExists bool
IgnoreUnknownUser bool
}

var _ Statement = (*RevokeRole)(nil)
Expand All @@ -1200,6 +1162,9 @@ func (r *RevokeRole) iStatement() {}
// Format implements the interface Statement.
func (r *RevokeRole) Format(buf *TrackedBuffer) {
buf.Myprintf("revoke")
if r.IfExists {
buf.Myprintf(" if exists")
}
for i, role := range r.Roles {
if i > 0 {
buf.Myprintf(",")
Expand All @@ -1213,6 +1178,9 @@ func (r *RevokeRole) Format(buf *TrackedBuffer) {
}
buf.Myprintf(" %s", user.String())
}
if r.IgnoreUnknownUser {
buf.Myprintf(" ignore unknown user")
}
}

// GetAuthInformation implements the AuthNode interface.
Expand Down Expand Up @@ -1245,6 +1213,9 @@ type RevokeProxy struct {
On AccountName
From []AccountName
Auth AuthInformation

IfExists bool
IgnoreUnknownUser bool
}

var _ Statement = (*RevokeProxy)(nil)
Expand All @@ -1255,13 +1226,20 @@ func (r *RevokeProxy) iStatement() {}

// Format implements the interface Statement.
func (r *RevokeProxy) Format(buf *TrackedBuffer) {
buf.Myprintf("revoke proxy on %s from", r.On.String())
buf.Myprintf("revoke")
if r.IfExists {
buf.Myprintf(" if exists")
}
buf.Myprintf(" proxy on %s from", r.On.String())
for i, user := range r.From {
if i > 0 {
buf.Myprintf(",")
}
buf.Myprintf(" %s", user.String())
}
if r.IgnoreUnknownUser {
buf.Myprintf(" ignore unknown user")
}
}

// GetAuthInformation implements the AuthNode interface.
Expand Down Expand Up @@ -1350,7 +1328,7 @@ func (s *ShowGrants) SetExtra(extra any) {
}

// ShowPrivileges represents the SHOW PRIVILEGES statement.
type ShowPrivileges struct{
type ShowPrivileges struct {
Auth AuthInformation
}

Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ var keywords = map[string]int{
"union": UNION,
"unique": UNIQUE,
"unlock": UNLOCK,
"unknown": UNKNOWN,
"unsigned": UNSIGNED,
"until": UNTIL,
"update": UPDATE,
Expand Down
100 changes: 82 additions & 18 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3291,52 +3291,116 @@ var (
}, {
input: "GRANT REPLICATION_SLAVE_ADMIN, GROUP_REPLICATION_ADMIN, BINLOG_ADMIN ON *.* TO 'u1'@'localhost'",
output: "grant replication_slave_admin, group_replication_admin, binlog_admin on *.* to `u1`@`localhost`",
}, {
},
{
input: "REVOKE ALL ON * FROM UserName",
output: "revoke all on * from `UserName`@`%`",
}, {
},
{
input: "REVOKE ALL ON *.* FROM UserName",
output: "revoke all on *.* from `UserName`@`%`",
}, {
},
{
input: "REVOKE IF EXISTS ALL ON *.* FROM UserName",
output: "revoke if exists all on *.* from `UserName`@`%`",
},
{
input: "REVOKE ALL ON *.* FROM UserName IGNORE UNKNOWN USER",
output: "revoke all on *.* from `UserName`@`%` ignore unknown user",
},
{
input: "REVOKE ALL ON db.* FROM UserName",
output: "revoke all on `db`.* from `UserName`@`%`",
}, {
},
{
input: "REVOKE ALL ON db.tbl FROM UserName",
output: "revoke all on `db`.`tbl` from `UserName`@`%`",
}, {
},
{
input: "REVOKE ALL ON `db`.`tbl` FROM UserName",
output: "revoke all on `db`.`tbl` from `UserName`@`%`",
}, {
},
{
input: "REVOKE ALL ON tbl FROM UserName",
output: "revoke all on `tbl` from `UserName`@`%`",
}, {
},
{
input: "REVOKE ALL ON TABLE tbl FROM UserName",
output: "revoke all on table `tbl` from `UserName`@`%`",
}, {
},
{
input: "REVOKE SELECT (col1, col2), UPDATE (col2) ON db.tbl FROM UserName",
output: "revoke select (`col1`, `col2`), update (`col2`) on `db`.`tbl` from `UserName`@`%`",
}, {
},
{
input: "REVOKE IF EXISTS SELECT (col1, col2), UPDATE (col2) ON db.tbl FROM UserName",
output: "revoke if exists select (`col1`, `col2`), update (`col2`) on `db`.`tbl` from `UserName`@`%`",
},
{
input: "REVOKE SELECT (col1, col2), UPDATE (col2) ON db.tbl FROM UserName IGNORE UNKNOWN USER",
output: "revoke select (`col1`, `col2`), update (`col2`) on `db`.`tbl` from `UserName`@`%` ignore unknown user",
},
{
input: "REVOKE ALL ON tbl FROM UserName1@localhost, UserName2",
output: "revoke all on `tbl` from `UserName1`@`localhost`, `UserName2`@`%`",
}, {
},
{
input: "REVOKE ALL, GRANT OPTION FROM UserName",
output: "revoke all privileges, grant option from `UserName`@`%`",
}, {
output: "revoke all on *.* from `UserName`@`%`",
},
{
input: "REVOKE IF EXISTS ALL, GRANT OPTION FROM UserName",
output: "revoke if exists all on *.* from `UserName`@`%`",
},
{
input: "REVOKE ALL, GRANT OPTION FROM UserName IGNORE UNKNOWN USER",
output: "revoke all on *.* from `UserName`@`%` ignore unknown user",
},
{
input: "REVOKE ALL PRIVILEGES, GRANT OPTION FROM UserName",
output: "revoke all privileges, grant option from `UserName`@`%`",
}, {
output: "revoke all on *.* from `UserName`@`%`",
},
{
input: "REVOKE IF EXISTS ALL PRIVILEGES, GRANT OPTION FROM UserName",
output: "revoke if exists all on *.* from `UserName`@`%`",
},
{
input: "REVOKE ALL PRIVILEGES, GRANT OPTION FROM UserName IGNORE UNKNOWN USER",
output: "revoke all on *.* from `UserName`@`%` ignore unknown user",
},
{
input: "REVOKE Role1 FROM UserName",
output: "revoke `Role1`@`%` from `UserName`@`%`",
}, {
},
{
input: "REVOKE IF EXISTS Role1 FROM UserName",
output: "revoke if exists `Role1`@`%` from `UserName`@`%`",
},
{
input: "REVOKE Role1 FROM UserName IGNORE UNKNOWN USER",
output: "revoke `Role1`@`%` from `UserName`@`%` ignore unknown user",
},
{
input: "REVOKE Role1, Role2 FROM UserName1, UserName2",
output: "revoke `Role1`@`%`, `Role2`@`%` from `UserName1`@`%`, `UserName2`@`%`",
}, {
},
{
input: "REVOKE PROXY ON UserName FROM Role1, Role2",
output: "revoke proxy on `UserName`@`%` from `Role1`@`%`, `Role2`@`%`",
}, {
},
{
input: "REVOKE IF EXISTS PROXY ON UserName FROM Role1, Role2",
output: "revoke if exists proxy on `UserName`@`%` from `Role1`@`%`, `Role2`@`%`",
},
{
input: "REVOKE PROXY ON UserName FROM Role1, Role2 IGNORE UNKNOWN USER",
output: "revoke proxy on `UserName`@`%` from `Role1`@`%`, `Role2`@`%` ignore unknown user",
},
{
input: "REVOKE PROXY ON UserName FROM Role1, Role2",
output: "revoke proxy on `UserName`@`%` from `Role1`@`%`, `Role2`@`%`",
}, {
},
{
input: "FLUSH PRIVILEGES",
output: "flush privileges",
}, {
Expand Down
Loading