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 2020/01/30 16:55:08 UTC

[GitHub] [trafficcontrol] mattjackson220 opened a new pull request #4356: Update generic API Create to allow arrays in POST if set on object

mattjackson220 opened a new pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356
 
 
   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [x] This PR fixes #3103, #3093
   
   This PR updates the generic API Create function to allow arrays as part of the POST if the struct passed in has it enabled.
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - Documentation
   - Traffic Control Client Go <!-- Please specify which; e.g. 'Python', 'Go', 'Java' -->
   - Traffic Ops
   
   ## What is the best way to verify this PR?
   - run TO locally and verify that POSTs to the /profileparameters and /parameters endpoints allow a single object, an array with only 1 object, and an array with multiple objects and that all get correctly inserted into the database.
   - verify that logs get added in the log table for each added parameter
   - run the same POSTs again with AllowMultipleCreates() set to false and verify that the array format does not work
   - run the same POSTs again with AllowMultipleCreates() completely removed from from the object and verify that the array format does not work
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '2697ebac'), in v3.0.0,
   and in the current 3.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (2697ebac)
   - 3.0.0
   - 3.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [x] This PR includes tests
   - [x] This PR includes documentation
   - [x] This PR includes an update to CHANGELOG.md
   - [x] This PR includes any and all required license headers
   - [x] This PR does not include a database migration
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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.
   -->
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601219
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
+	}
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
+	}
+
+	profileID := profileResp[0].ID
+	parameterID := paramResp[0].ID
+
+	pp := tc.ProfileParameter{
+		ProfileID:   profileID,
+		ParameterID: parameterID,
+	}
+
+	secondProfile := testData.Profiles[1]
+	secondProfileResp, _, err := TOSession.GetProfileByName(secondProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", secondProfile.Name, err)
+	}
+
+	secondParameter := testData.Parameters[0]
+	secondParamResp, _, err := TOSession.GetParameterByName(secondParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379528820
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
+	}
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
 
 Review comment:
   should be `t.Fatalf`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601161
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
+	}
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601193
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
+	}
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
+	}
+
+	profileID := profileResp[0].ID
+	parameterID := paramResp[0].ID
+
+	pp := tc.ProfileParameter{
+		ProfileID:   profileID,
+		ParameterID: parameterID,
+	}
+
+	secondProfile := testData.Profiles[1]
+	secondProfileResp, _, err := TOSession.GetProfileByName(secondProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", secondProfile.Name, err)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379528379
 
 

 ##########
 File path: traffic_ops/client/profile_parameter.go
 ##########
 @@ -49,6 +49,25 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
+// Create multiple ProfileParameters
+func (to *Session) CreateMultipleProfileParameters(pps []tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pps)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Profile_Parameters, reqBody)
 
 Review comment:
   same here 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r378412642
 
 

 ##########
 File path: traffic_ops/testing/api/v1/parameters_test.go
 ##########
 @@ -45,6 +45,20 @@ func CreateTestParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestParameters(t *testing.T) {
+
+	pls := []tc.Parameter{}
+	for _, pl := range testData.Parameters {
+		pls = append(pls, pl)
+	}
+	resp, _, err := TOSession.CreateMultipleParameters(pls)
+	log.Debugln("Response: ", resp)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] zrhoffman commented on issue #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on issue #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#issuecomment-585367898
 
 
   - docs build without warnings
   - `go fmt` comes up clean
   - unit tests pass
   - API tests pass
   
   Looks good to me!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r373712618
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
 ##########
 @@ -44,8 +44,9 @@ type TOProfileParameter struct {
 	tc.ProfileParameterNullable
 }
 
-func (v *TOProfileParameter) NewReadObj() interface{} { return &tc.ProfileParametersNullable{} }
-func (v *TOProfileParameter) SelectQuery() string     { return selectQuery() }
+func (v *TOProfileParameter) AllowMultipleCreates() bool { return true }
 
 Review comment:
   `TOProfileParameter.AllowMultipleCreates()` has the same name as the `v1.AllowMultipleCreates` interface. Should one of these names change?
   
   Also, please comment this function.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379528313
 
 

 ##########
 File path: traffic_ops/client/parameter.go
 ##########
 @@ -48,6 +48,25 @@ func (to *Session) CreateParameter(pl tc.Parameter) (tc.Alerts, ReqInf, error) {
 	return alerts, reqInf, nil
 }
 
