File tree 2 files changed +54
-0
lines changed
2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const BbPromise = require ( 'bluebird' ) ;
4
+ const invokeFunction = require ( './lib/invokeFunction' ) ;
5
+ const validate = require ( '../shared/validate' ) ;
6
+
7
+ class GoogleInvoke {
8
+ constructor ( serverless , options ) {
9
+ this . serverless = serverless ;
10
+ this . options = options ;
11
+ this . provider = this . serverless . getProvider ( 'google' ) ;
12
+
13
+ Object . assign (
14
+ this ,
15
+ validate ,
16
+ invokeFunction
17
+ ) ;
18
+
19
+ this . hooks = {
20
+ 'before:invoke:invoke' : ( ) => BbPromise . bind ( this )
21
+ . then ( this . validate ) ,
22
+
23
+ 'invoke:invoke' : ( ) => BbPromise . bind ( this )
24
+ . then ( this . invokeFunction ) ,
25
+ } ;
26
+ }
27
+ }
28
+
29
+ module . exports = GoogleInvoke ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ module . exports = {
4
+ invokeFunction ( ) {
5
+ const project = this . serverless . service . provider . project ;
6
+ const region = this . options . region ;
7
+ const func = this . options . function ;
8
+
9
+ const params = {
10
+ name : `projects/${ project } /locations/${ region } /functions/${ func } ` ,
11
+ } ;
12
+
13
+ return this . provider . request ( 'functions' , 'call' , params )
14
+ . then ( ( ) => this . provider . request ( 'logging' , 'getEntries' , { filter : func } ) )
15
+ . then ( ( logs ) => {
16
+ let log = {
17
+ textPayload : `There's no log data for function "${ func } " available right now…` ,
18
+ } ;
19
+
20
+ if ( logs . length ) log = logs [ 0 ] ;
21
+
22
+ this . serverless . cli . log ( JSON . stringify ( log , null , 2 ) ) ;
23
+ } ) ;
24
+ } ,
25
+ } ;
You can’t perform that action at this time.
0 commit comments