Extracted the release function -> getReleaseInformation in the shell.js controller
This commit is contained in:
parent
0e105588da
commit
fa2d20e72d
@ -13,6 +13,24 @@ const mapLines = (data) => {
|
|||||||
return infoData;
|
return infoData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.getReleaseInformation = (session, endSession = true) => {
|
||||||
|
let infoData = {};
|
||||||
|
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
session.exec("cat /etc/os-release", (err, stream) => {
|
||||||
|
stream.on("close", (code) => {
|
||||||
|
if (endSession) session.end();
|
||||||
|
if (code === 0) return resolve(infoData);
|
||||||
|
|
||||||
|
reject("Error while checking distro");
|
||||||
|
}).on("data", (data) => {
|
||||||
|
infoData = {...infoData, ...mapLines(data)};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.checkServer = async ({hostname, username = "root", password, privateKey}) => {
|
module.exports.checkServer = async ({hostname, username = "root", password, privateKey}) => {
|
||||||
const port = hostname.split(":")[1] || 22;
|
const port = hostname.split(":")[1] || 22;
|
||||||
hostname = hostname.split(":")[0];
|
hostname = hostname.split(":")[0];
|
||||||
@ -21,19 +39,11 @@ module.exports.checkServer = async ({hostname, username = "root", password, priv
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
session.on("ready", () => {
|
session.on("ready", () => {
|
||||||
let infoData = {};
|
this.getReleaseInformation(session).then((infoData) => {
|
||||||
|
resolve(infoData);
|
||||||
session.exec("cat /etc/os-release", (err, stream) => {
|
}).catch((err) => {
|
||||||
stream.on("close", (code) => {
|
reject(err);
|
||||||
session.end();
|
|
||||||
if (code === 0) return resolve(infoData);
|
|
||||||
|
|
||||||
reject("Error while checking distro");
|
|
||||||
}).on("data", (data) => {
|
|
||||||
infoData = {...infoData, ...mapLines(data)};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}).connect({host: hostname, port, username, password, privateKey, readyTimeout: 5000}).on("error", () => {
|
}).connect({host: hostname, port, username, password, privateKey, readyTimeout: 5000}).on("error", () => {
|
||||||
reject("Error while connecting to server");
|
reject("Error while connecting to server");
|
||||||
session.end();
|
session.end();
|
||||||
|
Reference in New Issue
Block a user