Skip to content

Commit 398ae15

Browse files
committed
feat: supautils.extension_custom_scripts_path
Also deprecate `supautils.privileged_extensions_custom_scripts_path`
1 parent 437a329 commit 398ae15

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,20 @@ This also works for updating and dropping privileged extensions.
169169

170170
If you don't want to enable this functionality, simply leave `supautils.privileged_extensions` empty. Extensions **not** in `supautils.privileged_extensions` would behave normally, i.e. created using the current role.
171171

172-
supautils also lets you set custom scripts per privileged extension that gets run at certain events. Currently supported scripts are `before-create` and `after-create`.
172+
### Extension Custom Scripts
173+
174+
supautils also lets you set custom scripts per extension that gets run at certain events. Currently supported scripts are `before-create` and `after-create`.
173175

174176
To make this work, configure the setting below:
175177

176178
```
177-
supautils.privileged_extensions_custom_scripts_path = '/opt/postgresql/privileged_extensions_custom_scripts'
179+
supautils.extension_custom_scripts_path = '/some/path/extension-custom-scripts'
178180
```
179181

180182
Then put the scripts inside the path, e.g.:
181183

182184
```sql
183-
-- /opt/postgresql/privileged_extensions_custom_scripts/hstore/after-create.sql
185+
-- /some/path/extension-custom-scripts/hstore/after-create.sql
184186
grant all on type hstore to non_superuser_role;
185187
```
186188

src/supautils.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static char *placeholders_disallowed_values = NULL;
3939
static char *empty_placeholder = NULL;
4040
static char *privileged_extensions = NULL;
4141
static char *supautils_superuser = NULL;
42-
static char *privileged_extensions_custom_scripts_path = NULL;
42+
static char *extension_custom_scripts_path = NULL;
4343
static char *privileged_role = NULL; // the privileged_role is a proxy role for the `supautils.superuser` role
4444
static char *privileged_role_allowed_configs = NULL;
4545

@@ -452,9 +452,9 @@ static void supautils_hook(PROCESS_UTILITY_PARAMS) {
452452

453453
switch_to_superuser(supautils_superuser, &already_switched_to_superuser);
454454

455-
run_global_before_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
455+
run_global_before_create_script(stmt->extname, stmt->options, extension_custom_scripts_path);
456456

457-
run_ext_before_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
457+
run_ext_before_create_script(stmt->extname, stmt->options, extension_custom_scripts_path);
458458

459459
override_create_ext_statement(stmt, total_epos, epos);
460460

@@ -471,7 +471,7 @@ static void supautils_hook(PROCESS_UTILITY_PARAMS) {
471471
run_process_utility_hook(prev_hook);
472472
}
473473

474-
run_ext_after_create_script(stmt->extname, stmt->options, privileged_extensions_custom_scripts_path);
474+
run_ext_after_create_script(stmt->extname, stmt->options, extension_custom_scripts_path);
475475

476476
if (!already_switched_to_superuser) {
477477
switch_to_original_role();
@@ -1267,10 +1267,20 @@ void _PG_init(void) {
12671267
NULL,
12681268
NULL);
12691269

1270+
DefineCustomStringVariable("supautils.extension_custom_scripts_path",
1271+
"Path to load extension custom scripts from",
1272+
NULL,
1273+
&extension_custom_scripts_path,
1274+
NULL,
1275+
PGC_SIGHUP, 0,
1276+
NULL,
1277+
NULL,
1278+
NULL);
1279+
12701280
DefineCustomStringVariable("supautils.privileged_extensions_custom_scripts_path",
1271-
"Path to load privileged extensions' custom scripts from",
1281+
"Path to load privileged extensions' custom scripts from. Deprecated: use supautils.extension_custom_scripts_path instead.",
12721282
NULL,
1273-
&privileged_extensions_custom_scripts_path,
1283+
&extension_custom_scripts_path,
12741284
NULL,
12751285
PGC_SIGHUP, 0,
12761286
NULL,

test/init.conf.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ supautils.placeholders_disallowed_values='"content-type","x-special-header",spec
1515
supautils.extensions_parameter_overrides='{"sslinfo":{"schema":"pg_catalog"}}'
1616
supautils.drop_trigger_grants='{"privileged_role":["allow_drop_triggers.my_table"]}'
1717
supautils.policy_grants='{"privileged_role":["allow_policies.my_table","allow_policies.nonexistent_table"]}'
18-
supautils.privileged_extensions_custom_scripts_path='@TMPDIR@/privileged_extensions_custom_scripts'
18+
supautils.extension_custom_scripts_path='@TMPDIR@/extension-custom-scripts'

test/init.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# print notice when creating an extension
2-
mkdir -p "$TMPDIR/privileged_extensions_custom_scripts"
2+
mkdir -p "$TMPDIR/extension-custom-scripts"
33
echo "do \$\$
44
begin
55
if not (@extname@ = ANY(ARRAY['dict_xsyn', 'insert_username'])) then
@@ -8,12 +8,12 @@ echo "do \$\$
88
if exists (select from pg_available_extensions where name = @extname@) then
99
raise notice 'extname: %, extschema: %, extversion: %, extcascade: %', @extname@, @extschema@, @extversion@, @extcascade@;
1010
end if;
11-
end \$\$;" > "$TMPDIR/privileged_extensions_custom_scripts/before-create.sql"
11+
end \$\$;" > "$TMPDIR/extension-custom-scripts/before-create.sql"
1212

13-
mkdir -p "$TMPDIR/privileged_extensions_custom_scripts/autoinc"
14-
echo 'create extension citext;' > "$TMPDIR/privileged_extensions_custom_scripts/autoinc/after-create.sql"
13+
mkdir -p "$TMPDIR/extension-custom-scripts/autoinc"
14+
echo 'create extension citext;' > "$TMPDIR/extension-custom-scripts/autoinc/after-create.sql"
1515

1616
# assert both before-create and after-create scripts are run
17-
mkdir -p "$TMPDIR/privileged_extensions_custom_scripts/hstore"
18-
echo 'create table t1();' > "$TMPDIR/privileged_extensions_custom_scripts/hstore/before-create.sql"
19-
echo 'drop table t1; create table t2 as values (1);' > "$TMPDIR/privileged_extensions_custom_scripts/hstore/after-create.sql"
17+
mkdir -p "$TMPDIR/extension-custom-scripts/hstore"
18+
echo 'create table t1();' > "$TMPDIR/extension-custom-scripts/hstore/before-create.sql"
19+
echo 'drop table t1; create table t2 as values (1);' > "$TMPDIR/extension-custom-scripts/hstore/after-create.sql"

0 commit comments

Comments
 (0)