Skip to content

Commit 66da4cb

Browse files
committed
Add GoogleInvoke plugin
1 parent e3def3a commit 66da4cb

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

invoke/googleInvoke.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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;

invoke/lib/invokeFunction.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
};

0 commit comments

Comments
 (0)