Skip to content
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
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: 2

# Node image for node project
node_env: &node_env
docker:
- image: circleci/node:6.14.3-stretch-browsers

# Python image to run aws utilities
python_env: &python_env
docker:
- image: circleci/python:2.7-stretch-browsers

# Instructions of installing aws utilities
install_awscli: &install_awscli
name: "Install awscli"
command: |
sudo pip install awscli awsebcli --upgrade
aws --version
eb --version

# Instructions of deployment
deploy_steps: &deploy_steps
- checkout
- attach_workspace:
at: .
- run: *install_awscli
- setup_remote_docker
- run: cd consumer && ./deploy/eb-deploy.sh tc-connect2sf DEV $CIRCLE_BUILD_NUM

jobs:
build:
<<: *node_env
steps:
- checkout
- restore_cache:
key: node-modules-{{ checksum "consumer/package.json" }}
- run: cd consumer && npm install
- save_cache:
key: node-modules-{{ checksum "consumer/package.json" }}
paths:
- consumer/node_modules
- run: cd consumer && npm run test
- persist_to_workspace:
root: .
paths:
- ./consumer/node_modules

deploy_prod:
<<: *python_env
environment:
DEPLOY_ENV: "PROD"
steps: *deploy_steps

deploy_dev:
<<: *python_env
environment:
DEPLOY_ENV: "DEV"
steps: *deploy_steps

workflows:
version: 2
build-and-deploy:
jobs:
- build
- deploy_dev:
filters:
branches:
only: [ dev, dev-circleci2 ]
requires:
- build
- deploy_prod:
filters:
branches:
only: master
requires:
- build
24 changes: 0 additions & 24 deletions circle.yml

This file was deleted.

12 changes: 12 additions & 0 deletions consumer/.ebextensions/01-environment-variables.config
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,15 @@ option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: SCHEDULED_WORKER_SCHEDULE
value: '*/5 * * * *'
- namespace: aws:elasticbeanstalk:application:environment
option_name: PORT
value: 3000
- namespace: aws:elasticbeanstalk:application:environment
option_name: API_VERSION
value: v4
- namespace: aws:elasticbeanstalk:application:environment
option_name: AUTH_SECRET
value: TBD
- namespace: aws:elasticbeanstalk:application:environment
option_name: VALID_ISSUERS
value: TBD
23 changes: 23 additions & 0 deletions consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,26 @@ For example: duplicated project id added to the queue, Lead cannot be found etc.
In such situation, the message from rabbitmq will be marked as ACK (removed).
If we won't remove it from queue, the message will be stuck forever.
For any other type of error the message from the rabbitmq will me marked as ACK as well, however, it would requeued into another queue for later inspection. It right now publishes the message content to the same rabbitmq exchange (configured as mentioned in Configuration section) with routing key being `connect2sf.failed`. So, we have to map the exchange and routing key comibation to a queue to which no consumer is listeting e.g. `tc-connect2sf.failed` is used in dev environment. Now we can see messages, via rabbitmq manager UI, in this queue to check if any of the messages failed and what was id of the project which failed. We can either remove those messages from the queue, if we are going to add those leads manually in saleforce or move them again to the original queue after fixing the deployed environment.


## Express Rest API verification

## Pre-requisites

1. Postman

### Steps to verify

1. Open Postman

2. Import Postman collection and environment from `docs` directory

3. Assuming that API is served at http://localhost:3150/v5 and AUTH_SECRET used in the API is `mysecret`, requests in the Postman collection can be triggered

4. Requests in Postman collection covers the status codes 200, 400 and 403

### Notes

1. Express Rest API will be served at http://localhost:3150/v5 if you use the values from `config/sample-local.json`.

2. JWT token in the Postman collection is signed with secret `mysecret`
6 changes: 6 additions & 0 deletions consumer/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export const EVENT = {
FAILED_SUFFIX: '.failed'
},
};

