Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelAngelo13 committed Apr 2, 2023
2 parents e55314f + 0d341a5 commit aab2c9c
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ src/database/docketeerdb
server/database/docketeerdb
dist/
.env
/imageConfigs/grafana/data
/imageConfigs/prometheus/promData
/imageConfigs/postgres/docketeerdb

coverage/

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exec(
return;
}
console.log(`stdout: ${stdout}`);
}
},
);

// Importing routers...
Expand Down Expand Up @@ -81,7 +81,7 @@ app.get(
};
const errorObj: ServerError = Object.assign(defaultErr, err);
return res.status(errorObj.status).json(errorObj.message);
}
},
);

// Exporting app...
Expand Down
6 changes: 4 additions & 2 deletions server/controllers/commandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -535,7 +535,7 @@ const commandController: CommandController = {
}
res.locals.output = parseDockerOutput;
return next();
}
},
);
},

Expand Down Expand Up @@ -605,6 +605,8 @@ const commandController: CommandController = {
return next();
}
);
res.locals.containers = dockerOutput;
return next();
},

getLogs: (req: Request, res: Response, next: NextFunction) => {
Expand Down
2 changes: 2 additions & 0 deletions server/controllers/configController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions server/controllers/initController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions server/controllers/signupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
},
Expand Down
39 changes: 39 additions & 0 deletions server/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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.',
// },
// });
// });
// }
// },
6 changes: 6 additions & 0 deletions server/database/cloudModel.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion server/routes/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
36 changes: 18 additions & 18 deletions server/routes/commandRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -89,7 +89,7 @@ router.delete(
commandController.removeImage,
(req: Request, res: Response) => {
return res.status(200);
}
},
);

// Route for running the docker prune command
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -186,7 +186,7 @@ router.post(
commandController.getLogs,
(req: Request, res: Response) => {
return res.status(201).json(res.locals.logs);
}
},
);

export default router;
2 changes: 1 addition & 1 deletion src/helpers/dispatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const useSurvey = () => {
dispatch(getLogs(data));
},
}),
[dispatch]
[dispatch],
);
return actions;
};
Expand Down

0 comments on commit aab2c9c

Please sign in to comment.