Skip to content
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: Added column level access #135

Merged
merged 8 commits into from
Mar 18, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Squashme: Fixes to pass linting test
Kayssar Daher authored and kda-jt committed Nov 28, 2022
commit 6b06ed15a6098fa43c44b3b4ce3f95bd9317d730
5 changes: 1 addition & 4 deletions postgresql/helpers.go
Original file line number Diff line number Diff line change
@@ -288,10 +288,7 @@ func setToPgIdentList(schema string, idents *schema.Set) string {
func setToPgIdentSimpleList(idents *schema.Set) string {
quotedIdents := make([]string, idents.Len())
for i, ident := range idents.List() {
quotedIdents[i] = fmt.Sprintf(
"%s",
ident.(string),
)
quotedIdents[i] = ident.(string)
}
return strings.Join(quotedIdents, ",")
}
19 changes: 12 additions & 7 deletions postgresql/resource_postgresql_grant.go
Original file line number Diff line number Diff line change
@@ -652,13 +652,18 @@ func createRevokeQuery(d *schema.ResourceData) string {
objects := d.Get("objects").(*schema.Set)
columns := d.Get("columns").(*schema.Set)
privileges := d.Get("privileges").(*schema.Set)
query = fmt.Sprintf(
"REVOKE %s (%s) ON TABLE %s FROM %s",
setToPgIdentSimpleList(privileges),
setToPgIdentSimpleList(columns),
setToPgIdentList(d.Get("schema").(string), objects),
pq.QuoteIdentifier(d.Get("role").(string)),
)
if privileges.Len() == 0 || columns.Len() == 0 {
// No privileges to revoke, so don't revoke anything
query = "SELECT NULL"
kda-jt marked this conversation as resolved.
Show resolved Hide resolved
} else {
query = fmt.Sprintf(
"REVOKE %s (%s) ON TABLE %s FROM %s",
kda-jt marked this conversation as resolved.
Show resolved Hide resolved
setToPgIdentSimpleList(privileges),
setToPgIdentSimpleList(columns),
setToPgIdentList(d.Get("schema").(string), objects),
pq.QuoteIdentifier(d.Get("role").(string)),
)
}
case "TABLE", "SEQUENCE", "FUNCTION", "PROCEDURE", "ROUTINE":
objects := d.Get("objects").(*schema.Set)
if objects.Len() > 0 {
2 changes: 1 addition & 1 deletion postgresql/utils_test.go
Original file line number Diff line number Diff line change
@@ -356,7 +356,7 @@ func testCheckColumnPrivileges(t *testing.T, dbName, roleName string, tables []s
}

updateColumnValues := []string{}
for i, _ := range columns {
for i := range columns {
updateColumnValues = append(updateColumnValues, fmt.Sprint(columns[i], " = ", columnValues[i]))
}