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

Commit 60d368d

Browse files
Merge branch 'develop' into health-check
2 parents 0d9ad99 + 3b9e573 commit 60d368d

37 files changed

+6569
-233
lines changed

README.md

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,79 @@
55
- node 12.x
66
- npm 6.x
77
- docker
8+
- elasticsearch 6.x
9+
10+
## Configuration
11+
12+
Configuration for the application is at config/default.js and config/production.js. The following parameters can be set in config files or in env variables:
13+
14+
- LOG_LEVEL: the log level
15+
- PORT: the server port
16+
- AUTH_SECRET: TC Authentication secret
17+
- VALID_ISSUERS: valid issuers for TC authentication
18+
- PAGE_SIZE: the default pagination limit
19+
- API_VERSION: the API version
20+
- AWS_ACCESS_KEY_ID: The AWS access key
21+
- AWS_SECRET_ACCESS_KEY: The AWS secret key
22+
- AWS_REGION: The Amazon region to use when connecting.
23+
- DATABASE: The QLDB ledger name
24+
- AUTH0_URL: Auth0 URL, used to get TC M2M token
25+
- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token
26+
- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token
27+
- AUTH0_CLIENT_ID: Auth0 client id, used to get TC M2M token
28+
- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token
29+
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
30+
- GROUP_API_URL: Topcoder Group API URL
31+
- BUSAPI_URL: Topcoder Bus API URL
32+
- KAFKA_ERROR_TOPIC: The error topic at which bus api will publish any errors
33+
- KAFKA_MESSAGE_ORIGINATOR: The originator value for the kafka messages
34+
- UBAHN_CREATE_TOPIC: Kafka topic for create message
35+
- UBAHN_UPDATE_TOPIC: Kafka topic for update message
36+
- UBAHN_DELETE_TOPIC: Kafka topic for delete message
37+
- ES.HOST: Elasticsearch host
38+
- ES.API_VERSION: Elasticsearch API version
39+
- ES.DOCUMENTS: Elasticsearch index, type and id mapping for resources.
40+
41+
For `ES.DOCUMENTS` configuration, you will find multiple other configurations below it. Each has default values that you can override using the environment variables
842

943
## Local deployment
1044

