You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by dg...@apache.org on 2019/08/14 19:30:51 UTC

[trafficcontrol] branch 3.1.x updated: 3.1.x backport: to go fix server ipv6 validation allow empty str (#3869)

This is an automated email from the ASF dual-hosted git repository.

dgelinas pushed a commit to branch 3.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/3.1.x by this push:
     new 0212637  3.1.x backport: to go fix server ipv6 validation allow empty str (#3869)
0212637 is described below

commit 02126378dca86121904ab2b7d4ec839e0829531b
Author: Steve Malenfant <sm...@users.noreply.github.com>
AuthorDate: Wed Aug 14 15:30:44 2019 -0400

    3.1.x backport: to go fix server ipv6 validation allow empty str (#3869)
    
    * Fix TO Servers validation to allow "" ipv6
    
    Fixes #2844
---
 CHANGELOG.md                                     | 1 +
 lib/go-tc/tovalidate/rules.go                    | 2 +-
 traffic_ops/traffic_ops_golang/server/servers.go | 8 +++++++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ee168d..db4aaf7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 ### Added
 
 ### Changed
+- Fix TO Servers validation to allow "" ipv6
 
 
 ### Fixed
diff --git a/lib/go-tc/tovalidate/rules.go b/lib/go-tc/tovalidate/rules.go
index 3ea3ae1..f155810 100644
--- a/lib/go-tc/tovalidate/rules.go
+++ b/lib/go-tc/tovalidate/rules.go
@@ -154,7 +154,7 @@ func IsValidIPv6CIDROrAddress(value interface{}) error {
 				}
 			}
 		}
-		return fmt.Errorf("unable to parse an IPv6 address or CIDR from: %s", v)
+		return fmt.Errorf("unable to parse an IPv6 address or CIDR from: %s", *v)
 	default:
 		return fmt.Errorf("IsValidIPv6CIDROrAddress validation failure: unknown type %T", value)
 	}
diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go
index 0d9590c..5e60a20 100644
--- a/traffic_ops/traffic_ops_golang/server/servers.go
+++ b/traffic_ops/traffic_ops_golang/server/servers.go
@@ -91,8 +91,14 @@ func (server *TOServer) GetType() string {
 	return "server"
 }
 
-func (server *TOServer) Validate() error {
+func (server *TOServer) Sanitize() {
+	if server.IP6Address != nil && *server.IP6Address == "" {
+		server.IP6Address = nil
+	}
+}
 
+func (server *TOServer) Validate() error {
+	server.Sanitize()
 	noSpaces := validation.NewStringRule(tovalidate.NoSpaces, "cannot contain spaces")
 
 	validateErrs := validation.Errors{