apf-node-common 1.0.109 → 1.0.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ApplicationContextService.js +103 -103
- package/CoreUtils.js +59 -59
- package/Logger/index.js +93 -93
- package/Logger/loggerTransports.js +137 -137
- package/SSMConfig.js +44 -44
- package/ScheduleCalculationService.js +0 -0
- package/auditlog/AuditLogger.js +58 -58
- package/auditlog/AuditLoggerRepository.js +38 -38
- package/auditlog/AuditLoggerService.js +37 -37
- package/config/SSMParameters.js +16 -16
- package/constants/CommonMessages.js +14 -14
- package/constants/Frequency.js +8 -8
- package/constants/TimeZone.js +11 -11
- package/constants/UserType.js +9 -9
- package/exception/CustomException.js +36 -36
- package/exception/SendResponse.js +139 -139
- package/index.js +187 -187
- package/package.json +29 -29
- package/test/AWSUtilityIntegrationTest.js +94 -94
- package/test/FrequencyValidatorTest.js +0 -0
- package/test/LambdaCommunicationServiceTest.js +83 -83
- package/test/ScheduleCalculationServiceTest.js +0 -0
- package/utils/HashIds.js +139 -139
- package/utils/NumberFormatter.js +253 -253
- package/utils/aws/AESEncryptionUsingKMS.js +106 -106
- package/utils/aws/AWSAPIKeyGenerator.js +307 -307
- package/utils/aws/AWSS3Utils.js +128 -128
- package/utils/aws/AWSSMSUtils.js +63 -63
- package/utils/aws/AWSSNSBasedEmailDispatcher.js +37 -37
- package/utils/aws/AWSSNSBasedSMSDispatcher.js +37 -37
- package/utils/aws/AWSSNSUtils.js +38 -38
- package/utils/aws/LambdaCommunicationService.js +232 -232
- package/utils/enumHelper.js +7 -7
- package/utils/thirdparty/URLShorteningService.js +25 -25
- package/validation/CoreValidations.js +45 -45
- package/validation/FrequencyValidator.js +0 -0
- package/validation/SchemaValidation.js +106 -106
package/utils/aws/AWSS3Utils.js
CHANGED
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
const log = require('../../Logger').getLogger();
|
|
2
|
-
const AWS = require('aws-sdk');
|
|
3
|
-
|
|
4
|
-
const awsEnv = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
5
|
-
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
6
|
-
AWS.config.update({ region: awsRegion });
|
|
7
|
-
|
|
8
|
-
var s3 = new AWS.S3();
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
|
|
12
|
-
/* This api is used to get file from s3 bucket */
|
|
13
|
-
async getS3File(bucket,file) {
|
|
14
|
-
|
|
15
|
-
log.info("AWSUtility : getS3File Start ");
|
|
16
|
-
try{
|
|
17
|
-
validate(bucket, file);
|
|
18
|
-
const params = {
|
|
19
|
-
Bucket: bucket,
|
|
20
|
-
Key: file
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const response = await s3.getObject(params).promise();
|
|
24
|
-
let content = response.Body.toString();
|
|
25
|
-
log.info(`s3 response - ${content}`);
|
|
26
|
-
log.info("AWSUtility : getS3File End ");
|
|
27
|
-
return content;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
log.info(`error occured while fetching ${file} file from s3 bucket ${bucket}`);
|
|
30
|
-
log.error("AWSUtility : getS3File Error : " + error.message);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
/* This api is used to get file from s3 bucket */
|
|
35
|
-
async getS3FileStream(bucket,file) {
|
|
36
|
-
|
|
37
|
-
log.info("AWSUtility : getS3File Start ");
|
|
38
|
-
try{
|
|
39
|
-
validate(bucket, file);
|
|
40
|
-
const params = {
|
|
41
|
-
Bucket: bucket,
|
|
42
|
-
Key: file
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const response = await s3.getObject(params).promise();
|
|
46
|
-
let content = response.Body;
|
|
47
|
-
log.info("AWSUtility : getS3File End ");
|
|
48
|
-
return content;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
log.info(`error occured while fetching ${file} file from s3 bucket ${bucket}`);
|
|
51
|
-
log.error("AWSUtility : getS3File Error : " + error.message);
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
async deleteS3File(bucket, file, content, contentType) {
|
|
56
|
-
|
|
57
|
-
log.info("AWSUtility : deleteS3File Start ");
|
|
58
|
-
try {
|
|
59
|
-
|
|
60
|
-
validate(bucket, file);
|
|
61
|
-
const params = {
|
|
62
|
-
Bucket: bucket,
|
|
63
|
-
Key: file
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const response = await s3.deleteObject(params).promise();
|
|
67
|
-
|
|
68
|
-
log.info(`${file} deleteS3File successfully on s3 ${response}`);
|
|
69
|
-
log.info("AWSUtility : deleteS3File End ");
|
|
70
|
-
return content;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
log.info(`error occured while uploading ${file} file to s3 bucket ${bucket}`)
|
|
73
|
-
|
|
74
|
-
log.error("AWSUtility : deleteS3File Error : " + error);
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
async putS3File(bucket,file,content,contentType) {
|
|
79
|
-
|
|
80
|
-
log.info("AWSUtility : putS3File Start ");
|
|
81
|
-
try{
|
|
82
|
-
if (content === undefined) {
|
|
83
|
-
log.info('content is invalid');
|
|
84
|
-
throw new Error('content is invalid');
|
|
85
|
-
}
|
|
86
|
-
validate(bucket, file);
|
|
87
|
-
const params = {
|
|
88
|
-
Bucket: bucket,
|
|
89
|
-
Key: file,
|
|
90
|
-
Body: content,
|
|
91
|
-
ACL: 'public-read'
|
|
92
|
-
};
|
|
93
|
-
if(contentType!= undefined && contentType != null && contentType != ""){
|
|
94
|
-
params.ContentType = contentType
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/* const response = await s3.putObject(params, (err) => {
|
|
100
|
-
if (err) {
|
|
101
|
-
log.info(`error occured while uploading ${file} file to s3 bucket ${bucket}`)
|
|
102
|
-
}
|
|
103
|
-
}).promise();*/
|
|
104
|
-
const response = await s3.putObject(params).promise();
|
|
105
|
-
|
|
106
|
-
log.info(`${file} uploaded successfully on s3 ${response}`);
|
|
107
|
-
log.info("AWSUtility : putS3File End ");
|
|
108
|
-
return content;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
log.info(`error occured while uploading ${file} file to s3 bucket ${bucket}`)
|
|
111
|
-
|
|
112
|
-
log.error("AWSUtility : putS3File Error : " + error);
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function validate(bucket, file) {
|
|
118
|
-
if (bucket === undefined) {
|
|
119
|
-
log.error('bucket name is invalid');
|
|
120
|
-
throw new Error('bucket name is invalid');
|
|
121
|
-
}
|
|
122
|
-
else if (file === undefined) {
|
|
123
|
-
log.error('file name is invalid');
|
|
124
|
-
throw new Error('file name is invalid');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
const log = require('../../Logger').getLogger();
|
|
2
|
+
const AWS = require('aws-sdk');
|
|
3
|
+
|
|
4
|
+
const awsEnv = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
5
|
+
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
6
|
+
AWS.config.update({ region: awsRegion });
|
|
7
|
+
|
|
8
|
+
var s3 = new AWS.S3();
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
|
|
12
|
+
/* This api is used to get file from s3 bucket */
|
|
13
|
+
async getS3File(bucket,file) {
|
|
14
|
+
|
|
15
|
+
log.info("AWSUtility : getS3File Start ");
|
|
16
|
+
try{
|
|
17
|
+
validate(bucket, file);
|
|
18
|
+
const params = {
|
|
19
|
+
Bucket: bucket,
|
|
20
|
+
Key: file
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const response = await s3.getObject(params).promise();
|
|
24
|
+
let content = response.Body.toString();
|
|
25
|
+
log.info(`s3 response - ${content}`);
|
|
26
|
+
log.info("AWSUtility : getS3File End ");
|
|
27
|
+
return content;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
log.info(`error occured while fetching ${file} file from s3 bucket ${bucket}`);
|
|
30
|
+
log.error("AWSUtility : getS3File Error : " + error.message);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
/* This api is used to get file from s3 bucket */
|
|
35
|
+
async getS3FileStream(bucket,file) {
|
|
36
|
+
|
|
37
|
+
log.info("AWSUtility : getS3File Start ");
|
|
38
|
+
try{
|
|
39
|
+
validate(bucket, file);
|
|
40
|
+
const params = {
|
|
41
|
+
Bucket: bucket,
|
|
42
|
+
Key: file
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const response = await s3.getObject(params).promise();
|
|
46
|
+
let content = response.Body;
|
|
47
|
+
log.info("AWSUtility : getS3File End ");
|
|
48
|
+
return content;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
log.info(`error occured while fetching ${file} file from s3 bucket ${bucket}`);
|
|
51
|
+
log.error("AWSUtility : getS3File Error : " + error.message);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
async deleteS3File(bucket, file, content, contentType) {
|
|
56
|
+
|
|
57
|
+
log.info("AWSUtility : deleteS3File Start ");
|
|
58
|
+
try {
|
|
59
|
+
|
|
60
|
+
validate(bucket, file);
|
|
61
|
+
const params = {
|
|
62
|
+
Bucket: bucket,
|
|
63
|
+
Key: file
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const response = await s3.deleteObject(params).promise();
|
|
67
|
+
|
|
68
|
+
log.info(`${file} deleteS3File successfully on s3 ${response}`);
|
|
69
|
+
log.info("AWSUtility : deleteS3File End ");
|
|
70
|
+
return content;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
log.info(`error occured while uploading ${file} file to s3 bucket ${bucket}`)
|
|
73
|
+
|
|
74
|
+
log.error("AWSUtility : deleteS3File Error : " + error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async putS3File(bucket,file,content,contentType) {
|
|
79
|
+
|
|
80
|
+
log.info("AWSUtility : putS3File Start ");
|
|
81
|
+
try{
|
|
82
|
+
if (content === undefined) {
|
|
83
|
+
log.info('content is invalid');
|
|
84
|
+
throw new Error('content is invalid');
|
|
85
|
+
}
|
|
86
|
+
validate(bucket, file);
|
|
87
|
+
const params = {
|
|
88
|
+
Bucket: bucket,
|
|
89
|
+
Key: file,
|
|
90
|
+
Body: content,
|
|
91
|
+
ACL: 'public-read'
|
|
92
|
+
};
|
|
93
|
+
if(contentType!= undefined && contentType != null && contentType != ""){
|
|
94
|
+
params.ContentType = contentType
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
/* const response = await s3.putObject(params, (err) => {
|
|
100
|
+
if (err) {
|
|
101
|
+
log.info(`error occured while uploading ${file} file to s3 bucket ${bucket}`)
|
|
102
|
+
}
|
|
103
|
+
}).promise();*/
|
|
104
|
+
const response = await s3.putObject(params).promise();
|
|
105
|
+
|
|
106
|
+
log.info(`${file} uploaded successfully on s3 ${response}`);
|
|
107
|
+
log.info("AWSUtility : putS3File End ");
|
|
108
|
+
return content;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
log.info(`error occured while uploading ${file} file to s3 bucket ${bucket}`)
|
|
111
|
+
|
|
112
|
+
log.error("AWSUtility : putS3File Error : " + error);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function validate(bucket, file) {
|
|
118
|
+
if (bucket === undefined) {
|
|
119
|
+
log.error('bucket name is invalid');
|
|
120
|
+
throw new Error('bucket name is invalid');
|
|
121
|
+
}
|
|
122
|
+
else if (file === undefined) {
|
|
123
|
+
log.error('file name is invalid');
|
|
124
|
+
throw new Error('file name is invalid');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
package/utils/aws/AWSSMSUtils.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
const log = require('../../Logger').getLogger();
|
|
2
|
-
const AWS = require('aws-sdk');
|
|
3
|
-
|
|
4
|
-
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
5
|
-
const awsRegion = 'us-east-1';//(process.env.AWS_DEFAULT_REGION || 'us-east-1');
|
|
6
|
-
AWS.config.update({ region: awsRegion });
|
|
7
|
-
|
|
8
|
-
var sns = new AWS.SNS({apiVersion: '2010-03-31'});
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
|
|
12
|
-
async sendSMS(smsParams) {
|
|
13
|
-
validate(smsParams);
|
|
14
|
-
try{
|
|
15
|
-
var params = {
|
|
16
|
-
Message: smsParams.message, /* required */
|
|
17
|
-
PhoneNumber: smsParams.phoneNumber,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const data = await sns.publish({
|
|
21
|
-
PhoneNumber: smsParams.phoneNumber,
|
|
22
|
-
Message: smsParams.message,
|
|
23
|
-
MessageAttributes:{
|
|
24
|
-
'AWS.SNS.SMS.SenderID': {
|
|
25
|
-
'DataType': 'String',
|
|
26
|
-
'StringValue': 'aurionpro'
|
|
27
|
-
},
|
|
28
|
-
'AWS.SNS.SMS.SMSType': {
|
|
29
|
-
'DataType': 'String',
|
|
30
|
-
'StringValue': 'Transactional'
|
|
31
|
-
}
|
|
32
|
-
}}
|
|
33
|
-
).promise();
|
|
34
|
-
console.log("MessageID is " + data.MessageId);
|
|
35
|
-
|
|
36
|
-
return data.MessageId;
|
|
37
|
-
|
|
38
|
-
}catch(error){
|
|
39
|
-
log.error(`error occured while sending sms`)
|
|
40
|
-
log.error(error, error.stack);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function validate(smsParams) {
|
|
46
|
-
if (!smsParams) {
|
|
47
|
-
console.log('smsParams request is required.');
|
|
48
|
-
throw new Error('smsParams request is required.');
|
|
49
|
-
}
|
|
50
|
-
else if (!smsParams.message) {
|
|
51
|
-
console.log('message is required.');
|
|
52
|
-
throw new Error('message is required.');
|
|
53
|
-
}
|
|
54
|
-
else if (!smsParams.phoneNumber) {
|
|
55
|
-
console.log('phoneNumber is required.');
|
|
56
|
-
throw new Error('phoneNumber is required.');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
const log = require('../../Logger').getLogger();
|
|
2
|
+
const AWS = require('aws-sdk');
|
|
3
|
+
|
|
4
|
+
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
5
|
+
const awsRegion = 'us-east-1';//(process.env.AWS_DEFAULT_REGION || 'us-east-1');
|
|
6
|
+
AWS.config.update({ region: awsRegion });
|
|
7
|
+
|
|
8
|
+
var sns = new AWS.SNS({apiVersion: '2010-03-31'});
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
|
|
12
|
+
async sendSMS(smsParams) {
|
|
13
|
+
validate(smsParams);
|
|
14
|
+
try{
|
|
15
|
+
var params = {
|
|
16
|
+
Message: smsParams.message, /* required */
|
|
17
|
+
PhoneNumber: smsParams.phoneNumber,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const data = await sns.publish({
|
|
21
|
+
PhoneNumber: smsParams.phoneNumber,
|
|
22
|
+
Message: smsParams.message,
|
|
23
|
+
MessageAttributes:{
|
|
24
|
+
'AWS.SNS.SMS.SenderID': {
|
|
25
|
+
'DataType': 'String',
|
|
26
|
+
'StringValue': 'aurionpro'
|
|
27
|
+
},
|
|
28
|
+
'AWS.SNS.SMS.SMSType': {
|
|
29
|
+
'DataType': 'String',
|
|
30
|
+
'StringValue': 'Transactional'
|
|
31
|
+
}
|
|
32
|
+
}}
|
|
33
|
+
).promise();
|
|
34
|
+
console.log("MessageID is " + data.MessageId);
|
|
35
|
+
|
|
36
|
+
return data.MessageId;
|
|
37
|
+
|
|
38
|
+
}catch(error){
|
|
39
|
+
log.error(`error occured while sending sms`)
|
|
40
|
+
log.error(error, error.stack);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function validate(smsParams) {
|
|
46
|
+
if (!smsParams) {
|
|
47
|
+
console.log('smsParams request is required.');
|
|
48
|
+
throw new Error('smsParams request is required.');
|
|
49
|
+
}
|
|
50
|
+
else if (!smsParams.message) {
|
|
51
|
+
console.log('message is required.');
|
|
52
|
+
throw new Error('message is required.');
|
|
53
|
+
}
|
|
54
|
+
else if (!smsParams.phoneNumber) {
|
|
55
|
+
console.log('phoneNumber is required.');
|
|
56
|
+
throw new Error('phoneNumber is required.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
const log = require('../../Logger').getLogger();
|
|
2
|
-
const AWS = require('aws-sdk');
|
|
3
|
-
|
|
4
|
-
const AWSSNSUtils = require('./AWSSNSUtils');
|
|
5
|
-
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
6
|
-
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
7
|
-
|
|
8
|
-
AWS.config.update({ region: awsRegion });
|
|
9
|
-
const topicName = "Infrastructure-EmailHandler";
|
|
10
|
-
const subject = 'Infrastructure-EmailHandler';
|
|
11
|
-
|
|
12
|
-
var sns = new AWS.SNS();
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
|
|
16
|
-
async dispatchNotification(tagData, context) {
|
|
17
|
-
const messageAttributes = getAttributs(context);
|
|
18
|
-
await AWSSNSUtils.publish(topicName, subject, JSON.stringify(tagData),messageAttributes);
|
|
19
|
-
log.info('email notification published!!')
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getAttributs(context) {
|
|
25
|
-
let messageAttributes = {};
|
|
26
|
-
context.forEach((contextValue) =>{
|
|
27
|
-
var value = {
|
|
28
|
-
DataType : "String",
|
|
29
|
-
StringValue : contextValue.Value
|
|
30
|
-
}
|
|
31
|
-
messageAttributes[contextValue.Key] = value;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return messageAttributes;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
const log = require('../../Logger').getLogger();
|
|
2
|
+
const AWS = require('aws-sdk');
|
|
3
|
+
|
|
4
|
+
const AWSSNSUtils = require('./AWSSNSUtils');
|
|
5
|
+
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
6
|
+
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
7
|
+
|
|
8
|
+
AWS.config.update({ region: awsRegion });
|
|
9
|
+
const topicName = "Infrastructure-EmailHandler";
|
|
10
|
+
const subject = 'Infrastructure-EmailHandler';
|
|
11
|
+
|
|
12
|
+
var sns = new AWS.SNS();
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
|
|
16
|
+
async dispatchNotification(tagData, context) {
|
|
17
|
+
const messageAttributes = getAttributs(context);
|
|
18
|
+
await AWSSNSUtils.publish(topicName, subject, JSON.stringify(tagData),messageAttributes);
|
|
19
|
+
log.info('email notification published!!')
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getAttributs(context) {
|
|
25
|
+
let messageAttributes = {};
|
|
26
|
+
context.forEach((contextValue) =>{
|
|
27
|
+
var value = {
|
|
28
|
+
DataType : "String",
|
|
29
|
+
StringValue : contextValue.Value
|
|
30
|
+
}
|
|
31
|
+
messageAttributes[contextValue.Key] = value;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return messageAttributes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
const log = require('../../Logger').getLogger();
|
|
2
|
-
const AWS = require('aws-sdk');
|
|
3
|
-
|
|
4
|
-
const AWSSNSUtils = require('./AWSSNSUtils');
|
|
5
|
-
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
6
|
-
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
7
|
-
|
|
8
|
-
AWS.config.update({ region: awsRegion });
|
|
9
|
-
const topicName = "Infrastructure-SmsHandler";
|
|
10
|
-
const subject = 'Infrastructure-SmsHandler';
|
|
11
|
-
|
|
12
|
-
var sns = new AWS.SNS();
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
|
|
16
|
-
async dispatchNotification(tagData, context) {
|
|
17
|
-
const messageAttributes = getAttributs(context);
|
|
18
|
-
await AWSSNSUtils.publish(topicName, subject, JSON.stringify(tagData),messageAttributes);
|
|
19
|
-
log.info('sms notification published!!')
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function getAttributs(context) {
|
|
25
|
-
let messageAttributes = {};
|
|
26
|
-
context.forEach((contextValue) =>{
|
|
27
|
-
var value = {
|
|
28
|
-
DataType : "String",
|
|
29
|
-
StringValue : contextValue.Value
|
|
30
|
-
}
|
|
31
|
-
messageAttributes[contextValue.Key] = value;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
return messageAttributes;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
const log = require('../../Logger').getLogger();
|
|
2
|
+
const AWS = require('aws-sdk');
|
|
3
|
+
|
|
4
|
+
const AWSSNSUtils = require('./AWSSNSUtils');
|
|
5
|
+
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
6
|
+
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
7
|
+
|
|
8
|
+
AWS.config.update({ region: awsRegion });
|
|
9
|
+
const topicName = "Infrastructure-SmsHandler";
|
|
10
|
+
const subject = 'Infrastructure-SmsHandler';
|
|
11
|
+
|
|
12
|
+
var sns = new AWS.SNS();
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
|
|
16
|
+
async dispatchNotification(tagData, context) {
|
|
17
|
+
const messageAttributes = getAttributs(context);
|
|
18
|
+
await AWSSNSUtils.publish(topicName, subject, JSON.stringify(tagData),messageAttributes);
|
|
19
|
+
log.info('sms notification published!!')
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getAttributs(context) {
|
|
25
|
+
let messageAttributes = {};
|
|
26
|
+
context.forEach((contextValue) =>{
|
|
27
|
+
var value = {
|
|
28
|
+
DataType : "String",
|
|
29
|
+
StringValue : contextValue.Value
|
|
30
|
+
}
|
|
31
|
+
messageAttributes[contextValue.Key] = value;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return messageAttributes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
package/utils/aws/AWSSNSUtils.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
const log = require('../../Logger').getLogger();
|
|
2
|
-
const AWS = require('aws-sdk');
|
|
3
|
-
|
|
4
|
-
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
5
|
-
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
6
|
-
AWS.config.update({ region: awsRegion });
|
|
7
|
-
AuditLogger = require("../../auditlog/AuditLogger");
|
|
8
|
-
var sns = new AWS.SNS({apiVersion: '2010-03-31'});
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
|
|
12
|
-
async publish(topic, subject, message,messageAttributes) {
|
|
13
|
-
var arn = '';
|
|
14
|
-
try{
|
|
15
|
-
const topicName = `${environment}-${topic}`;
|
|
16
|
-
|
|
17
|
-
var response = await sns.createTopic({ Name: topicName }).promise();
|
|
18
|
-
arn = response.TopicArn;
|
|
19
|
-
const snsParameters = {
|
|
20
|
-
Message: message,
|
|
21
|
-
MessageAttributes:messageAttributes,
|
|
22
|
-
Subject: subject,
|
|
23
|
-
TopicArn: arn
|
|
24
|
-
};
|
|
25
|
-
log.info("Topic ARN is " + arn);
|
|
26
|
-
var data = await sns.publish(snsParameters).promise();
|
|
27
|
-
|
|
28
|
-
log.info("MessageID is " + data.MessageId);
|
|
29
|
-
let auditLogger = new AuditLogger();
|
|
30
|
-
await auditLogger.audit(message, subject,messageAttributes);
|
|
31
|
-
}catch(error){
|
|
32
|
-
log.error(`error occured while publishing event ${subject} to SNS `)
|
|
33
|
-
log.error(error, error.stack);
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
1
|
+
const log = require('../../Logger').getLogger();
|
|
2
|
+
const AWS = require('aws-sdk');
|
|
3
|
+
|
|
4
|
+
const environment = (process.env.NODE_ENVIRONMENT || 'Test');
|
|
5
|
+
const awsRegion = (process.env.AWS_DEFAULT_REGION || 'us-east-2');
|
|
6
|
+
AWS.config.update({ region: awsRegion });
|
|
7
|
+
AuditLogger = require("../../auditlog/AuditLogger");
|
|
8
|
+
var sns = new AWS.SNS({apiVersion: '2010-03-31'});
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
|
|
12
|
+
async publish(topic, subject, message,messageAttributes) {
|
|
13
|
+
var arn = '';
|
|
14
|
+
try{
|
|
15
|
+
const topicName = `${environment}-${topic}`;
|
|
16
|
+
|
|
17
|
+
var response = await sns.createTopic({ Name: topicName }).promise();
|
|
18
|
+
arn = response.TopicArn;
|
|
19
|
+
const snsParameters = {
|
|
20
|
+
Message: message,
|
|
21
|
+
MessageAttributes:messageAttributes,
|
|
22
|
+
Subject: subject,
|
|
23
|
+
TopicArn: arn
|
|
24
|
+
};
|
|
25
|
+
log.info("Topic ARN is " + arn);
|
|
26
|
+
var data = await sns.publish(snsParameters).promise();
|
|
27
|
+
|
|
28
|
+
log.info("MessageID is " + data.MessageId);
|
|
29
|
+
let auditLogger = new AuditLogger();
|
|
30
|
+
await auditLogger.audit(message, subject,messageAttributes);
|
|
31
|
+
}catch(error){
|
|
32
|
+
log.error(`error occured while publishing event ${subject} to SNS `)
|
|
33
|
+
log.error(error, error.stack);
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|