Skip to content

Commit b5bc778

Browse files
Merge pull request #10 from zsudraco/develop
post bus events and some fixes
2 parents 70c4c14 + db142a8 commit b5bc778

18 files changed

+867
-326
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The following parameters can be set in config files or in env variables:
2222
- TOKEN_CACHE_TIME: AUTH0 token cache time, used to get M2M token
2323
- AUTH0_CLIENT_ID: AUTH0 client id, used to get M2M token
2424
- AUTH0_CLIENT_SECRET: AUTH0 client secret, used to get M2M token
25+
- BUSAPI_URL: Bus API URL
26+
- KAFKA_ERROR_TOPIC: Kafka error topic used by bus API wrapper
2527
- AMAZON.AWS_ACCESS_KEY_ID: The Amazon certificate key to use when connecting. Use local dynamodb you can set fake value
2628
- AMAZON.AWS_SECRET_ACCESS_KEY: The Amazon certificate access key to use when connecting. Use local dynamodb you can set fake value
2729
- AMAZON.AWS_REGION: The Amazon certificate region to use when connecting. Use local dynamodb you can set fake value
@@ -32,6 +34,7 @@ The following parameters can be set in config files or in env variables:
3234
- CHALLENGES_API_URL: TC challenges API base URL
3335
- GROUPS_API_URL: TC groups API base URL
3436
- COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
37+
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds
3538

3639

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

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

Verification.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ aws dynamodb scan --table-name Attachment --endpoint-url http://localhost:7777
2222

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

25+
26+
## Bus Event Verification
27+
28+
- login `https://lauscher.topcoder-dev.com/` with credential `tonyj / appirio123`
29+
- then select topic to view, see app-constants.js Topics field for used topics, then click `View` button to view related messages
30+

app-constants.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,31 @@ const challengeStatuses = {
1919
Completed: 'Completed'
2020
}
2121

22+
const EVENT_ORIGINATOR = 'topcoder-challenges-api'
23+
24+
const EVENT_MIME_TYPE = 'application/json'
25+
26+
// using a testing topc, should be changed to use real topics in comments when they are created
27+
const Topics = {
28+
ChallengeCreated: 'test.new.bus.events', // 'challenge.action.created',
29+
ChallengeUpdated: 'test.new.bus.events', // 'challenge.action.updated',
30+
ChallengeTypeCreated: 'test.new.bus.events', // 'challenge.action.type.created',
31+
ChallengeTypeUpdated: 'test.new.bus.events', // 'challenge.action.type.updated',
32+
ChallengeSettingCreated: 'test.new.bus.events', // 'challenge.action.setting.created',
33+
ChallengeSettingUpdated: 'test.new.bus.events', // 'challenge.action.setting.updated',
34+
ChallengePhaseCreated: 'test.new.bus.events', // 'challenge.action.phase.created',
35+
ChallengePhaseUpdated: 'test.new.bus.events', // 'challenge.action.phase.updated',
36+
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',
37+
TimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
38+
TimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
39+
TimelineTemplateDeleted: 'test.new.bus.events' // 'challenge.action.timeline.template.deleted'
40+
}
41+
2242
module.exports = {
2343
UserRoles,
2444
prizeSetTypes,
25-
challengeStatuses
45+
challengeStatuses,
46+
EVENT_ORIGINATOR,
47+
EVENT_MIME_TYPE,
48+
Topics
2649
}

app.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ const app = express()
1919

2020
app.use(cors())
2121
app.use(fileUpload({
22-
limits: { fileSize: config.FILE_UPLOAD_SIZE_LIMIT },
23-
useTempFiles : true,
24-
tempFileDir : config.FILE_UPLOAD_TEMP_DIR
22+
limits: { fileSize: config.FILE_UPLOAD_SIZE_LIMIT }
2523
}))
2624
app.use(bodyParser.json())
2725
app.use(bodyParser.urlencoded({ extended: true }))

