Skip to content

Commit 5c6b30c

Browse files
author
vikasrohit
authored
Merge pull request #20 from topcoder-platform/dev
sendgrid v3 Api, response logging and lib vulnerability fixes.
2 parents 0fbcb52 + 161c292 commit 5c6b30c

13 files changed

+1352
-1341
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ Configuration for the notification server is at `config/default.js`.
1313
The following parameters can be set in config files or in env variables:
1414
- LOG_LEVEL: the log level
1515
- PORT: the notification server port
16-
- authSecret: TC auth secret
17-
- authDomain: TC auth domain
18-
- validIssuers: TC auth valid issuers
19-
- jwksUri: TC auth JWKS URI
16+
- AUTH_SECRET: TC auth secret
17+
- VALID_ISSUERS: TC auth valid issuers
2018
- DATABASE_URL: URI to PostgreSQL database
2119
- DATABASE_OPTIONS: database connection options
2220
- KAFKA_URL: comma separated Kafka hosts
23-
- KAFKA_TOPIC_IGNORE_PREFIX: ignore this prefix for topics in the Kafka
2421
- KAFKA_GROUP_ID: Kafka consumer group id
2522
- KAFKA_CLIENT_CERT: Kafka connection certificate, optional;
2623
if not provided, then SSL connection is not used, direct insecure connection is used;
@@ -59,10 +56,8 @@ In case it expires, you may get a new token in this way:
5956

6057
## Local deployment
6158
- for local development environment you can set variables as following:
62-
- `authSecret`, `authDomain`, `validIssuers` can get from [tc-project-service config](https://github.com/topcoder-platform/tc-project-service/blob/dev/config/default.json)
59+
- `AUTH_SECRET`, `VALID_ISSUERS` can get from [tc-project-service config](https://github.com/topcoder-platform/tc-project-service/blob/dev/config/default.json)
6360
- `PORT=4001` because **connect-app** call this port by default
64-
- `jwksUri` - any
65-
- `KAFKA_TOPIC_IGNORE_PREFIX=joan-26673.` (with point at the end)
6661
- `KAFKA_URL`, `KAFKA_CLIENT_CERT` and `KAFKA_CLIENT_CERT_KEY` get from [tc-bus-api readme](https://github.com/topcoder-platform/tc-bus-api/tree/dev)
6762
- start local PostgreSQL db, create an empty database, update the config/default.js DATABASE_URL param to point to the db
6863
- install dependencies `npm i`

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports = {
2121

2222
VALID_ISSUERS: process.env.VALID_ISSUERS,
2323
KAFKA_URL: process.env.KAFKA_URL,
24-
KAFKA_TOPIC_IGNORE_PREFIX: process.env.KAFKA_TOPIC_IGNORE_PREFIX,
2524
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID,
2625
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT ? process.env.KAFKA_CLIENT_CERT.replace('\\n', '\n') : null,
2726
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY ?
@@ -38,6 +37,8 @@ module.exports = {
3837

3938
//in every 2 minutes will retry for failed status
4039
EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *',
40+
//wont't retry failed emails older than this time (msec)
41+
EMAIL_RETRY_MAX_AGE: process.env.EMAIL_RETRY_MAX_AGE || 1000*60*60*24,
4142

4243
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email',
4344

connect/service.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,31 @@ const sendEmail = (templateId, message) => { // send email
1818
const to = message.recipients;
1919
const cc = message.cc ? message.cc : [];
2020
const bcc = message.bcc ? message.bcc : [];
21-
22-
return sgMail.send({
23-
to,
24-
templateId,
25-
substitutions,
26-
from,
27-
substitutionWrappers: ['{{', '}}'],
28-
replyTo,
29-
categories,
30-
cc,
31-
bcc,
32-
});
21+
22+
if (message.version && message.version=="v3"){
23+
return sgMail.send({
24+
to,
25+
templateId,
26+
dynamicTemplateData: substitutions,
27+
from,
28+
replyTo,
29+
categories,
30+
cc,
31+
bcc,
32+
});
33+
} else{
34+
return sgMail.send({
35+
to,
36+
templateId,
37+
substitutions,
38+
substitutionWrappers: ['{{', '}}'],
39+
from,
40+
replyTo,
41+
categories,
42+
cc,
43+
bcc,
44+
});
45+
}
3346
}
3447
module.exports = {
3548
sendEmail,

deploy.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ TEMPLATE_MAP=$(eval "echo \$${ENV}_TEMPLATE_MAP")
6262
EMAIL_MAX_ERRORS=$(eval "echo \$${ENV}_EMAIL_MAX_ERRORS")
6363
EMAIL_PAUSE_TIME=$(eval "echo \$${ENV}_EMAIL_PAUSE_TIME")
6464
EMAIL_RETRY_SCHEDULE=$(eval "echo \"\$${ENV}_EMAIL_RETRY_SCHEDULE\"")
65+
EMAIL_RETRY_MAX_AGE=$(eval "echo \"\$${ENV}_EMAIL_RETRY_MAX_AGE\"")
6566
DISABLE_LOGGING=$(eval "echo \$${ENV}_DISABLE_LOGGING")
6667

6768
API_CONTEXT_PATH=$(eval "echo \$${ENV}_API_CONTEXT_PATH")
@@ -177,6 +178,10 @@ make_task_def(){
177178
"name": "EMAIL_RETRY_SCHEDULE",
178179
"value": "%s"
179180
},
181+
{
182+
"name": "EMAIL_RETRY_MAX_AGE",
183+
"value": "%s"
184+
},
180185
{
181186
"name": "DISABLE_LOGGING",
182187
"value": "%s"
@@ -205,7 +210,7 @@ make_task_def(){
205210
]
206211
}'
207212

208-
task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$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)
213+
task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$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" $EMAIL_RETRY_MAX_AGE "$DISABLE_LOGGING" "$API_CONTEXT_PATH" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV)
209214

210215
}
211216

docs/swagger_api.yaml

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,20 @@ securityDefinitions:
1515
description: JWT Authentication. Provide API Key in the form 'Bearer <token>'.
1616

1717
paths:
18-
/templates/{name}:
18+
/health:
1919
get:
2020
description:
21-
get email template placholders name
21+
health check endpoint
2222
produces:
2323
- application/json
24-
security:
25-
- jwt: []
26-
parameters:
27-
- name: name
28-
in: path
29-
description: The Kafka topic name
30-
required: true
31-
type: string
3224
responses:
3325
200:
3426
description: OK
3527
schema:
3628
type: object
3729
properties:
38-
items:
39-
type: array
40-
items:
41-
type: string
42-
400:
43-
description: "Bad request error."
44-
schema:
45-
$ref: "#/definitions/Error"
46-
404:
47-
description: "Template is not found error."
48-
schema:
49-
$ref: "#/definitions/Error"
50-
401:
51-
description: "Authentication failed."
52-
schema:
53-
$ref: "#/definitions/Error"
54-
500:
55-
description: "Internal server error."
56-
schema:
57-
$ref: "#/definitions/Error"
30+
health:
31+
type: string
5832
definitions:
5933
Error:
6034
properties:

0 commit comments

Comments
 (0)