github-code-scanning[bot] commented on code in PR #7596:
URL: https://github.com/apache/trafficcontrol/pull/7596#discussion_r1242687094
##########
traffic_ops/traffic_ops_golang/federation_resolvers/federation_resolvers.go:
##########
@@ -301,3 +306,232 @@
return alert, result, userErr, sysErr, statusCode
}
+
+// [Version - 5] - We fixed time to respond with RFC3339-format date strings.
+// [Version - 5] GetFederationResolvers get all federation resolver or
requested id or ipAddress or type
+func GetFederationResolversV5(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 federationResolverList []tc.FederationResolverV5
+
+ tx := inf.Tx
+
+ federationResolverList, maxTime, code, usrErr, syErr = func(tx
*sqlx.Tx, params map[string]string, useIMS bool, header http.Header)
([]tc.FederationResolverV5, time.Time, int, error, error) {
+ var runSecond bool
+ var maxTime time.Time
+ federationResolverList := []tc.FederationResolverV5{}
+
+ selectQuery := `
+SELECT federation_resolver.id,
+ federation_resolver.ip_address,
+ federation_resolver.last_updated,
+ type.name AS type
+FROM federation_resolver
+LEFT OUTER JOIN type ON type.id = federation_resolver.type
+`
+
+ // Query Parameters to Database Query column mappings
+ 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 := params["orderby"]; !ok {
+ params["orderby"] = "id"
+ }
+ where, orderBy, pagination, queryValues, errs :=
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ return nil, time.Time{}, http.StatusBadRequest,
util.JoinErrs(errs), nil
+ }
+
+ if useIMS {
+ runSecond, maxTime = TryIfModifiedSinceQueryV5(header,
tx, where, queryValues)
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ return federationResolverList, 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/283)
--
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]