45+
Setup your Elasticsearch instance and ensure that it is up and running.
46+
1147
1. Visit [this link](https://console.aws.amazon.com/qldb/home?region=us-east-1#gettingStarted), login and create one **ledger** databases named `ubahn-db`
1248
2. Visit [this link](https://console.aws.amazon.com/iam/home?region=us-east-1#/security_credentials) to download your "Access keys"
1349
3. Follow *Configuration* section to update config values, like database, aws key/secret etc ..
1450
4. Goto *UBahn-api*, run `npm i` and `npm run lint`
1551
5. Import mock data, `node scripts/db/genData.js`, this will create tables and gen some data for test (if you need this)
1652
6. Startup server `node app.js` or `npm run start`
1753

18-
## Docker
54+
## Working with mock data
55+
56+
You can use the scripts `npm run insert-data` (and `npm run delete-data`) to insert mock data (and delete mock data respectively). The data is inserted into QLDB and Elasticsearch. You need to setup the configurations beforehand and also start the elasticsearch instance before you run these scripts
57+
58+
## Local Deployment with Docker
1959

2060
Make sure all config values are right(aws key and secret), and you can run on local successful, then run below commands
2161

22-
- Run `docker build -t tc/ubahn_api .` to build image
23-
- Then run `docker run tc/ubahn_api -d` to startup image
62+
1. Navigate to the directory `docker`
63+
64+
2. Rename the file `sample.api.env` to `api.env`
65+
66+
3. Set the required AUTH0 configurations, AWS credentials and ElasticSearch host in the file `api.env`
67+
68+
4. Once that is done, run the following command
69+
70+
```bash
71+
docker-compose up
72+
```
73+
74+
5. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies
2475

2576
## API endpoints verification
2677

2778
1. open postman
2879
2. import *docs/UBahn_API.postman_collection.json* , *UBahn_ENV.postman_environment.json* and then check endpoints
2980

30-
## Configuration
31-
32-
| key | system Environment name | description |
33-
| ------------- | ----------------------- | -------------------------- |
34-
| PORT | PORT | the server port |
35-
| AUTH_SECRET | AUTH_SECRET | the jwt client secret |
36-
| VALID_ISSUERS | VALID_ISSUERS | jwt token issuers |
37-
| API_VERSION | | the api prefix version |
38-
| AWS_KEY | AWS_KEY | the aws Access key |
39-
| AWS_SECRET | AWS_SECRET | the aws Access secret |
40-
| AWS_REGION | AWS_REGION | the aws service region |
41-
| DATABASE | DATABASE | the aws QLDB database name |
42-
4381
## Test token
4482

4583
you can use below token to test role and permissions

VERIFICATION.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## Verification
2+
The verification needs data in ES, there are two ways to populate data to ES.
3+
4+
Please install and run [kibana](https://www.elastic.co/downloads/past-releases/kibana-6-8-0), validate data in ES during the testing, I found this is very useful for developing and testing.
5+
The data in ES is confusing, please validate data in ES before making a decision success or failure.
6+
7+
#### Using u-bahn-api service
8+
Start the `u-bahn-api` service and create data with postman.
9+
As you create data, verify data is read from ES using resource GET methods from postman.
10+
When create a resource, the postman sets the Id of corresponding resource, so be carefully after create resource
11+
12+
According to the [forum](https://apps.topcoder.com/forums/?module=Thread&threadID=956692&start=0),
13+
the u-bahn topics isn't set up in TC bus api, so the posting message to bus API doesn't work currently.
14+
Fix TC bus api to accept u-bahn topics, please use this approach, this is the easiest way.
15+
16+
17+
#### Using u-bahn-es-processor
18+
19+
Publish messages to [u-bahn-es-processor](https://github.com/topcoder-platform/u-bahn-es-processor) through kafka.
20+
This is very hard and error prune, but if this is the only way, use this approach.
21+
22+
Follow the instructions in the README file in the `u-bahm-es-processor`, start kafka server, start elasticsearch, initialize Elasticsearch, start `u-bahn-es-processor` app
23+
24+
1. start kafka-console-producer to write messages to `u-bahn.action.create`
25+
topic:
26+
`docker exec -it ubahn-data-processor-es_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic u-bahn.action.create`
27+
3. write message:
28+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"user","id":"391a3656-9a01-47d4-8c6d-64b68c44f212","handle":"user"}}`
29+
4. Watch the app console, It will show message successfully handled.
30+
5. Get the user from the postman by GET /users or /users/391a3656-9a01-47d4-8c6d-64b68c44f212.
31+
32+
6. write message:
33+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"achievement","userId":"391a3656-9a01-47d4-8c6d-64b68c44f212","achievementsProviderId":"c77326d8-ef16-4be0-b844-d5c384b7bb8b","name":"achievement","uri":"https://google.com","certifierId":"b8726ca1-557e-4502-8f9b-25044b9c123d","certifiedDate":"2019-07-08T00:00:00.000Z"}}`
34+
7. Watch the app console, It will show message successfully handled.
35+
8. Get the achievement from the postman.
36+
37+
9. write message:
38+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"achievementprovider","id":"c77326d8-ef16-4be0-b844-d5c384b7bb8b","name":"achievementprovider"}}`
39+
10. Watch the app console, It will show message successfully handled.
40+
11. Get the achievementprovider from the postman.
41+
42+
12. write message:
43+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"attributegroup","id":"720c34f9-0fd4-46fd-9293-4a8cfdcd3e96","organizationId":"017733ad-4704-4c7e-ae60-36b3332731df","name":"attributegroup"}}`
44+
13. Watch the app console, It will show message successfully handled.
45+
14. Get the attributegroup from the postman.
46+
47+
15. write message:
48+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"externalprofile","userId":"391a3656-9a01-47d4-8c6d-64b68c44f212","organizationId":"017733ad-4704-4c7e-ae60-36b3332731df","uri":"https:google.com"}}`
49+
16. Watch the app console, It will show message successfully handled.
50+
17. Get the externalprofile from the postman.
51+
52+
18. write message:
53+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"organization","id":"017733ad-4704-4c7e-ae60-36b3332731df","name":"organization"}}`
54+
19. Watch the app console, It will show message successfully handled.
55+
20. Get the organization from the postman.
56+
57+
21. write message:
58+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"role","id":"188446f1-02dc-4fc7-b74e-ab7ea3033a57","name":"role"}}`
59+
22. Watch the app console, It will show message successfully handled.
60+
23. Get the role from the postman.
61+
62+
24. write message:
63+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"skill","id":"8a8c8d3a-9165-4dae-8a8c-f828cbe01d5d","skillProviderId":"63061b84-9784-4b71-b695-4a777eeb7601","externalId":"ba395d36-6ce8-4bd1-9d6c-754f0389abcb","uri":"https://google.com","name":"skill"}}`
64+
25. Watch the app console, It will show message successfully handled.
65+
26. Get the skill from the postman.
66+
67+
27. write message:
68+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"skillprovider","id":"63061b84-9784-4b71-b695-4a777eeb7601","name":"skillprovider"}}`
69+
28. Watch the app console, It will show message successfully handled.
70+
29. Get the skillprovider from the postman.
71+
72+
30. write message:
73+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"userattribute","userId":"391a3656-9a01-47d4-8c6d-64b68c44f212","attributeId":"b5a50f73-08e2-43d1-a78a-4652f15d950e","value":"userattribute"}}`
74+
31. Watch the app console, It will show message successfully handled.
75+
32. Get the userattribute from the postman.
76+
77+
33. write message:
78+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"userrole","userId":"391a3656-9a01-47d4-8c6d-64b68c44f212","roleId":"188446f1-02dc-4fc7-b74e-ab7ea3033a57"}}`
79+
34. Watch the app console, It will show message successfully handled.
80+
35. Get the userrole from the postman.
81+
82+
36. write message:
83+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"userskill","userId":"391a3656-9a01-47d4-8c6d-64b68c44f212","skillId":"8a8c8d3a-9165-4dae-8a8c-f828cbe01d5d","metricValue":"userskill","certifierId":"7cf786d9-a8c0-48ed-a7cc-09dcf91d904c","certifiedDate":"2019-07-08T00:00:00.000Z"}}`
84+
37. Watch the app console, It will show message successfully handled.
85+
38. Get the userskill from the postman.
86+
87+
39. write message:
88+
`{"topic":"u-bahn.action.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"resource":"attribute","id":"b5a50f73-08e2-43d1-a78a-4652f15d950e","name":"attribute", "attributeGroupId": "720c34f9-0fd4-46fd-9293-4a8cfdcd3e96"}}`
89+
40. Watch the app console, It will show message successfully handled.
90+
41. Get the attribute from the postman.
91+
92+
42. These are full set of data for one user.
93+
Get users with enrich=true, verify all data above are returned
94+
95+
43. Verify query parameters in each resource are works based on the swagger doc.
96+
When setting query parameter to the non-existing value, verify the app tries to get the data from QLDB in the console.
97+
98+
44. By changing id values from above data, create another users or other resources.
99+
100+
45. Test paging, query filtering with multiple resources.
101+
102+
46. Please verify all specifications in the project.