export const ERROR = {
SERVER_ERROR: 500,
CLIENT_ERROR: 400,
MESSAGE: 'Internal Server Error'
};
6 changes: 5 additions & 1 deletion consumer/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
"project": "QUEUE_PROJECTS",
"connect2sf": "QUEUE_CONNECT2SF"
}
}
},
"apiVersion": "API_VERSION",
"port": "PORT",
"authSecret": "AUTH_SECRET",
"validIssuers": "VALID_ISSUERS"
}
7 changes: 6 additions & 1 deletion consumer/config/sample-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"logLevel": "error",
"rabbitmqURL": "****UPDATE****",
"ownerId": "****UPDATE****",
"scheduledWorkerSchedule": "* * * 1 * *",
"aws": {
"endpoint": "http://dockerhost:7777",
"region": "us-east-1",
Expand All @@ -23,5 +24,9 @@
"queues": {
"project": "dev.project.service"
}
}
},
"apiVersion": "/v5",
"port": 3150,
"authSecret": "mysecret",
"validIssuers": "[\"https://api.topcoder.com\",\"https://topcoder-dev.auth0.com\", \"https://topcoder-newauth.auth0.com\"]"
}
102 changes: 102 additions & 0 deletions consumer/docs/tc-connects2f.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"info": {
"_postman_id": "23a8d300-23f5-40e8-ae69-edd7b7ff357e",
"name": "TC Connect S2F",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Valid LeadInfo request",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{ADMIN_TOKEN}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"firstName\": \"Test\",\n\t\"lastName\": \"Work\",\n\t\"businessEmail\": \"abc@tes\",\n\t\"title\": \"Mr\",\n\t\"companyName\": \"Topcoder\",\n\t\"companySize\": \"Big\",\n\t\"userName\": \"abcd\"\n}"
},
"url": {
"raw": "{{URL}}/connect2sf/leadInfo",
"host": [
"{{URL}}"
],
"path": [
"connect2sf",
"leadInfo"
]
}
},
"response": []
},
{
"name": "Invalid LeadInfo request",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{ADMIN_TOKEN}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"firstName\": \"Test\",\n\t\"lastName\": \"Work\",\n\t\"businessEmail\": \"abc@tes\",\n\t\"title\": \"Mr\",\n\t\"companyName\": \"Topcoder\",\n\t\"companySize\": \"Big\"\n}"
},
"url": {
"raw": "{{URL}}/connect2sf/leadInfo",
"host": [
"{{URL}}"
],
"path": [
"connect2sf",
"leadInfo"
]
}
},
"response": []
},
{
"name": "LeadInfo request with invalid token",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer 123"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"firstName\": \"Test\",\n\t\"lastName\": \"Work\",\n\t\"businessEmail\": \"abc@tes\",\n\t\"title\": \"Mr\",\n\t\"companyName\": \"Topcoder\",\n\t\"companySize\": \"Big\",\n\t\"userName\": \"abcd\"\n}"
},
"url": {
"raw": "{{URL}}/connect2sf/leadInfo",
"host": [
"{{URL}}"
],
"path": [
"connect2sf",
"leadInfo"
]
}
},
"response": []
}
]
}
23 changes: 23 additions & 0 deletions consumer/docs/tc-connects2f.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"id": "493febdc-2611-442a-ae08-b42ed24688fd",
"name": "tc-connects2f",
"values": [
{
"key": "ADMIN_TOKEN",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJBZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlRvbnlKIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0MzMyODgiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiYWRtaW5AdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.pIHUtMwIV07ZgfaUk9916X49rgjKclM9kzQP419LBo0",
"description": "",
"type": "text",
"enabled": true
},
{
"key": "URL",
"value": "http://localhost:3150/v5",
"description": "",
"type": "text",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2018-09-24T08:55:49.448Z",
"_postman_exported_using": "Postman/6.1.3"
}
4 changes: 4 additions & 0 deletions consumer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.23.0",
"better-npm-run": "0.0.10",
"body-parser": "^1.18.3",
"config": "^1.21.0",
"cors": "^2.8.4",
"debug": "^2.2.0",
"express": "^4.16.3",
"joi": "^9.0.4",
"jsonwebtoken": "^7.1.7",
"lodash": "^4.14.2",
"node-cron": "^1.1.3",
"superagent": "^2.1.0",
"superagent-promise": "^1.1.0",
"tc-core-library-js": "appirio-tech/tc-core-library-js.git",
"winston": "^2.2.0"
},
"devDependencies": {
Expand Down
Loading