1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- const { BigQuery } = require ( " @google-cloud/bigquery" ) ;
15+ const { BigQuery} = require ( ' @google-cloud/bigquery' ) ;
1616
1717/**
1818 * Revokes access to a BigQuery table or view
@@ -25,69 +25,69 @@ const { BigQuery } = require("@google-cloud/bigquery");
2525 * @returns {Promise<void> }
2626 */
2727async function revokeTableOrViewAccess ( {
28- projectId,
29- datasetId,
30- resourceId,
31- memberToRevoke,
32- roleToRevoke = " roles/bigquery.dataViewer" ,
28+ projectId,
29+ datasetId,
30+ resourceId,
31+ memberToRevoke,
32+ roleToRevoke = ' roles/bigquery.dataViewer' ,
3333} ) {
34- try {
35- // Create BigQuery client
36- const bigquery = new BigQuery ( {
37- projectId : projectId ,
38- } ) ;
34+ try {
35+ // Create BigQuery client
36+ const bigquery = new BigQuery ( {
37+ projectId : projectId ,
38+ } ) ;
3939
40- // Get reference to the table or view
41- const dataset = bigquery . dataset ( datasetId ) ;
42- const table = dataset . table ( resourceId ) ;
40+ // Get reference to the table or view
41+ const dataset = bigquery . dataset ( datasetId ) ;
42+ const table = dataset . table ( resourceId ) ;
4343
44- // Get current IAM policy
45- const [ policy ] = await table . iam . getPolicy ( ) ;
46- console . log (
47- " Current IAM Policy:" ,
48- JSON . stringify ( policy . bindings , null , 2 )
49- ) ;
44+ // Get current IAM policy
45+ const [ policy ] = await table . iam . getPolicy ( ) ;
46+ console . log (
47+ ' Current IAM Policy:' ,
48+ JSON . stringify ( policy . bindings , null , 2 )
49+ ) ;
5050
51- // Filter bindings based on parameters
52- let newBindings = policy . bindings ;
51+ // Filter bindings based on parameters
52+ let newBindings = policy . bindings ;
5353
54- if ( memberToRevoke ) {
55- // Remove specific member from specific role
56- newBindings = policy . bindings
57- . map ( ( binding ) => ( {
58- ...binding ,
59- members :
60- binding . role === roleToRevoke
61- ? binding . members . filter ( ( member ) => member !== memberToRevoke )
62- : binding . members ,
63- } ) )
64- . filter ( ( binding ) => binding . members . length > 0 ) ;
65- } else {
66- // Remove all bindings for the specified role
67- newBindings = policy . bindings . filter (
68- ( binding ) => binding . role !== roleToRevoke
69- ) ;
70- }
54+ if ( memberToRevoke ) {
55+ // Remove specific member from specific role
56+ newBindings = policy . bindings
57+ . map ( binding => ( {
58+ ...binding ,
59+ members :
60+ binding . role === roleToRevoke
61+ ? binding . members . filter ( member => member !== memberToRevoke )
62+ : binding . members ,
63+ } ) )
64+ . filter ( binding => binding . members . length > 0 ) ;
65+ } else {
66+ // Remove all bindings for the specified role
67+ newBindings = policy . bindings . filter (
68+ binding => binding . role !== roleToRevoke
69+ ) ;
70+ }
7171
72- // Create new policy with updated bindings
73- const newPolicy = {
74- bindings : newBindings ,
75- } ;
72+ // Create new policy with updated bindings
73+ const newPolicy = {
74+ bindings : newBindings ,
75+ } ;
7676
77- // Set the new IAM policy
78- await table . iam . setPolicy ( newPolicy ) ;
79- console . log ( `Access revoked successfully for ${ resourceId } ` ) ;
77+ // Set the new IAM policy
78+ await table . iam . setPolicy ( newPolicy ) ;
79+ console . log ( `Access revoked successfully for ${ resourceId } ` ) ;
8080
81- // Verify the changes
82- const [ updatedPolicy ] = await table . iam . getPolicy ( ) ;
83- console . log (
84- " Updated IAM Policy:" ,
85- JSON . stringify ( updatedPolicy . bindings , null , 2 )
86- ) ;
87- } catch ( error ) {
88- console . error ( " Error revoking access:" , error ) ;
89- throw error ;
90- }
81+ // Verify the changes
82+ const [ updatedPolicy ] = await table . iam . getPolicy ( ) ;
83+ console . log (
84+ ' Updated IAM Policy:' ,
85+ JSON . stringify ( updatedPolicy . bindings , null , 2 )
86+ ) ;
87+ } catch ( error ) {
88+ console . error ( ' Error revoking access:' , error ) ;
89+ throw error ;
90+ }
9191}
9292
93- module . exports = { revokeTableOrViewAccess } ;
93+ module . exports = { revokeTableOrViewAccess} ;
0 commit comments