Skip to content

Commit 70cfb83

Browse files
fix(bigquery): Update if/else to if/else if
1 parent 627536a commit 70cfb83

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bigquery/cloud-client/src/revokeTableOrViewAccess.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ async function revokeTableOrViewAccess({
3232
memberToRevoke,
3333
roleToRevoke = 'roles/bigquery.dataViewer',
3434
}) {
35+
// Validate required parameters
36+
if (!projectId || !datasetId || !resourceId) {
37+
throw new Error(
38+
'projectId, datasetId and resourceID are required parameters'
39+
);
40+
}
3541
try {
3642
// Create BigQuery client
3743
const bigquery = new BigQuery({
@@ -52,7 +58,7 @@ async function revokeTableOrViewAccess({
5258
// Filter bindings based on parameters
5359
let newBindings = policy.bindings;
5460

55-
if (memberToRevoke) {
61+
if (memberToRevoke && roleToRevoke) {
5662
// Remove specific member from specific role
5763
newBindings = policy.bindings
5864
.map(binding => ({
@@ -63,11 +69,14 @@ async function revokeTableOrViewAccess({
6369
: binding.members,
6470
}))
6571
.filter(binding => binding.members.length > 0);
66-
} else {
72+
} else if (!memberToRevoke && roleToRevoke) {
6773
// Remove all bindings for the specified role
6874
newBindings = policy.bindings.filter(
6975
binding => binding.role !== roleToRevoke
7076
);
77+
} else {
78+
// Keep the current binding as is
79+
newBindings = policy.bindings;
7180
}
7281

7382
// Create new policy with updated bindings

0 commit comments

Comments
 (0)