-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (44 loc) · 1.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const Promise = require( 'bluebird' );
const AUTHENTICATION_FAILURE_CODE = '403';
const VALIDATION_FAILURE_CODE = '422';
module.exports = function( S ) {
S.classes.RuntimeNode43Vandium = require( './lib/RuntimeNode43Vandium' ) ( S ) ;
return class VandiumServerless extends S.classes.Plugin {
constructor() {
super();
this.name = 'VandiumServerless';
}
registerHooks() {
S.addHook( this._hookPost.bind( this ), {
action: 'functionCreate',
event: 'post'
});
return Promise.resolve();
}
_hookPost( evt ) {
return new Promise( function( resolve, reject ) {
const filePath = S.getProject().getRootPath( evt.options.path, 's-function.json' );
let savedFunction = S.utils.readFileSync( filePath );
if( savedFunction.runtime === 'nodejs4.3-vandium' ) {
if( savedFunction.endpoints.length > 0 ) {
if( !savedFunction.endpoints[ 0 ].responses ) {
savedFunction.endpoints[ 0 ].responses = {};
}
savedFunction.endpoints[ 0 ].responses[ AUTHENTICATION_FAILURE_CODE ] = {
selectionPattern: '^authentication error.*',
statusCode: AUTHENTICATION_FAILURE_CODE
};
savedFunction.endpoints[ 0 ].responses[ VALIDATION_FAILURE_CODE ] = {
selectionPattern: '^validation error.*',
statusCode: VALIDATION_FAILURE_CODE
}
}
savedFunction.runtime = 'nodejs4.3';
}
S.utils.writeFileSync( filePath, savedFunction );
return resolve( evt );
});
}
}
}