Skip to content

Commit

Permalink
fix(aws/loadBalancers): Add validator for multiple listeners on same …
Browse files Browse the repository at this point in the history
…port (#8127)
  • Loading branch information
caseyhebebrand committed Apr 3, 2020
1 parent 8dd9fd6 commit 17dcc95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { $q } from 'ngimport';
import { SortableContainer, SortableElement, SortableHandle, arrayMove, SortEnd } from 'react-sortable-hoc';
import { difference, flatten, get, some, uniq } from 'lodash';
import { difference, flatten, get, some, uniq, uniqBy } from 'lodash';
import { FormikErrors, FormikProps } from 'formik';

import {
Expand Down Expand Up @@ -115,6 +115,11 @@ export class ALBListeners extends React.Component<IALBListenersProps, IALBListen
errors.listeners = `Target groups ${unusedTargetGroupNames.join(', ')} are unused.`;
}

const { listeners } = values;
if (uniqBy(listeners, 'port').length < listeners.length) {
errors.listenerPorts = 'Multiple listeners cannot use the same port.';
}

const missingRuleFields = values.listeners.find(l => {
const defaultActionsHaveMissingTarget = !!l.defaultActions.find(
da =>
Expand Down Expand Up @@ -578,6 +583,11 @@ export class ALBListeners extends React.Component<IALBListenersProps, IALBListen
</div>
</div>
))}
{errors.listenerPorts && (
<div className="wizard-pod-row-errors">
<ValidationMessage type="error" message={errors.listenerPorts} />
</div>
)}
{errors.listeners && (
<div className="wizard-pod-row-errors">
<ValidationMessage type="error" message={errors.listeners} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { difference, flatten, uniq } from 'lodash';
import { difference, flatten, uniq, uniqBy } from 'lodash';

import { ValidationMessage, IWizardPageComponent } from '@spinnaker/core';

Expand Down Expand Up @@ -34,6 +34,11 @@ export class NLBListeners extends React.Component<INLBListenersProps>
errors.listeners = `Target groups ${unusedTargetGroupNames.join(', ')} are unused.`;
}

const { listeners } = values;
if (uniqBy(listeners, 'port').length < listeners.length) {
errors.listenerPorts = 'Multiple listeners cannot use the same port.';
}

return errors;
}

Expand Down Expand Up @@ -170,6 +175,11 @@ export class NLBListeners extends React.Component<INLBListenersProps>
</div>
</div>
))}
{errors.listenerPorts && (
<div className="wizard-pod-row-errors">
<ValidationMessage type="error" message={errors.listenerPorts} />
</div>
)}
{errors.listeners && (
<div className="wizard-pod-row-errors">
<ValidationMessage type="error" message={errors.listeners} />
Expand Down

0 comments on commit 17dcc95

Please sign in to comment.