-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
resolve-external-plugin-sources.js
66 lines (62 loc) · 2.71 KB
/
resolve-external-plugin-sources.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
'use strict';
const ensurePlainObject = require('type/plain-object/ensure');
const ensurePlainFunction = require('type/plain-function/ensure');
const ServerlessError = require('../../../serverless-error');
const logDeprecation = require('../../../utils/logDeprecation');
module.exports = (configuration, resolverConfiguration, externalPlugins) => {
for (const externalPlugin of externalPlugins) {
const pluginName = externalPlugin.constructor.name;
if (externalPlugin.configurationVariablesSources != null) {
ensurePlainObject(externalPlugin.configurationVariablesSources, {
errorMessage:
'Invalid "configurationVariablesSources" ' +
`configuration on "${pluginName}", expected object, got: %v"`,
Error: ServerlessError,
errorCode: 'INVALID_VARIABLE_SOURCES_CONFIGURATION',
});
for (const [sourceName, sourceConfig] of Object.entries(
externalPlugin.configurationVariablesSources
)) {
if (resolverConfiguration.sources[sourceName]) {
throw new ServerlessError(
`Cannot add "${sourceName}" configuration variable source ` +
`(through "${pluginName}" plugin) as resolution rules ` +
'for this source name are already configured',
'DUPLICATE_VARIABLE_SOURCE_CONFIGURATION'
);
}
ensurePlainFunction(
ensurePlainObject(sourceConfig, {
errorMessage:
`Invalid "configurationVariablesSources.${sourceName}" ` +
`configuration on "${pluginName}", expected object, got: %v"`,
Error: ServerlessError,
errorCode: 'INVALID_VARIABLE_SOURCE_CONFIGURATION',
}).resolve,
{
errorMessage:
`Invalid "configurationVariablesSources.${sourceName}.resolve" ` +
`value on "${pluginName}", expected function, got: %v"`,
Error: ServerlessError,
errorCode: 'INVALID_VARIABLE_SOURCE_RESOLVER_CONFIGURATION',
}
);
resolverConfiguration.sources[sourceName] = sourceConfig;
resolverConfiguration.fulfilledSources.add(sourceName);
}
} else if (
externalPlugin.variableResolvers &&
configuration.variablesResolutionMode < 20210326
) {
logDeprecation(
'NEW_VARIABLES_RESOLVER',
`Plugin "${pluginName}" attempts to extend old variables resolver. ` +
'Ensure to rely on latest version of a plugin and if this warning is ' +
'still displayed please report the problem at plugin issue tracker' +
'Starting with next major release, ' +
'old variables resolver will not be supported.\n',
{ serviceConfig: configuration }
);
}
}
};