mitchell852 closed pull request #1817: [issue 1816] Add validation of value for
STEERING_WEIGHT type in steering target APIs
URL: https://github.com/apache/incubator-trafficcontrol/pull/1817
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
b/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
index 3372f839d4..a1f5c23673 100644
--- a/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
+++ b/traffic_ops/app/lib/API/DeliveryService/SteeringTarget.pm
@@ -284,7 +284,8 @@ sub is_target_valid {
my $self = shift;
my $params = shift;
- if ( !$self->is_valid_target_type( $params->{typeId} ) ) {
+ my ( $is_valid, $target_type ) = $self->is_valid_target_type(
$params->{typeId} );
+ if ( !$is_valid ) {
return ( 0, "Invalid target type" );
}
@@ -302,6 +303,9 @@ sub is_target_valid {
my $result = validate( $params, $rules );
if ( $result->{success} ) {
+ if ( ( $target_type eq "STEERING_WEIGHT" ) and (
$params->{value} < 0 ) ) {
+ return ( 0, "Invalid value for target type STEERING_WEIGHT:
can not be negative" );
+ }
return ( 1, $result->{data} );
}
else {
@@ -315,9 +319,9 @@ sub is_valid_target_type {
my $rs = $self->db->resultset("Type")->find( { id => $type_id } );
if ( defined($rs) && ( $rs->use_in_table eq "steering_target" ) ) {
- return 1;
+ return ( 1, $rs->name );
}
- return 0;
+ return ( 0, "" );
}
1;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services