Skip to content

Commit

Permalink
Squashme: Fixes to pass linting test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayssar Daher committed Feb 7, 2022
1 parent 5672740 commit 819cc90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 1 addition & 4 deletions postgresql/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")
}
Expand Down
19 changes: 12 additions & 7 deletions postgresql/resource_postgresql_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,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"
} else {
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)),
)
}
case "TABLE", "SEQUENCE", "FUNCTION", "PROCEDURE", "ROUTINE":
objects := d.Get("objects").(*schema.Set)
if objects.Len() > 0 {
Expand Down
2 changes: 1 addition & 1 deletion postgresql/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}

Expand Down

0 comments on commit 819cc90

Please sign in to comment.