import { flatten , isNil } from 'lodash' ; import type { IAmazonApplicationLoadBalancer , IAmazonHealth , IAmazonNetworkLoadBalancer , ITargetGroup , } from '../../domain' ; export const getAllTargetGroups = ( loadBalancers ) : ITargetGroup [ ] => { const allTargetGroups = loadBalancers . map ( ( d ) => d . targetGroups ) ; const targetGroups = flatten ( allTargetGroups ) ; return targetGroups ; } ; export const applyHealthCheckInfoToTargetGroups = ( healthMetrics , targetGroups , account ) => { healthMetrics . forEach ( ( metric ) => { if ( metric . type === 'TargetGroup' ) { metric . targetGroups . forEach ( ( tg ) => { const group = targetGroups . find ( ( g ) => g . name === tg . name && g . account === account ) ?? ( { } as ITargetGroup ) ; const useTrafficPort = group . healthCheckPort === 'traffic-port' || isNil ( group . healthCheckPort ) ; const port = useTrafficPort ? group . port : group . healthCheckPort ; tg . healthCheckProtocol = group . healthCheckProtocol ?. toLowerCase ( ) ; tg . healthCheckPath = `:${ port }${ group . healthCheckPath ?? '' }` ; } ) ; } } ) ; } ;