config/default.js

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,91 @@
55
module.exports = {
66
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
77
PORT: process.env.PORT || 3001,
8+
89
AUTH_SECRET: process.env.AUTH_SECRET || 'CLIENT_SECRET',
910
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '')
1011
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',
11-
API_VERSION: 'api/1.0',
1212

13-
AWS_KEY: process.env.AWS_KEY,
14-
AWS_SECRET: process.env.AWS_SECRET,
13+
PAGE_SIZE: process.env.PAGE_SIZE || 20,
14+
API_VERSION: process.env.API_VERSION || 'api/1.0',
15+
16+
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
17+
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
1518
AWS_REGION: process.env.AWS_REGION || 'us-east-1',
16-
DATABASE: process.env.DATABASE || 'ubahn-db'
19+
DATABASE: process.env.DATABASE || 'ubahn-db',
20+
21+
AUTH0_URL: process.env.AUTH0_URL,
22+
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
23+
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
24+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
25+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
26+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
27+
28+
GROUP_API_URL: process.env.GROUP_API_URL || 'https://api.topcoder-dev.com/v5/groups',
29+
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
30+
31+
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
32+
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'u-bahn-api',
33+
34+
// topics
35+
UBAHN_CREATE_TOPIC: process.env.UBAHN_CREATE_TOPIC || 'u-bahn.action.create',
36+
UBAHN_UPDATE_TOPIC: process.env.UBAHN_UPDATE_TOPIC || 'u-bahn.action.update',
37+
UBAHN_DELETE_TOPIC: process.env.UBAHN_DELETE_TOPIC || 'u-bahn.action.delete',
38+
39+
// ElasticSearch
40+
ES: {
41+
HOST: process.env.ES_HOST || 'localhost:9200',
42+
API_VERSION: process.env.ES_API_VERSION || '7.4',
43+
// es mapping: _index, _type, _id
44+
DOCUMENTS: {
45+
achievementprovider: {
46+
index: process.env.ACHIEVEMENT_PROVIDER_INDEX || 'achievement_provider',
47+
type: '_doc'
48+
},
49+
attribute: {
50+
index: process.env.ATTRIBUTE_INDEX || 'attribute',
51+
type: '_doc'
52+
},
53+
attributegroup: {
54+
index: process.env.ATTRIBUTE_GROUP_INDEX || 'attribute_group',
55+
type: '_doc'
56+
},
57+
organization: {
58+
index: process.env.ORGANIZATION_INDEX || 'organization',
59+
type: '_doc'
60+
},
61+
role: {
62+
index: process.env.ROLE_INDEX || 'role',
63+
type: '_doc'
64+
},
65+
skill: {
66+
index: process.env.SKILL_INDEX || 'skill',
67+
type: '_doc'
68+
},
69+
skillprovider: {
70+
index: process.env.SKILL_PROVIDER_INDEX || 'skill_provider',
71+
type: '_doc'
72+
},
73+
user: {
74+
index: process.env.USER_INDEX || 'user',
75+
type: '_doc'
76+
},
77+
// sub resources under user
78+
achievement: {
79+
userField: process.env.USER_ACHIEVEMENT_PROPERTY_NAME || 'achievements'
80+
},
81+
externalprofile: {
82+
userField: process.env.USER_EXTERNALPROFILE_PROPERTY_NAME || 'externalProfiles'
83+
},
84+
userattribute: {
85+
userField: process.env.USER_ATTRIBUTE_PROPERTY_NAME || 'attributes'
86+
},
87+
userrole: {
88+
userField: process.env.USER_ROLE_PROPERTY_NAME || 'roles'
89+
},
90+
userskill: {
91+
userField: process.env.USER_SKILL_PROPERTY_NAME || 'skills'
92+
}
93+
}
94+
}
1795
}

docker/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Use the base image with Node.js 12
2+
FROM node:12
3+
4+
# Copy the current directory into the Docker image
5+
COPY . /ubahn_api
6+
7+
# Set working directory for future use
8+
WORKDIR /ubahn_api
9+
10+
# Install the dependencies from package.json
11+
RUN npm install
12+
CMD npm start

docker/docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
services:
3+
ubahn_api:
4+
image: ubahn_api:latest
5+
build:
6+
context: ../
7+
dockerfile: docker/Dockerfile
8+
env_file:
9+
- api.env
10+
ports:
11+
- "3001:3001"

docker/sample.api.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
AWS_ACCESS_KEY_ID=<AWS Access Key ID>
2+
AWS_SECRET_ACCESS_KEY=<AWS Secret Access Key>
3+
ES_HOST=<ES Host Endpoint>
4+
5+
AUTH0_URL=<AUTH0 URL>
6+
AUTH0_AUDIENCE=<AUTH0 Audience>
7+
TOKEN_CACHE_TIME=500000
8+
AUTH0_CLIENT_ID=<AUTH0 Client ID>
9+
AUTH0_CLIENT_SECRET=<AUTH0 Client Secret>

0 commit comments

Comments
 (0)