-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (36 loc) · 969 Bytes
/
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
'use strict';
function formatParameters(parameters) {
if (!parameters) {
return null;
}
const result = {};
Object.values(parameters).map((param) => {
const [key, value] = param.split("=");
result[key] = value;
return null;
});
return result;
}
/** @type {import('serverless/classes/Plugin')} */
class RequiredOptionsServerlessPlugin {
/**
*
* @param {import('serverless')} _serverless
* @param {import('serverless').Options} options
*/
constructor(_serverless, options) {
this.configurationVariablesSources = {
requiredOpt: {
async resolve({ address }) {
const parameters = formatParameters(options.param);
const value = options[address] ?? parameters[address];
if (value) {
return { value };
}
throw new Error(`Required option "${address}" not provided`);
},
},
};
}
}
module.exports = RequiredOptionsServerlessPlugin;