@pgpmjs/core 7.32.8 → 7.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/init/client.js +3 -3
- package/esm/roles/index.js +7 -7
- package/init/client.d.ts +3 -2
- package/init/client.js +3 -3
- package/package.json +12 -12
- package/roles/index.d.ts +7 -3
- package/roles/index.js +7 -7
package/esm/init/client.js
CHANGED
|
@@ -69,12 +69,12 @@ export class PgpmInit {
|
|
|
69
69
|
* @param username - The username to create
|
|
70
70
|
* @param password - The password for the user
|
|
71
71
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
72
|
-
* @param
|
|
72
|
+
* @param options - Role locking and explicit RLS bypass (off by default).
|
|
73
73
|
*/
|
|
74
|
-
async bootstrapDbRoles(username, password, roles,
|
|
74
|
+
async bootstrapDbRoles(username, password, roles, options = {}) {
|
|
75
75
|
try {
|
|
76
76
|
log.info(`Bootstrapping PGPM database roles for user: ${username}...`);
|
|
77
|
-
const sql = generateCreateUserSQL(username, password, roles,
|
|
77
|
+
const sql = generateCreateUserSQL(username, password, roles, options);
|
|
78
78
|
await this.pool.query(sql);
|
|
79
79
|
log.success(`Successfully bootstrapped PGPM database roles for user: ${username}`);
|
|
80
80
|
}
|
package/esm/roles/index.js
CHANGED
|
@@ -183,12 +183,12 @@ COMMIT;
|
|
|
183
183
|
`;
|
|
184
184
|
}
|
|
185
185
|
/**
|
|
186
|
-
* Generate SQL to create
|
|
186
|
+
* Generate SQL to create or reconcile a login and grant base roles.
|
|
187
187
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
|
188
188
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
189
|
-
* @param
|
|
189
|
+
* @param options - Role locking and explicit RLS bypass (off by default).
|
|
190
190
|
*/
|
|
191
|
-
export function generateCreateUserSQL(username, password, roles, useLocksForRoles = false) {
|
|
191
|
+
export function generateCreateUserSQL(username, password, roles, { useLocksForRoles = false, bypassRls = false } = {}) {
|
|
192
192
|
if (!roles) {
|
|
193
193
|
throw new Error('generateCreateUserSQL: roles parameter is undefined. ' +
|
|
194
194
|
'Ensure getConnEnvOptions().roles is defined.');
|
|
@@ -231,6 +231,8 @@ BEGIN
|
|
|
231
231
|
END;
|
|
232
232
|
END IF;
|
|
233
233
|
|
|
234
|
+
EXECUTE format('ALTER ROLE %I LOGIN INHERIT NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION ${bypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'} PASSWORD %L', v_username, v_password);
|
|
235
|
+
|
|
234
236
|
-- Grant anonymous to user
|
|
235
237
|
IF NOT EXISTS (
|
|
236
238
|
SELECT 1 FROM pg_auth_members am
|
|
@@ -245,8 +247,7 @@ BEGIN
|
|
|
245
247
|
-- 23505: Membership was granted concurrently; safe to ignore
|
|
246
248
|
NULL;
|
|
247
249
|
WHEN undefined_object THEN
|
|
248
|
-
|
|
249
|
-
RAISE NOTICE 'Missing role when granting % to %', v_anonymous, v_username;
|
|
250
|
+
RAISE;
|
|
250
251
|
WHEN insufficient_privilege THEN
|
|
251
252
|
-- 42501: Must surface this error - caller lacks permission
|
|
252
253
|
RAISE;
|
|
@@ -270,8 +271,7 @@ BEGIN
|
|
|
270
271
|
-- 23505: Membership was granted concurrently; safe to ignore
|
|
271
272
|
NULL;
|
|
272
273
|
WHEN undefined_object THEN
|
|
273
|
-
|
|
274
|
-
RAISE NOTICE 'Missing role when granting % to %', v_authenticated, v_username;
|
|
274
|
+
RAISE;
|
|
275
275
|
WHEN insufficient_privilege THEN
|
|
276
276
|
-- 42501: Must surface this error - caller lacks permission
|
|
277
277
|
RAISE;
|
package/init/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RoleMapping, TestUserCredentials } from '@pgpmjs/types';
|
|
2
2
|
import { PgConfig } from 'pg-env';
|
|
3
|
+
import { CreateUserOptions } from '../roles';
|
|
3
4
|
export declare class PgpmInit {
|
|
4
5
|
private pool;
|
|
5
6
|
private pgConfig;
|
|
@@ -30,9 +31,9 @@ export declare class PgpmInit {
|
|
|
30
31
|
* @param username - The username to create
|
|
31
32
|
* @param password - The password for the user
|
|
32
33
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
33
|
-
* @param
|
|
34
|
+
* @param options - Role locking and explicit RLS bypass (off by default).
|
|
34
35
|
*/
|
|
35
|
-
bootstrapDbRoles(username: string, password: string, roles: RoleMapping,
|
|
36
|
+
bootstrapDbRoles(username: string, password: string, roles: RoleMapping, options?: CreateUserOptions): Promise<void>;
|
|
36
37
|
/**
|
|
37
38
|
* Remove database roles and revoke grants.
|
|
38
39
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
package/init/client.js
CHANGED
|
@@ -72,12 +72,12 @@ class PgpmInit {
|
|
|
72
72
|
* @param username - The username to create
|
|
73
73
|
* @param password - The password for the user
|
|
74
74
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
75
|
-
* @param
|
|
75
|
+
* @param options - Role locking and explicit RLS bypass (off by default).
|
|
76
76
|
*/
|
|
77
|
-
async bootstrapDbRoles(username, password, roles,
|
|
77
|
+
async bootstrapDbRoles(username, password, roles, options = {}) {
|
|
78
78
|
try {
|
|
79
79
|
log.info(`Bootstrapping PGPM database roles for user: ${username}...`);
|
|
80
|
-
const sql = (0, roles_1.generateCreateUserSQL)(username, password, roles,
|
|
80
|
+
const sql = (0, roles_1.generateCreateUserSQL)(username, password, roles, options);
|
|
81
81
|
await this.pool.query(sql);
|
|
82
82
|
log.success(`Successfully bootstrapped PGPM database roles for user: ${username}`);
|
|
83
83
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.33.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM Package and Migration Tools",
|
|
6
6
|
"main": "index.js",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"makage": "^0.8.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@pgpmjs/ast": "^0.15.
|
|
53
|
-
"@pgpmjs/bundle": "^0.18.
|
|
54
|
-
"@pgpmjs/diff": "^0.8.
|
|
55
|
-
"@pgpmjs/env": "^2.47.
|
|
52
|
+
"@pgpmjs/ast": "^0.15.8",
|
|
53
|
+
"@pgpmjs/bundle": "^0.18.8",
|
|
54
|
+
"@pgpmjs/diff": "^0.8.10",
|
|
55
|
+
"@pgpmjs/env": "^2.47.1",
|
|
56
56
|
"@pgpmjs/logger": "^2.26.0",
|
|
57
|
-
"@pgpmjs/server-utils": "^3.29.
|
|
58
|
-
"@pgpmjs/slice": "^0.19.
|
|
59
|
-
"@pgpmjs/transform": "^0.28.
|
|
60
|
-
"@pgpmjs/types": "^2.57.
|
|
57
|
+
"@pgpmjs/server-utils": "^3.29.8",
|
|
58
|
+
"@pgpmjs/slice": "^0.19.10",
|
|
59
|
+
"@pgpmjs/transform": "^0.28.10",
|
|
60
|
+
"@pgpmjs/types": "^2.57.1",
|
|
61
61
|
"cross-spawn": "^7.0.6",
|
|
62
62
|
"csv-to-pg": "^4.14.3",
|
|
63
63
|
"genomic": "^5.6.6",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"glob": "^13.0.6",
|
|
66
66
|
"parse-package-name": "^1.0.0",
|
|
67
67
|
"pg": "^8.21.0",
|
|
68
|
-
"pg-cache": "^3.29.
|
|
69
|
-
"pg-env": "^1.32.
|
|
68
|
+
"pg-cache": "^3.29.8",
|
|
69
|
+
"pg-env": "^1.32.1",
|
|
70
70
|
"pgsql-deparser": "^18.3.12",
|
|
71
71
|
"pgsql-parser": "^18.2.12",
|
|
72
72
|
"yaml": "^2.9.0",
|
|
73
73
|
"yanse": "^0.2.2"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "bf845a1b0701f57f6900d9e2a3c66ea48e125cc3"
|
|
76
76
|
}
|
package/roles/index.d.ts
CHANGED
|
@@ -20,13 +20,17 @@ export declare function generateCreateBaseRolesSQL(roles: RoleMapping): string;
|
|
|
20
20
|
* @param statementTimeout - Baseline statement_timeout for the role (default '15s')
|
|
21
21
|
*/
|
|
22
22
|
export declare function generateCreateClientRoleSQL(roles: RoleMapping, statementTimeout?: string): string;
|
|
23
|
+
export interface CreateUserOptions {
|
|
24
|
+
useLocksForRoles?: boolean;
|
|
25
|
+
bypassRls?: boolean;
|
|
26
|
+
}
|
|
23
27
|
/**
|
|
24
|
-
* Generate SQL to create
|
|
28
|
+
* Generate SQL to create or reconcile a login and grant base roles.
|
|
25
29
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
|
26
30
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
27
|
-
* @param
|
|
31
|
+
* @param options - Role locking and explicit RLS bypass (off by default).
|
|
28
32
|
*/
|
|
29
|
-
export declare function generateCreateUserSQL(username: string, password: string, roles: RoleMapping, useLocksForRoles?:
|
|
33
|
+
export declare function generateCreateUserSQL(username: string, password: string, roles: RoleMapping, { useLocksForRoles, bypassRls }?: CreateUserOptions): string;
|
|
30
34
|
/**
|
|
31
35
|
* Generate SQL to create test users with grants to base roles.
|
|
32
36
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
package/roles/index.js
CHANGED
|
@@ -192,12 +192,12 @@ COMMIT;
|
|
|
192
192
|
`;
|
|
193
193
|
}
|
|
194
194
|
/**
|
|
195
|
-
* Generate SQL to create
|
|
195
|
+
* Generate SQL to create or reconcile a login and grant base roles.
|
|
196
196
|
* Callers should use getConnEnvOptions() from @pgpmjs/env to get merged values.
|
|
197
197
|
* @param roles - Role mapping from getConnEnvOptions().roles!
|
|
198
|
-
* @param
|
|
198
|
+
* @param options - Role locking and explicit RLS bypass (off by default).
|
|
199
199
|
*/
|
|
200
|
-
function generateCreateUserSQL(username, password, roles, useLocksForRoles = false) {
|
|
200
|
+
function generateCreateUserSQL(username, password, roles, { useLocksForRoles = false, bypassRls = false } = {}) {
|
|
201
201
|
if (!roles) {
|
|
202
202
|
throw new Error('generateCreateUserSQL: roles parameter is undefined. ' +
|
|
203
203
|
'Ensure getConnEnvOptions().roles is defined.');
|
|
@@ -240,6 +240,8 @@ BEGIN
|
|
|
240
240
|
END;
|
|
241
241
|
END IF;
|
|
242
242
|
|
|
243
|
+
EXECUTE format('ALTER ROLE %I LOGIN INHERIT NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION ${bypassRls ? 'BYPASSRLS' : 'NOBYPASSRLS'} PASSWORD %L', v_username, v_password);
|
|
244
|
+
|
|
243
245
|
-- Grant anonymous to user
|
|
244
246
|
IF NOT EXISTS (
|
|
245
247
|
SELECT 1 FROM pg_auth_members am
|
|
@@ -254,8 +256,7 @@ BEGIN
|
|
|
254
256
|
-- 23505: Membership was granted concurrently; safe to ignore
|
|
255
257
|
NULL;
|
|
256
258
|
WHEN undefined_object THEN
|
|
257
|
-
|
|
258
|
-
RAISE NOTICE 'Missing role when granting % to %', v_anonymous, v_username;
|
|
259
|
+
RAISE;
|
|
259
260
|
WHEN insufficient_privilege THEN
|
|
260
261
|
-- 42501: Must surface this error - caller lacks permission
|
|
261
262
|
RAISE;
|
|
@@ -279,8 +280,7 @@ BEGIN
|
|
|
279
280
|
-- 23505: Membership was granted concurrently; safe to ignore
|
|
280
281
|
NULL;
|
|
281
282
|
WHEN undefined_object THEN
|
|
282
|
-
|
|
283
|
-
RAISE NOTICE 'Missing role when granting % to %', v_authenticated, v_username;
|
|
283
|
+
RAISE;
|
|
284
284
|
WHEN insufficient_privilege THEN
|
|
285
285
|
-- 42501: Must surface this error - caller lacks permission
|
|
286
286
|
RAISE;
|