You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/06/01 15:14:19 UTC

[incubator-trafficcontrol] 02/02: Change TO Go cdns/name to use CRUD interfaces

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 8e4b8fe720a666e9bcde34444166db32327dbeb1
Author: Robert Butts <ro...@apache.org>
AuthorDate: Wed May 30 16:09:24 2018 -0600

    Change TO Go cdns/name to use CRUD interfaces
---
 traffic_ops/traffic_ops_golang/cdn/name.go | 62 ------------------------------
 traffic_ops/traffic_ops_golang/routes.go   |  2 +-
 2 files changed, 1 insertion(+), 63 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/cdn/name.go b/traffic_ops/traffic_ops_golang/cdn/name.go
deleted file mode 100644
index 1157c78..0000000
--- a/traffic_ops/traffic_ops_golang/cdn/name.go
+++ /dev/null
@@ -1,62 +0,0 @@
-package cdn
-
-/*
- * 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.
- */
-
-import (
-	"database/sql"
-	"errors"
-	"net/http"
-
-	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
-	tcv13 "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
-	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
-)
-
-func GetName(db *sql.DB) http.HandlerFunc {
-	return func(w http.ResponseWriter, r *http.Request) {
-		params, _, userErr, sysErr, errCode := api.AllParams(r, nil)
-		if userErr != nil || sysErr != nil {
-			api.HandleErr(w, r, errCode, userErr, sysErr)
-			return
-		}
-		cdnName, ok := params["name"]
-		if !ok {
-			api.HandleErr(w, r, http.StatusInternalServerError, nil, errors.New("CDN name route missing param"))
-			return
-		}
-		api.RespWriter(w, r)(getCDNFromName(db, tc.CDNName(cdnName)))
-	}
-}
-
-func getCDNFromName(db *sql.DB, name tc.CDNName) ([]tcv13.CDN, error) {
-	rows, err := db.Query(`SELECT id, domain_name, last_updated, dnssec_enabled FROM cdn WHERE name = $1`, name)
-	if err != nil {
-		return nil, errors.New("querying cdns: " + err.Error())
-	}
-	cdns := []tcv13.CDN{}
-	for rows.Next() {
-		cdn := tcv13.CDN{Name: string(name)}
-		if err := rows.Scan(&cdn.ID, &cdn.DomainName, &cdn.LastUpdated, &cdn.DNSSECEnabled); err != nil {
-			return nil, errors.New("scanning cdns: " + err.Error())
-		}
-		cdns = append(cdns, cdn)
-	}
-	return cdns, nil
-}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 4d22703..ebe3ca3 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -108,7 +108,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		//CDN: CRUD
 		{1.1, http.MethodGet, `cdns/?(\.json)?$`, api.ReadHandler(cdn.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 		{1.1, http.MethodGet, `cdns/{id}$`, api.ReadHandler(cdn.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
-		{1.1, http.MethodGet, `cdns/name/{name}$`, cdn.GetName(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+		{1.1, http.MethodGet, `cdns/name/{name}/?(\.json)?$`, api.ReadHandler(cdn.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 		{1.1, http.MethodPut, `cdns/{id}$`, api.UpdateHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.1, http.MethodPost, `cdns/?$`, api.CreateHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
 		{1.1, http.MethodDelete, `cdns/{id}$`, api.DeleteHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},

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