|
|
|
@ -197,7 +197,7 @@ func getVulnerabilities(w http.ResponseWriter, r *http.Request, p httprouter.Par
|
|
|
|
|
if err != nil {
|
|
|
|
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{"invalid limit format: " + err.Error()}})
|
|
|
|
|
return getVulnerabilitiesRoute, http.StatusBadRequest
|
|
|
|
|
} else if limit <= 0 {
|
|
|
|
|
} else if limit < 0 {
|
|
|
|
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{"limit value should not be less than zero"}})
|
|
|
|
|
return getVulnerabilitiesRoute, http.StatusBadRequest
|
|
|
|
|
}
|
|
|
|
@ -205,7 +205,7 @@ func getVulnerabilities(w http.ResponseWriter, r *http.Request, p httprouter.Par
|
|
|
|
|
page := 0
|
|
|
|
|
pageStrs, pageExists := query["page"]
|
|
|
|
|
if pageExists {
|
|
|
|
|
page, err = tokenToNumber(pageStrs[0], ctx.Config.PaginationKey)
|
|
|
|
|
err = tokenUnmarshal(pageStrs[0], ctx.Config.PaginationKey, &page)
|
|
|
|
|
if err != nil {
|
|
|
|
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{"invalid page format: " + err.Error()}})
|
|
|
|
|
return getNotificationRoute, http.StatusBadRequest
|
|
|
|
@ -226,7 +226,12 @@ func getVulnerabilities(w http.ResponseWriter, r *http.Request, p httprouter.Par
|
|
|
|
|
|
|
|
|
|
var nextPageStr string
|
|
|
|
|
if nextPage != -1 {
|
|
|
|
|
nextPageStr = numberToToken(nextPage, ctx.Config.PaginationKey)
|
|
|
|
|
nextPageBytes, err := tokenMarshal(nextPage, ctx.Config.PaginationKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{"failed to marshal token: " + err.Error()}})
|
|
|
|
|
return getNotificationRoute, http.StatusBadRequest
|
|
|
|
|
}
|
|
|
|
|
nextPageStr = string(nextPageBytes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writeResponse(w, r, http.StatusOK, VulnerabilityEnvelope{Vulnerabilities: &vulns, NextPage: &nextPageStr})
|
|
|
|
@ -434,14 +439,19 @@ func getNotification(w http.ResponseWriter, r *http.Request, p httprouter.Params
|
|
|
|
|
page := database.VulnerabilityNotificationFirstPage
|
|
|
|
|
pageStrs, pageExists := query["page"]
|
|
|
|
|
if pageExists {
|
|
|
|
|
page, err = tokenToPageNumber(pageStrs[0], ctx.Config.PaginationKey)
|
|
|
|
|
err := tokenUnmarshal(pageStrs[0], ctx.Config.PaginationKey, &page)
|
|
|
|
|
if err != nil {
|
|
|
|
|
writeResponse(w, r, http.StatusBadRequest, NotificationEnvelope{Error: &Error{"invalid page format: " + err.Error()}})
|
|
|
|
|
return getNotificationRoute, http.StatusBadRequest
|
|
|
|
|
}
|
|
|
|
|
pageToken = pageStrs[0]
|
|
|
|
|
} else {
|
|
|
|
|
pageToken = pageNumberToToken(page, ctx.Config.PaginationKey)
|
|
|
|
|
pageTokenBytes, err := tokenMarshal(page, ctx.Config.PaginationKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
writeResponse(w, r, http.StatusBadRequest, NotificationEnvelope{Error: &Error{"failed to marshal token: " + err.Error()}})
|
|
|
|
|
return getNotificationRoute, http.StatusBadRequest
|
|
|
|
|
}
|
|
|
|
|
pageToken = string(pageTokenBytes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbNotification, nextPage, err := ctx.Store.GetNotification(p.ByName("notificationName"), limit, page)
|
|
|
|
|