Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Extracted all APIs to configuration variables #100

Merged
merged 4 commits into from
Jan 29, 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
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ defaults: &defaults
LOG_LEVEL: debug
AUTH_DOMAIN: topcoder-dev.com
AUTH_SECRET: secret
API_URL_PROJECTS: http://localhost:3001/v4/projects
API_URL_MEMBERS: http://localhost:3001/v3/members
API_URL_USERS: http://localhost:3001/v3/users
API_URL_AUTHORIZATIONS: http://localhost:3001/v3/authorizations
API_URL_TOPICS: http://localhost:3001/v5/topics

jobs:
test:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ To override default settings please add them to a file `./config/local.js`:
- `RABBITMQ.DELAY_DURATION`: Amount of delay before reposting unclaimed project
- `RABBITMQ.NOTIFICATIONS_EXCHANGE_NAME`: the notification RabbitMQ's topic exchange name
- `LOGENTRIES_TOKEN`: the Logentries token generated from https://logentries.com/
- `API_BASE_URL`: the base url to the API server to get project/user info
- `API_URL_PROJECTS`: the projects service url
- `API_URL_MEMBERS`: `API_BASE_URL` the members service url
- `API_URL_USERS`: `API_BASE_URL` the users service url
- `API_URL_AUTHORIZATIONS`: `API_BASE_URL` the authorizations service url
- `API_URL_TOPICS`: `API_BASE_URL` the topics service url
- `DISABLE_DELAY_EXCHANGE`: Disable exchage type delay and use 'direct' instead(Note: after changing this delete existing delay exchange )
- `TC_SLACK_WEBHOOK_URL`: slack webhook url
- `SLACK_ICON_URL`: slack webhook icon url
Expand Down
8 changes: 6 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ module.exports = {
// Token is generated from https://logentries.com/
LOGENTRIES_TOKEN: '',

// The base url to the project/user API server
API_BASE_URL: 'http://localhost:3001',
// The different services used by this project
API_URL_PROJECTS: 'http://localhost:3001/v4/projects',
API_URL_MEMBERS: 'http://localhost:3001/v3/members',
API_URL_USERS: 'http://localhost:3001/v3/users',
API_URL_AUTHORIZATIONS: 'http://localhost:3001/v3/authorizations',
API_URL_TOPICS: 'http://localhost:3001/v5/topics',

// Disable delay exchange and use direct instead ( delete existing delay exchnge after changing)
DISABLE_DELAY_EXCHANGE: false,
Expand Down
6 changes: 5 additions & 1 deletion config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
"DELAYED_NOTIFICATIONS_EXCHANGE_NAME": "dev.connect-notifications-reminders"
},

"API_BASE_URL": "https://api.topcoder-dev.com"
"API_URL_PROJECTS": "http://api.topcoder-dev.com/v4/projects",
"API_URL_MEMBERS": "http://api.topcoder-dev.com/v3/members",
"API_URL_USERS": "http://api.topcoder-dev.com/v3/users",
"API_URL_AUTHORIZATIONS": "http://api.topcoder-dev.com/v3/authorizations",
"API_URL_TOPICS": "http://api.topcoder-dev.com/v5/topics"
}
6 changes: 5 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
"SLACK_CHANNEL_COPILOTS": "#connect-copilots",
"SLACK_CHANNEL_NPS": "#customer-experience",

