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


##########
traffic_ops/traffic_ops_golang/trafficstats/stats_summary.go:
##########
@@ -157,6 +157,132 @@
        api.WriteRespAlert(w, r, tc.SuccessLevel, successMsg)
 }
 
+// GetStatsSummaryV5 handler for getting stats summaries
+func GetStatsSummaryV5(w http.ResponseWriter, r *http.Request) {
+       inf, userErr, sysErr, errCode := api.NewInfo(r, []string{}, []string{})
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+               return
+       }
+       defer inf.Close()
+
+       lastSummaryDateStr := inf.Params["lastSummaryDate"]
+       if len(lastSummaryDateStr) != 0 { // Perl only checked for existence of 
query param
+               GetLastSummaryDateV5(w, r, inf)
+               return
+       }
+
+       GetStatsSummariesV5(w, r, inf)
+       return
+}
+
+func GetLastSummaryDateV5(w http.ResponseWriter, r *http.Request, inf 
*api.APIInfo) {
+       queryParamsToSQLCols := map[string]dbhelpers.WhereColumnInfo{
+               "statName": dbhelpers.WhereColumnInfo{Column: "stat_name"},
+       }
+       where, _, _, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToSQLCols)
+       if len(errs) > 0 {
+               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, util.JoinErrs(errs))
+               return
+       }
+       query := selectQuery() + where + " ORDER BY summary_time DESC"
+       statsSummaries, err := QueryStatsSummaryV5(inf.Tx, query, queryValues)
+       if err != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, err)
+               return
+       }
+       resp := tc.StatsSummaryLastUpdatedV5{}
+       if len(statsSummaries) >= 1 {
+               resp.SummaryTime = &statsSummaries[0].SummaryTime
+       }
+       api.WriteResp(w, r, resp)
+}
+
+func GetStatsSummariesV5(w http.ResponseWriter, r *http.Request, inf 
*api.APIInfo) {
+       queryParamsToSQLCols := map[string]dbhelpers.WhereColumnInfo{
+               "statName":            dbhelpers.WhereColumnInfo{Column: 
"stat_name"},
+               "cdnName":             dbhelpers.WhereColumnInfo{Column: 
"cdn_name"},
+               "deliveryServiceName": dbhelpers.WhereColumnInfo{Column: 
"deliveryservice_name"},
+       }
+       where, orderBy, pagination, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToSQLCols)
+       if len(errs) > 0 {
+               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, util.JoinErrs(errs))
+               return
+       }
+       query := selectQuery() + where + orderBy + pagination
+       statsSummaries, err := QueryStatsSummaryV5(inf.Tx, query, queryValues)
+       if err != nil {
+               api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, 
nil, err)
+               return
+       }
+
+       api.WriteResp(w, r, statsSummaries)
+}
+
+func QueryStatsSummaryV5(tx *sqlx.Tx, q string, queryValues 
map[string]interface{}) ([]tc.StatsSummaryV5, error) {
+       rows, err := tx.NamedQuery(q, 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/268)



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