Fixing linting & adding documentation

This commit is contained in:
c0derMo 2022-07-22 15:57:40 +00:00
parent 0d098b0958
commit e356d5f623
7 changed files with 42 additions and 15 deletions

View File

@ -122,6 +122,11 @@ async function sendInfo(socket) {
}); });
} }
/**
* Send list of docker hosts to client
* @param {Socket} socket Socket.io socket instance
* @returns {Promise<Bean[]>}
*/
async function sendDockerHostList(socket) { async function sendDockerHostList(socket) {
const timeLogger = new TimeLogger(); const timeLogger = new TimeLogger();

View File

@ -4,6 +4,13 @@ const version = require("../package.json").version;
const https = require("https"); const https = require("https");
class DockerHost { class DockerHost {
/**
* Save a docker host
* @param {Object} dockerHost Docker host to save
* @param {?number} dockerHostID ID of the docker host to update
* @param {number} userID ID of the user who adds the docker host
* @returns {Promise<Bean>}
*/
static async save(dockerHost, dockerHostID, userID) { static async save(dockerHost, dockerHostID, userID) {
let bean; let bean;
@ -28,6 +35,12 @@ class DockerHost {
return bean; return bean;
} }
/**
* Delete a Docker host
* @param {number} dockerHostID ID of the Docker host to delete
* @param {number} userID ID of the user who created the Docker host
* @returns {Promise<void>}
*/
static async delete(dockerHostID, userID) { static async delete(dockerHostID, userID) {
let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]); let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
@ -38,6 +51,11 @@ class DockerHost {
await R.trash(bean); await R.trash(bean);
} }
/**
* Fetches the amount of containers on the Docker host
* @param {Object} dockerHost Docker host to check for
* @returns {number} Total amount of containers on the host
*/
static async getAmountContainer(dockerHost) { static async getAmountContainer(dockerHost) {
const options = { const options = {
url: "/containers/json?all=true", url: "/containers/json?all=true",
@ -64,4 +82,4 @@ class DockerHost {
module.exports = { module.exports = {
DockerHost, DockerHost,
} };

View File

@ -12,8 +12,8 @@ class DockerHost extends BeanModel {
daemon: this._dockerDaemon, daemon: this._dockerDaemon,
type: this._dockerType, type: this._dockerType,
name: this._name, name: this._name,
} };
} }
} }
module.exports = DockerHost; module.exports = DockerHost;

View File

@ -470,7 +470,7 @@ class Monitor extends BeanModel {
} else if (this.type === "docker") { } else if (this.type === "docker") {
log.debug(`[${this.name}] Prepare Options for Axios`); log.debug(`[${this.name}] Prepare Options for Axios`);
const docker_host = await R.load("docker_host", this.docker_host); const dockerHost = await R.load("docker_host", this.docker_host);
const options = { const options = {
url: `/containers/${this.docker_container}/json`, url: `/containers/${this.docker_container}/json`,
@ -484,10 +484,10 @@ class Monitor extends BeanModel {
}), }),
}; };
if (docker_host._dockerType === "socket") { if (dockerHost._dockerType === "socket") {
options.socketPath = docker_host._dockerDaemon; options.socketPath = dockerHost._dockerDaemon;
} else if (docker_host._dockerType === "tcp") { } else if (dockerHost._dockerType === "tcp") {
options.baseURL = docker_host._dockerDaemon; options.baseURL = dockerHost._dockerDaemon;
} }
log.debug(`[${this.name}] Axios Request`); log.debug(`[${this.name}] Axios Request`);

View File

@ -2,6 +2,10 @@ const { sendDockerHostList } = require("../client");
const { checkLogin } = require("../util-server"); const { checkLogin } = require("../util-server");
const { DockerHost } = require("../docker"); const { DockerHost } = require("../docker");
/**
* Handlers for docker hosts
* @param {Socket} socket Socket.io instance
*/
module.exports.dockerSocketHandler = (socket) => { module.exports.dockerSocketHandler = (socket) => {
socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => { socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => {
try { try {
@ -20,7 +24,7 @@ module.exports.dockerSocketHandler = (socket) => {
callback({ callback({
ok: false, ok: false,
msg: e.message, msg: e.message,
}) });
} }
}); });
@ -40,7 +44,7 @@ module.exports.dockerSocketHandler = (socket) => {
callback({ callback({
ok: false, ok: false,
msg: e.message, msg: e.message,
}) });
} }
}); });
@ -61,7 +65,7 @@ module.exports.dockerSocketHandler = (socket) => {
callback({ callback({
ok: false, ok: false,
msg: e.message, msg: e.message,
}) });
} }
}) });
} };

View File

@ -66,7 +66,7 @@ export default {
model: null, model: null,
processing: false, processing: false,
id: null, id: null,
connectionTypes: ["socket", "tcp"], connectionTypes: [ "socket", "tcp" ],
dockerHost: { dockerHost: {
name: "", name: "",
dockerDaemon: "", dockerDaemon: "",

View File

@ -144,7 +144,7 @@ export default {
socket.on("dockerHostList", (data) => { socket.on("dockerHostList", (data) => {
this.dockerHostList = data; this.dockerHostList = data;
}) });
socket.on("heartbeat", (data) => { socket.on("heartbeat", (data) => {
if (! (data.monitorID in this.heartbeatList)) { if (! (data.monitorID in this.heartbeatList)) {