Skip to content

Commit ce7847a

Browse files
TheoPthnfx
andauthored
Fixed privilege_assignment in databricks_sql_permissions (#1872)
* remove the backtick before the comparison otherwise the databases are not equal although they are the same * Add acc test for Database ACL with and without backtick in databases names Co-authored-by: Serge Smertin <[email protected]>
1 parent d9315c5 commit ce7847a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

access/resource_sql_permissions.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ func (ta *SqlPermissions) read() error {
148148
if !strings.EqualFold(currentType, thisType) {
149149
continue
150150
}
151-
if !strings.EqualFold(currentKey, thisKey) {
151+
152+
noBackticks := strings.ReplaceAll(thisKey, "`", "")
153+
if !strings.EqualFold(currentKey, thisKey) && !strings.EqualFold(currentKey, noBackticks) {
152154
continue
153155
}
156+
154157
if strings.HasPrefix(currentAction, "DENIED_") {
155158
// DENY statements are intentionally not supported.
156159
continue

access/resource_sql_permissions_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ func TestTableACLGrants(t *testing.T) {
8989
assert.Len(t, ta.PrivilegeAssignments[0].Privileges, 2)
9090
}
9191

92+
func TestDatabaseACLGrants(t *testing.T) {
93+
ta := SqlPermissions{ Database: "default",
94+
exec: mockData{
95+
"SHOW GRANT ON DATABASE `default`": {
96+
// principal, actionType, objType, objectKey
97+
// Test with and without backticks
98+
{"users", "SELECT", "database", "default"},
99+
{"users", "USAGE", "database", "`default`"},
100+
},
101+
}}
102+
err := ta.read()
103+
assert.NoError(t, err)
104+
assert.Len(t, ta.PrivilegeAssignments, 1)
105+
assert.Len(t, ta.PrivilegeAssignments[0].Privileges, 2)
106+
}
107+
92108
type failedCommand string
93109

94110
func (fc failedCommand) Execute(clusterID, language, commandStr string) common.CommandResults {

0 commit comments

Comments
 (0)