forked from LambdaTest/lambdatest-cypress-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_info.js
88 lines (83 loc) · 2.34 KB
/
build_info.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
const request = require("request");
const constants = require("./utils/constants.js");
const process = require("process");
function get_build_info(args) {
return new Promise(function (resolve, reject) {
var username = "";
var access_key = "";
//Check for username
if ("user" in args) {
username = args.user;
} else if (process.env.LT_USERNAME) {
console.log("Setting Username from ENV", process.env.LT_USERNAME);
username = process.env.LT_USERNAME;
} else {
reject("Username not provided");
}
//Check for access key
if ("access_key" in args) {
access_key = args.access_key;
} else if (process.env.LT_ACCESS_KEY) {
console.log("Setting Access Key from ENV", process.env.LT_ACCESS_KEY);
access_key = process.env.LT_ACCESS_KEY;
} else {
reject("Access Key not provided");
}
if (!("buildId" in args)) {
reject("Please provide a build ID");
}
var env = "prod";
if ("env" in args) {
if (constants.ENVS.includes(args["env"])) {
env = args["env"];
} else {
console.log(
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
);
}
}
let options = {
url: constants[env].BUILD_BASE_URL + args.buildId,
auth: {
username: username,
password: access_key,
},
};
if ("reject_unauthorized" in args) {
if (
args["reject_unauthorized"] != "false" &&
args["reject_unauthorized"] != "true"
) {
console.log("reject_unauthorized has to boolean");
return;
} else {
if (args["reject_unauthorized"] == "false") {
options["rejectUnauthorized"] = false;
console.log("Setting rejectUnauthorized to false for web requests");
}
}
}
request.get(options, (err, res, body) => {
if (err) {
reject(err);
} else {
if (res.statusCode == "401") {
resolve("Unauthorized");
} else if (JSON.parse(body).status == "success") {
resolve(JSON.parse(body).data);
} else {
resolve(JSON.parse(body).message);
}
}
});
});
}
module.exports = function (args) {
get_build_info(args)
.then(function (resp) {
console.log(resp);
})
.catch(function (err) {
console.log(err);
});
};