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

Extend grant detection also to views and materialized views. #31

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Changes from all commits
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
18 changes: 9 additions & 9 deletions redshift/resource_redshift_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var grantAllowedObjectTypes = []string{
"database",
}

var grantObjectTypesCodes = map[string]string{
"table": "r",
var grantObjectTypesCodes = map[string][]string{
"table": []string{"r", "m", "v"},
}

func redshiftGrant() *schema.Resource {
Expand Down Expand Up @@ -242,15 +242,15 @@ func readGroupTableGrants(db *DBConnection, d *schema.ResourceData) error {
query := `
SELECT
relname,
decode(charindex('r',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as select,
decode(charindex('w',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as update,
decode(charindex('a',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as insert,
decode(charindex('d',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as delete,
decode(charindex('x',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as references
decode(charindex('r',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), null,0, 0,0, 1) as select,
decode(charindex('w',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), null,0, 0,0, 1) as update,
decode(charindex('a',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), null,0, 0,0, 1) as insert,
decode(charindex('d',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), null,0, 0,0, 1) as delete,
decode(charindex('x',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), null,0, 0,0, 1) as references
FROM pg_group gr, pg_class cl
JOIN pg_namespace nsp ON nsp.oid = cl.relnamespace
WHERE
cl.relkind = $1
cl.relkind = ANY($1)
AND gr.groname=$2
AND nsp.nspname=$3
`
Expand All @@ -259,7 +259,7 @@ func readGroupTableGrants(db *DBConnection, d *schema.ResourceData) error {
schemaName := d.Get(grantSchemaAttr).(string)
objects := d.Get(grantObjectsAttr).(*schema.Set)

rows, err := db.Query(query, grantObjectTypesCodes["table"], groupName, schemaName)
rows, err := db.Query(query, pq.Array(grantObjectTypesCodes["table"]), groupName, schemaName)
if err != nil {
return err
}
Expand Down