Skip to content

Commit 4d513bc

Browse files
authored
chore: remove postman old credentials (#839)
## Problem After migrating over to the new postman credentials: [email protected], the old ones are not needed anymore. ## Solution Remove the LD flag, and old credentials ## TODOs - [ ] Remove the env variables and deploy to UAT/staging to test it works - [ ] Remove env variable for prod before deploying to prod - [ ] Remove LD flag once deployed to prod ## Tests - OTP emails can be received from the correct email - Emails can be sent from the postman action
1 parent 2def4fd commit 4d513bc

File tree

6 files changed

+4
-57
lines changed

6 files changed

+4
-57
lines changed

ecs/env.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
"name": "POSTMAN_FROM_ADDRESS",
3737
"value": "[email protected]"
3838
},
39-
{
40-
"name": "POSTMAN_OLD_FROM_ADDRESS",
41-
"value": "[email protected]"
42-
},
4339
{
4440
"name": "ADMIN_USER_EMAIL",
4541
"value": "[email protected]"
@@ -114,10 +110,6 @@
114110
"name": "POSTMAN_API_KEY",
115111
"valueFrom": "plumber-<ENVIRONMENT>-postman-api-key"
116112
},
117-
{
118-
"name": "POSTMAN_OLD_API_KEY",
119-
"valueFrom": "plumber-<ENVIRONMENT>-postman-old-api-key"
120-
},
121113
{
122114
"name": "FORMSG_API_KEY",
123115
"valueFrom": "plumber-formsg-api-key"

packages/backend/.env-example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ REDIS_CLUSTER_MODE=false
2020
ENABLE_BULLMQ_DASHBOARD=false
2121
2222
POSTMAN_API_KEY=api_key
23-
POSTMAN_OLD_API_KEY=api_key
2423
FORMSG_API_KEY=sample-formsg-api-key
2524
FORMSG_STAGING_API_KEY=sample-formsg-api-key
2625
FORMSG_UAT_API_KEY=sample-formsg-api-key

packages/backend/src/apps/postman/__tests__/actions/send-transactional-email.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const mocks = vi.hoisted(() => ({
1414
getObjectFromS3Id: vi.fn(),
1515
getDefaultReplyTo: vi.fn(() => '[email protected]'),
1616
sendBlacklistEmail: vi.fn(),
17-
getLdFlagValue: vi.fn(),
1817
}))
1918

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

40-
vi.mock('@/helpers/launch-darkly', () => ({
41-
getLdFlagValue: mocks.getLdFlagValue,
42-
}))
43-
4439
describe('send transactional email', () => {
4540
let $: IGlobalVariable
4641

packages/backend/src/apps/postman/common/email-helper.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { sortBy } from 'lodash'
55

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

109
import {
1110
PostmanEmailDataOut,
@@ -80,24 +79,14 @@ export async function sendTransactionalEmails(
8079
errorStatus?: PostmanEmailSendStatus
8180
error?: HttpError
8281
}> {
83-
const shouldUseNewCredentials = await getLdFlagValue<boolean>(
84-
'new_postman_credentials',
85-
'[email protected]', // mock email
86-
false,
87-
)
88-
8982
const promises = recipients.map(async (recipientEmail) => {
9083
const requestData = new FormData()
9184
requestData.append('subject', email.subject)
9285
requestData.append('body', email.body)
9386
requestData.append('recipient', recipientEmail)
9487
requestData.append(
9588
'from',
96-
`${email.senderName} <${
97-
shouldUseNewCredentials
98-
? appConfig.postman.fromAddress
99-
: appConfig.postman.oldFromAddress
100-
}>`,
89+
`${email.senderName} <${appConfig.postman.fromAddress}>`,
10190
)
10291
requestData.append('disable_tracking', 'true')
10392
if (email.ccList?.length > 0) {
@@ -123,11 +112,7 @@ export async function sendTransactionalEmails(
123112
{
124113
headers: {
125114
...requestData.getHeaders(),
126-
Authorization: `Bearer ${
127-
shouldUseNewCredentials
128-
? appConfig.postman.apiKey
129-
: appConfig.postman.oldApiKey
130-
}`,
115+
Authorization: `Bearer ${appConfig.postman.apiKey}`,
131116
},
132117
},
133118
)

packages/backend/src/config/app.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ type AppConfig = {
3636
apiKey: string
3737
fromAddress: string
3838
rateLimit: number
39-
oldApiKey: string
40-
oldFromAddress: string
4139
}
4240
isWorker: boolean
4341
workerActionConcurrency: number
@@ -104,9 +102,6 @@ const appConfig: AppConfig = {
104102
apiKey: process.env.POSTMAN_API_KEY,
105103
fromAddress: process.env.POSTMAN_FROM_ADDRESS || '[email protected]',
106104
rateLimit: parseInt(process.env.POSTMAN_RATE_LIMIT) || 169,
107-
oldApiKey: process.env.POSTMAN_OLD_API_KEY,
108-
oldFromAddress:
109-
process.env.POSTMAN_OLD_FROM_ADDRESS || '[email protected]',
110105
},
111106
launchDarklySdkKey: process.env.LAUNCH_DARKLY_SDK_KEY,
112107
maxJobAttempts: Number(process.env.MAX_JOB_ATTEMPTS ?? '10'),
@@ -128,10 +123,6 @@ if (!appConfig.postman.apiKey) {
128123
throw new Error('POSTMAN_API_KEY environment variable needs to be set!')
129124
}
130125

131-
if (!appConfig.postman.oldApiKey) {
132-
throw new Error('POSTMAN_OLD_API_KEY environment variable needs to be set!')
133-
}
134-
135126
if (
136127
!appConfig.sgid ||
137128
!appConfig.sgid.clientId ||

packages/backend/src/helpers/send-email.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import axios from 'axios'
33
import appConfig from '@/config/app'
44
import HttpError from '@/errors/http'
55

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

98
export interface PostmanEmailRequestBody {
@@ -20,34 +19,20 @@ export async function sendEmail({
2019
replyTo,
2120
}: PostmanEmailRequestBody): Promise<void> {
2221
try {
23-
const shouldUseNewCredentials = await getLdFlagValue<boolean>(
24-
'new_postman_credentials',
25-
'[email protected]', // mock email
26-
false,
27-
)
28-
2922
await axios.post(
3023
'https://api.postman.gov.sg/v1/transactional/email/send',
3124
{
3225
subject,
3326
body,
3427
recipient,
35-
from: `Plumber <${
36-
shouldUseNewCredentials
37-
? appConfig.postman.fromAddress
38-
: appConfig.postman.oldFromAddress
39-
}>`,
28+
from: `Plumber <${appConfig.postman.fromAddress}>`,
4029
...(replyTo && { reply_to: replyTo }),
4130
disable_tracking: true,
4231
},
4332
{
4433
headers: {
4534
'Content-Type': 'application/json',
46-
Authorization: `Bearer ${
47-
shouldUseNewCredentials
48-
? appConfig.postman.apiKey
49-
: appConfig.postman.oldApiKey
50-
}`,
35+
Authorization: `Bearer ${appConfig.postman.apiKey}`,
5136
},
5237
},
5338
)

0 commit comments

Comments
 (0)