You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/07/13 01:46:13 UTC

[trafficcontrol] 03/03: GetKeys once params processed

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

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit c6063784cb1d6dd7c41b7bbdd3f504bb3d1f7528
Author: Dan Kirkwood <da...@apache.org>
AuthorDate: Thu Jul 12 08:36:17 2018 -0600

    GetKeys once params processed
---
 .../traffic_ops_golang/api/shared_handlers.go      | 23 +++++++++++-----------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/api/shared_handlers.go b/traffic_ops/traffic_ops_golang/api/shared_handlers.go
index 68ede49..3e5295b 100644
--- a/traffic_ops/traffic_ops_golang/api/shared_handlers.go
+++ b/traffic_ops/traffic_ops_golang/api/shared_handlers.go
@@ -249,12 +249,9 @@ func UpdateHandler(typeFactory CRUDFactory) http.HandlerFunc {
 		}
 
 		keyFields := u.GetKeyFieldsInfo() //expecting a slice of the key fields info which is a struct with the field name and a function to convert a string into a {}interface of the right type. in most that will be [{Field:"id",Func: func(s string)({}interface,error){return strconv.Atoi(s)}}]
-		keys, ok := u.GetKeys()           // a map of keyField to keyValue where keyValue is an {}interface
-		if !ok {
-			log.Errorf("unable to parse keys from request: %++v", u)
-			handleErrs(http.StatusBadRequest, errors.New("unable to parse required keys from request body"))
-			return // TODO verify?
-		}
+		// ignoring ok value -- will be checked after param processing
+
+		keys := make(map[string]interface{}) // a map of keyField to keyValue where keyValue is an {}interface
 		for _, kf := range keyFields {
 			paramKey := params[kf.Field]
 			if paramKey == "" {
@@ -273,14 +270,16 @@ func UpdateHandler(typeFactory CRUDFactory) http.HandlerFunc {
 			if paramValue != "" {
 				// if key's value provided in params,  overwrite it and ignore that provided in JSON
 				keys[kf.Field] = paramValue
-				u.SetKeys(keys)
-				continue
 			}
+		}
 
-			if paramValue != keys[kf.Field] {
-				handleErrs(http.StatusBadRequest, errors.New("key in body does not match key in params"))
-				return
-			}
+		// check that all keys were properly filled in
+		u.SetKeys(keys)
+		_, ok := u.GetKeys()
+		if !ok {
+			log.Errorf("unable to parse keys from request: %++v", u)
+			handleErrs(http.StatusBadRequest, errors.New("unable to parse required keys from request body"))
+			return // TODO verify?
 		}
 
 		// if the object has tenancy enabled, check that user is able to access the tenant