-
Notifications
You must be signed in to change notification settings - Fork 29
API Endpoint: Sitemap-Generation #1641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ package controllers | |
| import ( | ||
| "fmt" | ||
| "net/url" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/l3montree-dev/devguard/database/models" | ||
| "github.com/l3montree-dev/devguard/dtos" | ||
|
|
@@ -150,3 +152,57 @@ func (c VulnDBController) PURLInspect(ctx shared.Context) error { | |
| MaliciousPackage: maliciousPackage, | ||
| }) | ||
| } | ||
|
|
||
| // returns a list of cve ids sorted by the creation date as well as the total amount of entries | ||
| // query parameter offset: offset the fetched data by the provided amount | ||
| // query parameter limit: limit the amount of entries in the data | ||
| func (c VulnDBController) ListIDsByCreationDate(ctx shared.Context) error { | ||
| type listIDsRow struct { | ||
| CVEID string `gorm:"column:cve"` | ||
| CreatedAt time.Time `gorm:"column:created_at"` | ||
| } | ||
| type responseDTO struct { | ||
| Count int `json:"total"` | ||
| CVEData []listIDsRow `json:"data"` | ||
| } | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
|
|
||
| // use an offset to query only a part of the data | ||
| offset := 0 | ||
| offsetParam := ctx.QueryParam("offset") | ||
| if offsetParam != "" { | ||
| var err error | ||
| offset, err = strconv.Atoi(offsetParam) | ||
| if err != nil { | ||
| return echo.NewHTTPError(400, "invalid offset value").WithInternal(err) | ||
| } | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
| } | ||
|
|
||
| var err error | ||
| results := make([]listIDsRow, 0, 1<<18) | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
|
|
||
| // use optional limit parameter to limit the amount of fetched data | ||
| limit := 0 | ||
| limitParam := ctx.QueryParam("limit") | ||
| if limitParam != "" { | ||
| limit, err = strconv.Atoi(limitParam) | ||
| if err != nil { | ||
| return echo.NewHTTPError(400, "invalid limit value").WithInternal(err) | ||
| } | ||
|
Hubtrick-Git marked this conversation as resolved.
Hubtrick-Git marked this conversation as resolved.
|
||
|
|
||
| sql := `SELECT cve,created_at FROM cves ORDER BY created_at DESC OFFSET ? LIMIT ?;` | ||
| err = c.cveRepository.GetDB(nil).Raw(sql, offset, limit).Find(&results).Error | ||
| } else { | ||
| sql := `SELECT cve,created_at FROM cves ORDER BY created_at DESC OFFSET ?;` | ||
| err = c.cveRepository.GetDB(nil).Raw(sql, offset).Find(&results).Error | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
| } | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
| if err != nil { | ||
| return echo.NewHTTPError(500, "could not get cve ids").WithInternal(err) | ||
| } | ||
|
|
||
| // build the response and return it | ||
| response := responseDTO{ | ||
| Count: len(results), | ||
| CVEData: results, | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
| } | ||
| return ctx.JSON(200, response) | ||
|
Hubtrick-Git marked this conversation as resolved.
|
||
| } | ||
|
Comment on lines
+159
to
+208
|
||
Uh oh!
There was an error while loading. Please reload this page.