You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ro...@apache.org on 2018/07/06 14:44:23 UTC
[trafficcontrol] 01/03: Add TO Go cdns/domains
This is an automated email from the ASF dual-hosted git repository.
rob pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 2757caa92b75115ae554ee9ca4a82285b6533e76
Author: moltzaum <ma...@moltzau.net>
AuthorDate: Fri Jun 29 15:13:23 2018 -0600
Add TO Go cdns/domains
Not yet complete. I need to set up a test while the route still points to perl,
then test the new handler I made. The handler's error registering needs to be
looked at.
---
traffic_ops/testing/api/v13/cdn_domains_test.go | 22 ++++++
traffic_ops/traffic_ops_golang/cdn/domains.go | 97 +++++++++++++++++++++++++
traffic_ops/traffic_ops_golang/routes.go | 3 +-
3 files changed, 121 insertions(+), 1 deletion(-)
diff --git a/traffic_ops/testing/api/v13/cdn_domains_test.go b/traffic_ops/testing/api/v13/cdn_domains_test.go
new file mode 100644
index 0000000..39d4ef3
--- /dev/null
+++ b/traffic_ops/testing/api/v13/cdn_domains_test.go
@@ -0,0 +1,22 @@
+package v13
+
+/*
+
+ 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.
+*/
+
+import "testing"
+
+func TestDomains(t *testing.T) {
+ //
+}
diff --git a/traffic_ops/traffic_ops_golang/cdn/domains.go b/traffic_ops/traffic_ops_golang/cdn/domains.go
new file mode 100644
index 0000000..d56cb9e
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/cdn/domains.go
@@ -0,0 +1,97 @@
+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 (
+ "net/http"
+ //"database/sql"
+ //"github.com/jmoiron/sqlx" //sql extra
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+func DomainsHandler (w http.ResponseWriter, r *http.Request) {
+
+ // inf is of type APIInfo
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ var (
+ cdn int
+ id int
+ name string
+ description string
+ domain_name string
+ resp []interface{} //really not sure about this
+ )
+
+ //how to prefetch 'cdn'?
+ q := `SELECT cdn, id, name, description FROM 'Profile' WHERE name LIKE 'CCR%'`
+ rows, err := inf.Tx.Query(q)
+ if err != nil {
+ //TODO change errCode, userErr, and sysErr
+ //which one is errors.New("Error: " + err.Error()?
+ //api.HandleErr(w, r, errCode, userErr, sysErr)
+ return
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+
+ //Do I even need to check for errors here since the perl doesn't?
+ if err := rows.Scan(&cdn, &id, &name, &description); err != nil {
+ //api.HandleErr(w, r, HTTP CODE,
+ // errors.New("Error scanning ...: " + err.Error()) user or system error?
+ }
+
+ err = inf.Tx.QueryRow("SELECT DOMAIN_NAME FROM CDN WHERE id = $1", 1).Scan(&domain_name)
+ if err != nil {
+ //api.HandleErr(w, r, HTTP CODE,
+ // errors.New("Error scanning ...: " + err.Error()") user or system error?
+ }
+
+ data := struct {
+ domain_name string
+ param_id int
+ id int
+ name string
+ description string
+ } {
+ domain_name,
+ -1, // it's not a parameter anymore
+ id,
+ name,
+ description,
+ }
+ resp = append(resp, data)
+ }
+
+ api.WriteResp(w, r, resp)
+ /* {
+ "domainName" => $row->cdn->domain_name,
+ "parameterId" => -1, # it's not a parameter anymore
+ "profileId" => $row->id,
+ "profileName" => $row->name,
+ "profileDescription" => $row->description,
+ } */
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index 60670a3..ccef612 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -110,7 +110,8 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
{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/?(\.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/domains$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}}, //old
+ //{1.1, http.MethodGet, `cdns/domains/?(\.json)?$`, cdn.DomainsHandler, auth.PrivLevelReadOnly, Authenticated, nil},
{1.1, http.MethodGet, `cdns/health$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
{1.1, http.MethodGet, `cdns/routing$`, handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},