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

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


The following commit(s) were added to refs/heads/4.1.x by this push:
     new cfafdd9  Fix OptionsDeleter audit log keys (#4704) (#4731)
cfafdd9 is described below

commit cfafdd9c7d5ffc78a8cef66f835e54625b48aec1
Author: Rawlin Peters <[email protected]>
AuthorDate: Thu May 28 10:36:32 2020 -0600

    Fix OptionsDeleter audit log keys (#4704) (#4731)
    
    * Fix OptionsDeleter audit log keys
    
    * Added TO API test to check audit log message
    
    * Undo whitespace addition in changelog message because it breaks tests
    
    * fixes timing of error message on delete
    
    Co-authored-by: Jeremy Mitchell <[email protected]>
    (cherry picked from commit 09bfc378284639fde6c8a9474ac831ba93b78de9)
---
 .../traffic_ops_golang/api/shared_handlers.go      | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/api/shared_handlers.go 
b/traffic_ops/traffic_ops_golang/api/shared_handlers.go
index faceffe..846822e 100644
--- a/traffic_ops/traffic_ops_golang/api/shared_handlers.go
+++ b/traffic_ops/traffic_ops_golang/api/shared_handlers.go
@@ -315,25 +315,23 @@ func DeleteHandler(deleter Deleter) http.HandlerFunc {
                        HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
                        return
                }
-               if !deleteKeyOptionExists {
-                       keyFields := obj.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 := make(map[string]interface{})
-                       for _, kf := range keyFields {
-                               paramKey := inf.Params[kf.Field]
-                               if paramKey == "" {
-                                       HandleErr(w, r, inf.Tx.Tx, 
http.StatusBadRequest, errors.New("missing key: "+kf.Field), nil)
-                                       return
-                               }
+               keyFields := obj.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 := make(map[string]interface{})
+               for _, kf := range keyFields {
+                       paramKey := inf.Params[kf.Field]
+                       if paramKey == "" {
+                               HandleErr(w, r, inf.Tx.Tx, 
http.StatusBadRequest, errors.New("missing key: "+kf.Field), nil)
+                               return
+                       }
 
-                               paramValue, err := kf.Func(paramKey)
-                               if err != nil {
-                                       HandleErr(w, r, inf.Tx.Tx, 
http.StatusBadRequest, errors.New("failed to parse key: "+kf.Field), nil)
-                                       return
-                               }
-                               keys[kf.Field] = paramValue
+                       paramValue, err := kf.Func(paramKey)
+                       if err != nil {
+                               HandleErr(w, r, inf.Tx.Tx, 
http.StatusBadRequest, errors.New("failed to parse key: "+kf.Field), nil)
+                               return
                        }
-                       obj.SetKeys(keys) // if the type assertion of a key 
fails it will be should be set to the zero value of the type and the delete 
should fail (this means the code is not written properly no changes of user 
input should cause this.)
+                       keys[kf.Field] = paramValue
                }
+               obj.SetKeys(keys) // if the type assertion of a key fails it 
will be should be set to the zero value of the type and the delete should fail 
(this means the code is not written properly no changes of user input should 
cause this.)
 
                if t, ok := obj.(Tenantable); ok {
                        authorized, err := t.IsTenantAuthorized(inf.User)

Reply via email to