File tree Expand file tree Collapse file tree 3 files changed +24
-23
lines changed Expand file tree Collapse file tree 3 files changed +24
-23
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const _ = require ( 'lodash' ) ;
43const BbPromise = require ( 'bluebird' ) ;
4+ const ServerlessError = require ( 'serverless/lib/classes/Error' ) . ServerlessError ;
55
66module . exports = {
77 setIamPolicy ( ) {
@@ -33,37 +33,40 @@ module.exports = {
3333 }
3434 this . serverless . cli . log ( 'Setting IAM policies...' ) ;
3535
36- _ . forEach ( policies , ( value , key ) => {
36+ const promises = [ ] ;
37+ Object . entries ( policies ) . forEach ( ( entry ) => {
3738 const func = functions . find ( ( fn ) => {
38- return fn . name === key ;
39+ return fn . name === entry [ 0 ] ;
3940 } ) ;
4041 if ( func ) {
4142 const params = {
4243 resource : func . name ,
4344 requestBody : {
4445 policy : {
45- bindings : value ,
46+ bindings : entry [ 1 ] ,
4647 } ,
4748 } ,
4849 } ;
4950
50- this . provider . request (
51- 'cloudfunctions' ,
52- 'projects' ,
53- 'locations' ,
54- 'functions' ,
55- 'setIamPolicy' ,
56- params
51+ promises . push (
52+ this . provider . request (
53+ 'cloudfunctions' ,
54+ 'projects' ,
55+ 'locations' ,
56+ 'functions' ,
57+ 'setIamPolicy' ,
58+ params
59+ )
5760 ) ;
5861 } else {
5962 const errorMessage = [
60- `Unable to set IAM bindings (${ value } ) for "${ key } ": function not found for` ,
63+ `Unable to set IAM bindings (${ entry [ 1 ] } ) for "${ entry [ 0 ] } ": function not found for` ,
6164 ` project "${ this . serverless . service . provider . project } " in region "${ this . options . region } ".` ,
6265 ] . join ( '' ) ;
63- throw new Error ( errorMessage ) ;
66+ throw new ServerlessError ( errorMessage ) ;
6467 }
6568 } ) ;
6669
67- return BbPromise . resolve ( ) ;
70+ return BbPromise . all ( promises ) ;
6871 } ,
6972} ;
Original file line number Diff line number Diff line change 4444 "chalk" : " ^3.0.0" ,
4545 "fs-extra" : " ^8.1.0" ,
4646 "googleapis" : " ^50.0.0" ,
47- "lodash" : " ^4.17.15"
47+ "lodash" : " ^4.17.15" ,
48+ "serverless" : " ^1.74.1"
4849 },
4950 "devDependencies" : {
5051 "@commitlint/cli" : " ^8.3.5" ,
Original file line number Diff line number Diff line change @@ -62,20 +62,17 @@ module.exports = {
6262 // Collect the configured IAM bindings at the function and provider level and merge the
6363 // members for each defined role. This transforms the array of IAM bindings into a mapping
6464 // in order to easily merge.
65- const iamBindings = _ . reduce (
66- _ . concat (
67- _ . get ( funcObject , 'iam.bindings' ) || [ ] ,
65+ const iamBindings = ( _ . get ( funcObject , 'iam.bindings' ) || [ ] )
66+ . concat (
6867 _ . get ( this , 'serverless.service.provider.iam.bindings' ) || [ ] ,
6968 allowUnauthenticated
7069 ? [ { role : 'roles/cloudfunctions.invoker' , members : [ 'allUsers' ] } ]
7170 : [ ]
72- ) ,
73- ( result , value ) => {
71+ )
72+ . reduce ( ( result , value ) => {
7473 result [ value . role ] = _ . union ( result [ value . role ] || [ ] , value . members ) ;
7574 return result ;
76- } ,
77- { }
78- ) ;
75+ } , { } ) ;
7976
8077 if ( ! funcTemplate . properties . serviceAccountEmail ) {
8178 delete funcTemplate . properties . serviceAccountEmail ;
You can’t perform that action at this time.
0 commit comments