|
5 | 5 | # @param db Specifies the database to which you are granting access.
|
6 | 6 | # @param object_type Specify target object type: 'FUNCTIONS', 'ROUTINES', 'SEQUENCES', 'TABLES', 'TYPES'.
|
7 | 7 | # @param privilege Specifies comma-separated list of privileges to grant. Valid options: depends on object type.
|
8 |
| -# @param schema Target schema. Defaults to 'public'. |
| 8 | +# @param schema Target schema. Defaults to all schemas. |
9 | 9 | # @param psql_db Defines the database to execute the grant against. This should not ordinarily be changed from the default.
|
10 | 10 | # @param psql_user Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
|
11 | 11 | # @param psql_path Specifies the OS user for running psql. Default value: The default user for the module, usually 'postgres'.
|
|
50 | 50 | case $ensure {
|
51 | 51 | default: {
|
52 | 52 | # default is 'present'
|
53 |
| - $sql_command = 'ALTER DEFAULT PRIVILEGES IN SCHEMA %s GRANT %s ON %s TO "%s"' |
| 53 | + $sql_command = 'ALTER DEFAULT PRIVILEGES%s GRANT %s ON %s TO "%s"' |
54 | 54 | $unless_is = true
|
55 | 55 | }
|
56 | 56 | 'absent': {
|
57 |
| - $sql_command = 'ALTER DEFAULT PRIVILEGES IN SCHEMA %s REVOKE %s ON %s FROM "%s"' |
| 57 | + $sql_command = 'ALTER DEFAULT PRIVILEGES%s REVOKE %s ON %s FROM "%s"' |
58 | 58 | $unless_is = false
|
59 | 59 | }
|
60 | 60 | }
|
|
70 | 70 | $port_override = $postgresql::server::port
|
71 | 71 | }
|
72 | 72 |
|
| 73 | + if $schema != '' { |
| 74 | + $_schema = " IN SCHEMA $schema" |
| 75 | + $_check_schema = " AND nspname = '$schema'" |
| 76 | + } else { |
| 77 | + $_schema = '' |
| 78 | + $_check_schema = ' AND nspname IS NULL' |
| 79 | + } |
73 | 80 | ## Munge the input values
|
74 | 81 | $_object_type = upcase($object_type)
|
75 | 82 | $_privilege = upcase($privilege)
|
|
128 | 135 | }
|
129 | 136 |
|
130 | 137 | $_unless = $ensure ? {
|
131 |
| - 'absent' => "SELECT 1 WHERE NOT EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '%s=%s' = ANY (defaclacl) AND nspname = '%s' and defaclobjtype = '%s')", |
132 |
| - default => "SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '%s=%s' = ANY (defaclacl) AND nspname = '%s' and defaclobjtype = '%s')" |
| 138 | + 'absent' => "SELECT 1 WHERE NOT EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '%s=%s' = ANY (defaclacl)%s and defaclobjtype = '%s')", |
| 139 | + default => "SELECT 1 WHERE EXISTS (SELECT * FROM pg_default_acl AS da LEFT JOIN pg_namespace AS n ON da.defaclnamespace = n.oid WHERE '%s=%s' = ANY (defaclacl)%s and defaclobjtype = '%s')" |
133 | 140 | }
|
134 | 141 |
|
135 |
| - $unless_cmd = sprintf($_unless, $role, $_check_privilege, $schema, $_check_type) |
136 |
| - $grant_cmd = sprintf($sql_command, $schema, $_privilege, $_object_type, $role) |
| 142 | + $unless_cmd = sprintf($_unless, $role, $_check_privilege, $_check_schema, $_check_type) |
| 143 | + $grant_cmd = sprintf($sql_command, $_schema, $_privilege, $_object_type, $role) |
137 | 144 |
|
138 | 145 | postgresql_psql { "default_privileges:${name}":
|
139 | 146 | command => $grant_cmd,
|
|
0 commit comments