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:35:47 UTC
[incubator-trafficcontrol] branch master updated: Add TO Go
profiles/trimmed
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 6ca2470 Add TO Go profiles/trimmed
6ca2470 is described below
commit 6ca24707b498d80dedb371af4d2705ad90b507c8
Author: Robert Butts <ro...@apache.org>
AuthorDate: Wed May 30 14:48:19 2018 -0600
Add TO Go profiles/trimmed
---
lib/go-tc/profiles.go | 4 ++
traffic_ops/traffic_ops_golang/profile/trimmed.go | 51 +++++++++++++++++++++++
traffic_ops/traffic_ops_golang/routes.go | 1 +
3 files changed, 56 insertions(+)
diff --git a/lib/go-tc/profiles.go b/lib/go-tc/profiles.go
index bf4f020..cc0175c 100644
--- a/lib/go-tc/profiles.go
+++ b/lib/go-tc/profiles.go
@@ -47,3 +47,7 @@ type ProfileNullable struct {
RoutingDisabled *bool `json:"routingDisabled" db:"routing_disabled"`
Type *string `json:"type" db:"type"`
}
+
+type ProfileTrimmed struct {
+ Name string `json:"name"`
+}
diff --git a/traffic_ops/traffic_ops_golang/profile/trimmed.go b/traffic_ops/traffic_ops_golang/profile/trimmed.go
new file mode 100644
index 0000000..114dcbe
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/profile/trimmed.go
@@ -0,0 +1,51 @@
+package profile
+
+/*
+ * 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 (
+ "errors"
+ "database/sql"
+ "net/http"
+
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+func Trimmed(db *sql.DB) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ api.RespWriter(w, r)(getTrimmedProfiles(db))
+ }
+}
+
+func getTrimmedProfiles(db *sql.DB) ([]tc.ProfileTrimmed, error) {
+ rows, err := db.Query(`SELECT name FROM profile`)
+ if err != nil {
+ return nil, errors.New("querying trimmed profiles: " + err.Error())
+ }
+ profiles := []tc.ProfileTrimmed{}
+ for rows.Next() {
+ name := ""
+ if err = rows.Scan(&name); err != nil {
+ return nil, errors.New("scanning trimmed profiles: " + err.Error())
+ }
+ profiles = append(profiles, tc.ProfileTrimmed{Name: name})
+ }
+ return profiles, nil
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go b/traffic_ops/traffic_ops_golang/routes.go
index ad6fba9..52509f5 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -152,6 +152,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, http.Handler, error) {
//Profile: CRUD
{1.1, http.MethodGet, `profiles/?(\.json)?$`, api.ReadHandler(profile.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.1, http.MethodGet, `profiles/trimmed/?(\.json)?$`, profile.Trimmed(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
{1.1, http.MethodGet, `profiles/{id}$`, api.ReadHandler(profile.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
{1.1, http.MethodPut, `profiles/{id}$`, api.UpdateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
{1.1, http.MethodPost, `profiles/?$`, api.CreateHandler(profile.GetRefType(), d.DB), auth.PrivLevelOperations, Authenticated, nil},
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.