Skip to content

Commit

Permalink
Merge branch 'master' into 2367-move-documentation-site-to-aws
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Grayson authored Dec 15, 2023
2 parents d083943 + caf785a commit 26fd3cf
Show file tree
Hide file tree
Showing 6 changed files with 514 additions and 602 deletions.
2 changes: 2 additions & 0 deletions backend/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ staging:
PE_CLUSTER_NAME: pe-staging-worker
SHODAN_QUEUE_URL: ${ssm:/crossfeed/staging/SHODAN_QUEUE_URL}
SHODAN_SERVICE_NAME: pe-staging-shodan
EMAIL_BUCKET_NAME: cisa-crossfeed-staging-html-email

prod:
DB_DIALECT: 'postgres'
Expand Down Expand Up @@ -86,6 +87,7 @@ prod:
PE_CLUSTER_NAME: pe-prod-worker
SHODAN_QUEUE_URL: ${ssm:/crossfeed/prod/SHODAN_QUEUE_URL}
SHODAN_SERVICE_NAME: pe-prod-shodan
EMAIL_BUCKET_NAME: cisa-crossfeed-staging-html-email

dev-vpc:
securityGroupIds:
Expand Down
40 changes: 20 additions & 20 deletions backend/src/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as nodemailer from 'nodemailer';
import * as fs from 'fs';
import * as handlebars from 'handlebars';
import * as util from 'util';
import S3Client from '../tasks/s3-client';

export const validateBody = async <T>(
obj: ClassType<T>,
Expand Down Expand Up @@ -111,8 +112,8 @@ export const sendUserNotificationEmail = async (
SES: new SES({ region: 'us-east-1' })
});

const fs = require('fs').promises;
const html = await fs.readFile(template_file, 'utf8');
const client = new S3Client();
const html = await client.getEmailAsset(template_file);
const template = handlebars.compile(html);
const data = {
first_name: p_firstName,
Expand All @@ -129,37 +130,37 @@ export const sendUserNotificationEmail = async (
attachments: [
{
filename: 'banner.png',
path: '/app/src/email_templates/banner.png',
content: await client.getEmailAsset('banner.png'),
cid: 'CISA Banner'
},
{
filename: 'web.png',
path: '/app/src/email_templates/banner.png',
content: await client.getEmailAsset('banner.png'),
cid: 'CISA Web'
},
{
filename: 'email.png',
path: '/app/src/email_templates/email.png',
content: await client.getEmailAsset('email.png'),
cid: 'CISA Email'
},
{
filename: 'linkedin.png',
path: '/app/src/email_templates/linkedin.png',
content: await client.getEmailAsset('linkedin.png'),
cid: 'CISA LinkedIn'
},
{
filename: 'twitter.png',
path: '/app/src/email_templates/twitter.png',
content: await client.getEmailAsset('twitter.png'),
cid: 'CISA Twitter'
},
{
filename: 'facebook.png',
path: '/app/src/email_templates/facebooK.png',
content: await client.getEmailAsset('facebooK.png'),
cid: 'CISA Facebook'
},
{
filename: 'instagram.png',
path: '/app/src/email_templates/instagram.png',
content: await client.getEmailAsset('instagram.png'),
cid: 'CISA Instagram'
}
]
Expand All @@ -179,10 +180,9 @@ export const sendRegionalAdminNotificationEmail = async (
SES: new SES({ region: 'us-east-1' })
});

const fs = require('fs').promises;
const html = await fs.readFile(
'/app/src/email_templates/crossfeed_regional_admin_notification.html',
'utf8'
const client = new S3Client();
const html = await client.getEmailAsset(
'crossfeed_regional_admin_notification.html'
);
const template = handlebars.compile(html);
const data = {
Expand All @@ -200,37 +200,37 @@ export const sendRegionalAdminNotificationEmail = async (
attachments: [
{
filename: 'banner.png',
path: '/app/src/email_templates/banner.png',
content: await client.getEmailAsset('banner.png'),
cid: 'CISA Banner'
},
{
filename: 'web.png',
path: '/app/src/email_templates/banner.png',
content: await client.getEmailAsset('banner.png'),
cid: 'CISA Web'
},
{
filename: 'email.png',
path: '/app/src/email_templates/email.png',
content: await client.getEmailAsset('email.png'),
cid: 'CISA Email'
},
{
filename: 'linkedin.png',
path: '/app/src/email_templates/linkedin.png',
content: await client.getEmailAsset('linkedin.png'),
cid: 'CISA LinkedIn'
},
{
filename: 'twitter.png',
path: '/app/src/email_templates/twitter.png',
content: await client.getEmailAsset('twitter.png'),
cid: 'CISA Twitter'
},
{
filename: 'facebook.png',
path: '/app/src/email_templates/facebooK.png',
content: await client.getEmailAsset('facebooK.png'),
cid: 'CISA Facebook'
},
{
filename: 'instagram.png',
path: '/app/src/email_templates/instagram.png',
content: await client.getEmailAsset('instagram.png'),
cid: 'CISA Instagram'
}
]
Expand Down
22 changes: 22 additions & 0 deletions backend/src/tasks/s3-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class S3Client {
throw e;
}
}

async listReports(orgId: string) {
try {
const params = {
Expand All @@ -93,6 +94,27 @@ class S3Client {
throw e;
}
}

async getEmailAsset(fileName: string) {
try {
const params = {
Bucket: process.env.EMAIL_BUCKET_NAME!,
Key: fileName
};

const data = await this.s3
.getObject(params, function (err, data) {
if (err) throw err;
})
.promise();
if (data && data.Body) {
return data.Body.toString('utf-8');
}
} catch (e) {
console.error(e);
throw e;
}
}
}

export default S3Client;
2 changes: 2 additions & 0 deletions dev.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ EXPORT_BUCKET_NAME=crossfeed-local-exports

REPORTS_BUCKET_NAME=crossfeed-local-reports

EMAIL_BUCKET_NAME=cisa-crossfeed-staging-html-email

IS_LOCAL=1
Loading

0 comments on commit 26fd3cf

Please sign in to comment.