ocket8888 commented on a change in pull request #4700:
URL: https://github.com/apache/trafficcontrol/pull/4700#discussion_r433358152



##########
File path: traffic_ops/traffic_ops_golang/server/servers.go
##########
@@ -139,94 +366,213 @@ func (s *TOServer) Validate() error {
                validateErrs["ip6Address"] = validation.Validate(s.IP6Address, 
validation.By(tovalidate.IsValidIPv6CIDROrAddress))
        }
        errs = append(errs, tovalidate.ToErrors(validateErrs)...)
-       if len(errs) > 0 {
-               return util.JoinErrs(errs)
-       }
+       errs = append(errs, validateCommon(s.CommonServerProperties, tx)...)
+
+       return util.JoinErrs(errs)
+}
+
+func validateV2(s *tc.ServerNullableV2, tx *sql.Tx) error {
+       var errs []error
 
-       if _, err := tc.ValidateTypeID(s.ReqInfo.Tx.Tx, s.TypeID, "server"); 
err != nil {
+       if err := validateV1(s.ServerNullableV11, tx); err != nil {
                return err
        }
 
-       rows, err := s.ReqInfo.Tx.Tx.Query("select cdn from profile where 
id=$1", s.ProfileID)
-       if err != nil {
-               log.Error.Printf("could not execute select cdnID from profile: 
%s\n", err)
-               errs = append(errs, tc.DBError)
-               return util.JoinErrs(errs)
+       // default boolean value is false
+       if s.IPIsService == nil {
+               s.IPIsService = new(bool)
        }
-       defer rows.Close()
-       var cdnID int
-       for rows.Next() {
-               if err := rows.Scan(&cdnID); err != nil {
-                       log.Error.Printf("could not scan cdnID from profile: 
%s\n", err)
-                       errs = append(errs, errors.New("associated profile must 
have a cdn associated"))
-                       return util.JoinErrs(errs)
-               }
+       if s.IP6IsService == nil {
+               s.IP6IsService = new(bool)
        }
-       log.Infof("got cdn id: %d from profile and cdn id: %d from server", 
cdnID, *s.CDNID)
-       if cdnID != *s.CDNID {
-               errs = append(errs, errors.New(fmt.Sprintf("CDN id '%d' for 
profile '%d' does not match Server CDN '%d'", cdnID, *s.ProfileID, *s.CDNID)))
+
+       if !*s.IPIsService && !*s.IP6IsService {
+               errs = append(errs, tc.NeedsAtLeastOneServiceAddressError)
        }
-       return util.JoinErrs(errs)
-}
 
-// ChangeLogMessage implements the api.ChangeLogger interface for a custom log 
message
-func (s TOServer) ChangeLogMessage(action string) (string, error) {
+       if *s.IPIsService && s.IPAddress == nil {
+               errs = append(errs, tc.EmptyAddressCannotBeAServiceAddressError)
+       }
 
-       var status string
-       if s.Status != nil {
-               status = *s.Status
+       if *s.IP6IsService && s.IP6Address == nil {
+               errs = append(errs, tc.EmptyAddressCannotBeAServiceAddressError)
        }
+       return util.JoinErrs(errs)
+}
 
-       var hostName string
-       if s.HostName != nil {
-               hostName = *s.HostName
+func validateMTU(mtu interface{}) error {
+       m := mtu.(*uint64)

Review comment:
       Sure. It shouldn't be a problem because this is a validation function 
only called on instances of `*uint64`, but there's no reason not to handle that.
   
   TBH I was sort of counting on the panic because if that's not getting called 
on a `*uint64` there's some kind of messed up server-side logic and that'd 
return a 500 error.




----------------------------------------------------------------
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