Skip to content

Commit 55cdf8f

Browse files
committed
perform validation in validator
1 parent 9f7ccb0 commit 55cdf8f

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

commands/utils/set_args.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,40 +326,29 @@ function sync_args_from_cmd(args) {
326326

327327
//Set the env variables
328328
let sys_env_vars = undefined;
329+
let envs = {};
329330
if ("sys-envs" in args) {
330331
sys_env_vars = args["sys-envs"];
331332
} else if (lt_config["run_settings"]["sys_envs"]) {
332333
sys_env_vars = lt_config["run_settings"]["sys_envs"];
333334
}
334335

335-
336-
337-
if (sys_env_vars) {
336+
if (sys_env_vars){
338337
sys_env_vars = sys_env_vars.trim();
339338
sys_env_vars = sys_env_vars.split(";");
340-
let envs = {};
341-
342-
let envItem;
343-
let envKey;
344-
345-
// perform validation
339+
346340
for (index in sys_env_vars) {
347341
envItem = sys_env_vars[index];
348342
if (envItem){
349-
envKey = envItem.split("=")[0];
350-
envKey=envKey.trim();
351-
if (envKey && ! constants.WHITELISTED_ENV_VARS.includes(envKey)){
352-
reject(`Usage of unwanted environment variable detected. Allowed variables are - ${constants.WHITELISTED_ENV_VARS}`);
353-
}
354-
envValue = envItem.split("=")[1];
355-
if (envValue == undefined || envValue === ""){
356-
reject("Value of environment variable cannot be left blank");
357-
}
343+
envKeyValue = envItem.split("=");
344+
envKey = envKeyValue[0];
345+
envValue = envKeyValue[1];
358346
envs[envKey] = envValue;
359347
}
360348
}
361-
lt_config["run_settings"]["sys_envs"] = envs;
362349
}
350+
lt_config["run_settings"]["sys_envs"] = envs;
351+
363352

364353
//get specs from current directory if specs are not passed in config or cli
365354
if (

commands/utils/validate.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require("fs");
22
const constants = require("./constants.js");
33
module.exports = validate_config = function (lt_config, validation_configs) {
4+
console.log("validating config");
45
return new Promise(function (resolve, reject) {
56
//validate auth keys are present
67
if (
@@ -319,6 +320,22 @@ module.exports = validate_config = function (lt_config, validation_configs) {
319320
reject("Error!! boolean value is expected in reject_unauthorized key");
320321
}
321322
}
323+
324+
// validate system env variables to be set up
325+
if ("sys_envs" in lt_config["run_settings"]) {
326+
let sys_envs = lt_config["run_settings"]["sys_envs"];
327+
let envValue;
328+
Object.keys(sys_envs).forEach(function(envKey) {
329+
envValue = sys_envs[envKey];
330+
if (envKey && ! constants.WHITELISTED_ENV_VARS.includes(envKey)){
331+
reject(`Usage of unwanted environment variable detected. Allowed variables are - ${constants.WHITELISTED_ENV_VARS}`);
332+
}
333+
if (envValue == undefined || envValue === ""){
334+
reject("Value of environment variable cannot be left blank");
335+
}
336+
})
337+
338+
}
322339
resolve("Validated the Config");
323340
});
324341
};

0 commit comments

Comments
 (0)