Skip to content

Commit

Permalink
Add fine-grained ACL support (#140)
Browse files Browse the repository at this point in the history
* Add fine-grained ACL support

* Update README.md
  • Loading branch information
apstndb authored Sep 16, 2022
1 parent baf8c22 commit d65f4b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ and `{}` for a mutually exclusive keyword.
| Truncate table | `TRUNCATE TABLE <table>;` | Only rows are deleted. Note: Non-atomically because executed as a [partitioned DML statement](https://cloud.google.com/spanner/docs/dml-partitioned?hl=en). |
| Create index | `CREATE INDEX ...;` | |
| Delete index | `DROP INDEX ...;` | |
| Create role | `CREATE ROLE ...;` | |
| Drop role | `DROP ROLE ...;` | |
| Grant | `GRANT ...;` | |
| Revoke | `REVOKE ...;` | |
| Query | `SELECT ...;` | |
| DML | `{INSERT\|UPDATE\|DELETE} ...;` | |
| Partitioned DML | `PARTITIONED {UPDATE\|DELETE} ...;` | |
Expand Down
6 changes: 6 additions & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ var (
dropDatabaseRe = regexp.MustCompile(`(?is)^DROP\s+DATABASE\s+(.+)$`)
createRe = regexp.MustCompile(`(?is)^CREATE\s.+$`)
dropRe = regexp.MustCompile(`(?is)^DROP\s.+$`)
grantRe = regexp.MustCompile(`(?is)^GRANT\s.+$`)
revokeRe = regexp.MustCompile(`(?is)^REVOKE\s.+$`)
alterRe = regexp.MustCompile(`(?is)^ALTER\s.+$`)
truncateTableRe = regexp.MustCompile(`(?is)^TRUNCATE\s+TABLE\s+(.+)$`)

Expand Down Expand Up @@ -143,6 +145,10 @@ func BuildStatement(input string) (Statement, error) {
return &DdlStatement{Ddl: input}, nil
case alterRe.MatchString(input):
return &DdlStatement{Ddl: input}, nil
case grantRe.MatchString(input):
return &DdlStatement{Ddl: input}, nil
case revokeRe.MatchString(input):
return &DdlStatement{Ddl: input}, nil
case truncateTableRe.MatchString(input):
matched := truncateTableRe.FindStringSubmatch(input)
return &TruncateTableStatement{Table: unquoteIdentifier(matched[1])}, nil
Expand Down
10 changes: 10 additions & 0 deletions statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ func TestBuildStatement(t *testing.T) {
input: "DROP CHANGE STREAM NamesAndAlbums",
want: &DdlStatement{Ddl: "DROP CHANGE STREAM NamesAndAlbums"},
},
{
desc: "GRANT statement",
input: "GRANT SELECT ON TABLE employees TO ROLE hr_rep",
want: &DdlStatement{Ddl: "GRANT SELECT ON TABLE employees TO ROLE hr_rep"},
},
{
desc: "REVOKE statement",
input: "REVOKE SELECT ON TABLE employees FROM ROLE hr_rep",
want: &DdlStatement{Ddl: "REVOKE SELECT ON TABLE employees FROM ROLE hr_rep"},
},
{
desc: "ALTER STATISTICS statement",
input: "ALTER STATISTICS package SET OPTIONS (allow_gc = false)",
Expand Down

0 comments on commit d65f4b6

Please sign in to comment.