Skip to content

Commit

Permalink
fix(core/amazon): validate target group healthcheck fields (#6962)
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed May 21, 2019
1 parent c9791e6 commit b55e3b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
SpInput,
ValidationMessage,
spelNumberCheck,
Validators,
robotToHuman,
} from '@spinnaker/core';

import { IAmazonApplicationLoadBalancer, IAmazonApplicationLoadBalancerUpsertCommand } from 'amazon/domain';
Expand Down Expand Up @@ -42,6 +44,15 @@ export class TargetGroups extends React.Component<ITargetGroupsProps, ITargetGro
};
}

private checkBetween(errors: any, object: any, fieldName: string, min: number, max: number) {
const field = object[fieldName];
if (!Number.isNaN(field)) {
errors[fieldName] =
Validators.minValue(min)(field, robotToHuman(fieldName)) ||
Validators.maxValue(max)(field, robotToHuman(fieldName));
}
}

public validate(
values: IAmazonApplicationLoadBalancerUpsertCommand,
): FormikErrors<IAmazonApplicationLoadBalancerUpsertCommand> {
Expand Down Expand Up @@ -79,6 +90,11 @@ export class TargetGroups extends React.Component<ITargetGroupsProps, ITargetGro
}
});

this.checkBetween(tgErrors, targetGroup, 'healthCheckTimeout', 2, 60);
this.checkBetween(tgErrors, targetGroup, 'healthCheckInterval', 5, 300);
this.checkBetween(tgErrors, targetGroup, 'healthyThreshold', 2, 10);
this.checkBetween(tgErrors, targetGroup, 'unhealthyThreshold', 2, 10);

if (targetGroup.healthCheckPort !== 'traffic-port') {
const err = spelNumberCheck(targetGroup.healthCheckPort);
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/core/src/presentation/FormElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const SpInput = (
) => {
const { error, ...inputProps } = props;
if (error) {
inputProps.className = inputProps.className ? `${inputProps.className} ` : 'invalid';
inputProps.className = `${inputProps.className || ''} invalid`;
}
inputProps.type = inputProps.type || 'text';
return (
Expand Down

0 comments on commit b55e3b8

Please sign in to comment.