srijeet0406 commented on a change in pull request #5345:
URL: https://github.com/apache/trafficcontrol/pull/5345#discussion_r540609574



##########
File path: lib/go-tc/deliveryservices.go
##########
@@ -532,6 +586,121 @@ func (ds *DeliveryServiceNullableV30) 
validateTypeFields(tx *sql.Tx) error {
        return nil
 }
 
+func (ds *DeliveryServiceV31) validateTypeFields(tx *sql.Tx) error {
+       // Validate the TypeName related fields below
+       err := error(nil)
+       DNSRegexType := "^DNS.*$"
+       HTTPRegexType := "^HTTP.*$"
+       SteeringRegexType := "^STEERING.*$"
+       latitudeErr := "Must be a floating point number within the range +-90"
+       longitudeErr := "Must be a floating point number within the range +-180"
+
+       typeName, err := ValidateTypeID(tx, ds.TypeID, "deliveryservice")
+       if err != nil {
+               return err
+       }
+
+       errs := validation.Errors{
+               "consistentHashQueryParams": validation.Validate(ds,
+                       validation.By(func(dsi interface{}) error {
+                               ds := dsi.(*DeliveryServiceV31)
+                               if len(ds.ConsistentHashQueryParams) == 0 || 
DSType(typeName).IsHTTP() {
+                                       return nil
+                               }
+                               return fmt.Errorf("consistentHashQueryParams 
not allowed for '%s' deliveryservice type", typeName)
+                       })),
+               "initialDispersion": validation.Validate(ds.InitialDispersion,
+                       
validation.By(requiredIfMatchesTypeName([]string{HTTPRegexType}, typeName)),
+                       validation.By(tovalidate.IsGreaterThanZero)),
+               "ipv6RoutingEnabled": validation.Validate(ds.IPV6RoutingEnabled,
+                       
validation.By(requiredIfMatchesTypeName([]string{SteeringRegexType, 
DNSRegexType, HTTPRegexType}, typeName))),
+               "missLat": validation.Validate(ds.MissLat,
+                       
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, 
typeName)),
+                       validation.Min(-90.0).Error(latitudeErr),
+                       validation.Max(90.0).Error(latitudeErr)),
+               "missLong": validation.Validate(ds.MissLong,
+                       
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, 
typeName)),
+                       validation.Min(-180.0).Error(longitudeErr),
+                       validation.Max(180.0).Error(longitudeErr)),
+               "multiSiteOrigin": validation.Validate(ds.MultiSiteOrigin,
+                       
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, 
typeName))),
+               "orgServerFqdn": validation.Validate(ds.OrgServerFQDN,
+                       
validation.By(requiredIfMatchesTypeName([]string{DNSRegexType, HTTPRegexType}, 
typeName)),
+                       validation.NewStringRule(validateOrgServerFQDN, "must 
start with http:// or https:// and be followed by a valid hostname with an 
optional port (no trailing slash)")),
+               "rangeSliceBlockSize": validation.Validate(ds,
+                       validation.By(func(dsi interface{}) error {
+                               ds := dsi.(*DeliveryServiceV31)
+                               if ds.RangeRequestHandling != nil {
+                                       if *ds.RangeRequestHandling == 3 {
+                                               return 
validation.Validate(ds.RangeSliceBlockSize, validation.Required,
+                                                       // Per Slice Plugin 
implementation
+                                                       validation.Min(262144), 
  // 256KiB
+                                                       
validation.Max(33554432), // 32MiB

Review comment:
       Made constants for these values as well.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to