From a2ac007b1c805cde2b64d215b3e29ec5af8602dc Mon Sep 17 00:00:00 2001 From: Michael Hoppal Date: Wed, 29 Jan 2020 14:08:54 -0700 Subject: [PATCH 1/2] Deprecate /cdns/configs --- CHANGELOG.md | 1 + docs/source/api/cdns_configs.rst | 37 ++++++++++++-- traffic_ops/traffic_ops_golang/cdn/configs.go | 50 +++++++++---------- .../traffic_ops_golang/routing/routes.go | 2 +- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cebebb0b78..efb64d3ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - /jobs/:id - /riak/stats - /stats_summary/create + - /cdns/configs ## [4.0.0] - 2019-12-16 ### Added diff --git a/docs/source/api/cdns_configs.rst b/docs/source/api/cdns_configs.rst index 066732658e..f0343f7f1a 100644 --- a/docs/source/api/cdns_configs.rst +++ b/docs/source/api/cdns_configs.rst @@ -17,7 +17,8 @@ **************** ``cdns/configs`` **************** - +.. deprecated:: ATCv4 + Use the ``GET`` method of :ref:`to-api-cdns` instead. .. danger:: This endpoint does not appear to work, and thus its use is strongly discouraged! ``GET`` @@ -34,9 +35,37 @@ No parameters available. Response Properties ------------------- -:config_file: Presumably the name of some configuration file\ [1]_ :id: The integral, unique identifier for this CDN :name: The CDN's name -:value: Presumably the content of some configuration file\ [1]_ -.. [1] These values are currently missing from this endpoint's output. **DO NOT count on this endpoint to provide this information**. +.. 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: z9P1NkxGebPncUhaChDHtYKYI+XVZfhE6Y84TuwoASZFIMfISELwADLpvpPTN+wwnzBfREksLYn+0313QoBWhA== + X-Server-Name: traffic_ops_golang/ + Date: Wed, 14 Nov 2018 20:46:57 GMT + Content-Length: 237 + + { "response": [ + { + "id": 1, + "name": "ALL" + }, + { + "id": 2, + "name": "CDN-in-a-Box" + } + ], + "alerts": [ + { + "text": "This endpoint is deprecated, please use GET /cdns instead", + "level": "warning" + } + ]} diff --git a/traffic_ops/traffic_ops_golang/cdn/configs.go b/traffic_ops/traffic_ops_golang/cdn/configs.go index 6075bff867..c79011546f 100644 --- a/traffic_ops/traffic_ops_golang/cdn/configs.go +++ b/traffic_ops/traffic_ops_golang/cdn/configs.go @@ -20,37 +20,33 @@ package cdn */ import ( - "database/sql" - "errors" - "net/http" - "github.com/apache/trafficcontrol/lib/go-tc" "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api" + "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers" ) -func GetConfigs(w http.ResponseWriter, r *http.Request) { - inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil) - if userErr != nil || sysErr != nil { - api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr) - return - } - defer inf.Close() - api.RespWriter(w, r, inf.Tx.Tx)(getConfigs(inf.Tx.Tx)) +//we need a type alias to define functions on +type TOCDNConf struct { + api.APIInfoImpl `json:"-"` +} + +func (v *TOCDNConf) NewReadObj() interface{} { return &tc.CDNConfig{} } +func (v *TOCDNConf) SelectQuery() string { return cdnConfSelectQuery() } +func (v *TOCDNConf) ParamColumns() map[string]dbhelpers.WhereColumnInfo { + return map[string]dbhelpers.WhereColumnInfo{} +} + +func cdnConfSelectQuery() string { + return `SELECT +name, +id +FROM cdn` +} + +func (v *TOCDNConf) Read() ([]interface{}, error, error, int) { + return api.GenericRead(v) } -func getConfigs(tx *sql.Tx) ([]tc.CDNConfig, error) { - rows, err := tx.Query(`SELECT name, id FROM cdn`) - if err != nil { - return nil, errors.New("querying cdn configs: " + err.Error()) - } - cdns := []tc.CDNConfig{} - defer rows.Close() - for rows.Next() { - c := tc.CDNConfig{} - if err := rows.Scan(&c.Name, &c.ID); err != nil { - return nil, errors.New("scanning cdn config: " + err.Error()) - } - cdns = append(cdns, c) - } - return cdns, nil +func (v TOCDNConf) GetType() string { + return "cdn_configs" } diff --git a/traffic_ops/traffic_ops_golang/routing/routes.go b/traffic_ops/traffic_ops_golang/routing/routes.go index 367de0b2fc..f9c7bdda41 100644 --- a/traffic_ops/traffic_ops_golang/routing/routes.go +++ b/traffic_ops/traffic_ops_golang/routing/routes.go @@ -180,7 +180,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) { {1.1, http.MethodGet, `cdns/metric_types`, notImplementedHandler, 0, NoAuth, nil, 683165463, noPerlBypass}, // MUST NOT end in $, because the 1.x route is longer {1.1, http.MethodGet, `cdns/capacity$`, cdn.GetCapacity, auth.PrivLevelReadOnly, Authenticated, nil, 697185281, perlBypass}, - {1.1, http.MethodGet, `cdns/configs/?(\.json)?$`, cdn.GetConfigs, auth.PrivLevelReadOnly, Authenticated, nil, 1768437852, noPerlBypass}, + {1.1, http.MethodGet, `cdns/configs/?(\.json)?$`, api.DeprecatedReadHandler(&cdn.TOCDNConf{}, util.StrPtr("GET /cdns")), auth.PrivLevelReadOnly, Authenticated, nil, 1768437852, noPerlBypass}, {1.1, http.MethodGet, `cdns/{name}/health/?(\.json)?$`, cdn.GetNameHealth, auth.PrivLevelReadOnly, Authenticated, nil, 1135348194, perlBypass}, {1.1, http.MethodGet, `cdns/health/?(\.json)?$`, cdn.GetHealth, auth.PrivLevelReadOnly, Authenticated, nil, 1085381134, perlBypass}, From 17700951b94e575d1ef1f60689c21a3be09953fb Mon Sep 17 00:00:00 2001 From: Michael Hoppal Date: Thu, 30 Jan 2020 11:21:20 -0700 Subject: [PATCH 2/2] Address documentation comments --- docs/source/api/cdns_configs.rst | 12 ++++++------ traffic_ops/traffic_ops_golang/cdn/configs.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/api/cdns_configs.rst b/docs/source/api/cdns_configs.rst index f0343f7f1a..12ab96fa0a 100644 --- a/docs/source/api/cdns_configs.rst +++ b/docs/source/api/cdns_configs.rst @@ -63,9 +63,9 @@ Response Properties "name": "CDN-in-a-Box" } ], - "alerts": [ - { - "text": "This endpoint is deprecated, please use GET /cdns instead", - "level": "warning" - } - ]} + "alerts": [ + { + "text": "This endpoint is deprecated, please use GET /cdns instead", + "level": "warning" + } + ]} diff --git a/traffic_ops/traffic_ops_golang/cdn/configs.go b/traffic_ops/traffic_ops_golang/cdn/configs.go index c79011546f..6dd2c506e3 100644 --- a/traffic_ops/traffic_ops_golang/cdn/configs.go +++ b/traffic_ops/traffic_ops_golang/cdn/configs.go @@ -25,7 +25,7 @@ import ( "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers" ) -//we need a type alias to define functions on +// TOCDNConf used as a type alias to define functions on to satisfy shared API REST interfaces. type TOCDNConf struct { api.APIInfoImpl `json:"-"` }