From a9139cc5a6630a165de55116fff3b0160d334758 Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 19 Nov 2024 22:13:31 +0800 Subject: [PATCH] feat: remove get/set for msgSrvcName, remove aws ssm --- docker-compose.yml | 2 +- .../__tests__/form.server.model.spec.ts | 34 ------------------- src/app/models/form.server.model.ts | 19 ++--------- .../form/admin-form/admin-form.service.ts | 8 +---- .../form/admin-form/admin-form.utils.ts | 18 ---------- src/types/form.ts | 16 --------- 6 files changed, 5 insertions(+), 92 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f7f99d3008..ee7b758a11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -162,7 +162,7 @@ services: depends_on: - backend environment: - - SERVICES=s3,sqs,secretsmanager + - SERVICES=s3,sqs - DNS_ADDRESS=0 - EXTRA_CORS_ALLOWED_ORIGINS=http://localhost:5173 volumes: diff --git a/src/app/models/__tests__/form.server.model.spec.ts b/src/app/models/__tests__/form.server.model.spec.ts index 24d6db0d1a..fd96554a20 100644 --- a/src/app/models/__tests__/form.server.model.spec.ts +++ b/src/app/models/__tests__/form.server.model.spec.ts @@ -2971,39 +2971,5 @@ describe('Form Model', () => { ) }) }) - - describe('updateMsgSrvcName', () => { - const MOCK_MSG_SRVC_NAME = 'mockTwilioName' - it('should update msgSrvcName of form to new msgSrvcName', async () => { - // Arrange - const form = await Form.create({ - admin: populatedAdmin._id, - title: 'mock mobile form', - }) - - // Act - const updatedForm = await form.updateMsgSrvcName(MOCK_MSG_SRVC_NAME) - // Assert - expect(updatedForm?.msgSrvcName).toBe(MOCK_MSG_SRVC_NAME) - }) - }) - - describe('deleteMsgSrvcName', () => { - const MOCK_MSG_SRVC_NAME = 'mockTwilioName' - it('should delete msgSrvcName of form', async () => { - // Arrange - const form = await Form.create({ - admin: populatedAdmin._id, - title: 'mock mobile form', - msgSrvcName: MOCK_MSG_SRVC_NAME, - }) - - // Act - const updatedForm = await form.deleteMsgSrvcName() - - // Assert - expect(updatedForm?.msgSrvcName).toBeUndefined() - }) - }) }) }) diff --git a/src/app/models/form.server.model.ts b/src/app/models/form.server.model.ts index cecde479bf..19e8424e42 100644 --- a/src/app/models/form.server.model.ts +++ b/src/app/models/form.server.model.ts @@ -652,6 +652,9 @@ const compileFormModel = (db: Mongoose): IFormModel => { }, }, + /** + * @deprecated Twilio is no longer supported as we have moved the functionality to postman-sms + */ msgSrvcName: { // Name of credentials for messaging service, stored in secrets manager type: String, @@ -803,22 +806,6 @@ const compileFormModel = (db: Mongoose): IFormModel => { return this.save() } - FormSchema.methods.updateMsgSrvcName = async function ( - msgSrvcName: string, - session?: ClientSession, - ) { - this.msgSrvcName = msgSrvcName - - return this.save({ session }) - } - - FormSchema.methods.deleteMsgSrvcName = async function ( - session?: ClientSession, - ) { - this.msgSrvcName = undefined - return this.save({ session }) - } - const FormDocumentSchema = FormSchema as unknown as Schema FormDocumentSchema.methods.getDashboardView = function ( diff --git a/src/app/modules/form/admin-form/admin-form.service.ts b/src/app/modules/form/admin-form/admin-form.service.ts index f10f0370d4..544e0656c3 100644 --- a/src/app/modules/form/admin-form/admin-form.service.ts +++ b/src/app/modules/form/admin-form/admin-form.service.ts @@ -1,4 +1,3 @@ -import { SecretsManager } from 'aws-sdk' import { PresignedPost } from 'aws-sdk/clients/s3' import { assignIn, last, omit, pick } from 'lodash' import mongoose, { ClientSession } from 'mongoose' @@ -60,7 +59,7 @@ import { IPopulatedUser, } from '../../../../types' import { EditFormFieldParams, FormUpdateParams } from '../../../../types/api' -import config, { aws as AwsConfig } from '../../../config/config' +import { aws as AwsConfig } from '../../../config/config' import { createLoggerWithLabel } from '../../../config/logger' import getAgencyModel from '../../../models/agency.server.model' import getFormModel from '../../../models/form.server.model' @@ -120,11 +119,6 @@ const WorkspaceModel = getWorkspaceModel(mongoose) const FormWhitelistedSubmitterIdsModel = getFormWhitelistSubmitterIdsModel(mongoose) -export const secretsManager = new SecretsManager({ - region: config.aws.region, - endpoint: process.env.AWS_ENDPOINT, -}) - type PresignedPostUrlParams = { fileId: string fileMd5Hash: string diff --git a/src/app/modules/form/admin-form/admin-form.utils.ts b/src/app/modules/form/admin-form/admin-form.utils.ts index 8b20773f8d..0635aa9588 100644 --- a/src/app/modules/form/admin-form/admin-form.utils.ts +++ b/src/app/modules/form/admin-form/admin-form.utils.ts @@ -29,9 +29,6 @@ import { DatabasePayloadSizeError, DatabaseValidationError, MalformedParametersError, - SecretsManagerConflictError, - SecretsManagerError, - SecretsManagerNotFoundError, } from '../../core/core.errors' import { ErrorResponseData } from '../../core/core.types' import { InvalidPaymentAmountError } from '../../payments/payments.errors' @@ -155,21 +152,6 @@ export const mapRouteError = ( statusCode: StatusCodes.INTERNAL_SERVER_ERROR, errorMessage: coreErrorMessage ?? error.message, } - case SecretsManagerNotFoundError: - return { - statusCode: StatusCodes.NOT_FOUND, - errorMessage: coreErrorMessage ?? error.message, - } - case SecretsManagerConflictError: - return { - statusCode: StatusCodes.CONFLICT, - errorMessage: coreErrorMessage ?? error.message, - } - case SecretsManagerError: - return { - statusCode: StatusCodes.INTERNAL_SERVER_ERROR, - errorMessage: coreErrorMessage ?? error.message, - } case StripeAccountError: return { statusCode: StatusCodes.BAD_GATEWAY, diff --git a/src/types/form.ts b/src/types/form.ts index 7c7288c9b2..ec9faed824 100644 --- a/src/types/form.ts +++ b/src/types/form.ts @@ -256,22 +256,6 @@ export interface IFormSchema extends IForm, Document, PublicView { getDuplicateParams( overrideProps: OverrideProps, ): PickDuplicateForm & OverrideProps - - /** - * Updates the msgSrvcName of the form with the specified msgSrvcName - * @param msgSrvcName msgSrvcName to update the Form docuemnt with - * @param session transaction session in which update operation is a part of - */ - updateMsgSrvcName( - msgSrvcName: string, - session?: ClientSession, - ): Promise - - /** - * Deletes the msgSrvcName of the form - * @param session transaction session in which delete operation is a part of - */ - deleteMsgSrvcName(session?: ClientSession): Promise } /**