From e356d5f62391fbcbaa523c291e2219372128ed7c Mon Sep 17 00:00:00 2001 From: c0derMo Date: Fri, 22 Jul 2022 15:57:40 +0000 Subject: [PATCH] Fixing linting & adding documentation --- server/client.js | 5 +++++ server/docker.js | 20 ++++++++++++++++++- server/model/docker_host.js | 4 ++-- server/model/monitor.js | 10 +++++----- .../socket-handlers/docker-socket-handler.js | 14 ++++++++----- src/components/DockerHostDialog.vue | 2 +- src/mixins/socket.js | 2 +- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/server/client.js b/server/client.js index 614038427..bda776427 100644 --- a/server/client.js +++ b/server/client.js @@ -122,6 +122,11 @@ async function sendInfo(socket) { }); } +/** + * Send list of docker hosts to client + * @param {Socket} socket Socket.io socket instance + * @returns {Promise} + */ async function sendDockerHostList(socket) { const timeLogger = new TimeLogger(); diff --git a/server/docker.js b/server/docker.js index a13236aa9..57e793ab4 100644 --- a/server/docker.js +++ b/server/docker.js @@ -4,6 +4,13 @@ const version = require("../package.json").version; const https = require("https"); 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} + */ static async save(dockerHost, dockerHostID, userID) { let bean; @@ -28,6 +35,12 @@ class DockerHost { 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} + */ static async delete(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); } + /** + * 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) { const options = { url: "/containers/json?all=true", @@ -64,4 +82,4 @@ class DockerHost { module.exports = { DockerHost, -} \ No newline at end of file +}; diff --git a/server/model/docker_host.js b/server/model/docker_host.js index 26f3035a5..229a9a52d 100644 --- a/server/model/docker_host.js +++ b/server/model/docker_host.js @@ -12,8 +12,8 @@ class DockerHost extends BeanModel { daemon: this._dockerDaemon, type: this._dockerType, name: this._name, - } + }; } } -module.exports = DockerHost; \ No newline at end of file +module.exports = DockerHost; diff --git a/server/model/monitor.js b/server/model/monitor.js index 373796e96..babff8761 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -470,7 +470,7 @@ class Monitor extends BeanModel { } else if (this.type === "docker") { 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 = { url: `/containers/${this.docker_container}/json`, @@ -484,10 +484,10 @@ class Monitor extends BeanModel { }), }; - if (docker_host._dockerType === "socket") { - options.socketPath = docker_host._dockerDaemon; - } else if (docker_host._dockerType === "tcp") { - options.baseURL = docker_host._dockerDaemon; + if (dockerHost._dockerType === "socket") { + options.socketPath = dockerHost._dockerDaemon; + } else if (dockerHost._dockerType === "tcp") { + options.baseURL = dockerHost._dockerDaemon; } log.debug(`[${this.name}] Axios Request`); diff --git a/server/socket-handlers/docker-socket-handler.js b/server/socket-handlers/docker-socket-handler.js index eddcd7b84..7f3646bb1 100644 --- a/server/socket-handlers/docker-socket-handler.js +++ b/server/socket-handlers/docker-socket-handler.js @@ -2,6 +2,10 @@ const { sendDockerHostList } = require("../client"); const { checkLogin } = require("../util-server"); const { DockerHost } = require("../docker"); +/** + * Handlers for docker hosts + * @param {Socket} socket Socket.io instance + */ module.exports.dockerSocketHandler = (socket) => { socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => { try { @@ -20,7 +24,7 @@ module.exports.dockerSocketHandler = (socket) => { callback({ ok: false, msg: e.message, - }) + }); } }); @@ -40,7 +44,7 @@ module.exports.dockerSocketHandler = (socket) => { callback({ ok: false, msg: e.message, - }) + }); } }); @@ -61,7 +65,7 @@ module.exports.dockerSocketHandler = (socket) => { callback({ ok: false, msg: e.message, - }) + }); } - }) -} \ No newline at end of file + }); +}; diff --git a/src/components/DockerHostDialog.vue b/src/components/DockerHostDialog.vue index e52c4ecf3..d7cf2de0d 100644 --- a/src/components/DockerHostDialog.vue +++ b/src/components/DockerHostDialog.vue @@ -66,7 +66,7 @@ export default { model: null, processing: false, id: null, - connectionTypes: ["socket", "tcp"], + connectionTypes: [ "socket", "tcp" ], dockerHost: { name: "", dockerDaemon: "", diff --git a/src/mixins/socket.js b/src/mixins/socket.js index f6de82c2b..e2096b372 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -144,7 +144,7 @@ export default { socket.on("dockerHostList", (data) => { this.dockerHostList = data; - }) + }); socket.on("heartbeat", (data) => { if (! (data.monitorID in this.heartbeatList)) {