wilfred-s commented on code in PR #428:
URL: https://github.com/apache/yunikorn-core/pull/428#discussion_r944064005
##########
pkg/webservice/handlers.go:
##########
@@ -677,6 +677,62 @@ func getQueueApplications(w http.ResponseWriter, r
*http.Request) {
}
}
+func getApplication(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ writeHeaders(w)
+ partition, partitionExists := vars["partition"]
+ if !partitionExists {
+ buildJSONErrorResponse(w, "Partition is missing in URL path.
Please check the usage documentation", http.StatusBadRequest)
+ return
+ }
+ queueName, queueNameExists := vars["queue"]
+ if !queueNameExists {
+ buildJSONErrorResponse(w, "Queue is missing in URL path. Please
check the usage documentation", http.StatusBadRequest)
+ return
+ }
+
+ application, applicationExists := vars["application"]
+ if !applicationExists {
+ buildJSONErrorResponse(w, "Application Id is missing in URL
path. Please check the usage documentation", http.StatusBadRequest)
+ return
+ }
+
+ queueErr := validateQueue(queueName)
+ if queueErr != nil {
+ buildJSONErrorResponse(w, queueErr.Error(),
http.StatusBadRequest)
+ return
+ }
+ if len(vars) != 3 {
+ buildJSONErrorResponse(w, "Incorrect URL path. Please check the
usage documentation", http.StatusBadRequest)
Review Comment:
Dug in a bit further: the URL matching inside gorilla already filters out
anything malformed. The definition of the route makes sure that we always get
the values. As per the [examples](https://github.com/gorilla/mux#examples) in
the docs:
```
Paths can have variables. They are defined using the format {name} or
{name:pattern}. If a regular expression pattern is not defined, the matched
variable will be anything until the next slash.
```
The mux code does a regexp on the URL to see if it matches the route. If
that regexp does not match a 404 is returned. I have tried to craft a request
that will call the handler which does not have the parameters set and I cannot.
When I get to the point that the handler is called I have the values in the
map. The content might be garbage but I have content. I was not able to match
the route in any other way.
In conclusion: anything that does not map to a route will give back a 404.
Check 1 and 2 are thus completely unneeded.
--
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]