You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org> on 2023/07/05 21:05:43 UTC

[GitHub] [trafficcontrol] github-code-scanning[bot] commented on a diff in pull request #7596: Federation resolvers v5

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


##########
traffic_ops/traffic_ops_golang/federation_resolvers/federation_resolvers.go:
##########
@@ -301,3 +306,153 @@
 
 	return alert, result, userErr, sysErr, statusCode
 }
+
+// GetFederationResolvers [V5] - get list of federation resolver for APIv5
+func GetFederationResolvers(w http.ResponseWriter, r *http.Request) {
+	var maxTime time.Time
+	var runSecond bool
+	inf, sysErr, userErr, errCode := api.NewInfo(r, nil, nil)
+	tx := inf.Tx
+	if sysErr != nil || userErr != nil {
+		api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+		return
+	}
+	defer inf.Close()
+
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"id":        dbhelpers.WhereColumnInfo{Column: "federation_resolver.id", Checker: api.IsInt},
+		"ipAddress": dbhelpers.WhereColumnInfo{Column: "federation_resolver.ip_address"},
+		"type":      dbhelpers.WhereColumnInfo{Column: "type.name"},
+	}
+	if _, ok := inf.Params["orderby"]; !ok {
+		inf.Params["orderby"] = "id"
+	}
+
+	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		sysErr = util.JoinErrs(errs)
+		errCode = http.StatusBadRequest
+		api.HandleErr(w, r, tx.Tx, errCode, nil, sysErr)
+		return
+	}
+
+	query := readQuery + where + orderBy + pagination
+	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)
+	}
+	if useIMS {
+		runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where, "federation_resolver"))
+		if !runSecond {
+			log.Debugln("IMS HIT")
+			api.AddLastModifiedHdr(w, maxTime)
+			w.WriteHeader(http.StatusNotModified)
+			api.WriteResp(w, r, []tc.FederationResolverV5{})
+			return
+		}
+		log.Debugln("IMS MISS")
+	} else {
+		log.Debugln("Non IMS request")
+	}
+
+	rows, err := inf.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/287)



-- 
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: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org