Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove postman old credentials #839

Draft
wants to merge 1 commit into
base: develop-v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ecs/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
"name": "POSTMAN_FROM_ADDRESS",
"value": "[email protected]"
},
{
"name": "POSTMAN_OLD_FROM_ADDRESS",
"value": "[email protected]"
},
{
"name": "ADMIN_USER_EMAIL",
"value": "[email protected]"
Expand Down Expand Up @@ -114,10 +110,6 @@
"name": "POSTMAN_API_KEY",
"valueFrom": "plumber-<ENVIRONMENT>-postman-api-key"
},
{
"name": "POSTMAN_OLD_API_KEY",
"valueFrom": "plumber-<ENVIRONMENT>-postman-old-api-key"
},
{
"name": "FORMSG_API_KEY",
"valueFrom": "plumber-formsg-api-key"
Expand Down
1 change: 0 additions & 1 deletion packages/backend/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ REDIS_CLUSTER_MODE=false
ENABLE_BULLMQ_DASHBOARD=false
[email protected]
POSTMAN_API_KEY=api_key
POSTMAN_OLD_API_KEY=api_key
FORMSG_API_KEY=sample-formsg-api-key
FORMSG_STAGING_API_KEY=sample-formsg-api-key
FORMSG_UAT_API_KEY=sample-formsg-api-key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const mocks = vi.hoisted(() => ({
getObjectFromS3Id: vi.fn(),
getDefaultReplyTo: vi.fn(() => '[email protected]'),
sendBlacklistEmail: vi.fn(),
getLdFlagValue: vi.fn(),
}))

vi.mock('@/helpers/s3', async () => {
Expand All @@ -37,10 +36,6 @@ vi.mock('../../common/send-blacklist-email', () => ({
createRequestBlacklistFormLink: vi.fn(),
}))

vi.mock('@/helpers/launch-darkly', () => ({
getLdFlagValue: mocks.getLdFlagValue,
}))

describe('send transactional email', () => {
let $: IGlobalVariable

Expand Down
19 changes: 2 additions & 17 deletions packages/backend/src/apps/postman/common/email-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { sortBy } from 'lodash'

import appConfig from '@/config/app'
import HttpError from '@/errors/http'
import { getLdFlagValue } from '@/helpers/launch-darkly'

import {
PostmanEmailDataOut,
Expand Down Expand Up @@ -80,24 +79,14 @@ export async function sendTransactionalEmails(
errorStatus?: PostmanEmailSendStatus
error?: HttpError
}> {
const shouldUseNewCredentials = await getLdFlagValue<boolean>(
'new_postman_credentials',
'[email protected]', // mock email
false,
)

const promises = recipients.map(async (recipientEmail) => {
const requestData = new FormData()
requestData.append('subject', email.subject)
requestData.append('body', email.body)
requestData.append('recipient', recipientEmail)
requestData.append(
'from',
`${email.senderName} <${
shouldUseNewCredentials
? appConfig.postman.fromAddress
: appConfig.postman.oldFromAddress
}>`,
`${email.senderName} <${appConfig.postman.fromAddress}>`,
)
requestData.append('disable_tracking', 'true')
if (email.ccList?.length > 0) {
Expand All @@ -123,11 +112,7 @@ export async function sendTransactionalEmails(
{
headers: {
...requestData.getHeaders(),
Authorization: `Bearer ${
shouldUseNewCredentials
? appConfig.postman.apiKey
: appConfig.postman.oldApiKey
}`,
Authorization: `Bearer ${appConfig.postman.apiKey}`,
},
},
)
Expand Down
9 changes: 0 additions & 9 deletions packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ type AppConfig = {
apiKey: string
fromAddress: string
rateLimit: number
oldApiKey: string
oldFromAddress: string
}
isWorker: boolean
workerActionConcurrency: number
Expand Down Expand Up @@ -104,9 +102,6 @@ const appConfig: AppConfig = {
apiKey: process.env.POSTMAN_API_KEY,
fromAddress: process.env.POSTMAN_FROM_ADDRESS || '[email protected]',
rateLimit: parseInt(process.env.POSTMAN_RATE_LIMIT) || 169,
oldApiKey: process.env.POSTMAN_OLD_API_KEY,
oldFromAddress:
process.env.POSTMAN_OLD_FROM_ADDRESS || '[email protected]',
},
launchDarklySdkKey: process.env.LAUNCH_DARKLY_SDK_KEY,
maxJobAttempts: Number(process.env.MAX_JOB_ATTEMPTS ?? '10'),
Expand All @@ -128,10 +123,6 @@ if (!appConfig.postman.apiKey) {
throw new Error('POSTMAN_API_KEY environment variable needs to be set!')
}

if (!appConfig.postman.oldApiKey) {
throw new Error('POSTMAN_OLD_API_KEY environment variable needs to be set!')
}

if (
!appConfig.sgid ||
!appConfig.sgid.clientId ||
Expand Down
19 changes: 2 additions & 17 deletions packages/backend/src/helpers/send-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import axios from 'axios'
import appConfig from '@/config/app'
import HttpError from '@/errors/http'

import { getLdFlagValue } from './launch-darkly'
import logger from './logger'

export interface PostmanEmailRequestBody {
Expand All @@ -20,34 +19,20 @@ export async function sendEmail({
replyTo,
}: PostmanEmailRequestBody): Promise<void> {
try {
const shouldUseNewCredentials = await getLdFlagValue<boolean>(
'new_postman_credentials',
'[email protected]', // mock email
false,
)

await axios.post(
'https://api.postman.gov.sg/v1/transactional/email/send',
{
subject,
body,
recipient,
from: `Plumber <${
shouldUseNewCredentials
? appConfig.postman.fromAddress
: appConfig.postman.oldFromAddress
}>`,
from: `Plumber <${appConfig.postman.fromAddress}>`,
...(replyTo && { reply_to: replyTo }),
disable_tracking: true,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${
shouldUseNewCredentials
? appConfig.postman.apiKey
: appConfig.postman.oldApiKey
}`,
Authorization: `Bearer ${appConfig.postman.apiKey}`,
},
},
)
Expand Down
Loading