diff --git a/.gitignore b/.gitignore index e8245208..bf0afa0b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ src/database/docketeerdb server/database/docketeerdb dist/ .env +/imageConfigs/grafana/data +/imageConfigs/prometheus/promData +/imageConfigs/postgres/docketeerdb coverage/ diff --git a/docker-compose.yml b/docker-compose.yml index dc82737d..f0eb2c18 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,8 +51,8 @@ services: container_name: prometheus ports: - '9090:9090' - - #can add volume here to persist the prometheus data. + volumes: + - ./imageConfigs/prometheus/promData:/prometheus depends_on: - node-exporter labels: diff --git a/dockerfile b/dockerfile index 39afc858..ab3b8811 100644 --- a/dockerfile +++ b/dockerfile @@ -7,6 +7,7 @@ WORKDIR /app # ENV PATH="/usr/local/bin:${PATH}" # COPY /usr/local/bin/docker /usr/local/bin/docker ENV DOCKERVERSION=19.03.12 + RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz \ && tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker \ && rm docker-${DOCKERVERSION}.tgz diff --git a/package.json b/package.json index 242359cc..a67d4072 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,10 @@ "@testing-library/user-event": "^14.4.3", "child_process": "^1.0.2", "colors": "^1.4.0", + "cookie-parser": "^1.4.6", "cors": "^2.8.5", "electron-squirrel-startup": "^1.0.0", + "jsonwebtoken": "^9.0.0", "os": "^0.1.2", "os-utils": "^0.0.14", "pg": "^8.8.0", diff --git a/server/app.ts b/server/app.ts index eeba0ba2..c3f130c9 100644 --- a/server/app.ts +++ b/server/app.ts @@ -25,7 +25,7 @@ exec( return; } console.log(`stdout: ${stdout}`); - } + }, ); // Importing routers... @@ -81,7 +81,7 @@ app.get( }; const errorObj: ServerError = Object.assign(defaultErr, err); return res.status(errorObj.status).json(errorObj.message); - } + }, ); // Exporting app... diff --git a/server/controllers/commandController.ts b/server/controllers/commandController.ts index 84dad1b5..e2c8e7c2 100644 --- a/server/controllers/commandController.ts +++ b/server/controllers/commandController.ts @@ -525,7 +525,7 @@ const commandController: CommandController = { parseDockerOutput.forEach((obj: composeStacksDockerObject): void => { if ( obj.Name.includes( - directoryNameArray[directoryNameArray.length - 1] + directoryNameArray[directoryNameArray.length - 1], ) ) { obj.FilePath = req.body.filePath; @@ -535,7 +535,7 @@ const commandController: CommandController = { } res.locals.output = parseDockerOutput; return next(); - } + }, ); }, @@ -605,6 +605,8 @@ const commandController: CommandController = { return next(); } ); + res.locals.containers = dockerOutput; + return next(); }, getLogs: (req: Request, res: Response, next: NextFunction) => { diff --git a/server/controllers/configController.ts b/server/controllers/configController.ts index c46a2c35..96c1266b 100644 --- a/server/controllers/configController.ts +++ b/server/controllers/configController.ts @@ -9,6 +9,8 @@ import { ConfigController, ServerError } from '../../types'; * @description | Contains middleware that updates a user's contact preference, CPU threshold, memory threshold, and container stop preference in database **/ const configController: ConfigController = { + // *** I don't believe any of these are currently in use *** + // update configuration thresholds // TODO: implement diff --git a/server/controllers/initController.ts b/server/controllers/initController.ts index 8a215623..07dab856 100644 --- a/server/controllers/initController.ts +++ b/server/controllers/initController.ts @@ -93,5 +93,18 @@ const initController: InitController = { return next(error); } }, + + // gitUrl: (req: Request, res: Response, next: NextFunction) => { + // const parameter = [req.body.githubUrl]; + // db.query('SELECT github_url FROM containers where name = $1', parameter) + // .then((data: any) => { + // res.locals.url = data; + // return next(); + // }) + // .catch((err: ServerError) => { + // console.log(err); + // if (err) return next(err); + // }); + // }, }; export default initController; diff --git a/server/controllers/signupController.ts b/server/controllers/signupController.ts index ca1dc9e5..0f055a50 100644 --- a/server/controllers/signupController.ts +++ b/server/controllers/signupController.ts @@ -26,6 +26,7 @@ const signupController: SignupController = { .catch((err: ServerError): void => { return next({ log: `Error in signupController usernameCheck: ${err}`, + status: 409, message: { err: `An error occured while checking if username exists. See signupController.usernameCheck., ${err.message}`, }, diff --git a/server/controllers/userController.ts b/server/controllers/userController.ts index dce75913..7a41da5a 100644 --- a/server/controllers/userController.ts +++ b/server/controllers/userController.ts @@ -247,6 +247,7 @@ const userController: UserController = { db.query(query, parameters) .then((data: { rows: UserInfo[] }): void => { res.locals.user = data.rows[0]; + delete res.locals.user.password; return next(); }) .catch((err: ServerError): void => { @@ -318,3 +319,41 @@ const userController: UserController = { }, }; export default userController; + +// not currently in use. + +// switches role of user upon designation by system admin +// switchUserRole: (req: Request, res: Response, next: NextFunction) => { +// const roleMap: { [k: string]: number } = { +// 'system admin': 1, +// admin: 2, +// user: 3, +// }; + +// const { _id, role } = req.body; + +// if (res.locals.sysAdmins === 1 && _id == res.locals.id) { +// res.locals.hasError = true; +// next(); +// } else { +// const query = +// 'UPDATE users SET role = $1, role_id = $2 WHERE _id = $3 RETURNING *;'; + +// const parameters = [role, roleMap[role], _id]; + +// db.query(query, parameters) +// .then((data: any) => { +// res.locals.role = data.rows[0].role; +// res.locals.hasError = false; +// return next(); +// }) +// .catch((err: ServerError) => { +// return next({ +// log: `Error in userController switchUserRole: ${err}`, +// message: { +// err: 'An error occurred while switching roles. See userController.switchUserRole.', +// }, +// }); +// }); +// } +// }, diff --git a/server/database/cloudModel.ts b/server/database/cloudModel.ts index b18a9788..8c720afb 100644 --- a/server/database/cloudModel.ts +++ b/server/database/cloudModel.ts @@ -1,5 +1,11 @@ import { Pool } from 'pg'; import { SqlQuery } from '../../types'; +import { + POSTGRES_SERVICE, + POSTGRES_USER, + POSTGRES_PASS, + POSTGRES_NAME, +} from '../../config.js'; const pool: Pool = new Pool({ host: 'db', diff --git a/server/routes/apiRouter.ts b/server/routes/apiRouter.ts index c49da336..8388eb3c 100644 --- a/server/routes/apiRouter.ts +++ b/server/routes/apiRouter.ts @@ -15,7 +15,7 @@ router.post( apiController.sendEmailAlert, (req: Request, res: Response): Response => { return res.status(201).json('alert email sent to user'); - } + }, ); export default router; diff --git a/server/routes/commandRouter.ts b/server/routes/commandRouter.ts index 6a13ef50..d6ac783a 100644 --- a/server/routes/commandRouter.ts +++ b/server/routes/commandRouter.ts @@ -19,7 +19,7 @@ router.get( commandController.getContainers, (req: Request, res: Response) => { return res.status(200).json(res.locals.containers); - } + }, ); // Route for adding a new running container to runningList state @@ -30,7 +30,7 @@ router.post( commandController.getContainers, (req: Request, res: Response) => { return res.status(201).json(res.locals.containers); - } + }, ); // Route for refreshing stopped containers @@ -39,7 +39,7 @@ router.get( commandController.refreshStopped, (req: Request, res: Response) => { return res.status(200).json(res.locals.stoppedContainers); - } + }, ); // Route to refresh list of images @@ -48,7 +48,7 @@ router.get( commandController.refreshImages, (req: Request, res: Response) => { return res.status(200).json(res.locals.imagesList); - } + }, ); // Route to remove a stopped container @@ -58,7 +58,7 @@ router.delete( commandController.remove, (req: Request, res: Response) => { return res.status(200).json(res.locals.idRemoved); - } + }, ); // Route to stop a running container @@ -69,7 +69,7 @@ router.delete( commandController.refreshStopped, (req: Request, res: Response) => { return res.status(200).json(res.locals.containerStopped); - } + }, ); // Route to run a stopped container @@ -79,7 +79,7 @@ router.get( commandController.runStopped, (req: Request, res: Response) => { return res.status(200).json(res.locals.containerRan); - } + }, ); // Route to remove an image @@ -89,7 +89,7 @@ router.delete( commandController.removeImage, (req: Request, res: Response) => { return res.status(200); - } + }, ); // Route for running the docker prune command @@ -99,7 +99,7 @@ router.delete( commandController.dockerPrune, (req: Request, res: Response) => { return res.status(200).json(res.locals.pruneMessage); - } + }, ); // Route to pull new images @@ -109,7 +109,7 @@ router.get( commandController.pullImage, (req: Request, res: Response) => { return res.status(200).json(res.locals.imgMessage); - } + }, ); // Route to get network container list @@ -118,7 +118,7 @@ router.get( commandController.networkContainers, (req: Request, res: Response) => { return res.status(200).json(res.locals.networkContainers); - } + }, ); // Route to inspect docker container @@ -127,7 +127,7 @@ router.get( commandController.inspectDockerContainer, (req: Request, res: Response) => { return res.status(200).json(res.locals.inspectOut); - } + }, ); // Route to compose a docker file @@ -138,7 +138,7 @@ router.post( commandController.composeStacks, (req: Request, res: Response) => { return res.status(201).json(res.locals.output); - } + }, ); // Route to compose DOWN a docker file @@ -149,7 +149,7 @@ router.post( commandController.composeStacks, (req: Request, res: Response) => { return res.status(201).json(res.locals.output); - } + }, ); // Route to get list of container networks @@ -159,7 +159,7 @@ router.get( commandController.composeStacks, (req: Request, res: Response) => { return res.status(200).json(res.locals.output); - } + }, ); // Route to get all Docker Volumes @@ -168,7 +168,7 @@ router.get( commandController.getAllDockerVolumes, (req: Request, res: Response) => { return res.status(200).json(res.locals.dockerVolumes); - } + }, ); // Route to get all containers running in specified volume @@ -177,7 +177,7 @@ router.get( commandController.getVolumeContainers, (req: Request, res: Response) => { return res.status(200).json(res.locals.volumeContainers); - } + }, ); // Route to get all container logs @@ -186,7 +186,7 @@ router.post( commandController.getLogs, (req: Request, res: Response) => { return res.status(201).json(res.locals.logs); - } + }, ); export default router; diff --git a/src/helpers/dispatch.tsx b/src/helpers/dispatch.tsx index fb646e23..fd9aef8c 100644 --- a/src/helpers/dispatch.tsx +++ b/src/helpers/dispatch.tsx @@ -178,7 +178,7 @@ const useSurvey = () => { dispatch(getLogs(data)); }, }), - [dispatch] + [dispatch], ); return actions; };