Skip to content

Commit

Permalink
Merge pull request #1152 from UKHSA-Internal/chore/restart-feedback-a…
Browse files Browse the repository at this point in the history
…pi-when-rotating-db-password

Restart feedback API when rotating db password
  • Loading branch information
phill-stanley authored Dec 23, 2024
2 parents ea3c692 + 62fa94d commit 247e42a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lambda-db-password-rotation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function restartMainDbECSServices(ecsClient = new ECSClient(), overridenDe
await dependencies.restartECSService(ecsClient, process.env.CMS_ADMIN_ECS_SERVICE_NAME)
await dependencies.restartECSService(ecsClient, process.env.PRIVATE_API_ECS_SERVICE_NAME)
await dependencies.restartECSService(ecsClient, process.env.PUBLIC_API_ECS_SERVICE_NAME)
await dependencies.restartECSService(ecsClient, process.env.FEEDBACK_API_ECS_SERVICE_NAME)
console.log(`All required ECS tasks have been restarted for main DB`);
};

Expand Down
5 changes: 3 additions & 2 deletions src/lambda-db-password-rotation/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ describe('restartMainDbECSServices', () => {
const fakeCMSAdminECSServiceName = 'fake-cms-admin-ecs-service-name'
const fakePrivateAPIECSServiceName = 'fake-private-api-ecs-service-name'
const fakePublicAPIECSServiceName = 'fake-public-api-ecs-service-name'
const fakeFeedbackAPIECSServiceName = 'fake-feedback-api-ecs-service-name'

const mockedEnvVar = sinon.stub(process, 'env').value(
{
CMS_ADMIN_ECS_SERVICE_NAME: fakeCMSAdminECSServiceName,
PRIVATE_API_ECS_SERVICE_NAME: fakePrivateAPIECSServiceName,
PUBLIC_API_ECS_SERVICE_NAME: fakePublicAPIECSServiceName,
FEEDBACK_API_ECS_SERVICE_NAME: fakeFeedbackAPIECSServiceName,
}
);

Expand All @@ -78,12 +80,11 @@ describe('restartMainDbECSServices', () => {
await restartMainDbECSServices(mockedECSClient, spyDependencies);

// Then
// The function should have been called 3 times, 1 for each ECS service
expect(restartECSServiceSpy.calledThrice).toBeTruthy();
// The function should have been called with each ECS service name
expect(restartECSServiceSpy.firstCall.lastArg).toEqual(fakeCMSAdminECSServiceName)
expect(restartECSServiceSpy.secondCall.lastArg).toEqual(fakePrivateAPIECSServiceName)
expect(restartECSServiceSpy.thirdCall.lastArg).toEqual(fakePublicAPIECSServiceName)
expect(restartECSServiceSpy.lastCall.lastArg).toEqual(fakeFeedbackAPIECSServiceName)

// Restore the environment variable
mockedEnvVar.restore();
Expand Down
3 changes: 3 additions & 0 deletions terraform/20-app/lambda.db-password-rotation.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module "lambda_db_password_rotation" {
CMS_ADMIN_ECS_SERVICE_NAME = module.ecs_service_cms_admin.name
PRIVATE_API_ECS_SERVICE_NAME = module.ecs_service_private_api.name
PUBLIC_API_ECS_SERVICE_NAME = module.ecs_service_public_api.name
FEEDBACK_API_ECS_SERVICE_NAME = module.ecs_service_feedback_api.name
FEATURE_FLAGS_ECS_SERVICE_NAME = module.ecs_service_feature_flags.name
}

Expand All @@ -31,7 +32,9 @@ module "lambda_db_password_rotation" {
module.ecs_service_private_api.id,
module.ecs_service_public_api.id,
module.ecs_service_cms_admin.id,
module.ecs_service_feedback_api.id,
module.ecs_service_feature_flags.id,

]
}
}
Expand Down

0 comments on commit 247e42a

Please sign in to comment.