11import { CloudWatchClient , PutMetricDataCommand } from "@aws-sdk/client-cloudwatch" ;
22import { LogWriterType } from "@libs/logWriter" ;
3+ import { getConfigValue } from "@libs/ssmUtils" ;
34import axios , { AxiosError , AxiosResponse } from "axios" ;
45
56type Status = "PASS" | "FAIL" | "ERROR" ;
@@ -17,11 +18,23 @@ const healthCheckEndPoints: Record<string, string> = {
1718 webserviceFormation : "webservice/formation" ,
1819 taxClearance : "tax-clearance" ,
1920 xrayRegistration : "xray-registration" ,
20- cigaretteEmailClient : "cigarette-email-client" ,
21- cigaretteLicense : "cigarette-license" ,
2221 taxFilingClient : "tax-filing-client" ,
2322} ;
2423
24+ const addFlaggedHealthChecks = (
25+ endpoints : Record < string , string > ,
26+ flagValues : { cigarette : boolean } ,
27+ ) : Record < string , string > => {
28+ if ( flagValues . cigarette ) {
29+ return {
30+ ...endpoints ,
31+ cigaretteEmailClient : "cigarette-email-client" ,
32+ cigaretteLicense : "cigarette-license" ,
33+ } ;
34+ }
35+ return endpoints ;
36+ } ;
37+
2538const healthCheck = async ( type : string , url : string , logger : LogWriterType ) : Promise < Status > => {
2639 const fullUrl = `${ url } /health/${ type } ` ;
2740
@@ -82,7 +95,14 @@ export const runHealthChecks = async (logger: LogWriterType): Promise<StatusResu
8295 throw new Error ( "API URL is undefined" ) ;
8396 }
8497
85- const entries = Object . entries ( healthCheckEndPoints ) . map ( ( [ type , endpoint ] ) =>
98+ const isCigaretteLicenseEnabled =
99+ ( await getConfigValue ( "FEATURE_CIGARETTE_LICENSE" , logger ) ) === "true" ;
100+
101+ const endpoints = addFlaggedHealthChecks ( healthCheckEndPoints , {
102+ cigarette : isCigaretteLicenseEnabled ,
103+ } ) ;
104+
105+ const entries = Object . entries ( endpoints ) . map ( ( [ type , endpoint ] ) =>
86106 healthCheck ( endpoint ?? "" , url , logger ) . then ( ( result ) => [ type , result ] as const ) ,
87107 ) ;
88108
0 commit comments