Skip to content

post bus events and some fixes #10

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 2 commits into from
Jun 4, 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The following parameters can be set in config files or in env variables:
- TOKEN_CACHE_TIME: AUTH0 token cache time, used to get M2M token
- AUTH0_CLIENT_ID: AUTH0 client id, used to get M2M token
- AUTH0_CLIENT_SECRET: AUTH0 client secret, used to get M2M token
- BUSAPI_URL: Bus API URL
- KAFKA_ERROR_TOPIC: Kafka error topic used by bus API wrapper
- AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting. Use local dynamodb you can set fake value
- AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting. Use local dynamodb you can set fake value
- AMAZON.AWS_REGION: The Amazon certificate region to use when connecting. Use local dynamodb you can set fake value
Expand All @@ -32,6 +34,7 @@ The following parameters can be set in config files or in env variables:
- CHALLENGES_API_URL: TC challenges API base URL
- GROUPS_API_URL: TC groups API base URL
- COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds


Set the following environment variables so that the app can get TC M2M token (use 'set' insted of 'export' for Windows OS):
Expand Down Expand Up @@ -104,5 +107,6 @@ Refer to the verification document `Verification.md`
challenge also have attachments field linking to its attachments,
this will speed up challenge CRUDS operations.

- updated swagger may be viewed and validated at `http://editor.swagger.io/`
- In the app-constants.js Topics field, the used topics are using a test topic,
the suggested ones are commented out, because these topics are not created in TC dev Kafka yet.

6 changes: 6 additions & 0 deletions Verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ aws dynamodb scan --table-name Attachment --endpoint-url http://localhost:7777

Login to AWS Console, S3 service, view the bucket content.


## Bus Event Verification

- login `https://lauscher.topcoder-dev.com/` with credential `tonyj / appirio123`
- then select topic to view, see app-constants.js Topics field for used topics, then click `View` button to view related messages

25 changes: 24 additions & 1 deletion app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,31 @@ const challengeStatuses = {
Completed: 'Completed'
}

const EVENT_ORIGINATOR = 'topcoder-challenges-api'

const EVENT_MIME_TYPE = 'application/json'

// using a testing topc, should be changed to use real topics in comments when they are created
const Topics = {
ChallengeCreated: 'test.new.bus.events', // 'challenge.action.created',
ChallengeUpdated: 'test.new.bus.events', // 'challenge.action.updated',
ChallengeTypeCreated: 'test.new.bus.events', // 'challenge.action.type.created',
ChallengeTypeUpdated: 'test.new.bus.events', // 'challenge.action.type.updated',
ChallengeSettingCreated: 'test.new.bus.events', // 'challenge.action.setting.created',
ChallengeSettingUpdated: 'test.new.bus.events', // 'challenge.action.setting.updated',
ChallengePhaseCreated: 'test.new.bus.events', // 'challenge.action.phase.created',
ChallengePhaseUpdated: 'test.new.bus.events', // 'challenge.action.phase.updated',
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',
TimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
TimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
TimelineTemplateDeleted: 'test.new.bus.events' // 'challenge.action.timeline.template.deleted'
}

module.exports = {
UserRoles,
prizeSetTypes,
challengeStatuses
challengeStatuses,
EVENT_ORIGINATOR,
EVENT_MIME_TYPE,
Topics
}
4 changes: 1 addition & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ const app = express()

app.use(cors())
app.use(fileUpload({
limits: { fileSize: config.FILE_UPLOAD_SIZE_LIMIT },
useTempFiles : true,
tempFileDir : config.FILE_UPLOAD_TEMP_DIR
limits: { fileSize: config.FILE_UPLOAD_SIZE_LIMIT }
}))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
Expand Down
10 changes: 8 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = {
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,

// bus API config params
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',

AMAZON: {
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID || 'FAKE_ACCESS_KEY',
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY || 'FAKE_SECRET_ACCESS_KEY',
Expand All @@ -28,10 +32,12 @@ module.exports = {
// in bytes
FILE_UPLOAD_SIZE_LIMIT: process.env.FILE_UPLOAD_SIZE_LIMIT
? Number(process.env.FILE_UPLOAD_SIZE_LIMIT) : 50 * 1024 * 1024, // 50M
FILE_UPLOAD_TEMP_DIR: process.env.FILE_UPLOAD_TEMP_DIR || '/tmp/',
CHALLENGES_API_URL: process.env.CHALLENGES_API_URL || 'http://localhost:4000/v5/challenges',
GROUPS_API_URL: process.env.GROUPS_API_URL || 'http://localhost:4000/v5/groups',
// copilot resource role ids allowed to upload attachment
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b']
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'],

// health check timeout in milliseconds
HEALTH_CHECK_TIMEOUT: process.env.HEALTH_CHECK_TIMEOUT || 3000
}
23 changes: 23 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,29 @@ paths:
schema:
$ref: '#/definitions/ErrorModel'

/health:
get:
tags:
- Health
description: |
Get health status of the app.
produces:
- application/json
responses:
'200':
description: OK
schema:
type: object
properties:
checksRun:
type: integer
required:
- checksRun
'503':
description: Service unavailable
schema:
$ref: '#/definitions/ErrorModel'

parameters:
page:
name: page
Expand Down
115 changes: 106 additions & 9 deletions docs/topcoder-challenge-api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "8f57467f-2adc-4cc8-ae5a-77c2fbbbd5d2",
"_postman_id": "4e17ab44-cafe-4aba-a5e5-060ac0204a20",
"name": "topcoder-challenge-api",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -10005,7 +10005,10 @@
"value": "Bearer {{admin_token}}"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID1}}/attachments/{{ATTACHMENT_ID1}}",
"host": [
Expand Down Expand Up @@ -10046,7 +10049,10 @@
"value": "Bearer {{copilot1_token}}"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
"host": [
Expand Down Expand Up @@ -10087,7 +10093,10 @@
"value": "Bearer {{user_token}}"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
"host": [
Expand Down Expand Up @@ -10128,7 +10137,10 @@
"value": "Bearer {{admin_token}}"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{TYPEA_ID}}/attachments/{{ATTACHMENT_ID1}}",
"host": [
Expand Down Expand Up @@ -10169,7 +10181,10 @@
"value": "Bearer {{expire_token}}"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID1}}/attachments/{{ATTACHMENT_ID1}}",
"host": [
Expand Down Expand Up @@ -10210,7 +10225,10 @@
"value": "Bearer invalid"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID1}}/attachments/{{ATTACHMENT_ID1}}",
"host": [
Expand Down Expand Up @@ -10251,7 +10269,10 @@
"value": "Bearer {{copilot2_token}}"
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
"host": [
Expand Down Expand Up @@ -10286,7 +10307,10 @@
"request": {
"method": "GET",
"header": [],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
"host": [
Expand Down Expand Up @@ -12256,6 +12280,79 @@
"response": []
}
]
},
{
"name": "HealthCheck",
"item": [
{
"name": "get app health status",
"event": [
{
"listen": "test",
"script": {
"id": "9fd8c9f4-13e3-47d0-9c78-1e544521d97d",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"type": "text",
"value": "application/json"
},
{
"key": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{URL}}/health",
"host": [
"{{URL}}"
],
"path": [
"health"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "38cbc788-59a2-448e-bd0f-8158b40d0f40",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "8f030397-7ae8-42c2-af6a-ec35a4a64443",
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
]
}
Loading