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

Commit f16d965

Browse files
Initial commit
0 parents  commit f16d965

File tree

14 files changed

+4162
-0
lines changed

14 files changed

+4162
-0
lines changed

.gitignore

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

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Identity - Data Processor
2+
3+
## Dependencies
4+
5+
- Nodejs(v12+)
6+
- Kafka
7+
8+
## Configuration
9+
10+
Configuration for the identity processor is at `config/default.js`.
11+
The following parameters can be set in config files or in env variables:
12+
13+
- LOG_LEVEL: the log level; default value: 'debug'
14+
- KAFKA_URL: comma separated Kafka hosts; default value: 'localhost:9092'
15+
- KAFKA_CLIENT_CERT: Kafka connection certificate, optional; default value is undefined;
16+
if not provided, then SSL connection is not used, direct insecure connection is used;
17+
if provided, it can be either path to certificate file or certificate content
18+
- KAFKA_CLIENT_CERT_KEY: Kafka connection private key, optional; default value is undefined;
19+
if not provided, then SSL connection is not used, direct insecure connection is used;
20+
if provided, it can be either path to private key file or private key content
21+
- KAFKA_GROUP_ID: the Kafka group id, default value is 'identity-processor'
22+
- IDENTITY_NOTIFICATION_CREATE: the identity create entity Kafka message topic, default value is 'identity.notification.create'
23+
- AUTH0_URL: The auth0 url
24+
- AUTH0_UBAHN_AUDIENCE: The auth0 audience for accessing ubahn api(s)
25+
- AUTH0_TOPCODER_AUDIENCE: The auth0 audience for accessing topcoder api(s)
26+
- AUTH0_CLIENT_ID: The auth0 client id
27+
- AUTH0_CLIENT_SECRET: The auth0 client secret
28+
- AUTH0_PROXY_SERVER_URL: The auth0 proxy server url
29+
- TOKEN_CACHE_TIME: The token cache time
30+
- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms
31+
- UBAHN_API_URL: The ubahn api url, default value: 'https://api.topcoder-dev.com/v5'
32+
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'
33+
- ATTRIBUTE_GROUP_NAME: The attribute group name
34+
- SKILL_PROVIDER_NAME: The skill provider name
35+
- ORGANIZATION_NAME: The organization name
36+
37+
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
38+
39+
## Local Kafka setup
40+
41+
1. Navigate to the directory `docker-kafka`
42+
43+
2. Run the following command
44+
45+
```bash
46+
docker-compose up -d
47+
```
48+
49+
## Local deployment
50+
51+
1. Make sure that Kafka is running as per instructions above.
52+
53+
2. From the project root directory, run the following command to install the dependencies
54+
55+
```bash
56+
npm install
57+
```
58+
59+
3. To run linters if required
60+
61+
```bash
62+
npm run lint
63+
```
64+
65+
To fix possible lint errors:
66+
67+
```bash
68+
npm run lint:fix
69+
```
70+
71+
5. Start the processor and health check dropin
72+
73+
```bash
74+
npm start
75+
```
76+
77+
## Local Deployment with Docker
78+
79+
To run the Processor using docker, follow the below steps
80+
81+
1. Navigate to the directory `docker`
82+
83+
2. Rename the file `sample.api.env` to `api.env`
84+
85+
3. Once that is done, run the following command
86+
87+
```bash
88+
docker-compose up
89+
```
90+
91+
4. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies
92+
93+
94+
## Verification
95+
96+
see [VERIFICATION.md](VERIFICATION.md)

