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/02/17 16:00:02 UTC

[GitHub] [trafficcontrol] shamrickus opened a new pull request #4406: Only allow changing of types based on useintable

shamrickus opened a new pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406
 
 
   <!--
   ************ 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 is not related to any Issue <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## 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. -->
   
   - Traffic Ops
   
   ## What is the best way to verify this PR?
   Run API tests and verify they pass.
   
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   
   
   ## 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 OR I have explained why tests are unnecessary
   - [x] This PR includes documentation OR I have explained why documentation is unnecessary
   - [x] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [x] This PR includes any and all required license headers
   - [x] This PR ensures that database migration sequence is correct OR 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] mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r391828111
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,48 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.UseInTable == nil {
 
 Review comment:
   when I try to delete an ID that doesnt exist I am getting 
   
   ```
   ERROR: api.go:789: 2020-03-12T18:53:41.8901632Z: a non-pq error was given
   ERROR: api.go:173: 2020-03-12T18:53:41.8916858Z: 172.28.0.1:60308 sql: no rows in result set
   DEBUG: api.go:178: 2020-03-12T18:53:41.8918061Z: Internal Server Error
   ```
   
   are you getting the same?
   
   Also wont `tp.UseInTable == nil` always be nil? since the object isnt passed in on request?

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r391645389
 
 

 ##########
 File path: docs/source/api/v2/types_id.rst
 ##########
 @@ -76,3 +76,140 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``PUT``
+=======
+Updates a type
+
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type:  Object
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------+
+	| Name | Description                                                 |
+	+======+=============================================================+
+	|  ID  | The integral, unique identifier of the type being inspected |
 
 Review comment:
   of the type being updated instead of inspected

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r394594463
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,46 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
 
 Review comment:
   the userErr goes first

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r394594534
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,46 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.ID != nil {
+		query := `SELECT use_in_table from type where id=$1`
+		err := tp.ReqInfo.Tx.Tx.QueryRow(query, tp.ID).Scan(&tp.UseInTable)
+		if err != nil {
+			return api.ParseDBError(err)
+		}
+	} else {
+		return errors.New("no type with that key found"), nil, http.StatusNotFound
+	}
+	if !tp.AllowMutation() {
+		return nil, errors.New(fmt.Sprintf("can not delete type")), http.StatusBadRequest
 
 Review comment:
   the userErr goes first

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387682614
 
 

 ##########
 File path: docs/source/api/v2/types_id.rst
 ##########
 @@ -76,3 +76,138 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``PUT``
+=======
+Updates a type
+
+:Auth. Required: Yes
+:Roles Required: None
+:Response Type:  Object
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------+
+	| Name | Description                                                 |
+	+======+=============================================================+
+	|  ID  | The integral, unique identifier of the type being inspected |
+	+------+-------------------------------------------------------------+
+
+:description: A short description of this type
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type.
+.. note:: Only types with useInTable set to 'server' are allowed to be updated.
+
+.. code-block:: http
+	:caption: Request Structure
+
+	PUT /api/2.0/type/3004
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 68
+	Content-Type: application/json
+
+	{
+		"name": "Example01",
+		"description": "Example2",
+		"useInServer": "server"
 
 Review comment:
   useInTable

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
ocket8888 merged pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406
 
 
   

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on issue #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#issuecomment-587061890
 
 
   > _"What does this PR (Pull Request) do?"_

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387682138
 
 

 ##########
 File path: docs/source/api/v2/types.rst
 ##########
 @@ -82,3 +82,77 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``POST``
+========
+Creates a type
+
+:Auth. Required: Yes
+:Roles Required: None
+:Response Type:  Object
+
+Request Structure
+-----------------
+:description: A short description of this type
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type.
+.. note:: The only useInTable value that is allowed to be created dynamically is 'server'
+
+.. code-block:: http
+	:caption: Request Structure
+
+	POST /api/2.0/type
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 67
+	Content-Type: application/json
+
+	{
+		"name": "Example01",
+		"description": "Example",
+		"useInServer": "server"
 
 Review comment:
   useInTable? instead of useInServer?

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mattjackson220 commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r391645611
 
 

 ##########
 File path: docs/source/api/v2/types_id.rst
 ##########
 @@ -76,3 +76,140 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``PUT``
+=======
+Updates a type
+
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type:  Object
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------+
+	| Name | Description                                                 |
+	+======+=============================================================+
+	|  ID  | The integral, unique identifier of the type being inspected |
+	+------+-------------------------------------------------------------+
+
+:description: A short description of this type
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type.
+
+.. note:: Only types with useInTable set to 'server' are allowed to be updated.
+
+.. code-block:: http
+	:caption: Request Structure
+
+	PUT /api/2.0/type/3004 HTTP/1.1
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 68
+	Content-Type: application/json
+
+	{
+		"name": "Example01",
+		"description": "Example2",
+		"useInTable": "server"
+	}
+
+Response Structure
+------------------
+:description: A short description of this type
+:id:          An integral, unique identifier for this type
+:lastUpdated: The date and time at which this type was last updated, in ISO format
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type
+
+.. code-block:: http
+	:caption: Response Example
+
+	HTTP/1.1 200 OK
+	Access-Control-Allow-Credentials: true
+	Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
+	Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
+	Access-Control-Allow-Origin: *
+	Content-Type: application/json
+	Set-Cookie: mojolicious=...; Path=/; Expires=Mon, 18 Nov 2019 17:40:54 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: EH8jo8OrCu79Tz9xpgT3YRyKJ/p2NcTmbS3huwtqRByHz9H6qZLQjA59RIPaVSq3ZxsU6QhTaox5nBkQ9LPSAA==
+	X-Server-Name: traffic_ops_golang/
+	Date: Wed, 26 Feb 2020 18:58:41 GMT
+	Content-Length: 172
+
+	{
+		"alerts": [
+		{
+			"text": "type was updated.",
+			"level": "success"
+		}],
+		"response": [
+		{
+			"id": 3004,
+			"lastUpdated": "2020-02-26 18:58:41+00",
+			"name": "Example02",
+			"description": "Example"
+			"useInTable": "server"
+		}]
+	}
+
+``DELETE``
+==========
+Deletes a type
+
+:Auth. Required: Yes
+:Roles Required: "admin" or "operations"
+:Response Type: Object
+
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------+
+	| Name | Description                                                 |
+	+======+=============================================================+
+	|  ID  | The integral, unique identifier of the type being inspected |
 
 Review comment:
   of the type being deleted instead of inspected

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387681771
 
 

 ##########
 File path: docs/source/api/v2/types.rst
 ##########
 @@ -82,3 +82,77 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``POST``
+========
+Creates a type
+
+:Auth. Required: Yes
+:Roles Required: None
 
 Review comment:
   Operations role?

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r394594577
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,46 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.ID != nil {
+		query := `SELECT use_in_table from type where id=$1`
+		err := tp.ReqInfo.Tx.Tx.QueryRow(query, tp.ID).Scan(&tp.UseInTable)
+		if err != nil {
+			return api.ParseDBError(err)
+		}
+	} else {
+		return errors.New("no type with that key found"), nil, http.StatusNotFound
+	}
+	if !tp.AllowMutation() {
+		return nil, errors.New(fmt.Sprintf("can not delete type")), http.StatusBadRequest
+	}
+	return api.GenericDelete(tp)
+}
+
+func (tp *TOType) Create() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not create type"), http.StatusBadRequest
 
 Review comment:
   the userErr goes first

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387682458
 
 

 ##########
 File path: docs/source/api/v2/types_id.rst
 ##########
 @@ -76,3 +76,138 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``PUT``
+=======
+Updates a type
+
+:Auth. Required: Yes
+:Roles Required: None
 
 Review comment:
   operations?

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r391828763
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,48 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.UseInTable == nil {
+		if tp.ID != nil {
+			query := `SELECT use_in_table from type where id=$1`
+			err := tp.ReqInfo.Tx.Tx.QueryRow(query, tp.ID).Scan(&tp.UseInTable)
+			if err != nil {
+				return api.ParseDBError(err)
+			}
+		} else {
+			return nil, errors.New("no type with that key found"), http.StatusNotFound
 
 Review comment:
   I think the returns on all these errors (here and in the update/create methods) are backwards I think it is `userErr,sysErr,statusCode` I believe you have it as `sysErr,userErr,statusCode`
   
   I am not getting any relevant errors back the API when I cause a failure

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387682707
 
 

 ##########
 File path: docs/source/api/v2/types_id.rst
 ##########
 @@ -76,3 +76,138 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``PUT``
+=======
+Updates a type
+
+:Auth. Required: Yes
+:Roles Required: None
+:Response Type:  Object
+
+Request Structure
+-----------------
+.. table:: Request Path Parameters
+
+	+------+-------------------------------------------------------------+
+	| Name | Description                                                 |
+	+======+=============================================================+
+	|  ID  | The integral, unique identifier of the type being inspected |
+	+------+-------------------------------------------------------------+
+
+:description: A short description of this type
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type.
+.. note:: Only types with useInTable set to 'server' are allowed to be updated.
+
+.. code-block:: http
+	:caption: Request Structure
+
+	PUT /api/2.0/type/3004
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 68
+	Content-Type: application/json
+
+	{
+		"name": "Example01",
+		"description": "Example2",
+		"useInServer": "server"
+	}
+
+Response Structure
+------------------
+:description: A short description of this type
+:id:          An integral, unique identifier for this type
+:lastUpdated: The date and time at which this type was last updated, in ISO format
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type
+
+.. code-block:: http
+	:caption: Response Example
+
+	HTTP/1.1 200 OK
+	Access-Control-Allow-Credentials: true
+	Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
+	Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
+	Access-Control-Allow-Origin: *
+	Content-Type: application/json
+	Set-Cookie: mojolicious=...; Path=/; Expires=Mon, 18 Nov 2019 17:40:54 GMT; Max-Age=3600; HttpOnly
+	Whole-Content-Sha512: EH8jo8OrCu79Tz9xpgT3YRyKJ/p2NcTmbS3huwtqRByHz9H6qZLQjA59RIPaVSq3ZxsU6QhTaox5nBkQ9LPSAA==
+	X-Server-Name: traffic_ops_golang/
+	Date: Wed, 26 Feb 2020 18:58:41 GMT
+	Content-Length: 172
+
+	{
+		"alerts": [
+		{
+			"text": "type was updated.",
+			"level": "success"
+		}],
+		"response": [
+		{
+			"id": 3004,
+			"lastUpdated": "2020-02-26 18:58:41+00",
+			"name": "Example02",
+			"description": "Example"
+			"useInTable": "server"
+		}]
+	}
+
+``DELETE``
+==========
+Deletes a type
+
+:Auth. Required: Yes
+:Roles Required: None
 
 Review comment:
   operations

----------------------------------------------------------------
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] shamrickus commented on a change in pull request #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
shamrickus commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r393314926
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,48 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.UseInTable == nil {
 
 Review comment:
   You are correct, at the time of writing i was confused as to how the generic CRUD was working. I'll remove it in my upcoming changes.

----------------------------------------------------------------
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] shamrickus commented on issue #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
shamrickus commented on issue #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#issuecomment-587591178
 
 
   It doesn't appear to need TP changes. It probably should only be in the v2 tests now that you mention it. I'll revert the v1 changes and apply them to v2 once #4374 is merged

----------------------------------------------------------------
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] shamrickus commented on a change in pull request #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
shamrickus commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387698485
 
 

 ##########
 File path: docs/source/api/v2/types.rst
 ##########
 @@ -82,3 +82,77 @@ Response Structure
 			"useInTable": "cachegroup"
 		}
 	]}
