You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ma...@apache.org on 2020/03/12 22:30:18 UTC

[trafficcontrol] branch master updated: Deprecate parameters/profile/:name (#4477)

This is an automated email from the ASF dual-hosted git repository.

mattjackson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new ec22a02  Deprecate parameters/profile/:name (#4477)
ec22a02 is described below

commit ec22a022da709114b837b2861b5225e10d53e5eb
Author: Steve Hamrick <sh...@users.noreply.github.com>
AuthorDate: Thu Mar 12 16:30:06 2020 -0600

    Deprecate parameters/profile/:name (#4477)
    
    * Deprecate parameters
    
    * Use new functions and fully update
    
    * Address code review
    
    Signed-off-by: Steve Hamrick <sh...@gmail.com>
    
    * Fix deprecations when there is no alternative
    
    * Move method up, actually deprecate endpoint
    
    * Add deprecation warning on success
    
    * Cleanup
    
    * Missed a spot
---
 CHANGELOG.md                                       |   1 +
 docs/source/api/v1/parameters_profile_name.rst     |  12 ++-
 docs/source/api/v2/parameters_profile_name.rst     | 107 ---------------------
 traffic_ops/traffic_ops_golang/api/api.go          |   8 ++
 .../profileparameter/parameterprofilebyname.go     |  27 +++++-
 traffic_ops/traffic_ops_golang/routing/routes.go   |   3 +-
 6 files changed, 45 insertions(+), 113 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c8aef1..692c449 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -70,6 +70,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
   - /logs/:days/days
   - /parameters/:id/profiles
   - /parameters/:id/unassigned_profiles
+  - /parameters/profile/:name
   - /parameters/validate
   - /profile/:id/unassigned_parameters
   - /regions/:region_name/phys_locations
diff --git a/docs/source/api/v1/parameters_profile_name.rst b/docs/source/api/v1/parameters_profile_name.rst
index 9c2dc4f..c9fd839 100644
--- a/docs/source/api/v1/parameters_profile_name.rst
+++ b/docs/source/api/v1/parameters_profile_name.rst
@@ -23,6 +23,9 @@
 =======
 Gets details about a specific :term:`Profile`'s :term:`Parameters`
 
+.. deprecated:: ATCv4
+	Use the ``GET`` method of :ref:`to-api-profiles-name-name-parameters` instead.
+
 :Auth. Required: Yes
 :Roles Required: None
 :Response Type:  Array
@@ -69,9 +72,14 @@ Response Structure
 	Whole-Content-Sha512: NudgZXUNyKNpmSFf856KEjyy+Pin/bFhG9NoRBDAxYbRKt2T5fF5Ze7sUNZfFI5n/ZZsgbx6Tsgtfd7oM6j+eg==
 	X-Server-Name: traffic_ops_golang/
 	Date: Wed, 05 Dec 2018 21:08:56 GMT
-	Content-Length: 542
+	Content-Length: 628
 
-	{ "response": [
+	{ "alerts": [
+		{
+			"level": "warning",
+			"text": "This endpoint is deprecated, please use /profiles/name/{name}/parameters instead"
+		}],
+			"response": [
 		{
 			"configFile": "global",
 			"id": 4,
diff --git a/docs/source/api/v2/parameters_profile_name.rst b/docs/source/api/v2/parameters_profile_name.rst
deleted file mode 100644
index c7a2f4b..0000000
--- a/docs/source/api/v2/parameters_profile_name.rst
+++ /dev/null
@@ -1,107 +0,0 @@
-..
-..
-.. Licensed 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.
-..
-
-.. _to-api-parameters-profile-name:
-
-*******************************
-``parameters/profile/{{name}}``
-*******************************
-
-``GET``
-=======
-Gets details about a specific :term:`Profile`'s :term:`Parameters`
-
-:Auth. Required: Yes
-:Roles Required: None
-:Response Type:  Array
-
-Request Structure
------------------
-.. table:: Request Path Parameters
-
-	+------+--------------------------------------------------------------------------------------------+
-	| Name | Description                                                                                |
-	+======+============================================================================================+
-	| name | The :ref:`profile-name` of the :term:`Profile` for which :term:`Parameters` will be listed |
-	+------+--------------------------------------------------------------------------------------------+
-
-.. code-block:: http
-	:caption: Request Example
-
-	GET /api/2.0/parameters/profile/GLOBAL HTTP/1.1
-	Host: trafficops.infra.ciab.test
-	User-Agent: curl/7.47.0
-	Accept: */*
-	Cookie: mojolicious=...
-
-Response Structure
-------------------
-:configFile:  The :term:`Parameter`'s :ref:`parameter-config-file`
-:id:          The :term:`Parameter`'s :ref:`parameter-id`
-:lastUpdated: The date and time at which this :term:`Parameter` was last updated, in an ISO-like format
-:name:        :ref:`parameter-name` of the :term:`Parameter`
-:profiles:    An array of :term:`Profile` :ref:`Names <profile-name>` that use this :term:`Parameter`
-:secure:      A boolean value that describes whether or not the :term:`Parameter` is :ref:`parameter-secure`
-:value:       The :term:`Parameter`'s :ref:`parameter-value`
-
-.. 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: NudgZXUNyKNpmSFf856KEjyy+Pin/bFhG9NoRBDAxYbRKt2T5fF5Ze7sUNZfFI5n/ZZsgbx6Tsgtfd7oM6j+eg==
-	X-Server-Name: traffic_ops_golang/
-	Date: Wed, 05 Dec 2018 21:08:56 GMT
-	Content-Length: 542
-
-	{ "response": [
-		{
-			"configFile": "global",
-			"id": 4,
-			"lastUpdated": "2018-12-05 17:50:49+00",
-			"name": "tm.instance_name",
-			"secure": false,
-			"value": "Traffic Ops CDN"
-		},
-		{
-			"configFile": "global",
-			"id": 5,
-			"lastUpdated": "2018-12-05 17:50:49+00",
-			"name": "tm.toolname",
-			"secure": false,
-			"value": "Traffic Ops"
-		},
-		{
-			"configFile": "global",
-			"id": 6,
-			"lastUpdated": "2018-12-05 17:50:51+00",
-			"name": "use_tenancy",
-			"secure": false,
-			"value": "1"
-		},
-		{
-			"configFile": "regex_revalidate.config",
-			"id": 7,
-			"lastUpdated": "2018-12-05 17:50:49+00",
-			"name": "maxRevalDurationDays",
-			"secure": false,
-			"value": "90"
-		}
-	]}
diff --git a/traffic_ops/traffic_ops_golang/api/api.go b/traffic_ops/traffic_ops_golang/api/api.go
index 033216c..2e2f2f7 100644
--- a/traffic_ops/traffic_ops_golang/api/api.go
+++ b/traffic_ops/traffic_ops_golang/api/api.go
@@ -138,6 +138,14 @@ func HandleErr(w http.ResponseWriter, r *http.Request, tx *sql.Tx, statusCode in
 	handleSimpleErr(w, r, statusCode, userErr, sysErr)
 }
 
+func HandleErrOptionalDeprecation(w http.ResponseWriter, r *http.Request, tx *sql.Tx, statusCode int, userErr error, sysErr error, deprecated bool, alternative *string) {
+	if deprecated {
+		HandleDeprecatedErr(w, r, tx, statusCode, userErr, sysErr, alternative)
+	} else {
+		HandleErr(w, r, tx, statusCode, userErr, sysErr)
+	}
+}
+
 // HandleDeprecatedErr handles an API error, adding a deprecation alert, rolling back the transaction, writing the given statusCode and userErr to the user, and logging the sysErr. If userErr is nil, the text of the HTTP statusCode is written.
 //
 // The alternative may be nil if there is no alternative and the deprecation message will be selected appropriately.
diff --git a/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go b/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
index 693d293..2ea8225 100644
--- a/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
+++ b/traffic_ops/traffic_ops_golang/profileparameter/parameterprofilebyname.go
@@ -22,20 +22,43 @@ package profileparameter
 import (
 	"database/sql"
 	"errors"
+	"github.com/apache/trafficcontrol/lib/go-util"
 	"net/http"
 
 	"github.com/apache/trafficcontrol/lib/go-tc"
 	"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
 )
 
+const API_PROFILES_NAME_NAME_PARAMETERS = "profiles/name/{name}/parameters"
+
+func GetProfileNameDeprecated(w http.ResponseWriter, r *http.Request) {
+	getProfileName(w, r, true)
+}
+
 func GetProfileName(w http.ResponseWriter, r *http.Request) {
+	getProfileName(w, r, false)
+}
+
+func getProfileName(w http.ResponseWriter, r *http.Request, deprecated bool) {
+	deprecation := util.StrPtr(API_PROFILES_NAME_NAME_PARAMETERS)
 	inf, userErr, sysErr, errCode := api.NewInfo(r, []string{"name"}, nil)
 	if userErr != nil || sysErr != nil {
-		api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+		api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, errCode, userErr, sysErr, deprecated, deprecation)
 		return
 	}
 	defer inf.Close()
-	api.RespWriter(w, r, inf.Tx.Tx)(getParametersByProfileName(inf.Tx.Tx, inf.Params["name"]))
+
+	name := inf.Params["name"]
+	if deprecated {
+		profiles, err := getParametersByProfileName(inf.Tx.Tx, name)
+		if err != nil {
+			api.HandleErrOptionalDeprecation(w, r, inf.Tx.Tx, http.StatusInternalServerError, err, nil, deprecated, deprecation)
+			return
+		}
+		api.WriteAlertsObj(w, r, http.StatusOK, api.CreateDeprecationAlerts(deprecation), profiles)
+	} else {
+		api.RespWriter(w, r, inf.Tx.Tx)(getParametersByProfileName(inf.Tx.Tx, name))
+	}
 }
 
 func getParametersByProfileName(tx *sql.Tx, profileName string) ([]tc.ProfileParameterByName, error) {
diff --git a/traffic_ops/traffic_ops_golang/routing/routes.go b/traffic_ops/traffic_ops_golang/routing/routes.go
index 5510bfe..7a1dd2b 100644
--- a/traffic_ops/traffic_ops_golang/routing/routes.go
+++ b/traffic_ops/traffic_ops_golang/routing/routes.go
@@ -435,7 +435,6 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		//ProfileParameters
 		{api.Version{2, 0}, http.MethodGet, `profiles/{id}/parameters/?$`, profileparameter.GetProfileID, auth.PrivLevelReadOnly, Authenticated, nil, 276464975, noPerlBypass},
 		{api.Version{2, 0}, http.MethodGet, `profiles/name/{name}/parameters/?$`, profileparameter.GetProfileName, auth.PrivLevelReadOnly, Authenticated, nil, 2267737832, noPerlBypass},
-		{api.Version{2, 0}, http.MethodGet, `parameters/profile/{name}/?$`, profileparameter.GetProfileName, auth.PrivLevelReadOnly, Authenticated, nil, 2802599194, noPerlBypass},
 		{api.Version{2, 0}, http.MethodPost, `profiles/name/{name}/parameters/?$`, profileparameter.PostProfileParamsByName, auth.PrivLevelOperations, Authenticated, nil, 2355945582, noPerlBypass},
 		{api.Version{2, 0}, http.MethodPost, `profiles/{id}/parameters/?$`, profileparameter.PostProfileParamsByID, auth.PrivLevelOperations, Authenticated, nil, 216818708, noPerlBypass},
 		{api.Version{2, 0}, http.MethodGet, `profileparameters/?$`, api.ReadHandler(&profileparameter.TOProfileParameter{}), auth.PrivLevelReadOnly, Authenticated, nil, 250609805, noPerlBypass},
@@ -851,7 +850,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		{api.Version{1, 1}, http.MethodGet, `profiles/{id}/parameters/?(\.json)?$`, profileparameter.GetProfileID, auth.PrivLevelReadOnly, Authenticated, nil, 876464975, noPerlBypass},
 		{api.Version{1, 1}, http.MethodGet, `profiles/{id}/unassigned_parameters/?(\.json)?$`, profileparameter.GetUnassigned, auth.PrivLevelReadOnly, Authenticated, nil, 574429262, noPerlBypass},
 		{api.Version{1, 1}, http.MethodGet, `profiles/name/{name}/parameters/?(\.json)?$`, profileparameter.GetProfileName, auth.PrivLevelReadOnly, Authenticated, nil, 2067737832, noPerlBypass},
-		{api.Version{1, 1}, http.MethodGet, `parameters/profile/{name}/?(\.json)?$`, profileparameter.GetProfileName, auth.PrivLevelReadOnly, Authenticated, nil, 1802599194, noPerlBypass},
+		{api.Version{1, 1}, http.MethodGet, `parameters/profile/{name}/?(\.json)?$`, profileparameter.GetProfileNameDeprecated, auth.PrivLevelReadOnly, Authenticated, nil, 1802599194, noPerlBypass},
 		{api.Version{1, 1}, http.MethodPost, `profiles/name/{name}/parameters/?$`, profileparameter.PostProfileParamsByName, auth.PrivLevelOperations, Authenticated, nil, 1355945582, noPerlBypass},
 		{api.Version{1, 1}, http.MethodPost, `profiles/{id}/parameters/?$`, profileparameter.PostProfileParamsByID, auth.PrivLevelOperations, Authenticated, nil, 316818708, noPerlBypass},
 		{api.Version{1, 1}, http.MethodGet, `profileparameters/?(\.json)?$`, api.ReadHandler(&profileparameter.TOProfileParameter{}), auth.PrivLevelReadOnly, Authenticated, nil, 850609805, noPerlBypass},