+// Create multiple Parameters
+func (to *Session) CreateMultipleParameters(pls []tc.Parameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pls)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Parameters, reqBody)
 
 Review comment:
   not your fault but can you change this to using apiBase directly instead of v13

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379600975
 
 

 ##########
 File path: traffic_ops/client/parameter.go
 ##########
 @@ -48,6 +48,25 @@ func (to *Session) CreateParameter(pl tc.Parameter) (tc.Alerts, ReqInf, error) {
 	return alerts, reqInf, nil
 }
 
+// Create multiple Parameters
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379532888
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
+	}
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
+	}
+
+	profileID := profileResp[0].ID
+	parameterID := paramResp[0].ID
+
+	pp := tc.ProfileParameter{
+		ProfileID:   profileID,
+		ParameterID: parameterID,
+	}
+
+	secondProfile := testData.Profiles[1]
+	secondProfileResp, _, err := TOSession.GetProfileByName(secondProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", secondProfile.Name, err)
 
 Review comment:
   should be t.Fatalf
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] ocket8888 commented on issue #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on issue #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#issuecomment-580364924
 
 
   This is an improvement in general, but it also fixes regression bugs in endpoints which used to accept either objects in the request body or arrays thereof.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601015
 
 

 ##########
 File path: traffic_ops/client/parameter.go
 ##########
 @@ -48,6 +48,25 @@ func (to *Session) CreateParameter(pl tc.Parameter) (tc.Alerts, ReqInf, error) {
 	return alerts, reqInf, nil
 }
 
