Skip to content

Commit 9a2bed4

Browse files
authored
Merge pull request #57 from IvanOfThings/feat/add-allowed-privileges
feat: add privileges to drop dictionaries and views
2 parents d93ba36 + c34d126 commit 9a2bed4

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

docs/resources/role.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Resource to manage Clickhouse roles
1717

1818
### Required
1919

20-
- `database` (String) Database where to grant permissions to the user
20+
- `database` (String) Database where to grant permissions to the user. You can apply privileges to all databases by using '*'
2121
- `name` (String) Role name
2222

2323
### Optional

pkg/resources/role/resource_role.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func ResourceRole() *schema.Resource {
2222
Required: true,
2323
},
2424
"database": {
25-
Description: "Database where to grant permissions to the user",
25+
Description: "Database where to grant permissions to the user. You can apply privileges to all databases by using '*'",
2626
Type: schema.TypeString,
2727
Required: true,
2828
},

pkg/resources/role/validators.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ var AllowedDbLevelPrivileges = []string{
1717
"CREATE DICTIONARY",
1818
"DROP DATABASE",
1919
"DROP TABLE",
20+
"DROP DICTIONARY",
21+
"DROP VIEW",
2022
"SHOW TABLES",
23+
"dictGet",
2124
}
2225

2326
var AllowedGlobalPrivileges = []string{
2427
"REMOTE",
28+
"SYSTEM RELOAD DICTIONARY",
2529
}
2630

2731
var AllowedPrivileges = append(AllowedDbLevelPrivileges, AllowedGlobalPrivileges...)
@@ -46,7 +50,6 @@ func ValidatePrivileges(database string, privileges *schema.Set) diag.Diagnostic
4650

4751
func validatePrivilege(database string, privilege string, diagnostics *diag.Diagnostics) {
4852
isAllowed := false
49-
upperCasePrivilege := strings.ToUpper(privilege)
5053

5154
if IsGlobalPrivilege(privilege) && database != "*" {
5255
diagnostic := diag.Diagnostic{
@@ -60,7 +63,7 @@ func validatePrivilege(database string, privilege string, diagnostics *diag.Diag
6063
return
6164
}
6265
for _, allowedPrivilege := range AllowedPrivileges {
63-
if upperCasePrivilege == allowedPrivilege {
66+
if privilege == allowedPrivilege {
6467
isAllowed = true
6568
break
6669
}

0 commit comments

Comments
 (0)