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

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

commit 3a76b65a258566cf90c52863fd5237bcb585c204
Author: Robert Butts <r...@apache.org>
AuthorDate: Wed May 2 16:04:04 2018 -0600

    Fix TO Go old CRConfig endpoint to omit 'response'
---
 traffic_ops/traffic_ops_golang/crconfig/handler.go | 28 ++++++++++++++++++++++
 traffic_ops/traffic_ops_golang/routes.go           |  2 +-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/traffic_ops/traffic_ops_golang/crconfig/handler.go 
b/traffic_ops/traffic_ops_golang/crconfig/handler.go
index 3c11d5e..0c4453c 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/handler.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/handler.go
@@ -113,6 +113,34 @@ func SnapshotGetHandler(db *sqlx.DB, cfg config.Config) 
http.HandlerFunc {
        }
 }
 
+// SnapshotOldGetHandler gets and serves the CRConfig from the snapshot table, 
not wrapped in response to match the old non-API CRConfig-Snapshots endpoint
+func SnapshotOldGetHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               handleErrs := tc.GetHandleErrorsFunc(w, r)
+               params, err := api.GetCombinedParams(r)
+               if err != nil {
+                       handleErrs(http.StatusInternalServerError, err)
+                       return
+               }
+               cdn, ok := params["cdn"]
+               if !ok {
+                       handleErrs(http.StatusInternalServerError, 
errors.New("params missing CDN"))
+                       return
+               }
+               snapshot, cdnExists, err := GetSnapshot(db.DB, cdn)
+               if err != nil {
+                       handleErrs(http.StatusInternalServerError, 
errors.New("getting snapshot: "+err.Error()))
+                       return
+               }
+               if !cdnExists {
+                       handleErrs(http.StatusNotFound, errors.New("CDN not 
found"))
+                       return
+               }
+               w.Header().Set("Content-Type", "application/json")
+               w.Write([]byte(snapshot))
+       }
+}
+
 // SnapshotHandler creates the CRConfig JSON and writes it to the snapshot 
table in the database.
 func SnapshotHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
        return func(w http.ResponseWriter, r *http.Request) {
diff --git a/traffic_ops/traffic_ops_golang/routes.go 
b/traffic_ops/traffic_ops_golang/routes.go
index 16b8ab9..3453d19 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -233,7 +233,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, 
http.Handler, error) {
                // DEPRECATED - use PUT /api/1.2/snapshot/{cdn}
                {http.MethodGet, `tools/write_crconfig/{cdn}/?$`, 
crconfig.SnapshotOldGUIHandler(d.DB, d.Config), crconfig.PrivLevel, 
Authenticated, nil},
                // DEPRECATED - use GET /api/1.2/cdns/{cdn}/snapshot
-               {http.MethodGet, `CRConfig-Snapshots/{cdn}/CRConfig.json?$`, 
crconfig.SnapshotGetHandler(d.DB, d.Config), crconfig.PrivLevel, Authenticated, 
nil},
+               {http.MethodGet, `CRConfig-Snapshots/{cdn}/CRConfig.json?$`, 
crconfig.SnapshotOldGetHandler(d.DB, d.Config), crconfig.PrivLevel, 
Authenticated, nil},
        }
 
        return routes, rawRoutes, proxyHandler, nil

-- 
To stop receiving notification emails like this one, please contact
mitchell...@apache.org.

Reply via email to