Skip to content

Migrate to Project Service V5 #162

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

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ workflows:
context : org-global
filters:
branches:
only: [dev, 'hotfix/V5-API-Standards']
only: [dev, 'hotfix/V5-API-Standards', 'v5-upgrade']
- "build-prod":
context : org-global
filters:
Expand Down
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tc-notifications (as a standard nodejs app) provides generic framework around no
5. Either add deployment for this new notification consumer/processor in existing deployment script (if you want to host the processor as separate service in the same ECS cluster) or write a new script if you want to keep the deployment separate.

## Dependencies
- nodejs https://nodejs.org/en/ (v6+, if newer version of node is used, e.g. v10, then it needs to install extra lib `npm i [email protected]` to support the gulp build)
- nodejs https://nodejs.org/en/ (v6+, if newer version of node is used, e.g. v10, then it needs to install extra lib `npm i [email protected]` to support the gulp build)
- Heroku Toolbelt https://toolbelt.heroku.com
- git
- PostgreSQL 9.5
Expand Down Expand Up @@ -50,8 +50,8 @@ The following parameters can be set in config files or in env variables:
if not provided, then SSL connection is not used, direct insecure connection is used;
if provided, it can be either path to private key file or private key content
- **Topcoder API**
- `TC_API_V3_BASE_URL`: the TopCoder API V3 base URL
- `TC_API_V4_BASE_URL`: the TopCoder API V4 base URL
- `TC_API_V3_BASE_URL`: the TopCoder API V3 base URL
- `TC_API_V4_BASE_URL`: the TopCoder API V4 base URL
- `TC_API_V5_BASE_URL`: the TopCoder API V5 base URL
- **Notifications API**
- `API_CONTEXT_PATH`: path to serve API on
Expand All @@ -61,16 +61,16 @@ The following parameters can be set in config files or in env variables:
- `TOKEN_CACHE_TIME`: time period of the cached token
- `AUTH0_CLIENT_ID`: auth0 client id
- `AUTH0_CLIENT_SECRET`: auth0 client secret
- `AUTH0_PROXY_SERVER_URL`: auth0 proxy server URL
- **Consumer handlers**
- `KAFKA_CONSUMER_HANDLERS`: mapping from consumer topic to handlers
- **Email notification**
- `ENV`: used to construct email category
- `ENABLE_EMAILS`: whether to enable email notifications
- `ENABLE_DEV_MODE`: whether to enable dev mode
- `DEV_MODE_EMAIL`: recipient email used in dev mode
- `DEFAULT_REPLY_EMAIL`: default reply email

- `AUTH0_PROXY_SERVER_URL`: auth0 proxy server URL
- **Consumer handlers**
- `KAFKA_CONSUMER_HANDLERS`: mapping from consumer topic to handlers
- **Email notification**
- `ENV`: used to construct email category
- `ENABLE_EMAILS`: whether to enable email notifications
- `ENABLE_DEV_MODE`: whether to enable dev mode
- `DEV_MODE_EMAIL`: recipient email used in dev mode
- `DEFAULT_REPLY_EMAIL`: default reply email

### Connect notification server
Configuration for the connect notification server is at `connect/config.js`.
Expand Down Expand Up @@ -137,6 +137,7 @@ You may reuse it during review.
- start local PostgreSQL db, create an empty database, update the config/default.js DATABASE_URL param to point to the db
- install dependencies `npm i`
- run code lint check `npm run lint`
- init DB `npm run reset:db`
- start connect notification server `npm start`
- the app is running at `http://localhost:4000`, it also starts Kafka consumer to listen for events and save unroll-ed notifications to db

Expand Down
1 change: 1 addition & 0 deletions connect/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
// TC API related variables
TC_API_V3_BASE_URL: process.env.TC_API_V3_BASE_URL || 'https://api.topcoder-dev.com/v3',
TC_API_V4_BASE_URL: process.env.TC_API_V4_BASE_URL || 'https://api.topcoder-dev.com/v4',
TC_API_V5_BASE_URL: process.env.TC_API_V5_BASE_URL || 'https://api.topcoder-dev.com/v5',
MESSAGE_API_BASE_URL: process.env.MESSAGE_API_BASE_URL || 'https://api.topcoder-dev.com/v5',

// id of the BOT user which creates post with various events in discussions
Expand Down
16 changes: 8 additions & 8 deletions connect/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ const getProject = (projectId) => (
M2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
.then((token) => (
request
.get(`${config.TC_API_V4_BASE_URL}/projects/${projectId}`)
.get(`${config.TC_API_V5_BASE_URL}/projects/${projectId}`)
.set('accept', 'application/json')
.set('authorization', `Bearer ${token}`)
.then((res) => {
if (!_.get(res, 'body.result.success')) {
const project = res.body;
if (!project) {
throw new Error(`Failed to get project details of project id: ${projectId}`);
}
const project = _.get(res, 'body.result.content');
return project;
}).catch((err) => {
const errorDetails = _.get(err, 'response.body.result.content.message');
const errorDetails = _.get(err, 'response.body.message');
throw new Error(
`Failed to get project details of project id: ${projectId}.` +
(errorDetails ? ' Server response: ' + errorDetails : '')
Expand Down Expand Up @@ -244,17 +244,17 @@ const getPhase = (projectId, phaseId) => (
M2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
.then((token) => (
request
.get(`${config.TC_API_V4_BASE_URL}/projects/${projectId}/phases/${phaseId}`)
.get(`${config.TC_API_V5_BASE_URL}/projects/${projectId}/phases/${phaseId}`)
.set('accept', 'application/json')
.set('authorization', `Bearer ${token}`)
.then((res) => {
if (!_.get(res, 'body.result.success')) {
const project = res.body;
if (!project) {
throw new Error(`Failed to get phase details of project id: ${projectId}, phase id: ${phaseId}`);
}
const project = _.get(res, 'body.result.content');
return project;
}).catch((err) => {
const errorDetails = _.get(err, 'response.body.result.content.message');
const errorDetails = _.get(err, 'response.body.message');
throw new Error(
`Failed to get phase details of project id: ${projectId}, phase id: ${phaseId}.` +
(errorDetails ? ' Server response: ' + errorDetails : '')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lint:fix": "eslint *.js --fix src config test connect",
"postinstall": "npm run build",
"build": "gulp build",
"watch": "gulp watch"
"watch": "gulp watch",
"reset:db": "node tools/resetDb.js"
},
"author": "TCSCODER",
"license": "none",
Expand Down
20 changes: 20 additions & 0 deletions tools/resetDb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Script for initializing/resetting DB.
*
* WARNING
* It recreates DB schema causing removing existent data if any.
*/
const notificationServer = require('../index');

console.info('Initializing db...');

notificationServer
.initDatabase()
.then(() => {
console.info('Database was successfully initialized.');
process.exit();
})
.catch((err) => {
console.error('Error initializing DB', err);
process.exit(1);
});