-
Notifications
You must be signed in to change notification settings - Fork 258
Open
Description
Problem
It would be highly beneficial to use the grantRoleDefaultPrivileges
resource to construct queries such as:
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO read_only;
Unfortunately, specifying a owner
is always mandatory, which translates into a FOR ROLE
part in the query. This requirement prevents the creation of more generalized default privileges queries.
Solution
Make the owner
optional, similar to how the schema
is handled. Below is a draft solution for this issue.
Expected Solution
Note
I'm not a Go expert.
role := d.Get("role").(string)
pgOwner := d.Get("owner").(string)
pgSchema := d.Get("schema").(string)
(...)
// If an owner is specified, build the query string to include it
var forOwner string
if pgOwner != "" {
forOwner = fmt.Sprintf("FOR ROLE %s", pq.QuoteIdentifier(pgOwner))
}
// If a schema is specified, build the query string to include it
var inSchema string
if pgSchema != "" {
inSchema = fmt.Sprintf("IN SCHEMA %s", pq.QuoteIdentifier(pgSchema))
}
query := fmt.Sprintf("ALTER DEFAULT PRIVILEGES %s %s GRANT %s ON %sS TO %s",
forOwner,
inSchema,
strings.Join(privileges, ","),
strings.ToUpper(d.Get("object_type").(string)),
pq.QuoteIdentifier(role),
)
glangho, mehrosejethi, atorrescogollo, yacinehmito and lindeskar
Metadata
Metadata
Assignees
Labels
No labels