github-code-scanning[bot] commented on code in PR #7734:
URL: https://github.com/apache/trafficcontrol/pull/7734#discussion_r1298543799


##########
traffic_ops/traffic_ops_golang/profile/profiles.go:
##########
@@ -360,3 +362,252 @@
 func deleteQuery() string {
        return `DELETE FROM profile WHERE id = :id`
 }
+
+// Read gets list of Profiles for APIv5
+func Read(w http.ResponseWriter, r *http.Request) {
+       var runSecond bool
+       var maxTime time.Time
+       inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+       tx := inf.Tx
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+               return
+       }
+       defer inf.Close()
+
+       // Query Parameters to Database Query column mappings
+       queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+               "cdn":   {Column: "c.id", Checker: api.IsInt},
+               "name":  {Column: "prof.name", Checker: nil},
+               "id":    {Column: "prof.id", Checker: api.IsInt},
+               "param": {Column: "pp.parameter", Checker: api.IsInt},
+       }
+
+       query := selectProfilesQuery()
+       if paramValue, ok := inf.Params["param"]; ok {
+               if len(paramValue) > 0 {
+                       query += " LEFT JOIN profile_parameter pp ON prof.id = 
pp.profile"
+               }
+       }
+
+       where, orderBy, pagination, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+       if len(errs) > 0 {
+               api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, 
util.JoinErrs(errs), nil)
+       }
+
+       if inf.Config.UseIMS {
+               runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, 
queryValues, selectMaxLastUpdatedQuery(where))
+               if !runSecond {
+                       log.Debugln("IMS HIT")
+                       api.AddLastModifiedHdr(w, maxTime)
+                       w.WriteHeader(http.StatusNotModified)
+                       return
+               }
+               log.Debugln("IMS MISS")
+       } else {
+               log.Debugln("Non IMS request")
+       }
+
+       query += where + orderBy + pagination
+       rows, err := tx.NamedQuery(query, queryValues)

Review Comment:
   ## Database query built from user-controlled sources
   
   This query depends on a [user-provided value](1).
   
   [Show more 
details](https://github.com/apache/trafficcontrol/security/code-scanning/301)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to