[GitHub] incubator-trafficcontrol pull request #605: [TC-355] Add CDN match checks wh...

2017-06-01 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/incubator-trafficcontrol/pull/605


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-trafficcontrol pull request #605: [TC-355] Add CDN match checks wh...

2017-05-31 Thread mitchell852
Github user mitchell852 commented on a diff in the pull request:


https://github.com/apache/incubator-trafficcontrol/pull/605#discussion_r119394809
  
--- Diff: traffic_ops/app/lib/API/Server.pm ---
@@ -911,6 +911,21 @@ sub is_server_valid {
return ( 0, "Invalid server type" );
}
 
+   my $cdn_mismatch;
+   if ($id) {
+   my $profile = $self->db->resultset('Profile')->search( { 
'me.id' => $params->{profileId}}, { prefetch => ['cdn'] } )->single();
+   if ( !defined($profile->cdn) ) {
+   $cdn_mismatch = 1;
+   } 
+   elsif ( $params->{cdnId} != $profile->cdn->id ) {
+   $cdn_mismatch = 1;
+   }
+   }
+
+   if ($cdn_mismatch) {
+   return ( 0, "CDN of profile does not match Server CDN" );
+   }
--- End diff --

you could simplify all this code to simply:

if ($id) {
my $profile = $self->db->resultset('Profile')->search( { 
'me.id' => $params->{profileId}}, { prefetch => ['cdn'] } )->single();
if ( !defined($profile->cdn) || $params->{cdnId} != 
$profile->cdn->id ) {
return ( 0, "CDN of profile does not match Server CDN" 
);
}
}


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---