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

Commit 2717d64

Browse files
Implement API using QLDB
1 parent 3486eb2 commit 2717d64

File tree

122 files changed

+9389
-3457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+9389
-3457
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.idea
3+
**/.DS_Store
4+
docs
5+
.env
6+
coverage

.gitignore

Lines changed: 6 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,8 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
1+
node_modules
2+
.idea
3+
**/.DS_Store
4+
upload
5+
scripts/generate
266
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
727
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
8+
coverage

.swagger-codegen-ignore

Lines changed: 0 additions & 23 deletions
This file was deleted.

.swagger-codegen/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:12
2+
WORKDIR /usr/src/app
3+
COPY package.json ./
4+
COPY app.js ./
5+
COPY ./src ./src
6+
COPY ./config ./config
7+
COPY ./scripts ./scripts
8+
9+
RUN npm install
10+
ENTRYPOINT [ "node", "app.js" ]

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

100644100755
Lines changed: 152 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,162 @@
11
# U-Bahn API
22

3-
Universal Identity API
3+
## Install software
44

5-
## Overview
5+
- node 12.x
6+
- npm 6.x
7+
- docker
68

7-
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
9+
## Local deployment
810

9-
### Running the server
11+
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`
12+
2. Visit [this link](https://console.aws.amazon.com/iam/home?region=us-east-1#/security_credentials) to download your "Access keys"
13+
3. Follow *Configuration* section to update config values, like database, aws key/secret etc ..
14+
4. Goto *UBahn-api*, run `npm i` and `npm run lint`
15+
5. Import mock data, `node scripts/db/genData.js`, this will create tables and gen some data for test (if you need this)
16+
6. Startup server `node app.js` or `npm run start`
1017

11-
To run the server, run:
18+
## Docker
1219

13-
```bash
14-
npm start
15-
```
20+
Make sure all config values are right(aws key and secret), and you can run on local successful, then run below commands
1621

17-
To view the Swagger UI interface:
22+
- Run `docker build -t tc/ubahn_api .` to build image
23+
- Then run `docker run tc/ubahn_api -d` to startup image
1824

19-
```bash
20-
open http://localhost:8080/docs
21-
```
25+
## API endpoints verification
2226

23-
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.
27+
1. open postman
28+
2. import *docs/UBahn_API.postman_collection.json* , *UBahn_ENV.postman_environment.json* and then check endpoints
29+
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+
43+
## Test token
44+
45+
you can use below token to test role and permissions
46+
47+
### 01 Topcoder User
48+
49+
- payload
50+
51+
```json
52+
{
53+
"roles": [
54+
"Topcoder User"
55+
],
56+
"iss": "https://api.topcoder.com",
57+
"handle": "tc-user",
58+
"exp": 1685571460,
59+
"userId": "23166766",
60+
"iat": 1585570860,
61+
"email": "tc-user@gmail.com",
62+
"jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9627"
63+
}
64+
```
65+
66+
- token
67+
68+
```json
69+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6InRjLXVzZXIiLCJleHAiOjE2ODU1NzE0NjAsInVzZXJJZCI6IjIzMTY2NzY2IiwiaWF0IjoxNTg1NTcwODYwLCJlbWFpbCI6InRjLXVzZXJAZ21haWwuY29tIiwianRpIjoiMGYxZWYxZDMtMmIzMy00OTAwLWJiNDMtNDhmMjI4NWY5NjI3In0.eBhXqSBe8zMRg2nBeGeZDgKiJdAYs0zOMzGfJCjWfcs
70+
```
71+
72+
#### 02 Copilot
73+
74+
- payload
75+
76+
```json
77+
{
78+
"roles": [
79+
"Topcoder User","Copilot"
80+
],
81+
"iss": "https://api.topcoder.com",
82+
"handle": "tc-Copilot",
83+
"exp": 1685571460,
84+
"userId": "23166767",
85+
"iat": 1585570860,
86+
"email": "tc-Copilot@gmail.com",
87+
"jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9628"
88+
}
89+
```
90+
91+
- token
92+
93+
```json
94+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiQ29waWxvdCJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci5jb20iLCJoYW5kbGUiOiJ0Yy1Db3BpbG90IiwiZXhwIjoxNjg1NTcxNDYwLCJ1c2VySWQiOiIyMzE2Njc2NyIsImlhdCI6MTU4NTU3MDg2MCwiZW1haWwiOiJ0Yy1Db3BpbG90QGdtYWlsLmNvbSIsImp0aSI6IjBmMWVmMWQzLTJiMzMtNDkwMC1iYjQzLTQ4ZjIyODVmOTYyOCJ9.gP5JqJGCnOjO_gYs2r3-AQt5x8YIym15m3t43603cgc
95+
```
96+
97+
#### 03 Admin
98+
99+
- payload
100+
101+
```json
102+
{
103+
"roles": [
104+
"Topcoder User","Copilot","Admin"
105+
],
106+
"iss": "https://api.topcoder.com",
107+
"handle": "tc-Admin",
108+
"exp": 1685571460,
109+
"userId": "23166768",
110+
"iat": 1585570860,
111+
"email": "tc-Admin@gmail.com",
112+
"jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9630"
113+
}
114+
```
115+
116+
- token
117+
118+
```json
119+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiQ29waWxvdCIsIkFkbWluIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6InRjLUFkbWluIiwiZXhwIjoxNjg1NTcxNDYwLCJ1c2VySWQiOiIyMzE2Njc2OCIsImlhdCI6MTU4NTU3MDg2MCwiZW1haWwiOiJ0Yy1BZG1pbkBnbWFpbC5jb20iLCJqdGkiOiIwZjFlZjFkMy0yYjMzLTQ5MDAtYmI0My00OGYyMjg1Zjk2MzAifQ.eR97kePT0Gu-t7vUE0Ed8A88Dnmtgebyml2jrRyxhOk
120+
```
121+
122+
#### M2M token 01
123+
124+
- payload, this token missing `all:usersSkill`, so all endpoints in usersSkill group will return 403
125+
126+
```json
127+
{
128+
"scopes": "all:user all:role all:skill all:usersRole all:organization all:skillsProvider",
129+
"iss": "https://api.topcoder.com",
130+
"handle":"tc-mm-01",
131+
"exp": 1685571460,
132+
"iat": 1585570860,
133+
"jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9630"
134+
}
135+
```
136+
137+
- token
138+
139+
```json
140+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZXMiOiJhbGw6dXNlciBhbGw6cm9sZSBhbGw6c2tpbGwgYWxsOnVzZXJzUm9sZSBhbGw6b3JnYW5pemF0aW9uIGFsbDpza2lsbHNQcm92aWRlciIsImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6InRjLW1tLTAxIiwiZXhwIjoxNjg1NTcxNDYwLCJpYXQiOjE1ODU1NzA4NjAsImp0aSI6IjBmMWVmMWQzLTJiMzMtNDkwMC1iYjQzLTQ4ZjIyODVmOTYzMCJ9.BlDIYsCTcHTib9XhpyzpO-KkMTTMy0egq_7qlLWRmoM
141+
```
142+
143+
#### M2M token 02
144+
145+
- payload, this token contains scope, can request all endpoints
146+
147+
```json
148+
{
149+
"scopes": "all:user all:role all:skill all:usersRole all:organization all:skillsProvider all:usersSkill all:externalProfile all:achievementsProvider all:achievement all:attributeGroup all:attribute all:userAttribute",
150+
"iss": "https://api.topcoder.com",
151+
"handle": "tc-mm-02",
152+
"exp": 1685571460,
153+
"iat": 1585570860,
154+
"jti": "0f1ef1d3-2b33-4900-bb43-48f2285f9630"
155+
}
156+
```
157+
158+
- token
159+
160+
```json
161+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZXMiOiJhbGw6dXNlciBhbGw6cm9sZSBhbGw6c2tpbGwgYWxsOnVzZXJzUm9sZSBhbGw6b3JnYW5pemF0aW9uIGFsbDpza2lsbHNQcm92aWRlciBhbGw6dXNlcnNTa2lsbCBhbGw6ZXh0ZXJuYWxQcm9maWxlIGFsbDphY2hpZXZlbWVudHNQcm92aWRlciBhbGw6YWNoaWV2ZW1lbnQgYWxsOmF0dHJpYnV0ZUdyb3VwIGFsbDphdHRyaWJ1dGUgYWxsOnVzZXJBdHRyaWJ1dGUiLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci5jb20iLCJoYW5kbGUiOiJ0Yy1tbS0wMiIsImV4cCI6MTY4NTU3MTQ2MCwiaWF0IjoxNTg1NTcwODYwLCJqdGkiOiIwZjFlZjFkMy0yYjMzLTQ5MDAtYmI0My00OGYyMjg1Zjk2MzAifQ.8XJahLdv9mkgkL7EsOwsf8uKg4J9u-1UM73pvZ9n3JY
162+
```

0 commit comments

Comments
 (0)