Skip to content

Commit 6143be0

Browse files
Added endpoint to verify entire set of configurations
This includes an extra random string for enhanced security
1 parent 902ac27 commit 6143be0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/configurations.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as dotenv from 'dotenv';
22
import * as dotenvExpand from 'dotenv-expand';
33
import * as _ from 'lodash';
4+
import * as crypto from 'crypto';
45
dotenv.config();
56
dotenvExpand(dotenv.config({ path: './prisma/.env' }));
67
import { LoggingLevelType, LOGGING_LEVEL } from './utilities/logger-logging-levels';
@@ -113,6 +114,7 @@ const configurations = {
113114
isProduction: isProduction,
114115
logMissingConfigurations: readBooleanValue('LOG_MISSING_CONFIGURATIONS', true),
115116
failOnMissingConfigurations: readBooleanValue('FAIL_ON_MISSING_CONFIGURATIONS', isProduction),
117+
configSalt: readStringValue('CONFIG_SALT', ''),
116118
},
117119
server: {
118120
port: readStringValue('SERVER_PORT', '3004'),
@@ -168,7 +170,14 @@ const configurations = {
168170
// After we log the warnings we can drop the logs, figured it would cause cleanup
169171
logs = null;
170172
});
171-
})
173+
}),
174+
hash: ''
172175
};
173176

177+
configurations.loadPromise
178+
.then(() => {
179+
configurations.hash = crypto.createHash('sha256').update(JSON.stringify(configurations)).digest('hex');
180+
})
181+
.catch(() => null);
182+
174183
export default configurations;

src/routes/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const router = express.Router();
77
import { PrismaClient } from '@prisma/client';
88
import _ = require('lodash');
99
import logger from '../utilities/logger';
10+
import configurations from '../configurations';
1011
const prisma = new PrismaClient({
1112
// log: ['query', 'warn', 'error']
1213
});
@@ -71,6 +72,12 @@ async (_req: Request, _res: Response, next: NextFunction) => {
7172
}
7273
});
7374

75+
router.use('/secret-to-everyone',
76+
// No validation
77+
(_req: Request, _res: Response, next: NextFunction) => {
78+
next(httpResponse.Ok(null, configurations.hash));
79+
});
80+
7481
router.get('/subjects', async (_req: Request, _res: Response, next: NextFunction) => {
7582
try {
7683
const subjects = await prisma.opl_dbsubject.findMany();

0 commit comments

Comments
 (0)