You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2019/03/01 16:59:23 UTC

[GitHub] rob05c commented on a change in pull request #3360: Cache Config Parser

rob05c commented on a change in pull request #3360: Cache Config Parser
URL: https://github.com/apache/trafficcontrol/pull/3360#discussion_r261681190
 
 

 ##########
 File path: traffic_ops/testing/api/v14/config/cache_config/cache_config.go
 ##########
 @@ -0,0 +1,256 @@
+/*
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+package cache_config
+
+import (
+	"regexp"
+	"strings"
+
+	. "github.com/apache/trafficcontrol/traffic_ops/testing/api/v14/config"
+	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/test"
+	"github.com/go-ozzo/ozzo-validation/is"
+)
+
+func parseCacheConfig(config string) test.Error {
+	lines := strings.Split(config, "\n")
+
+	if len(lines) == 1 {
+		return parseCacheConfigRule(lines[0])
+	}
+
+	for i, ln := range lines {
+		err := parseCacheConfigRule(ln)
+		if err != nil {
+			return err.Prepend("error on line %d: ", i+1)
+		}
+	}
+
+	return nil
+}
+
+type parser func(string, string) test.Error
+
+func parsePrimaryDestinations(lhs string, rhs string) test.Error {
+
+	switch lhs {
+	case "dest_domain":
+		// dest_host is an alias for dest_domain
+		fallthrough
+	case "dest_host":
+		if err := is.Host.Validate(rhs); err != nil {
+			return ErrorContext.NewError(InvalidHost, `"%s" %v`, rhs, err)
+		}
+	case "dest_ip":
+		if err := is.IP.Validate(rhs); err != nil {
+			return ErrorContext.NewError(InvalidIP, `"%s" %v`, rhs, err)
+		}
+	case "host_regex":
+		// only makes sure the regex compiles, not that the regex generates valid hosts
+		if _, err := regexp.Compile(rhs); err != nil {
+			return ErrorContext.NewError(InvalidRegex, "%v", err)
+		}
+	case "url_regex":
+		// only makes sure the regex compiles, not that the regex generates valid urls
 
 Review comment:
   These can fallthrough to reduce duplicate code:
   ```
   	case "host_regex":
   		fallthrough
   	case "url_regex":
   		// only makes sure the regex compiles, not that the regex generates valid hosts
   		if _, err := regexp.Compile(rhs); err != nil {
   			return ErrorContext.NewError(InvalidRegex, "%v", err)
   		}
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services