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

MCR-4893: Adjust Apollo handler to use feature flag #3099

Closed
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN;

-- AlterTable
ALTER TABLE "EmailSettings" ALTER COLUMN "emailSource" SET DEFAULT '[email protected]',
ALTER COLUMN "devReviewTeamEmails" SET DEFAULT ARRAY['<Dev Team <[email protected]>']::TEXT[],
ALTER COLUMN "helpDeskEmail" SET DEFAULT ARRAY['Helpdesk <[email protected]>']::TEXT[];

-- UpdateRecord
UPDATE "EmailSettings"
SET
"emailSource" = '[email protected]',
"devReviewTeamEmails" = ARRAY['<Dev Team <[email protected]>']::TEXT[],
"helpDeskEmail" = ARRAY['Helpdesk <[email protected]>']::TEXT[]
WHERE id = 1;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN;

-- AlterTable
ALTER TABLE "EmailSettings" ALTER COLUMN "devReviewTeamEmails" SET DEFAULT ARRAY['Dev Team <[email protected]>']::TEXT[];

-- UpdateRecord
UPDATE "EmailSettings"
SET
"devReviewTeamEmails" = ARRAY['Dev Team <[email protected]>']::TEXT[]
WHERE id = 1;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BEGIN;

-- AlterTable
ALTER TABLE "EmailSettings" ALTER COLUMN "emailSource" SET DEFAULT '[email protected]',
ALTER COLUMN "devReviewTeamEmails" SET DEFAULT ARRAY['[email protected]']::TEXT[],
ALTER COLUMN "cmsReviewHelpEmailAddress" SET DEFAULT ARRAY['[email protected]']::TEXT[],
ALTER COLUMN "cmsRateHelpEmailAddress" SET DEFAULT ARRAY['[email protected]']::TEXT[],
ALTER COLUMN "oactEmails" SET DEFAULT ARRAY['[email protected]', '[email protected]']::TEXT[],
ALTER COLUMN "dmcpReviewEmails" SET DEFAULT ARRAY['[email protected]', '[email protected]']::TEXT[],
ALTER COLUMN "dmcpSubmissionEmails" SET DEFAULT ARRAY['[email protected]', '[email protected]']::TEXT[],
ALTER COLUMN "dmcoEmails" SET DEFAULT ARRAY['[email protected]', '[email protected]']::TEXT[],
ALTER COLUMN "helpDeskEmail" SET DEFAULT ARRAY['[email protected]']::TEXT[];

-- Update existing record
UPDATE "EmailSettings"
SET
"emailSource" = '[email protected]',
"devReviewTeamEmails" = ARRAY['[email protected]']::TEXT[],
"cmsReviewHelpEmailAddress" = ARRAY['[email protected]']::TEXT[],
"cmsRateHelpEmailAddress" = ARRAY['[email protected]']::TEXT[],
"oactEmails" = ARRAY['[email protected]', '[email protected]']::TEXT[],
"dmcpReviewEmails" = ARRAY['[email protected]', '[email protected]']::TEXT[],
"dmcpSubmissionEmails" = ARRAY['[email protected]', '[email protected]']::TEXT[],
"dmcoEmails" = ARRAY['[email protected]', '[email protected]']::TEXT[],
"helpDeskEmail" = ARRAY['[email protected]']::TEXT[]
WHERE id = 1;

