Skip to content

Commit

Permalink
fix(amazon/loadBalancers): Don't allow to create if duplicate target …
Browse files Browse the repository at this point in the history
…group names
  • Loading branch information
Justin Reynolds committed Mar 19, 2018
1 parent d1bab47 commit 2a657a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ const Rule = SortableElement((props: IRuleProps) => (
required={true}
>
<option value=""/>
{props.targetGroups.map((tg) => <option key={tg.name}>{tg.name}</option>)}
{uniq(props.targetGroups.map((tg) => tg.name)).map((name) => <option key={name}>{name}</option>)}
</select>
</td>
<td>
Expand Down Expand Up @@ -489,7 +489,7 @@ const Rules = SortableContainer((props: IRulesProps) => (
required={true}
>
<option value=""/>
{props.targetGroups.map((targetGroup) => <option key={targetGroup.name}>{targetGroup.name}</option>)}
{uniq(props.targetGroups.map((tg) => tg.name)).map((name) => <option key={name}>{name}</option>)}
</select>
</td>
<td/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { get, set } from 'lodash';
import { filter, flatten, get, groupBy, set, uniq } from 'lodash';
import { BindAll } from 'lodash-decorators';
import { FormikErrors, FormikProps } from 'formik';
import { Observable, Subject } from 'rxjs';
Expand Down Expand Up @@ -44,6 +44,7 @@ class TargetGroupsImpl extends React.Component<ITargetGroupsProps & IWizardPageP
const errors = {} as FormikErrors<IAmazonApplicationLoadBalancerUpsertCommand>;

let hasErrors = false;
const duplicateTargetGroups = uniq(flatten(filter(groupBy(values.targetGroups, 'name'), (count) => count.length > 1)).map((tg) => tg.name));
const targetGroupsErrors = values.targetGroups.map((targetGroup: any) => {
const tgErrors: { [key: string]: string } = {};

Expand All @@ -55,6 +56,10 @@ class TargetGroupsImpl extends React.Component<ITargetGroupsProps & IWizardPageP
tgErrors.name = 'Target group name is automatically prefixed with the application name and cannot exceed 32 characters in length.';
}

if (duplicateTargetGroups.includes(targetGroup.name)) {
tgErrors.name = 'Duplicate target group name in this load balancer.';
}

['port', 'healthCheckInterval', 'healthCheckPort', 'healthyThreshold', 'unhealthyThreshold'].forEach((key) => {
const err = spelNumberCheck(targetGroup[key]);
if (err) { tgErrors[key] = err; }
Expand Down

0 comments on commit 2a657a2

Please sign in to comment.