@@ -32,36 +32,29 @@ function main(projectId = 'my-project-id') {
3232 const [ buckets ] = await storage . getBuckets ( ) ;
3333
3434 for ( const bucket of buckets ) {
35- if ( bucket . metadata . ipFilter ) {
36- try {
37- const [ metadata ] = await storage . bucket ( bucket . name ) . getMetadata ( ) ;
38- const ipFilter = metadata . ipFilter ;
39- console . log ( `${ bucket . name } : IP Filter Mode - ${ ipFilter . mode } ` ) ;
35+ const ipFilter = bucket . metadata ?. ipFilter ;
36+ if ( ipFilter ) {
37+ console . log ( `${ bucket . name } : IP Filter Mode - ${ ipFilter . mode } ` ) ;
4038
41- const publicNetworkSource = ipFilter . publicNetworkSource ;
42- if ( publicNetworkSource && publicNetworkSource . allowedIpCidrRanges ) {
43- console . log ( ' Public Network Allowed IP Ranges:' ) ;
44- publicNetworkSource . allowedIpCidrRanges . forEach ( range => {
45- console . log ( ` - ${ range } ` ) ;
46- } ) ;
47- }
39+ const publicNetworkSource = ipFilter . publicNetworkSource ;
40+ if ( publicNetworkSource && publicNetworkSource . allowedIpCidrRanges ) {
41+ console . log ( ' Public Network Allowed IP Ranges:' ) ;
42+ publicNetworkSource . allowedIpCidrRanges . forEach ( range => {
43+ console . log ( ` - ${ range } ` ) ;
44+ } ) ;
45+ }
4846
49- const vpcNetworkSources = ipFilter . vpcNetworkSources ;
50- if ( vpcNetworkSources && vpcNetworkSources . length > 0 ) {
51- console . log ( ' VPC Network Sources:' ) ;
52- vpcNetworkSources . forEach ( source => {
53- console . log ( ` - Network: ${ source . network } ` ) ;
54- if ( source . allowedIpCidrRanges ) {
55- source . allowedIpCidrRanges . forEach ( range => {
56- console . log ( ` - ${ range } ` ) ;
57- } ) ;
58- }
59- } ) ;
60- }
61- } catch ( err ) {
62- console . log (
63- `${ bucket . name } : Error fetching IP filter - ${ err . message } `
64- ) ;
47+ const vpcNetworkSources = ipFilter . vpcNetworkSources ;
48+ if ( vpcNetworkSources && vpcNetworkSources . length > 0 ) {
49+ console . log ( ' VPC Network Sources:' ) ;
50+ vpcNetworkSources . forEach ( source => {
51+ console . log ( ` - Network: ${ source . network } ` ) ;
52+ if ( source . allowedIpCidrRanges ) {
53+ source . allowedIpCidrRanges . forEach ( range => {
54+ console . log ( ` - ${ range } ` ) ;
55+ } ) ;
56+ }
57+ } ) ;
6558 }
6659 }
6760 }
0 commit comments