diff --git a/docker-compose.yml b/docker-compose.yml index 0f3cb16..a4edfaf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,4 +17,4 @@ services: KAFKA_ADVERTISED_HOST_NAME: localhost KAFKA_ADVERTISED_PORT: 9092 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_CREATE_TOPICS: "challenge.notification.create:1:1,challenge.notification.update:1:1,challenge.notification.events:1:1,challenge.action.resource.create:1:1,challenge.action.resource.delete:1:1" + KAFKA_CREATE_TOPICS: "challenge.notification.create:1:1,challenge.notification.update:1:1,challenge.action.resource.create:1:1,challenge.action.resource.delete:1:1" diff --git a/package-lock.json b/package-lock.json index 13267b2..e1af6e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -354,109 +354,6 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, - "auth0-js": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/auth0-js/-/auth0-js-9.14.0.tgz", - "integrity": "sha512-40gIBUejmYAYse06ck6sxdNO0KU0pX+KDIQsWAkcyFtI0HU6dY5aeHxZfVYkYjtbArKr5s13LuZFdKrUiGyCqQ==", - "requires": { - "base64-js": "^1.3.0", - "idtoken-verifier": "^2.0.3", - "js-cookie": "^2.2.0", - "qs": "^6.7.0", - "superagent": "^5.3.1", - "url-join": "^4.0.1", - "winchan": "^0.2.2" - }, - "dependencies": { - "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", - "requires": { - "ms": "2.1.2" - } - }, - "form-data": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", - "integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, - "formidable": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz", - "integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q==" - }, - "lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "requires": { - "yallist": "^4.0.0" - } - }, - "mime": { - "version": "2.4.6", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.6.tgz", - "integrity": "sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==" - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, - "qs": { - "version": "6.9.4", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.4.tgz", - "integrity": "sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==" - }, - "readable-stream": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "semver": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", - "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", - "requires": { - "lru-cache": "^6.0.0" - } - }, - "superagent": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.3.1.tgz", - "integrity": "sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==", - "requires": { - "component-emitter": "^1.3.0", - "cookiejar": "^2.1.2", - "debug": "^4.1.1", - "fast-safe-stringify": "^2.0.7", - "form-data": "^3.0.0", - "formidable": "^1.2.2", - "methods": "^1.1.2", - "mime": "^2.4.6", - "qs": "^6.9.4", - "readable-stream": "^3.6.0", - "semver": "^7.3.2" - } - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - } - } - }, "aws-sign2": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", @@ -496,11 +393,6 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, - "base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" - }, "bcrypt-pbkdf": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", @@ -970,11 +862,6 @@ } } }, - "crypto-js": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.3.0.tgz", - "integrity": "sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q==" - }, "crypto-random-string": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz", @@ -1300,11 +1187,6 @@ "is-symbol": "^1.0.2" } }, - "es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" - }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -2069,26 +1951,6 @@ "safer-buffer": ">= 2.1.2 < 3" } }, - "idtoken-verifier": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/idtoken-verifier/-/idtoken-verifier-2.1.0.tgz", - "integrity": "sha512-X0423UM4Rc5bFb39Ai0YHr35rcexlu4oakKdYzSGZxtoPy84P86hhAbzlpgbgomcLOFRgzgKRvhY7YjO5g8OPA==", - "requires": { - "base64-js": "^1.3.0", - "crypto-js": "^3.2.1", - "es6-promise": "^4.2.8", - "jsbn": "^1.1.0", - "unfetch": "^4.1.0", - "url-join": "^4.0.1" - }, - "dependencies": { - "jsbn": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", - "integrity": "sha1-sBMHyym2GKHtJux56RH4A8TaAEA=" - } - } - }, "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", @@ -2352,11 +2214,6 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, - "js-cookie": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz", - "integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==" - }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -2555,31 +2412,6 @@ "package-json": "^4.0.0" } }, - "le_node": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/le_node/-/le_node-1.8.0.tgz", - "integrity": "sha512-NXzjxBskZ4QawTNwlGdRG05jYU0LhV2nxxmP3x7sRMHyROV0jPdyyikO9at+uYrWX3VFt0Y/am11oKITedx0iw==", - "requires": { - "babel-runtime": "6.6.1", - "codependency": "0.1.4", - "json-stringify-safe": "5.0.1", - "lodash": "4.17.11", - "reconnect-core": "1.3.0", - "semver": "5.1.0" - }, - "dependencies": { - "lodash": { - "version": "4.17.11", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" - }, - "semver": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.1.0.tgz", - "integrity": "sha1-hfLPhVBGXE3wAM99hvawVBBqueU=" - } - } - }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -4579,14 +4411,13 @@ "version": "github:appirio-tech/tc-core-library-js#f45352974dafe5a10c86fc50bdd59ef399b50c65", "from": "github:appirio-tech/tc-core-library-js", "requires": { - "auth0-js": "^9.4.2", "axios": "^0.19.0", "bunyan": "^1.8.12", - "jsonwebtoken": "^8.3.0", - "jwks-rsa": "^1.3.0", - "le_node": "^1.3.1", - "lodash": "^4.17.10", + "jsonwebtoken": "^8.5.1", + "jwks-rsa": "^1.6.0", + "lodash": "^4.17.15", "millisecond": "^0.1.2", + "r7insight_node": "^1.8.4", "request": "^2.88.0" } }, @@ -4711,11 +4542,6 @@ "debug": "^2.2.0" } }, - "unfetch": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-4.2.0.tgz", - "integrity": "sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==" - }, "uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", @@ -4779,11 +4605,6 @@ } } }, - "url-join": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", - "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" - }, "url-parse-lax": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz", @@ -4847,11 +4668,6 @@ "string-width": "^2.1.1" } }, - "winchan": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/winchan/-/winchan-0.2.2.tgz", - "integrity": "sha512-pvN+IFAbRP74n/6mc6phNyCH8oVkzXsto4KCHPJ2AScniAnA1AmeLI03I2BzjePpaClGSI4GUMowzsD3qz5PRQ==" - }, "winston": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/winston/-/winston-3.2.1.tgz", diff --git a/sample-data/challenge.notification.events-registeration.json b/sample-data/challenge.notification.events-registeration.json deleted file mode 100644 index b70a689..0000000 --- a/sample-data/challenge.notification.events-registeration.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "topic": "challenge.notification.events", - "originator": "topcoder-challenges-api", - "timestamp": "2019-11-24T00:22:41.164Z", - "mime-type": "application/json", - "payload": { - "type": "USER_REGISTRATION", - "data": { - "challengeId": "d28f85e8-1fa1-43d1-8fee-a44119ccee55", - "userId": 151743 - } - } -} \ No newline at end of file diff --git a/sample-data/challenge.notification.events-unregisteration.json b/sample-data/challenge.notification.events-unregisteration.json deleted file mode 100644 index 7946755..0000000 --- a/sample-data/challenge.notification.events-unregisteration.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "topic": "challenge.notification.events", - "originator": "topcoder-challenges-api", - "timestamp": "2019-11-24T00:22:41.164Z", - "mime-type": "application/json", - "payload": { - "type": "USER_UNREGISTRATION", - "data": { - "challengeId": "d28f85e8-1fa1-43d1-8fee-a44119ccee55", - "userId": 151743 - } - } -} \ No newline at end of file diff --git a/src/constants.js b/src/constants.js index a9e7030..bc4ca20 100644 --- a/src/constants.js +++ b/src/constants.js @@ -11,16 +11,9 @@ module.exports = { CHALLENGE_CREATE_TOPIC: 'challenge.notification.create', // For challenge update CHALLENGE_UPDATE_TOPIC: 'challenge.notification.update', - // For member registrations and de-registrations - CHALLENGE_NOTIFICATION_TOPIC: 'challenge.notification.events', - // For co-pilots,PMs,etc. + // For member registrations and de-registrations, co-pilots,PMs,etc. RESOURCE_CREATE_TOPIC: 'challenge.action.resource.create', RESOURCE_DELETE_TOPIC: 'challenge.action.resource.delete' - }, - // Values of `type` in payload of challenge.notification.events - CHALLENGE_NOTIFICATION_EVENT_TYPES: { - USER_REGISTRATION: 'USER_REGISTRATION', - USER_UNREGISTRATION: 'USER_UNREGISTRATION' } }, TEMPLATES: { diff --git a/src/modules/user_management/handler.js b/src/modules/user_management/handler.js index 11f0566..bf22fce 100644 --- a/src/modules/user_management/handler.js +++ b/src/modules/user_management/handler.js @@ -22,17 +22,10 @@ if (config.VANILLA_ENABLED) { services.push(manageVanillaUser) } -function canProcessEvent (payload, topic) { - if (topic === constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC) { - const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES - const actionMap = { - [eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE, - [eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK - } - if (!(payload.type in actionMap)) { - logger.debug(`Not supported ${payload.type}. Only message types ${JSON.stringify(Object.keys(eventTypes))} are processed from '${topic}'`) - return false - } +function canProcessEvent (topic) { + if (!_.includes([constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC, constants.KAFKA.TOPICS.RESOURCE_DELETE_TOPIC], topic)) { + logger.debug('Not supported topic.') + return false } return true } @@ -65,7 +58,7 @@ async function handler (messageSet, topic) { return } for (const item of messageSet) { - if (!canProcessEvent(item, topic)) { + if (!canProcessEvent(topic)) { continue } if (_.isArray(item)) { diff --git a/src/modules/user_management/helpers.js b/src/modules/user_management/helpers.js index 90d6a3b..bd0e9d5 100644 --- a/src/modules/user_management/helpers.js +++ b/src/modules/user_management/helpers.js @@ -9,11 +9,6 @@ const topcoderApi = require('../../utils/topcoder-api.util') * @param {String} topic */ function processPayload (payload, topic) { - const eventTypes = constants.KAFKA.CHALLENGE_NOTIFICATION_EVENT_TYPES - const actionMap = { - [eventTypes.USER_REGISTRATION]: constants.USER_ACTIONS.INVITE, - [eventTypes.USER_UNREGISTRATION]: constants.USER_ACTIONS.KICK - } switch (topic) { case constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC: return { @@ -29,20 +24,6 @@ function processPayload (payload, topic) { handle: payload.memberHandle, action: constants.USER_ACTIONS.KICK } - case constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC: - if (payload.detail && payload.detail.challengeId) { - // hack due to inconsistent payload from USER_UNREGISTRATION event - return { - challengeId: payload.detail.challengeId, - userId: payload.detail.userId, - action: actionMap[payload.type] - } - } - return { - challengeId: payload.data.challengeId, - userId: payload.data.userId, - action: actionMap[payload.type] - } default: throw new Error(`Received message from unrecognized '${topic}'`) } diff --git a/src/modules/user_management/index.js b/src/modules/user_management/index.js index 0c758bf..acf5129 100644 --- a/src/modules/user_management/index.js +++ b/src/modules/user_management/index.js @@ -4,7 +4,6 @@ const handler = require('./handler') module.exports = { topics: [ - constants.KAFKA.TOPICS.CHALLENGE_NOTIFICATION_TOPIC, constants.KAFKA.TOPICS.RESOURCE_CREATE_TOPIC, constants.KAFKA.TOPICS.RESOURCE_DELETE_TOPIC ],