From ccfa7990220f40899614f86229c625c245f63a8d Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Thu, 29 Mar 2018 08:37:48 +0530 Subject: [PATCH 1/3] changing core tc auth lib. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aabeec4..e18dbec 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "pg": "^7.3.0", "sequelize": "^4.21.0", "superagent": "^3.8.0", - "tc-core-library-js": "gondzo/tc-core-library-js.git#dev", + "tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2", "winston": "^2.4.0" }, "engines": { From 2b4c84d904a5ac12946617b15e181402fc24f0fe Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Mon, 2 Apr 2018 15:57:52 +0530 Subject: [PATCH 2/3] changes after finalizing endpoint naming convention. --- config/default.js | 3 +-- src/app.js | 53 +++++++++++++++++++++++------------------------ src/routes.js | 50 ++++++++++++-------------------------------- 3 files changed, 40 insertions(+), 66 deletions(-) diff --git a/config/default.js b/config/default.js index fc397a0..fb0a9fa 100644 --- a/config/default.js +++ b/config/default.js @@ -41,7 +41,6 @@ module.exports = { //in every 2 minutes will retry for failed status EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *', - API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || 'email', - API_VERSION: process.env.API_VERSION || 'v5', + API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email', }; diff --git a/src/app.js b/src/app.js index c01c78c..9cd88ec 100644 --- a/src/app.js +++ b/src/app.js @@ -79,27 +79,27 @@ function configureKafkaConsumer(handlers) { // emailTries[topicName] += 1; //temporary disabling this feature emailModel.status = 'FAILED'; return emailModel.save().then(() => { - /* - * temporary disabling this feature as there is chance of losing message during - * unsubscribe/pausing due to simple kafka consumer - */ - /* - const currentTries = emailTries[topicName]; - if (currentTries > maxErrors) { - logger.debug(`Failed to send email. Will sleep for ${pauseTime}s`); - emailTries[topicName] = 0; - - schedule.scheduleJob(new Date(now.getTime() + pauseTime * 1000), () => { - consumer.subscribe(topic, dataHandler); - }); - - return consumer.unsubscribe(topic, partition).then(() => { - throw result.error - }); - } else { - logger.debug(`Failed to send email (retries left ${maxErrors - currentTries})`); - throw result.error; - }*/ + /* + * temporary disabling this feature as there is chance of losing message during + * unsubscribe/pausing due to simple kafka consumer + */ + /* + const currentTries = emailTries[topicName]; + if (currentTries > maxErrors) { + logger.debug(`Failed to send email. Will sleep for ${pauseTime}s`); + emailTries[topicName] = 0; + + schedule.scheduleJob(new Date(now.getTime() + pauseTime * 1000), () => { + consumer.subscribe(topic, dataHandler); + }); + + return consumer.unsubscribe(topic, partition).then(() => { + throw result.error + }); + } else { + logger.debug(`Failed to send email (retries left ${maxErrors - currentTries})`); + throw result.error; + }*/ }); } }).then(() => consumer.commitOffset({ topic, partition, offset: m.offset })) // commit offset @@ -124,9 +124,9 @@ function startKafkaConsumer(consumer, handlers, dataHandler) { return consumer .init() .then(() => Promise.each(_.keys(handlers), (topicName) => { // add back the ignored topic prefix to use full topic name - emailTries[topicName] = 0; - return consumer.subscribe(`${config.KAFKA_TOPIC_IGNORE_PREFIX || ''}${topicName}`, dataHandler); - }) + emailTries[topicName] = 0; + return consumer.subscribe(`${config.KAFKA_TOPIC_IGNORE_PREFIX || ''}${topicName}`, dataHandler); + }) ); } @@ -189,8 +189,7 @@ function start(handlers) { req.signature = `${def.controller}#${def.method}`; next(); }); - if ((url !== '/email/health') - && (url !== `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/health`)) { + if (url !== '/health') { actions.push(jwtAuth()); actions.push((req, res, next) => { if (!req.authUser) { @@ -205,7 +204,7 @@ function start(handlers) { }); }); - app.use('/', apiRouter); + app.use(config.API_CONTEXT_PATH, apiRouter); app.use((req, res) => { res.status(404).json({ error: 'route not found' }); diff --git a/src/routes.js b/src/routes.js index 8a9ae74..4fe56d5 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,40 +1,16 @@ 'use strict'; -const config = require('config'); - -const routes = {}; - -const oldkeyEventType = '/email/templates/eventType/:name' -routes[oldkeyEventType] = { - get: { - controller: 'TemplateController', - method: 'eventTypes', - } -}; - -const oldkeyHealthCheck = '/email/health' -routes[oldkeyHealthCheck] = { - get: { - controller: 'HealthController', - method: 'health', - } -}; - -const keyEventType = `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/templates/eventType/:name`; -routes[keyEventType] = { - get: { - controller: 'TemplateController', - method: 'eventTypes', - } -}; - -const keyHealthCheck = `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/health`; -routes[keyHealthCheck] = { - get: { - controller: 'HealthController', - method: 'health', - } +module.exports = { + '/templates/:name': { + get: { + controller: 'TemplateController', + method: 'eventTypes', + }, + }, + '/health': { + get: { + controller: 'HealthController', + method: 'health', + }, + }, }; - - -module.exports = routes; From 99e06910d9e1ae02d5a7fc2887f079f3d26350ce Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Mon, 2 Apr 2018 16:02:01 +0530 Subject: [PATCH 3/3] changes in deploy.sh accordingly. --- deploy.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/deploy.sh b/deploy.sh index 60f8cb6..a833097 100755 --- a/deploy.sh +++ b/deploy.sh @@ -67,7 +67,6 @@ EMAIL_RETRY_SCHEDULE=$(eval "echo \"\$${ENV}_EMAIL_RETRY_SCHEDULE\"") DISABLE_LOGGING=$(eval "echo \$${ENV}_DISABLE_LOGGING") API_CONTEXT_PATH=$(eval "echo \$${ENV}_API_CONTEXT_PATH") -API_VERSION=$(eval "echo \$${ENV}_API_VERSION") configure_aws_cli() { aws --version @@ -195,10 +194,6 @@ make_task_def(){ { "name": "API_CONTEXT_PATH", "value": "%s" - }, - { - "name": "API_VERSION", - "value": "%s" } ], "portMappings": [ @@ -220,7 +215,7 @@ make_task_def(){ ] }' - task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_DOMAIN $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$JWKS_URI" "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL $LOG_LEVEL $PORT $SENDGRID_API_KEY "$TEMPLATE_MAP" "$VALID_ISSUERS" $EMAIL_MAX_ERRORS $EMAIL_PAUSE_TIME "$EMAIL_RETRY_SCHEDULE" "$DISABLE_LOGGING" "$API_CONTEXT_PATH" "$API_VERSION" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV) + task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_DOMAIN $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$JWKS_URI" "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL $LOG_LEVEL $PORT $SENDGRID_API_KEY "$TEMPLATE_MAP" "$VALID_ISSUERS" $EMAIL_MAX_ERRORS $EMAIL_PAUSE_TIME "$EMAIL_RETRY_SCHEDULE" "$DISABLE_LOGGING" "$API_CONTEXT_PATH" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV) }