-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
96 lines (89 loc) · 2.63 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const BbPromise = require('bluebird');
const validate = require('serverless/lib/plugins/aws/lib/validate');
const encrypt = require('./lib/encrypt');
const decrypt = require('./lib/decrypt');
const saveSecret = require('./lib/saveSecret');
const addLibraries = require('./lib/addLibraries');
const removeLibraries = require('./lib/removeLibraries');
const SECRET_FILE = '.serverless-secret.json';
class Crypt {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options || {};
this.provider = this.serverless.getProvider('aws');
this.secret_file = SECRET_FILE;
Object.assign(
this,
validate,
encrypt,
decrypt,
saveSecret,
addLibraries,
removeLibraries
);
this.commands = {
encrypt: {
usage: 'Encrypt the secret',
lifecycleEvents: [
'encrypt',
],
options: {
name: {
usage: 'Name of the secert',
shortcut: 'n',
required: true,
},
text: {
usage: 'Plaintext to encrypt',
shortcut: 't',
},
save: {
usage: `Save the encrypted secret (to ${SECRET_FILE}`,
},
},
},
decrypt: {
usage: 'Decrypt the encrypted secret',
lifecycleEvents: [
'decrypt',
],
options: {
name: {
usage: 'Name of the secert',
shortcut: 'n',
required: true,
},
},
},
};
this.hooks = {
'before:deploy:function:packageFunction': () => BbPromise.bind(this)
.then(this.validate)
.then(this.addLibraries),
'after:deploy:function:packageFunction': () => BbPromise.bind(this)
.then(this.validate)
.then(this.removeLibraries),
'before:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.validate)
.then(this.addLibraries),
'after:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.validate)
.then(this.removeLibraries),
'before:invoke:local:invoke': () => BbPromise.bind(this)
.then(this.validate)
.then(this.addLibraries),
'after:invoke:local:invoke': () => BbPromise.bind(this)
.then(this.validate)
.then(this.removeLibraries),
'encrypt:encrypt': () => BbPromise.bind(this)
.then(this.validate)
.then(this.encrypt)
.then(this.saveSecret),
'decrypt:decrypt': () => BbPromise.bind(this)
.then(this.validate)
.then(this.decrypt),
};
}
}
module.exports = Crypt;