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

Shapeup#2: v5 user fortification #6

Merged
merged 2 commits into from
Apr 6, 2021
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ The following parameters can be set in config files or in env variables:
- TOKEN_CACHE_TIME: The token cache time
- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms
- UBAHN_API_URL: The ubahn api url, default value: 'https://api.topcoder-dev.com/v5'
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'
- MEMBERS_API_URL: The topcoder member api url, default value: 'https://api.topcoder-dev.com/v5/members'. Not in use anymore. Retained for any future use
- ATTRIBUTE_GROUP_NAME: The attribute group name
- SKILL_PROVIDER_NAME: The skill provider name
- SKILL_PROVIDER_NAME: The skill provider name. Not in use anymore. Retained for any future use
- ORGANIZATION_NAME: The organization name

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
Expand Down
6 changes: 4 additions & 2 deletions VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},
"profiles":null,
"status":"A",
"country":null,
"country":{
"isoAlpha3Code": "IND"
},
"regSource":"null",
"utmSource":"null",
"utmMedium":"null",
Expand All @@ -44,5 +46,5 @@ docker exec -it identity-data-processor_kafka /opt/kafka/bin/kafka-console-produ
`{"recipients":[],"notificationType":"useractivation"}`
3. Watch the app console, It will show error message.
4. write message:
`{"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":"[email protected]","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}}`
`{"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":"[email protected]","firstName":"theuserfirstname","lastName":"theuserlastname","credential":{"activationCode":"FOOBAR2","resetToken":null,"hasPassword":false},"profiles":null,"status":"A","country":{"isoAlpha3Code":"IND"},"regSource":"null","utmSource":"null","utmMedium":"null","utmCampaign":"null","roles":null,"ssoLogin":false,"active":true,"profile":null,"emailActive":true}}`
5. Watch the app console, It will show message successfully handled.
6 changes: 6 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function getUbahnToken () {
/**
* Function to get M2M token
* (U-Bahn APIs only)
* * Unused for now. Retained for any future use
* @returns {Promise}
*/
async function getTopcoderToken () {
Expand Down Expand Up @@ -96,6 +97,7 @@ async function getAttributes (token) {

/**
* Get all skills
* * Unused for now. Retained for any future use
* @param {String} token
* @returns a map (name -> id)
*/
Expand All @@ -108,6 +110,7 @@ async function getSkillProviderId (token) {

/**
* Get the skillId
* * Unused for now. Retained for any future use
* @param {String} skillProviderId
* @param {String} name
* @param {String} token
Expand All @@ -121,6 +124,7 @@ async function getSkillId (skillProviderId, name, token) {

/**
* Returns the member location for the member handle
* * Unused for now. Retained for any future use
* @param {String} handle The member handle
*/
async function getMemberLocation (handle, token) {
Expand All @@ -131,6 +135,7 @@ async function getMemberLocation (handle, token) {

/**
* Returns the member's skills
* * Unused for now. Retained for any future use
* @param {String} handle The member's handle
*/
async function getMemberSkills (handle, token) {
Expand Down Expand Up @@ -185,6 +190,7 @@ async function createExternalProfile (userId, body, token) {

/**
* Create user skill
* * Unused for now. Retained for any future use
* @param {String} userId
* @param {String} skillId
* @param {String} metricValue
Expand Down
20 changes: 5 additions & 15 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ const helper = require('../common/helper')
*/
async function processCreate (message) {
const ubahnToken = await helper.getUbahnToken()
const topcoderToken = await helper.getTopcoderToken()
const organizationId = await helper.getOrganizationId(ubahnToken)
const attributes = await helper.getAttributes(ubahnToken)
const skillProviderId = await helper.getSkillProviderId(ubahnToken)
const location = await helper.getMemberLocation(message.payload.handle, topcoderToken)
const userSkills = await helper.getMemberSkills(message.payload.handle, topcoderToken)
const location = message.payload.country.isoAlpha3Code

const userId = await helper.createUser(_.pick(message.payload, 'handle', 'firstName', 'lastName'), ubahnToken)
logger.info(`user: ${message.payload.handle} created`)
Expand All @@ -37,16 +34,6 @@ async function processCreate (message) {
helper.sleep()
await helper.createUserAttribute(userId, _.get(attributes, 'location'), location, ubahnToken)
logger.info('user attribute: location created')
for (const userSkill of userSkills) {
helper.sleep()
const skillId = await helper.getSkillId(skillProviderId, userSkill.name, ubahnToken)
if (skillId) {
await helper.createUserSkill(userId, skillId, userSkill.score, ubahnToken)
logger.info(`user skill: ${userSkill.name}:${userSkill.score} created`)
} else {
throw Error(`Cannot find skill with name ${userSkill.name} and skill provider id ${skillProviderId} in u-bahn`)
}
}
}

processCreate.schema = {
Expand All @@ -59,7 +46,10 @@ processCreate.schema = {
id: Joi.string().required(),
handle: Joi.string().required(),
firstName: Joi.string().required(),
lastName: Joi.string().required()
lastName: Joi.string().required(),
country: Joi.object().keys({
isoAlpha3Code: Joi.string().required()
}).required().unknown(true)
}).required().unknown(true)
}).required().unknown(true)
}
Expand Down