File tree 3 files changed +24
-23
lines changed
3 files changed +24
-23
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- const _ = require ( 'lodash' ) ;
4
3
const BbPromise = require ( 'bluebird' ) ;
4
+ const ServerlessError = require ( 'serverless/lib/classes/Error' ) . ServerlessError ;
5
5
6
6
module . exports = {
7
7
setIamPolicy ( ) {
@@ -33,37 +33,40 @@ module.exports = {
33
33
}
34
34
this . serverless . cli . log ( 'Setting IAM policies...' ) ;
35
35
36
- _ . forEach ( policies , ( value , key ) => {
36
+ const promises = [ ] ;
37
+ Object . entries ( policies ) . forEach ( ( entry ) => {
37
38
const func = functions . find ( ( fn ) => {
38
- return fn . name === key ;
39
+ return fn . name === entry [ 0 ] ;
39
40
} ) ;
40
41
if ( func ) {
41
42
const params = {
42
43
resource : func . name ,
43
44
requestBody : {
44
45
policy : {
45
- bindings : value ,
46
+ bindings : entry [ 1 ] ,
46
47
} ,
47
48
} ,
48
49
} ;
49
50
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
+ )
57
60
) ;
58
61
} else {
59
62
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` ,
61
64
` project "${ this . serverless . service . provider . project } " in region "${ this . options . region } ".` ,
62
65
] . join ( '' ) ;
63
- throw new Error ( errorMessage ) ;
66
+ throw new ServerlessError ( errorMessage ) ;
64
67
}
65
68
} ) ;
66
69
67
- return BbPromise . resolve ( ) ;
70
+ return BbPromise . all ( promises ) ;
68
71
} ,
69
72
} ;
Original file line number Diff line number Diff line change 44
44
"chalk" : " ^3.0.0" ,
45
45
"fs-extra" : " ^8.1.0" ,
46
46
"googleapis" : " ^50.0.0" ,
47
- "lodash" : " ^4.17.15"
47
+ "lodash" : " ^4.17.15" ,
48
+ "serverless" : " ^1.74.1"
48
49
},
49
50
"devDependencies" : {
50
51
"@commitlint/cli" : " ^8.3.5" ,
Original file line number Diff line number Diff line change @@ -62,20 +62,17 @@ module.exports = {
62
62
// Collect the configured IAM bindings at the function and provider level and merge the
63
63
// members for each defined role. This transforms the array of IAM bindings into a mapping
64
64
// 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 (
68
67
_ . get ( this , 'serverless.service.provider.iam.bindings' ) || [ ] ,
69
68
allowUnauthenticated
70
69
? [ { role : 'roles/cloudfunctions.invoker' , members : [ 'allUsers' ] } ]
71
70
: [ ]
72
- ) ,
73
- ( result , value ) => {
71
+ )
72
+ . reduce ( ( result , value ) => {
74
73
result [ value . role ] = _ . union ( result [ value . role ] || [ ] , value . members ) ;
75
74
return result ;
76
- } ,
77
- { }
78
- ) ;
75
+ } , { } ) ;
79
76
80
77
if ( ! funcTemplate . properties . serviceAccountEmail ) {
81
78
delete funcTemplate . properties . serviceAccountEmail ;
You can’t perform that action at this time.
0 commit comments