svn commit: r26084 - /release/incubator/trafficcontrol/2.0.0-incubating/
Author: rob Date: Mon Apr 2 16:29:53 2018 New Revision: 26084 Log: removing old 2.0.0 version Removed: release/incubator/trafficcontrol/2.0.0-incubating/
[incubator-trafficcontrol] branch master updated: added SetID function
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/incubator-trafficcontrol.git The following commit(s) were added to refs/heads/master by this push: new 2a5a87e added SetID function 2a5a87e is described below commit 2a5a87e0a9c51f9ae1f2647336d9a025a4a9ffbf Author: Dewayne Richardson AuthorDate: Mon Apr 2 08:07:41 2018 -0600 added SetID function --- traffic_ops/traffic_ops_golang/server/servers.go | 4 1 file changed, 4 insertions(+) diff --git a/traffic_ops/traffic_ops_golang/server/servers.go b/traffic_ops/traffic_ops_golang/server/servers.go index a08a33d..bd25b20 100644 --- a/traffic_ops/traffic_ops_golang/server/servers.go +++ b/traffic_ops/traffic_ops_golang/server/servers.go @@ -48,6 +48,10 @@ func GetRefType() *TOServer { return &refType } +func (server *TOServer) SetID(i int) { + server.ID = &i +} + func (server TOServer) GetKeyFieldsInfo() []api.KeyFieldInfo { return []api.KeyFieldInfo{{"id", api.GetIntKey}} } -- To stop receiving notification emails like this one, please contact mitchell...@apache.org.
[incubator-trafficcontrol] branch master updated (fdb38dc -> 01efc18)
This is an automated email from the ASF dual-hosted git repository. dewrich pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git. from fdb38dc fixed the API tests new 53ec33c intial work to support compound keys, only cdn implemented new 01efc18 convert all implementations of CRUD interfaces to use Keys methods The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: traffic_ops/traffic_ops_golang/api/change_log.go | 11 +++- .../traffic_ops_golang/api/change_log_test.go | 12 ++-- .../traffic_ops_golang/api/shared_handlers.go | 71 +- .../traffic_ops_golang/api/shared_handlers_test.go | 19 +++--- .../traffic_ops_golang/api/shared_interfaces.go| 7 ++- traffic_ops/traffic_ops_golang/asn/asns.go | 31 ++ traffic_ops/traffic_ops_golang/cdn/cdns.go | 21 --- .../deliveryservice/deliveryservices.go| 22 --- .../deliveryservice/request/comment/comments.go| 26 +--- .../request/comment/comments_test.go | 1 - .../deliveryservice/request/requests.go| 31 ++ .../deliveryservice/request/requests_test.go | 8 +-- .../traffic_ops_golang/division/divisions.go | 25 +--- .../traffic_ops_golang/parameter/parameters.go | 21 --- .../physlocation/phys_locations.go | 21 --- traffic_ops/traffic_ops_golang/profile/profiles.go | 21 --- traffic_ops/traffic_ops_golang/region/regions.go | 19 +++--- traffic_ops/traffic_ops_golang/server/servers.go | 27 +--- traffic_ops/traffic_ops_golang/status/statuses.go | 31 ++ traffic_ops/traffic_ops_golang/types/types.go | 21 --- 20 files changed, 289 insertions(+), 157 deletions(-) -- To stop receiving notification emails like this one, please contact dewr...@apache.org.
[incubator-trafficcontrol] 02/02: convert all implementations of CRUD interfaces to use Keys methods
This is an automated email from the ASF dual-hosted git repository. dewrich pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git commit 01efc18a5965c2dd2efc2b458330a6c9e3a7fc85 Author: Dylan Volz AuthorDate: Wed Mar 28 14:17:37 2018 -0600 convert all implementations of CRUD interfaces to use Keys methods --- traffic_ops/traffic_ops_golang/api/change_log.go | 11 +--- .../traffic_ops_golang/api/change_log_test.go | 12 ++--- .../traffic_ops_golang/api/shared_handlers.go | 24 - .../traffic_ops_golang/api/shared_handlers_test.go | 19 - traffic_ops/traffic_ops_golang/asn/asns.go | 31 +- traffic_ops/traffic_ops_golang/cdn/cdns.go | 8 +++--- .../deliveryservice/deliveryservices.go| 22 +-- .../deliveryservice/request/comment/comments.go| 26 +++--- .../request/comment/comments_test.go | 1 - .../deliveryservice/request/requests.go| 31 +- .../deliveryservice/request/requests_test.go | 8 +++--- .../traffic_ops_golang/division/divisions.go | 25 ++--- .../traffic_ops_golang/parameter/parameters.go | 21 +-- .../physlocation/phys_locations.go | 21 +-- traffic_ops/traffic_ops_golang/profile/profiles.go | 21 +-- traffic_ops/traffic_ops_golang/region/regions.go | 19 - traffic_ops/traffic_ops_golang/server/servers.go | 27 --- traffic_ops/traffic_ops_golang/status/statuses.go | 31 +- traffic_ops/traffic_ops_golang/types/types.go | 21 +-- 19 files changed, 232 insertions(+), 147 deletions(-) diff --git a/traffic_ops/traffic_ops_golang/api/change_log.go b/traffic_ops/traffic_ops_golang/api/change_log.go index 579d063..17c54a7 100644 --- a/traffic_ops/traffic_ops_golang/api/change_log.go +++ b/traffic_ops/traffic_ops_golang/api/change_log.go @@ -20,7 +20,7 @@ package api */ import ( - "strconv" + "fmt" "github.com/apache/incubator-trafficcontrol/lib/go-log" "github.com/apache/incubator-trafficcontrol/lib/go-tc" @@ -49,8 +49,13 @@ const ( ) func CreateChangeLog(level string, action string, i Identifier, user auth.CurrentUser, db *sqlx.DB) error { - id, _ := i.GetID() - message := action + " " + i.GetType() + ": " + i.GetAuditName() + " id: " + strconv.Itoa(id) + keys, _ := i.GetKeys() + keysString := "{ " + for key, value := range keys { + keysString += key + ":" + fmt.Sprintf("%v", value) + " " + } + keysString += "}" + message := action + " " + i.GetType() + ": " + i.GetAuditName() + " keys: " + keysString // if the object has its own log message generation, use it if t, ok := i.(ChangeLogger); ok { m, err := t.ChangeLogMessage(action) diff --git a/traffic_ops/traffic_ops_golang/api/change_log_test.go b/traffic_ops/traffic_ops_golang/api/change_log_test.go index bfbcab2..cfd9230 100644 --- a/traffic_ops/traffic_ops_golang/api/change_log_test.go +++ b/traffic_ops/traffic_ops_golang/api/change_log_test.go @@ -32,8 +32,12 @@ import ( type testIdentifier struct { } -func (i *testIdentifier) GetID() (int, bool) { - return 1, true +func (i testIdentifier) GetKeyFieldsInfo() []KeyFieldInfo { + return []KeyFieldInfo{{"id", GetIntKey}} +} + +func (i *testIdentifier) GetKeys() (map[string]interface{}, bool) { + return map[string]interface{}{"id": 1}, true } func (i *testIdentifier) GetType() string { @@ -55,8 +59,8 @@ func TestCreateChangeLog(t *testing.T) { defer db.Close() i := testIdentifier{} - id, _ := i.GetID() - expectedMessage := Created + " " + i.GetType() + ": " + i.GetAuditName() + " id: " + strconv.Itoa(id) + keys, _ := i.GetKeys() + expectedMessage := Created + " " + i.GetType() + ": " + i.GetAuditName() + " keys: { id:" + strconv.Itoa(keys["id"].(int)) + " }" mock.ExpectExec("INSERT").WithArgs(ApiChange, expectedMessage, 1).WillReturnResult(sqlmock.NewResult(1, 1)) user := auth.CurrentUser{ID: 1} diff --git a/traffic_ops/traffic_ops_golang/api/shared_handlers.go b/traffic_ops/traffic_ops_golang/api/shared_handlers.go index 298f32f..8652455 100644 --- a/traffic_ops/traffic_ops_golang/api/shared_handlers.go +++ b/traffic_ops/traffic_ops_golang/api/shared_handlers.go @@ -33,21 +33,20 @@ import ( "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth" "github.com/jmoiron/sqlx" - "strings" ) const PathParamsKey = "pathParams" -type KeyFieldInfo struct{ +type KeyFieldInfo struct { Field string - Func func(string)(interface{},error) + Func func(string) (interface{}, error) } -func GetIntKey(s string)(interface{},error){ +func G
[incubator-trafficcontrol] 01/02: intial work to support compound keys, only cdn implemented
This is an automated email from the ASF dual-hosted git repository. dewrich pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git commit 53ec33c6583889c82d2b624dea815f2827cf8aa7 Author: Dylan Volz AuthorDate: Tue Mar 27 14:40:39 2018 -0600 intial work to support compound keys, only cdn implemented --- .../traffic_ops_golang/api/shared_handlers.go | 71 +- .../traffic_ops_golang/api/shared_interfaces.go| 7 ++- traffic_ops/traffic_ops_golang/cdn/cdns.go | 19 -- 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/traffic_ops/traffic_ops_golang/api/shared_handlers.go b/traffic_ops/traffic_ops_golang/api/shared_handlers.go index f1edb0d..298f32f 100644 --- a/traffic_ops/traffic_ops_golang/api/shared_handlers.go +++ b/traffic_ops/traffic_ops_golang/api/shared_handlers.go @@ -33,10 +33,24 @@ import ( "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth" "github.com/jmoiron/sqlx" + "strings" ) const PathParamsKey = "pathParams" +type KeyFieldInfo struct{ + Field string + Func func(string)(interface{},error) +} + +func GetIntKey(s string)(interface{},error){ + return strconv.Atoi(s) +} + +func GetStringKey(s string)(interface{},error){ + return s, nil +} + func GetPathParams(ctx context.Context) (map[string]string, error) { val := ctx.Value(PathParamsKey) if val != nil { @@ -175,7 +189,7 @@ func UpdateHandler(typeRef Updater, db *sqlx.DB) http.HandlerFunc { //collect path parameters and user from context ctx := r.Context() - pathParams, err := GetPathParams(ctx) + params, err := GetCombinedParams(r) if err != nil { log.Errorf("received error trying to get path parameters: %s", err) handleErrs(http.StatusInternalServerError, err) @@ -187,17 +201,30 @@ func UpdateHandler(typeRef Updater, db *sqlx.DB) http.HandlerFunc { handleErrs(http.StatusInternalServerError, err) return } - id, err := strconv.Atoi(pathParams["id"]) - if err != nil { - log.Errorf("received error trying to convert id path parameter: %s", err) - handleErrs(http.StatusBadRequest, errors.New("id from path not parseable as int")) - return + + 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 { + } + for _,keyFieldInfo := range keyFields { + paramKey := params[keyFieldInfo.Field] + if paramKey == "" { + log.Errorf("missing key: %s", keyFieldInfo.Field) + handleErrs(http.StatusBadRequest, errors.New("missing key: " + keyFieldInfo.Field)) + return + } - iid, ok := u.GetID() - if !ok || iid != id { - handleErrs(http.StatusBadRequest, errors.New("id in body does not match id in path")) - return + paramValue, err := keyFieldInfo.Func(paramKey) + if err != nil { + log.Errorf("failed to parse key %s: %s", keyFieldInfo.Field, err) + handleErrs(http.StatusBadRequest, errors.New("failed to parse key: " + keyFieldInfo.Field)) + } + + if paramValue != keys[keyFieldInfo.Field] { + handleErrs(http.StatusBadRequest, errors.New("key in body does not match key in params")) + return + } } // if the object has tenancy enabled, check that user is able to access the tenant @@ -252,7 +279,7 @@ func DeleteHandler(typeRef Deleter, db *sqlx.DB) http.HandlerFunc { d := typeRef ctx := r.Context() - pathParams, err := GetPathParams(ctx) + params, err := GetCombinedParams(r) if err != nil { handleErrs(http.StatusInternalServerError, err) return @@ -264,12 +291,24 @@ func DeleteHandler(typeRef Deleter, db *sqlx.DB) http.HandlerFunc { return } - id, err := strconv.Atoi(pathParams["id"]) -
[incubator-trafficcontrol] branch master updated: fixed the API tests
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/incubator-trafficcontrol.git The following commit(s) were added to refs/heads/master by this push: new fdb38dc fixed the API tests fdb38dc is described below commit fdb38dc998d7b422260d044a40c388bd2ee00dc9 Author: Dewayne Richardson AuthorDate: Mon Apr 2 07:47:31 2018 -0600 fixed the API tests --- traffic_ops/testing/api/v13/cdns_test.go| 4 ++-- .../testing/api/v13/deliveryservice_request_comments_test.go| 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/traffic_ops/testing/api/v13/cdns_test.go b/traffic_ops/testing/api/v13/cdns_test.go index 2c9ab4c..a3fe7f5 100644 --- a/traffic_ops/testing/api/v13/cdns_test.go +++ b/traffic_ops/testing/api/v13/cdns_test.go @@ -49,7 +49,7 @@ func UpdateTestCDNs(t *testing.T) { // Retrieve the CDN by name so we can get the id for the Update resp, _, err := TOSession.GetCDNByName(firstCDN.Name) if err != nil { - t.Errorf("cannot GET CDN by name: '%s' %v - %v\n", firstCDN.Name, err) + t.Errorf("cannot GET CDN by name: '%s', %v\n", firstCDN.Name, err) } remoteCDN := resp[0] expectedCDNDomain := "domain2" @@ -63,7 +63,7 @@ func UpdateTestCDNs(t *testing.T) { // Retrieve the CDN to check CDN name got updated resp, _, err = TOSession.GetCDNByID(remoteCDN.ID) if err != nil { - t.Errorf("cannot GET CDN by name: '$%s' %v - %v\n", firstCDN.Name, err) + t.Errorf("cannot GET CDN by name: '$%s', %v\n", firstCDN.Name, err) } respCDN := resp[0] if respCDN.DomainName != expectedCDNDomain { diff --git a/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go b/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go index b5eda00..40fda20 100644 --- a/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go +++ b/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go @@ -72,7 +72,7 @@ func UpdateTestDeliveryServiceRequestComments(t *testing.T) { // Retrieve the delivery service request comment to check that the value got updated resp, _, err := TOSession.GetDeliveryServiceRequestCommentByID(firstComment.ID) if err != nil { - t.Errorf("cannot GET delivery service request comment by id: '$%s' %v - %v\n", firstComment.ID, err) + t.Errorf("cannot GET delivery service request comment by id: '$%d', %v\n", firstComment.ID, err) } respDSRC := resp[0] if respDSRC.Value != newFirstCommentValue { @@ -100,7 +100,7 @@ func DeleteTestDeliveryServiceRequestComments(t *testing.T) { for _, comment := range comments { _, _, err := TOSession.DeleteDeliveryServiceRequestCommentByID(comment.ID) if err != nil { - t.Errorf("cannot DELETE delivery service request comment by id: '%s' %v\n", comment.ID, err) + t.Errorf("cannot DELETE delivery service request comment by id: '%d' %v\n", comment.ID, err) } // Retrieve the delivery service request comment to see if it got deleted @@ -109,7 +109,7 @@ func DeleteTestDeliveryServiceRequestComments(t *testing.T) { t.Errorf("error deleting delivery service request comment: %s\n", err.Error()) } if len(comments) > 0 { - t.Errorf("expected delivery service request comment: %s to be deleted\n", comment.ID) + t.Errorf("expected delivery service request comment: %d to be deleted\n", comment.ID) } } } -- To stop receiving notification emails like this one, please contact mitchell...@apache.org.