Skip to content

Commit 5f2e26a

Browse files
committed
Merge branch 'dev' of https://github.com/oslabs-beta/Docketeer into dev
2 parents d3b3266 + 3ac6419 commit 5f2e26a

29 files changed

+55
-142
lines changed

__tests__/ProcessLogHelper.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ describe('dummy test', () => {
44
});
55
});
66

7+
//Testing for Process logs needs to be implemented
8+
79
// /**
810
// * @jest-environment jsdom
911
// */

__tests__/ServerRoutes.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ describe('test test', () => {
5757
describe('key test ', () => {
5858
test('Get request', async () => {
5959
const res = await request(app).get('/gapi/key');
60-
console.log(res.body);
6160
expect(typeof res.body).toBe('string');
6261
expect(res.status).toBe(200);
6362
testKey = res.body
@@ -66,7 +65,6 @@ describe('key test ', () => {
6665

6766
describe('uid test', () => {
6867
test('Post request', async () => {
69-
console.log('WE HERE', testKey)
7068
const requestBody = {
7169
key: testKey,
7270
dashboard: 'Node Exporter / Nodes',
@@ -75,7 +73,6 @@ describe('uid test', () => {
7573
.post('/gapi/uidkey')
7674
// .set('Content-Type', 'application/json')
7775
.send(requestBody);
78-
console.log('RES BODY', res.body)
7976
expect(typeof res.body).toBe('string');
8077
expect(res.status).toBe(200);
8178
});

__tests__/dockerComposeReducer.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ describe('dummy test', () => {
44
});
55
});
66

7+
//Docker Compose testing needs refactoring
8+
79
// import dockerComposeReducer from '../src/redux/reducers/dockerComposeReducer'
810
// import { describe, beforeEach, expect, test, jest } from '@jest/globals'
911
// import '@testing-library/jest-dom'

server/app.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import express, { Request, Response } from 'express';
33
import { ServerError, GlobalErrorObject } from '../types';
44
import cors from 'cors';
55
import { exec } from 'child_process';
6-
import cookieParser from 'cookie-parser'; // for when cookies get implemented
6+
import cookieParser from 'cookie-parser';
77
import * as path from 'path';
88

99
const app = express();
@@ -47,24 +47,10 @@ app.use(express.json());
4747
app.use(express.urlencoded({ extended: true }));
4848
app.use(express.static('SetupApp'));
4949

50-
// app.use(cookieParser()); // for when cookies get implemented
51-
52-
// check for cookie
53-
// app.use('/', userController.checkCookie, (req: Request, res: Response): void => {
54-
// console.log('cookffffffs', req.headers.cookie, req.cookies);
55-
// if (res.locals.notSignedIn) res.redirect('/login');
56-
// else res.redirect('/');
57-
// });
58-
5950

6051
// Defining routers...
6152

6253
app.use('/k8', (req: Request, res: Response) => {
63-
// const options = {
64-
// headers: {
65-
// 'Content-Type': 'application/javascript'
66-
// }
67-
// };
6854
res.status(200).sendFile(path.join(__dirname, '../SetupApp/index.html'));
6955
});
7056

server/controllers/apiController.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// !
22
// !
33
// ! Currently not used, is meant to send email alerts
4-
// currently not used, is meant to send email alerts
54

65
import { Request, Response, NextFunction } from 'express';
76
import nodemailer from 'nodemailer';
@@ -12,6 +11,7 @@ import { ApiController, ServerError } from '../../types';
1211
// Function: transporter
1312
// Purpose: create transporter object to make sure these values are filled out in email.js
1413
// ==========================================================
14+
1515
const transporter = nodemailer.createTransport({
1616
host: email.host,
1717
port: email.port,
@@ -27,20 +27,16 @@ const transporter = nodemailer.createTransport({
2727
* @description | contains middleware that sends emails to user for container issues and signup information
2828
**/
2929
const apiController: ApiController = {
30-
// testing: (req, res, next) => {
31-
// console.log("HELLO WE'RE TESTING!!!")
32-
// res.locals.testingData = "HELLLOOOOO OBJECT HERE"
33-
// return next();
34-
// }
3530
testing: (req: Request, res: Response, next: NextFunction) => {
36-
console.log('HELLO WERE TESTING');
37-
res.locals.testingData = 'HELLOOOO OBJECT HERE';
31+
res.locals.testingData = 'test';
3832
return next();
3933
},
34+
4035
// ==========================================================
4136
// Middleware: sendEmailAlert
4237
// Purpose:
4338
// ==========================================================
39+
4440
sendEmailAlert: (req: Request, res: Response, next: NextFunction) => {
4541
const { email, containerName, time, date, stopped } = req.body;
4642
let emailBody: string;
@@ -74,7 +70,7 @@ const apiController: ApiController = {
7470

7571
transporter
7672
.sendMail(mailDetails)
77-
.then((info: any) => {
73+
.then(() => {
7874
return next();
7975
})
8076
.catch((err: ServerError) => {
@@ -115,10 +111,10 @@ const apiController: ApiController = {
115111
// create transporter with Nodemailer to send email.
116112
transporter
117113

118-
// .sendMail is part of nodemailer package, sends an email and returns a promise with details on the email (info)
114+
// .sendMail is part of nodemailer package, sends an email and returns a promise with details on the email (info)
119115

120116
.sendMail(mailDetails)
121-
.then((info: any) => {
117+
.then(() => {
122118
return next();
123119
})
124120
.catch((err: ServerError) => {

server/controllers/grafanaApiController.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import fetch from 'node-fetch';
55
interface GrafanaResponse {
66
key: string;
77
}
8+
9+
// use localhost version for npm run dev or testing, but host.docker.internal when running compose up
810
// http://localhost:3000/api/auth/keys
911
// 'http://host.docker.internal:3000/api/auth/keys'
10-
// http://host.docker.internal:3000/api/search?query=${encodeURIComponent(dashboard)}`
1112
const grafanaApiController: GrafanaApiController = {
1213
getApi: async (req, res, next): Promise<void> => {
1314
try {
@@ -42,6 +43,9 @@ const grafanaApiController: GrafanaApiController = {
4243
}
4344
},
4445

46+
// use localhost version for npm run dev or testing, but host.docker.internal when running compose up
47+
// http://localhost:3000/api/search?query=${encodeURIComponent(dashboard)}`
48+
// http://host.docker.internal:3000/api/search?query=${encodeURIComponent(dashboard)}`
4549
getUid: async (req, res, next): Promise<void> => {
4650
const { key, dashboard }: { key: string; dashboard: string } = req.body;
4751
try {

server/controllers/setupController.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Request, Response, NextFunction } from 'express';
22
import { exec, execSync, spawn, spawnSync } from 'child_process';
33
import { SetupController } from '../../types';
44

5+
/**
6+
* @description v12.0 implemented k8 cluster metrics! In order to set this up, run npm run dev, go to
7+
* localhost:/3000 click the three buttons in sequence, this will run the necessary shell lines on your host terminal.
8+
* Than you can compose up to see your k8 metrics.
9+
*/
510

611
const setupController: SetupController = {
712
promInstall: (req: Request, res: Response, next: NextFunction): void => {

server/controllers/userController.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { UserController, ServerError, UserInfo } from '../../types';
77
// const secret = JWT_SECRET;
88

99
/**
10-
* @description Contains middleware that creates new user in database, gets all users from database for system admin, and verifies user exists before sending back user data to login component
10+
* @description Contains middleware that creates new user in database, gets all users from database verifies if user exists before sending back user data to login component
11+
* v12.0 implemented cookies for user sessions and commented out all system admin implementaion since it was nonfunctional
1112
*/
1213

1314
const userController: UserController = {
@@ -16,14 +17,13 @@ const userController: UserController = {
1617
res: Response,
1718
next: NextFunction
1819
): Promise<void> => {
19-
console.log('in userController.createUser');
2020

2121
try {
2222
const {
2323
username,
2424
password,
2525
// role_id,
26-
}: { username: string; password: string;} = req.body;
26+
}: { username: string; password: string; } = req.body;
2727
// hash password
2828
const hashedPassword = await bcrypt.hash(password, 10);
2929

@@ -48,9 +48,6 @@ const userController: UserController = {
4848
// create an array, userDetails, to hold values from our createUser SQL query placeholders.
4949
const userDetails: string[] = [username, hashedPassword];
5050
const createdUser = await db.query(createUser, userDetails);
51-
52-
console.log('createdUser: ', createdUser.rows[0]);
53-
5451
res.locals.user = createdUser.rows[0];
5552
return next();
5653
} catch (err: unknown) {
@@ -107,12 +104,10 @@ const userController: UserController = {
107104
req.body;
108105
// using username we create a query string to grab that user
109106
const getUser = 'SELECT * FROM users WHERE username=$1;';
110-
// using bcrypt we check if client's password input matches the password of that username in the db; we then add to locals accordingly
107+
// using bcrypt we check if client's password input matches the password of that username in the db; we then add to locals accordingly
111108
db.query(getUser, [username])
112109
.then(async (data: any) => {
113-
console.log(data.rows[0]);
114110
const match = await bcrypt.compare(password, data.rows[0].password);
115-
console.log(match);
116111
if (!data.rows[0] || !match) {
117112
return next({
118113
log: 'Error in userController\'s verifyUser method',
@@ -124,9 +119,8 @@ const userController: UserController = {
124119
}
125120
const verifiedUser = data.rows[0];
126121
res.locals.user = verifiedUser;
127-
console.log('verified user', verifiedUser);
128122
return next();
129-
123+
130124
// const verifiedRole = verifiedUser.role;
131125
// if (verifiedRole === 'system admin') {
132126
// await jwt.sign({ verifiedRole }, secret, (err, token) => {
@@ -157,11 +151,8 @@ const userController: UserController = {
157151
});
158152
},
159153

160-
161154

162155
updatePassword: (req: Request, res: Response, next: NextFunction): void => {
163-
// if there is an error property on res.locals, return next(). i.e., incorrect password entered
164-
165156
const { newHashedPassword }: { newHashedPassword: string } = res.locals as {
166157
newHashedPassword: string;
167158
};
@@ -226,29 +217,29 @@ const userController: UserController = {
226217
});
227218
},
228219

220+
// adding cookie
229221
addCookie: (req: Request, res: Response, next: NextFunction): void => {
230-
console.log('we are adding the cookie here right now');
231222
res.cookie('loggedIn', true);
232223
return next();
233224
},
234225

226+
// verify cookie on refresh
235227
checkCookie: (req: Request, res: Response, next: NextFunction): void => {
236228
if (req.cookies.loggedIn) res.locals.signedIn = true;
237229
else res.locals.signedIn = false;
238230
return next();
239231
},
240232

233+
// remove cookie on logout
241234
removeCookie: (req: Request, res: Response, next: NextFunction): void => {
242-
console.log('abt to rmv cookie');
243235
res.clearCookie('loggedIn');
244-
console.log('cookied rmvd');
245236
res.locals.loggedOut = true;
246237
return next();
247238
},
248239
};
249240
export default userController;
250241

251-
// not currently in use.
242+
// not currently in use (from v12.0)
252243

253244
// switches role of user upon designation by system admin
254245
// switchUserRole: (req: Request, res: Response, next: NextFunction) => {
@@ -303,7 +294,6 @@ export default userController;
303294
// });
304295
// }
305296
// const verifiedUser = data.rows[0];
306-
// console.log('verified user', verifiedUser);
307297
// res.locals.verifiedUser = verifiedUser;
308298
// const verifiedRole = verifiedUser.role;
309299
// if (verifiedRole === 'system admin') {

server/database/cloudModel.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { Pool } from 'pg';
22
import { SqlQuery } from '../../types';
3-
import {
4-
POSTGRES_SERVICE,
5-
POSTGRES_USER,
6-
POSTGRES_PASS,
7-
POSTGRES_NAME,
8-
} from '../../config.js';
93

104
const pool: Pool = new Pool({
115
host: 'db',

server/routes/adminRouter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/**
22
* @module AdminRouter
33
* @description Routes all requests to admin endpoint
4+
* v12.0 depreciated all admin / system admin functionality since it was nonfunctional
45
*/
6+
7+
58
// import { Router, Request, Response } from 'express';
69
// import userController from '../controllers/userController';
710

0 commit comments

Comments
 (0)