"API_BASE_URL": "https://api.topcoder.com"
"API_URL_PROJECTS": "http://api.topcoder.com/v4/projects",
"API_URL_MEMBERS": "http://api.topcoder.com/v3/members",
"API_URL_USERS": "http://api.topcoder.com/v3/users",
"API_URL_AUTHORIZATIONS": "http://api.topcoder.com/v3/authorizations",
"API_URL_TOPICS": "http://api.topcoder.com/v5/topics"
}
6 changes: 5 additions & 1 deletion config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ module.exports = {
DELAY_DURATION: 0,
},
TC_SLACK_WEBHOOK_URL: 'http://localhost:3001/slack',
API_BASE_URL: 'http://localhost:3001',
API_URL_PROJECTS: 'http://localhost:3001/v4/projects',
API_URL_MEMBERS: 'http://localhost:3001/v3/members',
API_URL_USERS: 'http://localhost:3001/v3/users',
API_URL_AUTHORIZATIONS: 'http://localhost:3001/v3/authorizations',
API_URL_TOPICS: 'http://localhost:3001/v5/topics',
AUTH0_URL: process.env.DEV_AUTH0_URL || '',
AUTH0_AUDIENCE: process.env.DEV_AUTH0_AUDIENCE || '',
TOKEN_CACHE_TIME: process.env.DEV_TOKEN_CACHE_TIME || 86400000,
Expand Down
27 changes: 26 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ make_task_def(){
{
"name": "AUTH0_PROXY_SERVER_URL",
"value": "%s"
},
{
"name": "API_URL_PROJECTS",
"value": "%s"
},
{
"name": "API_URL_MEMBERS",
"value": "%s"
},
{
"name": "API_URL_USERS",
"value": "%s"
},
{
"name": "API_URL_AUTHORIZATIONS",
"value": "%s"
},
{
"name": "API_URL_TOPICS",
"value": "%s"
}
],
"logConfiguration": {
Expand All @@ -108,14 +128,19 @@ make_task_def(){
AUTH0_CLIENT_ID=$(eval "echo \$${ENV}_AUTH0_CLIENT_ID")
AUTH0_CLIENT_SECRET=$(eval "echo \$${ENV}_AUTH0_CLIENT_SECRET")
AUTH0_PROXY_SERVER_URL=$(eval "echo \$${ENV}_AUTH0_PROXY_SERVER_URL")
API_URL_PROJECTS=$(eval "echo \$${ENV}_API_URL_PROJECTS")
API_URL_MEMBERS=$(eval "echo \$${ENV}_API_URL_MEMBERS")
API_URL_USERS=$(eval "echo \$${ENV}_API_URL_USERS")
API_URL_AUTHORIZATIONS=$(eval "echo \$${ENV}_API_URL_AUTHORIZATIONS")
API_URL_TOPICS=$(eval "echo \$${ENV}_API_URL_TOPICS")

if [ "$ENV" = "PROD" ]; then
NODE_ENV=production
elif [ "$ENV" = "DEV" ]; then
NODE_ENV=development
fi

task_def=$(printf "$task_template" $ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $CIRCLE_SHA1 $NODE_ENV $LOG_LEVEL $CAPTURE_LOGS $LOGENTRIES_TOKEN $RABBITMQ_URL $TC_SLACK_WEBHOOK_URL "$AUTH0_URL" "$AUTH0_AUDIENCE" $AUTH0_CLIENT_ID "$AUTH0_CLIENT_SECRET" $TOKEN_CACHE_TIME "$AUTH0_PROXY_SERVER_URL" $AWS_ECS_CLUSTER $AWS_REGION $NODE_ENV)
task_def=$(printf "$task_template" $ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $CIRCLE_SHA1 $NODE_ENV $LOG_LEVEL $CAPTURE_LOGS $LOGENTRIES_TOKEN $RABBITMQ_URL $TC_SLACK_WEBHOOK_URL "$AUTH0_URL" "$AUTH0_AUDIENCE" $AUTH0_CLIENT_ID "$AUTH0_CLIENT_SECRET" $TOKEN_CACHE_TIME "$AUTH0_PROXY_SERVER_URL" "$API_URL_PROJECTS" "$API_URL_MEMBERS" "$API_URL_USERS" "$API_URL_AUTHORIZATIONS" "$API_URL_TOPICS" $AWS_ECS_CLUSTER $AWS_REGION $NODE_ENV)
}

push_ecr_image(){
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const createProjectDiscourseNotification = Promise.coroutine(
return Promise.reject(new Error('Error retrieving system token'));
}
const options = {
url: `${config.get('API_BASE_URL')}/v5/topics/create`,
url: `${config.get('API_URL_TOPICS')}/create`,
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -138,7 +138,7 @@ function* getProjectById(id) {
return Promise.reject(new Error('Error retrieving system token'));
}
return yield requestPromise({
url: `${config.get('API_BASE_URL')}/v4/projects/${id}`,
url: `${config.get('API_URL_PROJECTS')}/${id}`,
headers: {
Authorization: `Bearer ${token}`,
},
Expand Down Expand Up @@ -179,7 +179,7 @@ function* getUserById(id) { // eslint-disable-line require-yield
}
return reject(new Error('user not found'));
};
return requestPromise({ url: `${config.get('API_BASE_URL')}/v3/members/_search/?query=userId:${id}` }, cb);
return requestPromise({ url: `${config.get('API_URL_MEMBERS')}/_search/?query=userId:${id}` }, cb);
}


Expand Down
16 changes: 8 additions & 8 deletions src/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,33 @@ describe('app', () => {
// Stub the calls to API server
stub = sinon.stub(request, 'get');
const stubArgs = {
url: `${config.API_BASE_URL}/v4/projects/1`,
url: `${config.API_URL_PROJECTS}/1`,
};
stub.withArgs(sinon.match.has('url', stubArgs.url))
.yields(null, { statusCode: 200 }, sampleProjects.project1);

stubArgs.url = `${config.API_BASE_URL}/v4/projects/1000`;
stubArgs.url = `${config.API_URL_PROJECTS}/1000`;
stub.withArgs(sinon.match.has('url', stubArgs.url))
.yields(null, { statusCode: 404 });

stubArgs.url = `${config.API_BASE_URL}/v3/members/_search/?query=userId:1`;
stubArgs.url = `${config.API_URL_MEMBERS}/_search/?query=userId:1`;
stub.withArgs(sinon.match.has('url', stubArgs.url))
.yields(null, { statusCode: 200 }, sampleUsers.user1);

stubArgs.url = `${config.API_BASE_URL}/v3/users/1000`;
stubArgs.url = `${config.API_URL_USERS}/1000`;
stub.withArgs(sinon.match.has('url', stubArgs.url))
.yields(null, { statusCode: 404 });

stubArgs.url = `${config.API_BASE_URL}/v3/members/_search/?query=userId:40051331`;
stubArgs.url = `${config.API_URL_MEMBERS}/_search/?query=userId:40051331`;
stub.withArgs(sinon.match.has('url', stubArgs.url))
.yields(null, { statusCode: 200 }, sampleUsers.user1);

stubArgs.url = `${config.API_BASE_URL}/v3/members/_search/?query=userId:50051333`;
stubArgs.url = `${config.API_URL_MEMBERS}/_search/?query=userId:50051333`;
stub.withArgs(sinon.match.has('url', stubArgs.url))
.yields(null, { statusCode: 200 }, sampleUsers.user1);

postStub = sinon.stub(request, 'post');
postStub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v3/authorizations/`))
postStub.withArgs(sinon.match.has('url', `${config.API_URL_AUTHORIZATIONS}/`))
.yields(null, { statusCode: 200 }, sampleAuth);

postStub.withArgs(sinon.match.has('url', config.TC_SLACK_WEBHOOK_URL))
Expand Down Expand Up @@ -319,7 +319,7 @@ describe('app', () => {
const callbackCount = 1;
request.get.restore();
stub = sinon.stub(request, 'get');
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v3/members/_search/?query=userId:8547900`))
stub.withArgs(sinon.match.has('url', `${config.API_URL_MEMBERS}/_search/?query=userId:8547900`))
.yields(null, { statusCode: 200 }, sampleUsers.user1);

sendTestEvent(sampleEvents.updatedInReview, 'project.updated');
Expand Down