You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/07/04 02:39:33 UTC
[trafficcontrol] 08/15: fix profiles by removing nested query with
rows.Next loop and fix routes for deliveryservice_requests
This is an automated email from the ASF dual-hosted git repository.
dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit a323f5af8848a2e6376a5605882425c64f583e3d
Author: Dylan Volz <Dy...@comcast.com>
AuthorDate: Tue Jun 26 23:44:20 2018 -0600
fix profiles by removing nested query with rows.Next loop and fix routes for deliveryservice_requests
---
traffic_ops/traffic_ops_golang/profile/profiles.go | 23 +++++++++++++---------
traffic_ops/traffic_ops_golang/routes.go | 6 +++---
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/profile/profiles.go b/traffic_ops/traffic_ops_golang/profile/profiles.go
index 6b39006..87c99a0 100644
--- a/traffic_ops/traffic_ops_golang/profile/profiles.go
+++ b/traffic_ops/traffic_ops_golang/profile/profiles.go
@@ -47,13 +47,13 @@ const (
)
//we need a type alias to define functions on
-type TOProfile struct{
+type TOProfile struct {
ReqInfo *api.APIInfo `json:"-"`
v13.ProfileNullable
}
-func GetTypeSingleton() func(reqInfo *api.APIInfo)api.CRUDer {
- return func(reqInfo *api.APIInfo)api.CRUDer {
+func GetTypeSingleton() func(reqInfo *api.APIInfo) api.CRUDer {
+ return func(reqInfo *api.APIInfo) api.CRUDer {
toReturn := TOProfile{reqInfo, v13.ProfileNullable{}}
return &toReturn
}
@@ -127,27 +127,32 @@ func (prof *TOProfile) Read(parameters map[string]string) ([]interface{}, []erro
}
defer rows.Close()
- profiles := []interface{}{}
+ profiles := []v13.ProfileNullable{}
+
for rows.Next() {
var p v13.ProfileNullable
if err = rows.StructScan(&p); err != nil {
log.Errorf("error parsing Profile rows: %v", err)
return nil, []error{tc.DBError}, tc.SystemError
}
-
+ profiles = append(profiles, p)
+ }
+ rows.Close()
+ profileInterfaces := []interface{}{}
+ for _, profile := range profiles {
// Attach Parameters if the 'id' parameter is sent
if _, ok := parameters[IDQueryParam]; ok {
- params, err := ReadParameters(prof.ReqInfo.Tx, parameters, prof.ReqInfo.User, p)
- p.Parameters = params
+ params, err := ReadParameters(prof.ReqInfo.Tx, parameters, prof.ReqInfo.User, profile)
+ profile.Parameters = params
if len(errs) > 0 {
log.Errorf("Error getting Parameters: %v", err)
return nil, []error{tc.DBError}, tc.SystemError
}
}
- profiles = append(profiles, p)
+ profileInterfaces = append(profileInterfaces, profile)
}
- return profiles, []error{}, tc.NoError
+ return profileInterfaces, []error{}, tc.NoError
}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 00edc23..c270424 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -251,10 +251,10 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
//Delivery service requests
{1.3, http.MethodGet, `deliveryservice_requests/?(\.json)?$`, api.ReadHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
- {1.3, http.MethodGet, `deliveryservice_requests/{id}$`, api.ReadHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
- {1.3, http.MethodPut, `deliveryservice_requests/{id}$`, api.UpdateHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelPortal, Authenticated, nil},
+ {1.3, http.MethodGet, `deliveryservice_requests/?$`, api.ReadHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.3, http.MethodPut, `deliveryservice_requests/?$`, api.UpdateHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelPortal, Authenticated, nil},
{1.3, http.MethodPost, `deliveryservice_requests/?$`, api.CreateHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelPortal, Authenticated, nil},
- {1.3, http.MethodDelete, `deliveryservice_requests/{id}$`, api.DeleteHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelPortal, Authenticated, nil},
+ {1.3, http.MethodDelete, `deliveryservice_requests/?$`, api.DeleteHandler(dsrequest.GetTypeSingleton()), auth.PrivLevelPortal, Authenticated, nil},
//Delivery service request: Actions
{1.3, http.MethodPut, `deliveryservice_requests/{id}/assign$`, api.UpdateHandler(dsrequest.GetAssignmentTypeSingleton()), auth.PrivLevelOperations, Authenticated, nil},