config/default.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ module.exports = {
1616
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
1717
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
1818

19+
// bus API config params
20+
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
21+
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
22+
1923
AMAZON: {
2024
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID || 'FAKE_ACCESS_KEY',
2125
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY || 'FAKE_SECRET_ACCESS_KEY',
@@ -28,10 +32,12 @@ module.exports = {
2832
// in bytes
2933
FILE_UPLOAD_SIZE_LIMIT: process.env.FILE_UPLOAD_SIZE_LIMIT
3034
? Number(process.env.FILE_UPLOAD_SIZE_LIMIT) : 50 * 1024 * 1024, // 50M
31-
FILE_UPLOAD_TEMP_DIR: process.env.FILE_UPLOAD_TEMP_DIR || '/tmp/',
3235
CHALLENGES_API_URL: process.env.CHALLENGES_API_URL || 'http://localhost:4000/v5/challenges',
3336
GROUPS_API_URL: process.env.GROUPS_API_URL || 'http://localhost:4000/v5/groups',
3437
// copilot resource role ids allowed to upload attachment
3538
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
36-
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b']
39+
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'],
40+
41+
// health check timeout in milliseconds
42+
HEALTH_CHECK_TIMEOUT: process.env.HEALTH_CHECK_TIMEOUT || 3000
3743
}

docs/swagger.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,29 @@ paths:
15041504
schema:
15051505
$ref: '#/definitions/ErrorModel'
15061506

1507+
/health:
1508+
get:
1509+
tags:
1510+
- Health
1511+
description: |
1512+
Get health status of the app.
1513+
produces:
1514+
- application/json
1515+
responses:
1516+
'200':
1517+
description: OK
1518+
schema:
1519+
type: object
1520+
properties:
1521+
checksRun:
1522+
type: integer
1523+
required:
1524+
- checksRun
1525+
'503':
1526+
description: Service unavailable
1527+
schema:
1528+
$ref: '#/definitions/ErrorModel'
1529+
15071530
parameters:
15081531
page:
15091532
name: page

docs/topcoder-challenge-api.postman_collection.json

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info": {
3-
"_postman_id": "8f57467f-2adc-4cc8-ae5a-77c2fbbbd5d2",
3+
"_postman_id": "4e17ab44-cafe-4aba-a5e5-060ac0204a20",
44
"name": "topcoder-challenge-api",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
66
},
@@ -10005,7 +10005,10 @@
1000510005
"value": "Bearer {{admin_token}}"
1000610006
}
1000710007
],
10008-
"body": {},
10008+
"body": {
10009+
"mode": "raw",
10010+
"raw": ""
10011+
},
1000910012
"url": {
1001010013
"raw": "{{URL}}/challenges/{{CHALLENGE_ID1}}/attachments/{{ATTACHMENT_ID1}}",
1001110014
"host": [
@@ -10046,7 +10049,10 @@
1004610049
"value": "Bearer {{copilot1_token}}"
1004710050
}
1004810051
],
10049-
"body": {},
10052+
"body": {
10053+
"mode": "raw",
10054+
"raw": ""
10055+
},
1005010056
"url": {
1005110057
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
1005210058
"host": [
@@ -10087,7 +10093,10 @@
1008710093
"value": "Bearer {{user_token}}"
1008810094
}
1008910095
],
10090-
"body": {},
10096+
"body": {
10097+
"mode": "raw",
10098+
"raw": ""
10099+
},
1009110100
"url": {
1009210101
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
1009310102
"host": [
@@ -10128,7 +10137,10 @@
1012810137
"value": "Bearer {{admin_token}}"
1012910138
}
1013010139
],
10131-
"body": {},
10140+
"body": {
10141+
"mode": "raw",
10142+
"raw": ""
10143+
},
1013210144
"url": {
1013310145
"raw": "{{URL}}/challenges/{{TYPEA_ID}}/attachments/{{ATTACHMENT_ID1}}",
1013410146
"host": [
@@ -10169,7 +10181,10 @@
1016910181
"value": "Bearer {{expire_token}}"
1017010182
}
1017110183
],
10172-
"body": {},
10184+
"body": {
10185+
"mode": "raw",
10186+
"raw": ""
10187+
},
1017310188
"url": {
1017410189
"raw": "{{URL}}/challenges/{{CHALLENGE_ID1}}/attachments/{{ATTACHMENT_ID1}}",
1017510190
"host": [
@@ -10210,7 +10225,10 @@
1021010225
"value": "Bearer invalid"
1021110226
}
1021210227
],
10213-
"body": {},
10228+
"body": {
10229+
"mode": "raw",
10230+
"raw": ""
10231+
},
1021410232
"url": {
1021510233
"raw": "{{URL}}/challenges/{{CHALLENGE_ID1}}/attachments/{{ATTACHMENT_ID1}}",
1021610234
"host": [
@@ -10251,7 +10269,10 @@
1025110269
"value": "Bearer {{copilot2_token}}"
1025210270
}
1025310271
],
10254-
"body": {},
10272+
"body": {
10273+
"mode": "raw",
10274+
"raw": ""
10275+
},
1025510276
"url": {
1025610277
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
1025710278
"host": [
@@ -10286,7 +10307,10 @@
1028610307
"request": {
1028710308
"method": "GET",
1028810309
"header": [],
10289-
"body": {},
10310+
"body": {
10311+
"mode": "raw",
10312+
"raw": ""
10313+
},
1029010314
"url": {
1029110315
"raw": "{{URL}}/challenges/{{CHALLENGE_ID2}}/attachments/{{ATTACHMENT_ID2}}",
1029210316
"host": [
@@ -12256,6 +12280,79 @@
1225612280
"response": []
1225712281
}
1225812282
]
12283+
},
12284+
{
12285+
"name": "HealthCheck",
12286+
"item": [
12287+
{
12288+
"name": "get app health status",
12289+
"event": [
12290+
{
12291+
"listen": "test",
12292+
"script": {
12293+
"id": "9fd8c9f4-13e3-47d0-9c78-1e544521d97d",
12294+
"exec": [
12295+
"pm.test(\"Status code is 200\", function () {",
12296+
" pm.response.to.have.status(200);",
12297+
"});"
12298+
],
12299+
"type": "text/javascript"
12300+
}
12301+
}
12302+
],
12303+
"request": {
12304+
"method": "GET",
12305+
"header": [
12306+
{
12307+
"key": "Accept",
12308+
"type": "text",
12309+
"value": "application/json"
12310+
},
12311+
{
12312+
"key": "Content-Type",
12313+
"type": "text",
12314+
"value": "application/json"
12315+
}
12316+
],
12317+
"body": {
12318+
"mode": "raw",
12319+
"raw": ""
12320+
},
12321+
"url": {
12322+
"raw": "{{URL}}/health",
12323+
"host": [
12324+
"{{URL}}"
12325+
],
12326+
"path": [
12327+
"health"
12328+
]
12329+
}
12330+
},
12331+
"response": []
12332+
}
12333+
],
12334+
"event": [
12335+
{
12336+
"listen": "prerequest",
12337+
"script": {
12338+
"id": "38cbc788-59a2-448e-bd0f-8158b40d0f40",
12339+
"type": "text/javascript",
12340+
"exec": [
12341+
""
12342+
]
12343+
}
12344+
},
12345+
{
12346+
"listen": "test",
12347+
"script": {
12348+
"id": "8f030397-7ae8-42c2-af6a-ec35a4a64443",
12349+
"type": "text/javascript",
12350+
"exec": [
12351+
""
12352+
]
12353+
}
12354+
}
12355+
]
1225912356
}
1226012357
]
1226112358
}

0 commit comments

Comments
 (0)