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 2019/09/18 19:46:42 UTC

[GitHub] [trafficcontrol] mitchell852 opened a new issue #3928: inconsistent responses for GET /api/profiles?id=

mitchell852 opened a new issue #3928: inconsistent responses for GET /api/profiles?id=
URL: https://github.com/apache/trafficcontrol/issues/3928
 
 
   ## I'm submitting a ...
   <!-- (check all that apply with "[x]") -->
   <!--- security vulnerability (STOP!! - see above)-->
   - [ ] bug report
   - [ ] new feature / enhancement request
   - [x] improvement request (usability, performance, tech debt, etc.)
   - [ ] other <!--(Please do not submit support requests here - see above)-->
   
   ## Traffic Control components affected ...
   <!-- (check all that apply with "[x]") -->
   - [ ] CDN in a Box
   - [ ] Documentation
   - [ ] Grove
   - [ ] Traffic Control Client
   - [ ] Traffic Monitor
   - [x] Traffic Ops
   - [ ] Traffic Ops ORT
   - [ ] Traffic Portal
   - [ ] Traffic Router
   - [ ] Traffic Stats
   - [ ] Traffic Vault
   - [ ] unknown
   
   ## Current behavior:
   <!-- Describe how the bug manifests / how the current features are insufficient. -->
   GET /api/profiles returns an array of profiles as such:
   
   `{
   	response: [
   		{
   			id: 1,
   			lastUpdated: "2017-05-03 19:23:06+00",
   			name: "profile-name",
   			description: "desc",
   			cdnName: "cdn-1",
   			cdn: 1,
   			routingDisabled: false,
   			type: "ATS_PROFILE"
   		},
   		...
   	]
   }`
   
   GET /api/profiles?id=x returns an array of one as such:
   `{
   	response: [
   		{
   			id: 1,
   			lastUpdated: "2017-05-03 19:23:06+00",
   			name: "profile-name",
   			description: "desc",
   			cdnName: "cdn-1",
   			cdn: 1,
   			routingDisabled: false,
   			type: "ATS_PROFILE",
   			params: [list of params attached to profile]
   		}
   	]
   }`
   
   I guess the idea was that if you ask for ONE profile, the api will also give you the params (attached to that profile) but if you ask for all profiles, you don't get the params as this would bloat the response i guess.
   
   Anyhow, to exclude the params key from the first response `omitempty` is added to the struct: https://github.com/apache/trafficcontrol/blob/master/lib/go-tc/profiles.go#L85
   
   This causes a problem with something like this:
   
   GET /api/profiles?id=[id where profile has no params]
   
   ^^ in this case you'd hope to see this response:
   
   `{
   	response: [
   		{
   			id: 1,
   			lastUpdated: "2017-05-03 19:23:06+00",
   			name: "profile-name",
   			description: "desc",
   			cdnName: "cdn-1",
   			cdn: 1,
   			routingDisabled: false,
   			type: "ATS_PROFILE",
   			params: []
   		}
   	]
   }`
   
   but instead the params key is removed entirely creating potential inconsistencies between responses to the same api call as such::
   
   GET /api/profiles?id=x
   GET /api/profiles?id=y
   
   ## Expected / new behavior:
   <!-- Describe what the behavior would be without the bug / how the feature would improve Traffic Control -->
   All calls to GET /api/profiles?id=[id] should return the same response structure as:
   
   `{
   	response: [
   		{
   			id: 1,
   			lastUpdated: "2017-05-03 19:23:06+00",
   			name: "profile-name",
   			description: "desc",
   			cdnName: "cdn-1",
   			cdn: 1,
   			routingDisabled: false,
   			type: "ATS_PROFILE",
   			params: [ list of params or empty array if no params attached to profile]
   		}
   	]
   }`
   
   ## Minimal reproduction of the problem with instructions:
   <!--
   If the current behavior is a bug or you can illustrate your feature request better with an example,
   please provide the *STEPS TO REPRODUCE* and include the applicable TC version.
   -->
   Create 2 profiles. One with params, one without. The make a request to:
   
   GET /profiles?id=one with params
   GET /profiles?id=one withOUT params
   
   notice the different response structure.
   
   ## Anything else:
   <!-- e.g. stacktraces, related issues, suggestions how to fix -->
   
   <!--
   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