Skip to content

Commit 082b9f8

Browse files
committed
refactor: rename bypassRls to grantBypassRls
1 parent 5c504da commit 082b9f8

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎cdk-postgresql/lib/read-access.handler.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface Props {
88
Role: string;
99
Schema: string;
1010
CreatorRoles: string[];
11-
BypassRls: boolean | "true" | "false";
11+
GrantBypassRls: boolean | "true" | "false";
1212
}
1313

1414
export const handler = async (event: CloudFormationCustomResourceEvent) => {
@@ -22,7 +22,7 @@ export const handler = async (event: CloudFormationCustomResourceEvent) => {
2222
const role = quote(props.Role);
2323
const schema = quote(props.Schema);
2424
const creators = props.CreatorRoles.map(quote).join(", ");
25-
const bypass = props.BypassRls === true || props.BypassRls === "true";
25+
const bypass = props.GrantBypassRls === true || props.GrantBypassRls === "true";
2626
const client = await getConnectedClient(props.Connection);
2727
try {
2828
await client.query(`

‎cdk-postgresql/lib/read-access.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export interface ReadAccessProps {
1111
schema?: string;
1212
/** Roles that create future tables, not the reader role. Must exist. */
1313
creatorRoles: string[];
14-
/** Grant a cluster-wide RLS exemption. Omitted/false leaves RLS attributes unchanged. */
15-
bypassRls?: boolean;
14+
/**
15+
* Grant a cluster-wide RLS exemption. False, omission and removal do not revoke it.
16+
*/
17+
grantBypassRls?: boolean;
1618
}
1719

1820
/**
@@ -38,7 +40,7 @@ export class ReadAccess extends Construct {
3840
role: props.role,
3941
schema: props.schema ?? "public",
4042
creatorRoles: props.creatorRoles,
41-
bypassRls: props.bypassRls ?? false,
43+
grantBypassRls: props.grantBypassRls ?? false,
4244
},
4345
pascalCaseProperties: true,
4446
removalPolicy: cdk.RemovalPolicy.RETAIN,

‎cdk-postgresql/test/constructs.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test("read access reuses the provider and retains grants", () => {
2323
database: "appdb",
2424
role: "reader",
2525
creatorRoles: ["app", "master"],
26-
bypassRls: true,
26+
grantBypassRls: true,
2727
});
2828
const template = Template.fromStack(stack);
2929
template.hasResource("Custom::Postgresql-ReadAccess", {
@@ -35,7 +35,7 @@ test("read access reuses the provider and retains grants", () => {
3535
Role: "reader",
3636
Schema: "public",
3737
CreatorRoles: ["app", "master"],
38-
BypassRls: true,
38+
GrantBypassRls: true,
3939
},
4040
});
4141
template.resourceCountIs("AWS::Lambda::Function", 3);

‎cdk-postgresql/test/lambda.integration.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ afterAll(async () => {
8181
// starts from a blank cluster:
8282
beforeEach(() => cluster.reset());
8383

84-
test.each([true, false, undefined])("read access covers existing/RLS and future tables without writes (BypassRls: %s)", async (bypassRls) => {
84+
test.each([true, false, undefined])("read access covers existing/RLS and future tables without writes (GrantBypassRls: %s)", async (grantBypassRls) => {
8585
const client = await cluster.connectTo(DB_DEFAULT_DB);
8686
try {
8787
await client.query(`
@@ -109,7 +109,7 @@ test.each([true, false, undefined])("read access covers existing/RLS and future
109109
},
110110
Role: "reader", Schema: "public",
111111
CreatorRoles: ["app", DB_MASTER_USERNAME],
112-
...(bypassRls === undefined ? {} : { BypassRls: bypassRls }),
112+
...(grantBypassRls === undefined ? {} : { GrantBypassRls: grantBypassRls }),
113113
},
114114
} as CloudFormationCustomResourceEvent;
115115
await expect(handler({
@@ -132,16 +132,16 @@ test.each([true, false, undefined])("read access covers existing/RLS and future
132132
`);
133133
expect((await client.query(
134134
"SELECT rolbypassrls FROM pg_roles WHERE rolname = current_user"
135-
)).rows[0].rolbypassrls).toBe(bypassRls === true);
136-
expect((await client.query("SELECT * FROM public.items")).rowCount).toBe(bypassRls ? 1 : 0);
135+
)).rows[0].rolbypassrls).toBe(grantBypassRls === true);
136+
expect((await client.query("SELECT * FROM public.items")).rowCount).toBe(grantBypassRls ? 1 : 0);
137137
for (const table of ["ordinary", "from_master", "from_app"]) {
138138
expect((await client.query(`SELECT * FROM public.${table}`)).rowCount).toBe(1);
139139
}
140140
await expect(client.query("INSERT INTO public.items VALUES (4)")).rejects.toThrow(/permission denied/);
141141
await expect(client.query("UPDATE public.items SET id = 4")).rejects.toThrow(/permission denied/);
142142
await expect(client.query("DELETE FROM public.items")).rejects.toThrow(/permission denied/);
143143
await handler({ ...event, RequestType: "Delete", PhysicalResourceId: "ReadAccess" });
144-
expect((await client.query("SELECT * FROM public.items")).rowCount).toBe(bypassRls ? 1 : 0);
144+
expect((await client.query("SELECT * FROM public.items")).rowCount).toBe(grantBypassRls ? 1 : 0);
145145
expect((await client.query("SELECT * FROM public.ordinary")).rowCount).toBe(1);
146146
} finally {
147147
await client.end();

0 commit comments

Comments
 (0)