-
Notifications
You must be signed in to change notification settings - Fork 9
Review Opportunities #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1e4e60b
0729f07
2820bbc
e035dac
08b12ce
aae1df9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" | ||
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb" | ||
POSTGRES_SCHEMA="public" | ||
# API configs | ||
BUS_API_URL="https://api.topcoder-dev.com/v5/bus/events" | ||
CHALLENGE_API_URL="https://api.topcoder-dev.com/v5/challenges/" | ||
MEMBER_API_URL="https://api.topcoder-dev.com/v5/members" | ||
# M2m configs | ||
M2M_AUTH_URL="https://auth0.topcoder-dev.com/oauth/token" | ||
M2M_AUTH_CLIENT_ID="jGIf2pd3f44B1jqvOai30BIKTZanYBfU" | ||
M2M_AUTH_CLIENT_SECRET="ldzqVaVEbqhwjM5KtZ79sG8djZpAVK8Z7qieVcC3vRjI4NirgcinKSBpPwk6mYYP" | ||
M2M_AUTH_DOMAIN="topcoder-dev.auth0.com" | ||
M2M_AUTH_AUDIENCE="https://m2m.topcoder-dev.com/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo correction: The variable name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billsedison - We shouldn't have any mock client ids, tokens, or secrets in the codebase, even though they aren't valid. We get pinged by Wipro security on those and they don't understand that these aren't usable. |
||
M2M_AUTH_PROXY_SERVER_URL= | ||
# Mock API configs | ||
M2M_MOCK_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3RvcGNvZGVyLWRldi5hdXRoMC5jb20vIiwic3ViIjoiakdJZjJwZDNmNDRCMWpxdk9haTMwQklLVFphbllCZlVAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vbTJtLnRvcGNvZGVyLWRldi5jb20vIiwiaWF0IjoxNzQ4MDk5NDk4LCJleHAiOjE4NDgxODU4OTgsInNjb3BlIjoid3JpdGU6YnVzX2FwaSxhbGw6Y2hhbGxlbmdlcyIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyIsImF6cCI6ImpHSWYycGQzZjQ0QjFqcXZPYWkzMEJJS1RaYW5ZQmZVIn0.h3ksdsdJm5USGF1VgROrpkTtStmCzv5ZA6y8bd8AnGY" | ||
|
||
#Sendgrid email templates | ||
SENDGRID_ACCEPT_REVIEW_APPLICATION="d-2de72880bd69499e9c16369398d34bb9" | ||
SENDGRID_REJECT_REVIEW_APPLICATION="d-82ed74e778e84d8c9bc02eeda0f44b5e" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,14 @@ set -eo pipefail | |
|
||
export DATABASE_URL=$(echo -e ${DATABASE_URL}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
||
# Set default schema to 'public' if not provided | ||
if [ -z "$POSTGRES_SCHEMA" ]; then | ||
echo "POSTGRES_SCHEMA not set, defaulting to 'public'" | ||
export POSTGRES_SCHEMA="public" | ||
else | ||
echo "Using PostgreSQL schema: $POSTGRES_SCHEMA" | ||
fi | ||
|
||
echo "Database - running migrations." | ||
if $RESET_DB; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition |
||
echo "Resetting DB" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const express = require('express') | ||
const winston = require('winston') | ||
const cors = require('cors') | ||
|
||
const app = express() | ||
app.use(cors()) | ||
app.use(express.json()) | ||
app.set('port', 4000) | ||
|
||
const logger = winston.createLogger({ | ||
transports: [ | ||
new winston.transports.Console({ | ||
level: 'debug', | ||
format: winston.format.combine( | ||
winston.format.colorize(), | ||
winston.format.simple() | ||
), | ||
}), | ||
] | ||
}); | ||
|
||
// Event bus | ||
app.post('/eventBus', (req, res) => { | ||
logger.info(`Event Bus received message: ${JSON.stringify(req.body)}`); | ||
res.statusCode = 200; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of setting |
||
res.json({}) | ||
}) | ||
|
||
// Use environment variable for M2M token instead of hardcoding | ||
const m2mToken = process.env.M2M_MOCK_TOKEN || 'dummy-token'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded fallback token ( |
||
|
||
const m2mScope = 'write:bus_api,all:challenges'; | ||
|
||
// Auth0 | ||
app.post('/oauth/token', (req, res) => { | ||
logger.info('Getting M2M tokens') | ||
res.json({ | ||
access_token: m2mToken, | ||
scope: m2mScope, | ||
expires_in: 94608000, | ||
token_type: 'Bearer' | ||
}) | ||
}) | ||
|
||
// Member API | ||
app.get('/members', (req, res) => { | ||
logger.info(`Member API receives params: ${JSON.stringify(req.query)}`) | ||
let userIdStr = req.query.userIds | ||
userIdStr = userIdStr.replaceAll('[', '').replaceAll(']', '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
const userIds = userIdStr.split(',') | ||
// return result | ||
const ret = userIds.map(id => ({ | ||
userId: parseInt(id), | ||
email: `${id}@topcoder.com` | ||
})) | ||
res.json(ret) | ||
}) | ||
|
||
// Challenge API | ||
app.get('/challenges/:id', (req, res) => { | ||
// directly challenge details | ||
const id = req.params.id | ||
logger.info(`Getting challenge with id ${id}`) | ||
if (id === '11111111-2222-3333-9999-444444444444') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using |
||
res.statusCode = 404 | ||
res.json({}) | ||
return | ||
} | ||
res.json({ | ||
id, | ||
name: `Test Challenge ${id}`, | ||
legacy: { | ||
track: 'DEVELOP', | ||
subTrack: 'CODE' | ||
}, | ||
numOfSubmissions: 2, | ||
legacyId: 30376875, | ||
tags: ['Prisma', 'NestJS'] | ||
}) | ||
}) | ||
|
||
|
||
app.listen(app.get('port'), '0.0.0.0', () => { | ||
logger.info(`Express server listening on port ${app.get('port')}`) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing the hardcoded credentials in the DATABASE_URL for security reasons. It's better to use placeholders like
<username>
and<password>
.