VERIFICATION.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Verification
2+
3+
```
4+
{
5+
"topic":"identity.notification.create",
6+
"originator":"u-bahn-api",
7+
"timestamp":"2019-07-08T00:00:00.000Z",
8+
"mime-type":"application/json",
9+
"payload":{
10+
"id":"90064000",
11+
"modifiedBy":null,
12+
"modifiedAt":"2021-01-05T14:01:40.336Z",
13+
"createdBy":null,
14+
"createdAt":"2021-01-05T14:01:40.336Z",
15+
"handle":"theuserhandle",
16+
"email":"foo@bar.com",
17+
"firstName":"theuserfirstname",
18+
"lastName":"theuserlastname",
19+
"credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},
20+
"profiles":null,
21+
"status":"A",
22+
"country":null,
23+
"regSource":"null",
24+
"utmSource":"null",
25+
"utmMedium":"null",
26+
"utmCampaign":"null",
27+
"roles":null,
28+
"ssoLogin":false,
29+
"active":true,
30+
"profile":null,
31+
"emailActive":true
32+
}
33+
}
34+
```
35+
36+
Additionally, you will be entering the messages into only one topic:
37+
38+
```
39+
docker exec -it identity-data-processor_kafka /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic identity.notification.create
40+
```
41+
42+
1. start kafka server, start processor app
43+
2. write message:
44+
`{"recipients":[],"notificationType":"useractivation"}`
45+
3. Watch the app console, It will show error message.
46+
4. write message:
47+
`{"topic":"identity.notification.create","originator":"u-bahn-api","timestamp":"2019-07-08T00:00:00.000Z","mime-type":"application/json","payload":{"id":"90064000","modifiedBy":null,"modifiedAt":"2021-01-05T14:01:40.336Z","createdBy":null,"createdAt":"2021-01-05T14:01:40.336Z","handle":"theuserhandle","email":"foo@bar.com","firstName":"theuserfirstname","lastName":"theuserlastname","credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},"profiles":null,"status":"A","country":null,"regSource":"null","utmSource":"null","utmMedium":"null","utmCampaign":"null","roles":null,"ssoLogin":false,"active":true,"profile":null,"emailActive":true}}`
48+
5. Watch the app console, It will show message successfully handled.

config/default.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* The default configuration file.
3+
*/
4+
5+
module.exports = {
6+
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
7+
8+
KAFKA_URL: process.env.KAFKA_URL || 'localhost:9092',
9+
// below are used for secure Kafka connection, they are optional
10+
// for the local Kafka, they are not needed
11+
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT,
12+
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY,
13+
14+
// Kafka group id
15+
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'identity-processor',
16+
17+
IDENTITY_NOTIFICATION_CREATE: process.env.IDENTITY_NOTIFICATION_CREATE || 'identity.notification.create',
18+
19+
AUTH0_URL: process.env.AUTH0_URL,
20+
AUTH0_UBAHN_AUDIENCE: process.env.AUTH0_UBAHN_AUDIENCE,
21+
AUTH0_TOPCODER_AUDIENCE: process.env.AUTH0_TOPCODER_AUDIENCE,
22+
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
23+
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
24+
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
25+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
26+
27+
SLEEP_TIME: process.env.SLEEP_TIME ? parseInt(process.env.SLEEP_TIME, 10) : 1000,
28+
29+
UBAHN_API_URL: process.env.UBAHN_API_URL || 'https://api.topcoder-dev.com/v5',
30+
ORGANIZATION_NAME: process.env.ORGANIZATION_NAME,
31+
ATTRIBUTE_GROUP_NAME: process.env.ATTRIBUTE_GROUP_NAME,
32+
SKILL_PROVIDER_NAME: process.env.SKILL_PROVIDER_NAME,
33+
MEMBERS_API_URL: process.env.MEMBERS_API_URL || 'https://api.topcoder-dev.com/v5/members'
34+
}

docker-kafka/docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
zookeeper:
4+
image: wurstmeister/zookeeper
5+
container_name: identity-data-processor_zookeeper
6+
ports:
7+
- "2181:2181"
8+
kafka:
9+
image: wurstmeister/kafka
10+
container_name: identity-data-processor_kafka
11+
ports:
12+
- "9092:9092"
13+
environment:
14+
KAFKA_ADVERTISED_HOST_NAME: localhost
15+
KAFKA_CREATE_TOPICS: "identity.notification.create:1:1"
16+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

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 8.11.3
2+
FROM node:12.16.3
3+
4+
# Copy the current directory into the Docker image
5+
COPY . /identity-processor
6+
7+
# Set working directory for future use
8+
WORKDIR /identity-processor
9+
10+
# Install the dependencies from package.json
11+
RUN npm install
12+
CMD npm start

docker/docker-compose.yml

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

docker/sample.api.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KAFKA_URL=<KAFKA Host Endpoint>

0 commit comments

Comments
 (0)