-
Notifications
You must be signed in to change notification settings - Fork 5
/
input.js
80 lines (73 loc) · 2.88 KB
/
input.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
const core = require('@actions/core');
const auth = require('./auth')
const stringInputs = {
'accessId': 'access-id',
'accessType': 'access-type',
'apiUrl': 'api-url',
'producerForAwsAccess': 'producer-for-aws-access',
};
const boolInputs = {
'exportSecretsToOutputs': 'export-secrets-to-outputs',
'exportSecretsToEnvironment': 'export-secrets-to-environment',
};
const dictInputs = {
'staticSecrets': 'static-secrets',
'dynamicSecrets': 'dynamic-secrets',
};
const fetchAndValidateInput = () => {
let params = {
accessId: core.getInput('access-id', { required: true }),
accessType: core.getInput('access-type'),
apiUrl: core.getInput('api-url'),
producerForAwsAccess: core.getInput('producer-for-aws-access'),
staticSecrets: core.getInput('static-secrets'),
dynamicSecrets: core.getInput('dynamic-secrets'),
exportSecretsToOutputs: core.getBooleanInput('export-secrets-to-outputs'),
exportSecretsToEnvironment: core.getBooleanInput('export-secrets-to-environment'),
};
// our only required parameter
if (!params['accessId']) {
throw new Error('You must provide the access id for your auth method via the access-id input');
}
// check for string types
for (const [paramKey, inputId] of Object.entries(stringInputs)) {
if (typeof params[paramKey] !== 'string') {
throw new Error(`Input '${inputId}' should be a string`);
}
}
// check for bool types
for (const [paramKey, inputId] of Object.entries(boolInputs)) {
if(typeof params[paramKey] !== 'boolean') {
throw new Error(`Input '${inputId}' should be a boolean`);
}
}
// check for dict types
for (const [paramKey, inputId] of Object.entries(dictInputs)) {
if (typeof params[paramKey] !== 'string') {
throw new Error(`Input '${inputId}' should be a serialized JSON dictionary with the secret path as a key and the output name as the value`);
}
if (!params[paramKey]) {
continue;
}
try {
parsed = JSON.parse(params[paramKey]);
if (parsed.constructor != Object) {
throw new Error(`Input '${inputId}' did not contain a valid JSON dictionary`)
}
params[paramKey] = parsed;
} catch (e) {
if (e instanceof SyntaxError) {
throw new Error(`Input '${inputId}' did not contain valid JSON`);
} else {
throw e;
}
}
}
// check access types
if (!auth.allowedAccessTypes.includes(params['accessType'].toLowerCase())) {
throw new Error("access-type must be one of: ['" + auth.allowedAccessTypes.join("', '") + "']");
}
params['accessType'] = params['accessType'].toLowerCase();
return params;
};
exports.fetchAndValidateInput = fetchAndValidateInput;