+
+
+``POST``
+========
+Creates a type
+
+:Auth. Required: Yes
+:Roles Required: None
+:Response Type:  Object
+
+Request Structure
+-----------------
+:description: A short description of this type
+:name:        The name of this type
+:useInTable:  The name of the Traffic Ops database table that contains objects which are grouped, identified, or described by this type.
+.. note:: The only useInTable value that is allowed to be created dynamically is 'server'
+
+.. code-block:: http
+	:caption: Request Structure
+
+	POST /api/2.0/type
+	Host: trafficops.infra.ciab.test
+	User-Agent: curl/7.47.0
+	Accept: */*
+	Cookie: mojolicious=...
+	Content-Length: 67
+	Content-Type: application/json
+
+	{
+		"name": "Example01",
+		"description": "Example",
+		"useInServer": "server"
 
 Review comment:
   Woops

----------------------------------------------------------------
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] shamrickus commented on a change in pull request #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
shamrickus commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387736803
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,46 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.UseInTable == nil {
+		if tp.ID != nil {
+			query := `SELECT use_in_table from type where id=$1`
+			err := tp.ReqInfo.Tx.Tx.QueryRow( query, tp.ID).Scan(&tp.UseInTable)
 
 Review comment:
   You are correct, it did return a 404 but doesn't now

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387684506
 
 

 ##########
 File path: traffic_ops/testing/api/v2/types_test.go
 ##########
 @@ -31,50 +32,78 @@ func TestTypes(t *testing.T) {
 func CreateTestTypes(t *testing.T) {
 	t.Log("---- CreateTestTypes ----")
 
+	db, err := OpenConnection()
+	if err != nil {
+		t.Fatal("cannot open db")
+	}
+	defer func() {
+		err := db.Close()
+		if err != nil {
+			t.Errorf("unable to close connection to db, error: %v", err.Error())
+		}
+	}()
+	dbQueryTemplate := "INSERT INTO type (name, description, use_in_table) VALUES ('%v', '%v', '%v');"
+
 	for _, typ := range testData.Types {
-		resp, _, err := TOSession.CreateType(typ)
+		foundTypes, _, err := TOSession.GetTypeByName(typ.Name)
+		if err == nil && len(foundTypes) > 0 {
+			t.Logf("Type %v already exists (%v match(es))", typ.Name, len(foundTypes))
+			continue
+		}
+
+		if typ.UseInTable != "server" {
+			err = execSQL(db, fmt.Sprintf(dbQueryTemplate, typ.Name, typ.Description, typ.UseInTable), "type")
+		} else {
+			_, _, err = TOSession.CreateType(typ)
+		}
+
 		if err != nil {
 			t.Errorf("could not CREATE types: %v", err)
 		}
-		t.Log("Response: ", resp)
 	}
 
 }
 
 func UpdateTestTypes(t *testing.T) {
 	t.Log("---- UpdateTestTypes ----")
+	expectedTypeName := "testType%v"
 
 Review comment:
   nit but does this need to be in a variable? can it just directly go into the Sprintf below? 

----------------------------------------------------------------
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 #4406: Only allow changing of types based on useintable

Posted by GitBox <gi...@apache.org>.
mhoppa commented on a change in pull request #4406: Only allow changing of types based on useintable
URL: https://github.com/apache/trafficcontrol/pull/4406#discussion_r387687163
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/types/types.go
 ##########
 @@ -95,9 +98,46 @@ func (typ *TOType) Validate() error {
 }
 
 func (tp *TOType) Read() ([]interface{}, error, error, int) { return api.GenericRead(tp) }
-func (tp *TOType) Update() (error, error, int)              { return api.GenericUpdate(tp) }
-func (tp *TOType) Create() (error, error, int)              { return api.GenericCreate(tp) }
-func (tp *TOType) Delete() (error, error, int)              { return api.GenericDelete(tp) }
+
+func (tp *TOType) Update() (error, error, int) {
+	if !tp.AllowMutation() {
+		return nil, errors.New("can not update type"), http.StatusBadRequest
+	}
+	return api.GenericUpdate(tp)
+}
+
+func (tp *TOType) Delete() (error, error, int) {
+	if tp.UseInTable == nil {
+		if tp.ID != nil {
+			query := `SELECT use_in_table from type where id=$1`
+			err := tp.ReqInfo.Tx.Tx.QueryRow( query, tp.ID).Scan(&tp.UseInTable)
 
 Review comment:
   I havent tested it but did the Delete used to return a 404 if the given id didnt exist? I think in this new logic it would return "can not delete type" -> 404 

----------------------------------------------------------------
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