COMMIT;
16 changes: 8 additions & 8 deletions services/app-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ model ApplicationSettings {
model EmailSettings {
id Int @id @default(1)
emailSource String @default("[email protected]")
devReviewTeamEmails String[] @default(["mc-review@cms.hhs.gov"])
cmsReviewHelpEmailAddress String[] @default(["MCOGDMCOActions <[email protected]>"])
cmsRateHelpEmailAddress String[] @default(["MMCratesetting <[email protected]>"])
oactEmails String[] @default(["OACT Dev1 <[email protected]>","OACT Dev2 <[email protected]>"])
dmcpReviewEmails String[] @default(["DMCP Review Dev1 <[email protected]>", "DMCP Review Dev2 <[email protected]>"])
dmcpSubmissionEmails String[] @default(["DMCP Submission Dev1 <[email protected]>", "DMCP Submission Dev2 <[email protected]>"])
dmcoEmails String[] @default(["DMCO Dev1 <[email protected]>", "DMCO Dev2 <[email protected]>"])
helpDeskEmail String[] @default(["MC_Review_HelpDesk@cms.hhs.gov"])
devReviewTeamEmails String[] @default(["mc-review[email protected]"])
cmsReviewHelpEmailAddress String[] @default(["[email protected]"])
cmsRateHelpEmailAddress String[] @default(["[email protected]"])
oactEmails String[] @default(["[email protected]", "[email protected]"])
dmcpReviewEmails String[] @default(["[email protected]", "[email protected]"])
dmcpSubmissionEmails String[] @default(["[email protected]", "[email protected]"])
dmcoEmails String[] @default(["[email protected]", "[email protected]"])
helpDeskEmail String[] @default(["mc-review-qa+MC_Review_HelpDesk@truss.works"])

applicationSettings ApplicationSettings? @relation(fields: [applicationSettingsId], references: [id])
applicationSettingsId Int? @unique @default(1)
Expand Down
23 changes: 23 additions & 0 deletions services/app-api/src/domain-models/SettingType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { z } from 'zod'

const emailSettingsSchema = z.object({
emailSource: z.string().email(),
devReviewTeamEmails: z.array(z.string().email()),
cmsReviewHelpEmailAddress: z.array(z.string().email()),
cmsRateHelpEmailAddress: z.array(z.string().email()),
oactEmails: z.array(z.string().email()),
dmcpReviewEmails: z.array(z.string().email()),
dmcpSubmissionEmails: z.array(z.string().email()),
dmcoEmails: z.array(z.string().email()),
helpDeskEmail: z.array(z.string().email()),
})

const applicationSettingsSchema = z.object({
emailSettings: emailSettingsSchema,
})

type EmailSettingsType = z.infer<typeof emailSettingsSchema>
type ApplicationSettingsType = z.infer<typeof applicationSettingsSchema>

export type { EmailSettingsType, ApplicationSettingsType }
export { applicationSettingsSchema, emailSettingsSchema }
3 changes: 3 additions & 0 deletions services/app-api/src/domain-models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ export type { APIKeyType } from './apiKey'

export type { AuditDocument } from './DocumentType'
export { auditDocumentSchema } from './DocumentType'

export type { EmailSettingsType, ApplicationSettingsType } from './SettingType'
export { emailSettingsSchema, applicationSettingsSchema } from './SettingType'
125 changes: 30 additions & 95 deletions services/app-api/src/handlers/apollo_gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import {
userFromLocalAuthProvider,
userFromThirdPartyAuthorizer,
} from '../authn'
import { newLocalEmailer, newSESEmailer } from '../emailer'
import { NewPostgresStore } from '../postgres/postgresStore'
import { configureResolvers } from '../resolvers'
import { configurePostgres } from './configuration'
import { configurePostgres, configureEmailer } from './configuration'
import { createTracer } from '../otel/otel_handler'
import {
newAWSEmailParameterStore,
Expand Down Expand Up @@ -233,63 +232,6 @@ async function initializeGQLHandler(): Promise<Handler> {

const store = NewPostgresStore(pgResult)

//Configure email parameter store.
const emailParameterStore =
parameterStoreMode === 'LOCAL'
? newLocalEmailParameterStore()
: newAWSEmailParameterStore()

// Configuring emails using emailParameterStore
// Moving setting these emails down here. We needed to retrieve all emails from parameter store using our
// emailParameterStore because serverless does not like array of strings as env variables.
// For more context see this ticket https://qmacbis.atlassian.net/browse/MR-2539.
const emailSource = await emailParameterStore.getSourceEmail()
const devReviewTeamEmails =
await emailParameterStore.getDevReviewTeamEmails()
const helpDeskEmail = await emailParameterStore.getHelpDeskEmail()
const cmsReviewHelpEmailAddress =
await emailParameterStore.getCmsReviewHelpEmail()
const cmsRateHelpEmailAddress =
await emailParameterStore.getCmsRateHelpEmail()
const oactEmails = await emailParameterStore.getOACTEmails()
const dmcpReviewEmails = await emailParameterStore.getDMCPReviewEmails()
const dmcpSubmissionEmails =
await emailParameterStore.getDMCPSubmissionEmails()
const dmcoEmails = await emailParameterStore.getDMCOEmails()

if (emailSource instanceof Error)
throw new Error(`Configuration Error: ${emailSource.message}`)

if (devReviewTeamEmails instanceof Error)
throw new Error(`Configuration Error: ${devReviewTeamEmails.message}`)

if (helpDeskEmail instanceof Error)
throw new Error(`Configuration Error: ${helpDeskEmail.message}`)

if (cmsReviewHelpEmailAddress instanceof Error) {
throw new Error(
`Configuration Error: ${cmsReviewHelpEmailAddress.message}`
)
}

if (cmsRateHelpEmailAddress instanceof Error) {
throw new Error(
`Configuration Error: ${cmsRateHelpEmailAddress.message}`
)
}

if (oactEmails instanceof Error)
throw new Error(`Configuration Error: ${oactEmails.message}`)

if (dmcpReviewEmails instanceof Error)
throw new Error(`Configuration Error: ${dmcpReviewEmails.message}`)

if (dmcpSubmissionEmails instanceof Error)
throw new Error(`Configuration Error: ${dmcpSubmissionEmails.message}`)

if (dmcoEmails instanceof Error)
throw new Error(`Configuration Error: ${dmcoEmails.message}`)

// Configure LaunchDarkly
const ldOptions: ld.LDOptions = {
streamUri: 'https://stream.launchdarkly.us',
Expand Down Expand Up @@ -328,46 +270,27 @@ async function initializeGQLHandler(): Promise<Handler> {
expirationDurationS: 90 * 24 * 60 * 60, // 90 days
})

// Print out all the variables we've been configured with. Leave sensitive ones out, please.
console.info('Running With Config: ', {
authMode,
//Configure email parameter store.
const emailParameterStore =
parameterStoreMode === 'LOCAL'
? newLocalEmailParameterStore()
: newAWSEmailParameterStore()

const emailer = await configureEmailer({
emailParameterStore,
store,
ldService: launchDarkly,
stageName,
dbURL,
applicationEndpoint,
emailSource,
emailerMode,
otelCollectorUrl,
parameterStoreMode,
applicationEndpoint,
})

const emailer =
emailerMode == 'LOCAL'
? newLocalEmailer({
emailSource,
stage: 'local',
baseUrl: applicationEndpoint,
devReviewTeamEmails,
cmsReviewHelpEmailAddress,
cmsRateHelpEmailAddress,
oactEmails,
dmcpReviewEmails,
dmcpSubmissionEmails,
dmcoEmails,
helpDeskEmail,
})
: newSESEmailer({
emailSource,
stage: stageName,
baseUrl: applicationEndpoint,
devReviewTeamEmails,
cmsReviewHelpEmailAddress,
cmsRateHelpEmailAddress,
oactEmails,
dmcpReviewEmails,
dmcpSubmissionEmails,
dmcoEmails,
helpDeskEmail,
})
if (emailer instanceof Error) {
const error = `Email Configuration error: ${emailer.message}`
console.error(error)
throw emailer
}

const S3_BUCKETS_CONFIG: S3BucketConfigType = {
HEALTH_PLAN_DOCS: s3DocumentsBucket,
QUESTION_ANSWER_DOCS: s3QABucket,
Expand All @@ -380,6 +303,18 @@ async function initializeGQLHandler(): Promise<Handler> {
s3Client = newDeployedS3Client(S3_BUCKETS_CONFIG, region)
}

// Print out all the variables we've been configured with. Leave sensitive ones out, please.
console.info('Running With Config: ', {
authMode,
stageName,
dbURL,
applicationEndpoint,
emailSource: emailer.config.emailSource,
emailerMode,
otelCollectorUrl,
parameterStoreMode,
})

// Resolvers are defined and tested in the resolvers package
const resolvers = configureResolvers(
store,
Expand Down
Loading
Loading