github-code-scanning[bot] commented on code in PR #7575:
URL: https://github.com/apache/trafficcontrol/pull/7575#discussion_r1228645990
##########
traffic_ops/traffic_ops_golang/types/types.go:
##########
@@ -211,3 +215,324 @@
WHERE id=:id`
return query
}
+
+// Get [Version :V5]
+func GetV5(w http.ResponseWriter, r *http.Request) {
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ code := http.StatusOK
+ useIMS := false
+ config, e := api.GetConfig(r.Context())
+ if e == nil && config != nil {
+ useIMS = config.UseIMS
+ } else {
+ log.Warnf("Couldn't get config %v", e)
+ }
+
+ var maxTime time.Time
+ var usrErr error
+ var syErr error
+
+ var typeList []tc.TypeV5
+
+ tx := inf.Tx
+
+ typeList, maxTime, code, usrErr, syErr = GetTypesV5(tx, inf.Params,
useIMS, r.Header)
+ if code == http.StatusNotModified {
+ w.WriteHeader(code)
+ api.WriteResp(w, r, []tc.TypeV5{})
+ return
+ }
+
+ if code == http.StatusBadRequest {
+ api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, usrErr,
nil)
+ return
+ }
+
+ if sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError,
nil, syErr)
+ return
+ }
+
+ if maxTime != (time.Time{}) && api.SetLastModifiedHeader(r, useIMS) {
+ api.AddLastModifiedHdr(w, maxTime)
+ }
+
+ api.WriteResp(w, r, typeList)
+}
+
+// GetTypes [Version : V5] returns types.
+func GetTypesV5(tx *sqlx.Tx, params map[string]string, useIMS bool, header
http.Header) ([]tc.TypeV5, time.Time, int, error, error) {
+ var runSecond bool
+ var maxTime time.Time
+ typeList := []tc.TypeV5{}
+
+ selectQuery := `SELECT id, name, description, use_in_table,
last_updated FROM type as typ`
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "name": {Column: "typ.name"},
+ "id": {Column: "typ.id", Checker: api.IsInt},
+ "useInTable": {Column: "typ.use_in_table"},
+ }
+ if _, ok := params["orderby"]; !ok {
+ params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs :=
dbhelpers.BuildWhereAndOrderByAndPagination(params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ return nil, time.Time{}, http.StatusBadRequest,
util.JoinErrs(errs), nil
+ }
+
+ if useIMS {
+ runSecond, maxTime = TryIfModifiedSinceQuery(header, tx, where,
queryValues)
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ return typeList, maxTime, http.StatusNotModified, nil,
nil
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery + 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/278)
--
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]