forked from nscuro/dtrack-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_finding_test.go
More file actions
38 lines (31 loc) · 861 Bytes
/
Copy pathexample_finding_test.go
File metadata and controls
38 lines (31 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package dtrack_test
import (
"context"
"github.com/google/uuid"
"github.com/nscuro/dtrack-client"
)
// This example demonstrates how to fetch all findings for a given project.
// It also shows how to navigate through Dependency-Track's API paging.
func Example_getAllFindings() {
client, _ := dtrack.NewClient("https://dtrack.example.com", dtrack.WithAPIKey("..."))
projectUUID := uuid.MustParse("2d16089e-6d3a-437e-b334-f27eb2cbd7f4")
var (
findings []dtrack.Finding
pageNumber = 1
pageSize = 10
)
for {
findingsPage, err := client.Finding.GetAll(context.TODO(), projectUUID, false, dtrack.PageOptions{
PageNumber: pageNumber,
PageSize: pageSize,
})
if err != nil {
panic(err)
}
findings = append(findings, findingsPage.Findings...)
if len(findings) >= findingsPage.TotalCount {
break
}
pageNumber++
}
}