mhoppa commented on a change in pull request #3900: Rewrite 
/cachegroups/{{id}}/parameters to Go
URL: https://github.com/apache/trafficcontrol/pull/3900#discussion_r320910049
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroup/parameters.go
 ##########
 @@ -0,0 +1,97 @@
+package cachegroup
+
+/*
+ * 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"
+       "net/http"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/lib/go-util"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/auth"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/parameter"
+)
+
+const (
+       CacheGroupIDQueryParam = "id"
+       ParameterIDQueryParam  = "parameterId"
+)
+
+//we need a type alias to define functions on
+type TOCacheGroupParameter struct {
+       api.APIInfoImpl `json:"-"`
+       tc.ParameterNullable
+}
+
+func (cgparam *TOCacheGroupParameter) ParamColumns() 
map[string]dbhelpers.WhereColumnInfo {
+       return map[string]dbhelpers.WhereColumnInfo{
+               CacheGroupIDQueryParam: 
dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+               ParameterIDQueryParam:  dbhelpers.WhereColumnInfo{"p.id", 
api.IsInt},
+       }
+}
+
+func (cgparam *TOCacheGroupParameter) GetType() string {
+       return "cachegroup_params"
+}
+
+func (cgparam *TOCacheGroupParameter) Read() ([]interface{}, error, error, 
int) {
+       queryParamsToQueryCols := cgparam.ParamColumns()
+       where, orderBy, pagination, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(cgparam.APIInfo().Params, 
queryParamsToQueryCols)
+       if len(errs) > 0 {
+               return nil, util.JoinErrs(errs), nil, http.StatusBadRequest
+       }
+
+       query := selectQuery() + where + orderBy + pagination
+       rows, err := cgparam.ReqInfo.Tx.NamedQuery(query, queryValues)
+       if err != nil {
+               return nil, nil, errors.New("querying " + cgparam.GetType() + 
": " + err.Error()), http.StatusInternalServerError
+       }
+       defer rows.Close()
+
+       params := []interface{}{}
+       for rows.Next() {
+               var p tc.ParameterNullable
+               if err = rows.StructScan(&p); err != nil {
+                       return nil, nil, errors.New("scanning " + 
cgparam.GetType() + ": " + err.Error()), http.StatusInternalServerError
+               }
+               if p.Secure != nil && *p.Secure && 
cgparam.ReqInfo.User.PrivLevel < auth.PrivLevelAdmin {
+                       p.Value = &parameter.HiddenField
+               }
+               params = append(params, p)
+       }
+
+       return params, nil, nil, http.StatusOK
 
 Review comment:
   The Perl implementation does not check for existence of the cache group its 
only checking if you give it a negative ID on the path
   
   Would you like me to match parity to that or actually checking if the cache 
group exists?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to