You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/06/05 16:34:31 UTC

[incubator-trafficcontrol] branch master updated: Add TO Go cdns/configs

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9fcfbd4  Add TO Go cdns/configs
9fcfbd4 is described below

commit 9fcfbd487bd2286fbc5008b8ba36474fbcc7f9d5
Author: Robert Butts <ro...@apache.org>
AuthorDate: Thu May 31 09:24:28 2018 -0600

    Add TO Go cdns/configs
---
 lib/go-tc/v13/cdns.go                         |  6 ++++
 traffic_ops/traffic_ops_golang/cdn/configs.go | 52 +++++++++++++++++++++++++++
 traffic_ops/traffic_ops_golang/routes.go      |  2 +-
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/lib/go-tc/v13/cdns.go b/lib/go-tc/v13/cdns.go
index 3037af9..5c12254 100644
--- a/lib/go-tc/v13/cdns.go
+++ b/lib/go-tc/v13/cdns.go
@@ -114,3 +114,9 @@ type CDNSSLKeysCertificate struct {
 	Crt string `json:"crt"`
 	Key string `json:"key"`
 }
+
+
+type CDNConfig struct {
+	Name *string `json:"name"`
+	ID   *int    `json:"id"`
+}
diff --git a/traffic_ops/traffic_ops_golang/cdn/configs.go b/traffic_ops/traffic_ops_golang/cdn/configs.go
new file mode 100644
index 0000000..376e264
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/cdn/configs.go
@@ -0,0 +1,52 @@
+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"
+
+	tc "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13"
+	"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+func GetConfigs(db *sql.DB) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		api.RespWriter(w, r)(getConfigs(db))
+	}
+}
+
+func getConfigs(db *sql.DB) ([]tc.CDNConfig, error) {
+	rows, err := db.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
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 6a39edb..032c80c 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -101,7 +101,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
 		//CDN
 		{1.1, http.MethodGet, `cdns/metric_types`, notImplementedHandler, 0, NoAuth, nil}, // MUST NOT end in $, because the 1.x route is longer
 		{1.1, http.MethodGet, `cdns/capacity$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
-		{1.1, http.MethodGet, `cdns/configs$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
+		{1.1, http.MethodGet, `cdns/configs/?(\.json)?$`, cdn.GetConfigs(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
 		{1.1, http.MethodGet, `cdns/domains$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
 		{1.1, http.MethodGet, `cdns/health$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
 		{1.1, http.MethodGet, `cdns/routing$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},

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