+// Create multiple Parameters
+func (to *Session) CreateMultipleParameters(pls []tc.Parameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pls)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Parameters, reqBody)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r378307498
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/shared_handlers.go
 ##########
 @@ -367,34 +369,123 @@ func CreateHandler(creator Creator) http.HandlerFunc {
 		obj := reflect.New(objectType).Interface().(Creator)
 		obj.SetInfo(inf)
 
-		err := decodeAndValidateRequestBody(r, obj)
-		if err != nil {
-			HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
-			return
-		}
+		if c, ok := obj.(AllowMultipleCreates); ok && c.AllowMultipleCreates() {
+			data, err := ioutil.ReadAll(r.Body)
+			if err != nil {
+				HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
+				return
+			}
 
-		if t, ok := obj.(Tenantable); ok {
-			authorized, err := t.IsTenantAuthorized(inf.User)
+			objSlice, err := parseMultipleCreates(data, objectType, inf)
 			if err != nil {
-				HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant authorized: "+err.Error()))
+				HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
 				return
 			}
-			if !authorized {
-				HandleErr(w, r, inf.Tx.Tx, http.StatusForbidden, errors.New("not authorized on this tenant"), nil)
+
+			for _, objElemInt := range objSlice {
+				objElem := reflect.ValueOf(objElemInt).Interface().(Creator)
+
+				err = objElem.Validate()
+				if err != nil {
+					HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
+					return
+				}
+
+				if t, ok := objElem.(Tenantable); ok {
+					authorized, err := t.IsTenantAuthorized(inf.User)
+					if err != nil {
+						HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant authorized: "+err.Error()))
+						return
+					}
+					if !authorized {
+						HandleErr(w, r, inf.Tx.Tx, http.StatusForbidden, errors.New("not authorized on this tenant"), nil)
+						return
+					}
+				}
+
+				userErr, sysErr, errCode = objElem.Create()
+				if userErr != nil || sysErr != nil {
+					HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+					return
+				}
+
+				if err = CreateChangeLog(ApiChange, Created, objElem, inf.User, inf.Tx.Tx); err != nil {
+					HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, tc.DBError, errors.New("inserting changelog: "+err.Error()))
+					return
+				}
+			}
+			if len(objSlice) == 1 {
+				WriteRespAlertObj(w, r, tc.SuccessLevel, objSlice[0].GetType()+" was created.", objSlice[0])
+			} else {
+				WriteRespAlertObj(w, r, tc.SuccessLevel, objSlice[0].GetType()+"s were created.", objSlice)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601085
 
 

 ##########
 File path: traffic_ops/client/profile_parameter.go
 ##########
 @@ -49,6 +49,25 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
+// Create multiple ProfileParameters
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] ocket8888 merged pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
ocket8888 merged pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r373710965
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/shared_interfaces.go
 ##########
 @@ -58,6 +58,10 @@ type Creator interface {
 	Validator
 }
 
+type AllowMultipleCreates interface {
 
 Review comment:
   Please add a comment for the `AllowMultipleCreates` interface.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r373214464
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/shared_handlers.go
 ##########
 @@ -367,34 +369,123 @@ func CreateHandler(creator Creator) http.HandlerFunc {
 		obj := reflect.New(objectType).Interface().(Creator)
 		obj.SetInfo(inf)
 
-		err := decodeAndValidateRequestBody(r, obj)
-		if err != nil {
-			HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
-			return
-		}
+		if c, ok := obj.(AllowMultipleCreates); ok && c.AllowMultipleCreates() {
+			data, err := ioutil.ReadAll(r.Body)
+			if err != nil {
+				HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
+				return
+			}
 
-		if t, ok := obj.(Tenantable); ok {
-			authorized, err := t.IsTenantAuthorized(inf.User)
+			objSlice, err := parseMultipleCreates(data, objectType, inf)
 			if err != nil {
-				HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant authorized: "+err.Error()))
+				HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
 				return
 			}
-			if !authorized {
-				HandleErr(w, r, inf.Tx.Tx, http.StatusForbidden, errors.New("not authorized on this tenant"), nil)
+
+			for _, objElemInt := range objSlice {
+				objElem := reflect.ValueOf(objElemInt).Interface().(Creator)
+
+				err = objElem.Validate()
+				if err != nil {
+					HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
+					return
+				}
+
+				if t, ok := objElem.(Tenantable); ok {
+					authorized, err := t.IsTenantAuthorized(inf.User)
+					if err != nil {
+						HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant authorized: "+err.Error()))
+						return
+					}
+					if !authorized {
+						HandleErr(w, r, inf.Tx.Tx, http.StatusForbidden, errors.New("not authorized on this tenant"), nil)
+						return
+					}
+				}
+
+				userErr, sysErr, errCode = objElem.Create()
+				if userErr != nil || sysErr != nil {
+					HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+					return
+				}
+
+				if err = CreateChangeLog(ApiChange, Created, objElem, inf.User, inf.Tx.Tx); err != nil {
+					HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, tc.DBError, errors.New("inserting changelog: "+err.Error()))
+					return
+				}
+			}
+			if len(objSlice) == 1 {
+				WriteRespAlertObj(w, r, tc.SuccessLevel, objSlice[0].GetType()+" was created.", objSlice[0])
+			} else {
+				WriteRespAlertObj(w, r, tc.SuccessLevel, objSlice[0].GetType()+"s were created.", objSlice)
 
 Review comment:
   This line makes the assumption that there are 1 or more objects, but there is no previous check to ensure this. Attempting to POST a 0-length array causes this line to error out:
   
   ```shell
   docker-compose exec mid sh -c 'topost parameters "[]" --insecure --to-user=$TO_ADMIN_USER --to-password=$TO_ADMIN_PASSWORD --to-url=https://$TO_HOST'
   ```
   
   Response (500):
   ```json
   {"alerts":[{"text":"Internal Server Error","level":"error"}]}
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r378389643
 
 

 ##########
 File path: traffic_ops/testing/api/v1/parameters_test.go
 ##########
 @@ -45,6 +45,20 @@ func CreateTestParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestParameters(t *testing.T) {
+
+	pls := []tc.Parameter{}
+	for _, pl := range testData.Parameters {
+		pls = append(pls, pl)
+	}
+	resp, _, err := TOSession.CreateMultipleParameters(pls)
+	log.Debugln("Response: ", resp)
 
 Review comment:
   When trying to run the API tests, I get this error:
   
   ```dockerfile
   Step 12/25 : RUN go test -c ./v1* -o traffic_ops_integration_test
    ---> Running in 32f467ccc60b
   # github.com/apache/trafficcontrol/traffic_ops/testing/api/v1 [github.com/apache/trafficcontrol/traffic_ops/testing/api/v1.test]
   v1/parameters_test.go:55:2: undefined: log
   v1/profile_parameters_test.go:111:2: undefined: log
   ERROR: Service 'integration' failed to build: The command '/bin/sh -c go test -c ./v1* -o traffic_ops_integration_test' returned a non-zero code: 2
   ```
   
   Edit: <details>
   <summary>Full log (click to expand)</summary>
   
   ```dockerfile
   [zhoffm468@COSML-1717912 cdn-in-a-box]$ time docker-compose -f docker-compose.yml -f docker-compose.traffic-ops-test.yml run --rm integration
   Creating volume "cdn-in-a-box_junit" with default driver
   Building integration
   Step 1/25 : FROM golang:1.11 AS integration-builder
    ---> 43a154fee764
   Step 2/25 : COPY ./lib/ /go/src/github.com/apache/trafficcontrol/lib/
    ---> dce2943bd0e2
   Step 3/25 : COPY ./vendor/ /go/src/github.com/apache/trafficcontrol/vendor/
    ---> 274715309412
   Step 4/25 : COPY ./traffic_ops/client/ /go/src/github.com/apache/trafficcontrol/traffic_ops/client/
    ---> 05cd80382ac7
   Step 5/25 : COPY ./traffic_ops/vendor/ /go/src/github.com/apache/trafficcontrol/traffic_ops/vendor/
    ---> 0babd1491a0e
   Step 6/25 : COPY ./infrastructure/cdn-in-a-box/traffic_ops_integration_test/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/traffic_ops_integration_test/
    ---> 8529c68b4d10
   Step 7/25 : COPY ./traffic_ops/testing/api /go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api
    ---> dd6c9642a725
   Step 8/25 : COPY ./traffic_ops/traffic_ops_golang /go/src/github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang
    ---> 288aae085ce0
   Step 9/25 : COPY ./infrastructure/cdn-in-a-box/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/
    ---> 2c80137a2e66
   Step 10/25 : WORKDIR /go/src/github.com/apache/trafficcontrol/traffic_ops/testing/api
    ---> Running in c77586ac07b8
   Removing intermediate container c77586ac07b8
    ---> 1f3730ac4321
   Step 11/25 : RUN go get -u golang.org/x/net/publicsuffix golang.org/x/crypto/scrypt
    ---> Running in d4c37fb54c66
   Removing intermediate container d4c37fb54c66
    ---> ca523d0a0eca
   Step 12/25 : RUN go test -c ./v1* -o traffic_ops_integration_test
    ---> Running in 32f467ccc60b
   # github.com/apache/trafficcontrol/traffic_ops/testing/api/v1 [github.com/apache/trafficcontrol/traffic_ops/testing/api/v1.test]
   v1/parameters_test.go:55:2: undefined: log
   v1/profile_parameters_test.go:111:2: undefined: log
   ERROR: Service 'integration' failed to build: The command '/bin/sh -c go test -c ./v1* -o traffic_ops_integration_test' returned a non-zero code: 2
   
   real    0m26.140s
   user    0m4.024s
   sys     0m1.073s
   ```
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379532940
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
+	}
+
+	firstParameter := testData.Parameters[0]
+	paramResp, _, err := TOSession.GetParameterByName(firstParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
+	}
+
+	profileID := profileResp[0].ID
+	parameterID := paramResp[0].ID
+
+	pp := tc.ProfileParameter{
+		ProfileID:   profileID,
+		ParameterID: parameterID,
+	}
+
+	secondProfile := testData.Profiles[1]
+	secondProfileResp, _, err := TOSession.GetProfileByName(secondProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", secondProfile.Name, err)
+	}
+
+	secondParameter := testData.Parameters[0]
+	secondParamResp, _, err := TOSession.GetParameterByName(secondParameter.Name)
+	if err != nil {
+		t.Errorf("cannot GET Parameter by name: %v - %v", firstParameter.Name, err)
 
 Review comment:
   should be t.Fatalf
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r378308425
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/shared_interfaces.go
 ##########
 @@ -58,6 +58,10 @@ type Creator interface {
 	Validator
 }
 
+type AllowMultipleCreates interface {
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r380897268
 
 

 ##########
 File path: traffic_ops/client/profile_parameter.go
 ##########
 @@ -49,6 +49,25 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
+// Create multiple ProfileParameters
+func (to *Session) CreateMultipleProfileParameters(pps []tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pps)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Profile_Parameters, reqBody)
 
 Review comment:
   ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r378310259
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/profileparameter/profile_parameters.go
 ##########
 @@ -44,8 +44,9 @@ type TOProfileParameter struct {
 	tc.ProfileParameterNullable
 }
 
-func (v *TOProfileParameter) NewReadObj() interface{} { return &tc.ProfileParametersNullable{} }
-func (v *TOProfileParameter) SelectQuery() string     { return selectQuery() }
+func (v *TOProfileParameter) AllowMultipleCreates() bool { return true }
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379063930
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/shared_handlers.go
 ##########
 @@ -395,34 +397,125 @@ func CreateHandler(creator Creator) http.HandlerFunc {
 		obj := reflect.New(objectType).Interface().(Creator)
 		obj.SetInfo(inf)
 
-		err := decodeAndValidateRequestBody(r, obj)
-		if err != nil {
-			HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
-			return
-		}
+		if c, ok := obj.(MultipleCreator); ok && c.AllowMultipleCreates() {
+			data, err := ioutil.ReadAll(r.Body)
+			if err != nil {
+				HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, err, nil)
+				return
+			}
 
-		if t, ok := obj.(Tenantable); ok {
-			authorized, err := t.IsTenantAuthorized(inf.User)
+			objSlice, err := parseMultipleCreates(data, objectType, inf)
 			if err != nil {
-				HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking tenant authorized: "+err.Error()))
+				HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, err)
 				return
 			}
-			if !authorized {
-				HandleErr(w, r, inf.Tx.Tx, http.StatusForbidden, errors.New("not authorized on this tenant"), nil)
+
+			for _, objElemInt := range objSlice {
 
 Review comment:
   this looks great! but I wonder if there is a different approach so we dont have to loop through and do n db calls but just one to do a bulk insert. Not blocking but more of a comment to think about.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
zrhoffman commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r378389643
 
 

 ##########
 File path: traffic_ops/testing/api/v1/parameters_test.go
 ##########
 @@ -45,6 +45,20 @@ func CreateTestParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestParameters(t *testing.T) {
+
+	pls := []tc.Parameter{}
+	for _, pl := range testData.Parameters {
+		pls = append(pls, pl)
+	}
+	resp, _, err := TOSession.CreateMultipleParameters(pls)
+	log.Debugln("Response: ", resp)
 
 Review comment:
   When trying to run the API tests, I get this error:
   
   ```dockerfile
   Step 12/25 : RUN go test -c ./v1* -o traffic_ops_integration_test
    ---> Running in 32f467ccc60b
   # github.com/apache/trafficcontrol/traffic_ops/testing/api/v1 [github.com/apache/trafficcontrol/traffic_ops/testing/api/v1.test]
   v1/parameters_test.go:55:2: undefined: log
   v1/profile_parameters_test.go:111:2: undefined: log
   ERROR: Service 'integration' failed to build: The command '/bin/sh -c go test -c ./v1* -o traffic_ops_integration_test' returned a non-zero code: 2
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379528415
 
 

 ##########
 File path: traffic_ops/client/profile_parameter.go
 ##########
 @@ -49,6 +49,25 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
+// Create multiple ProfileParameters
 
 Review comment:
   same here

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601054
 
 

 ##########
 File path: traffic_ops/client/profile_parameter.go
 ##########
 @@ -49,6 +49,25 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
+// Create multiple ProfileParameters
+func (to *Session) CreateMultipleProfileParameters(pps []tc.ProfileParameter) (tc.Alerts, ReqInf, error) {
+
+	var remoteAddr net.Addr
+	reqBody, err := json.Marshal(pps)
+	reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+	if err != nil {
+		return tc.Alerts{}, reqInf, err
+	}
+	resp, remoteAddr, err := to.request(http.MethodPost, API_v13_Profile_Parameters, reqBody)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r380897216
 
 

 ##########
 File path: traffic_ops/client/profile_parameter.go
 ##########
 @@ -49,6 +49,25 @@ func (to *Session) CreateProfileParameter(pp tc.ProfileParameter) (tc.Alerts, Re
 	return alerts, reqInf, nil
 }
 
+// Create multiple ProfileParameters
 
 Review comment:
   ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379528119
 
 

 ##########
 File path: traffic_ops/client/parameter.go
 ##########
 @@ -48,6 +48,25 @@ func (to *Session) CreateParameter(pl tc.Parameter) (tc.Alerts, ReqInf, error) {
 	return alerts, reqInf, nil
 }
 
+// Create multiple Parameters
 
 Review comment:
   nit incorrect go doc comment

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379601125
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

[GitHub] [trafficcontrol] mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4356: Update generic API Create to allow arrays in POST if set on object
URL: https://github.com/apache/trafficcontrol/pull/4356#discussion_r379528747
 
 

 ##########
 File path: traffic_ops/testing/api/v1/profile_parameters_test.go
 ##########
 @@ -60,6 +60,61 @@ func CreateTestProfileParameters(t *testing.T) {
 
 }
 
+func CreateMultipleTestProfileParameters(t *testing.T) {
+
+	firstProfile := testData.Profiles[0]
+	profileResp, _, err := TOSession.GetProfileByName(firstProfile.Name)
+	if err != nil {
+		t.Errorf("cannot GET Profile by name: %v - %v", firstProfile.Name, err)
 
 Review comment:
   should be `t.Fatalf`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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