forked from nscuro/dtrack-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_bom_test.go
More file actions
57 lines (49 loc) · 1.1 KB
/
Copy pathexample_bom_test.go
File metadata and controls
57 lines (49 loc) · 1.1 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dtrack_test
import (
"context"
"encoding/base64"
"github.com/nscuro/dtrack-client"
"os"
"sync"
"time"
)
// This example demonstrates how to upload a Bill of Materials and wait for its processing to complete.
func Example_uploadBOM() {
client, _ := dtrack.NewClient("https://dtrack.example.com", dtrack.WithAPIKey("..."))
bomContent, err := os.ReadFile("bom.xml")
if err != nil {
panic(err)
}
uploadToken, err := client.BOM.Upload(context.TODO(), dtrack.BOMUploadRequest{
ProjectName: "acme-app",
ProjectVersion: "1.0.0",
AutoCreate: true,
BOM: base64.StdEncoding.EncodeToString(bomContent),
})
if err != nil {
panic(err)
}
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
ticker := time.NewTicker(1 * time.Second)
timeout := time.After(30 * time.Second)
loop:
for {
select {
case <-ticker.C:
processing, err := client.BOM.IsBeingProcessed(context.TODO(), uploadToken)
if err != nil {
panic(err)
}
if !processing {
break loop
}
case <-timeout:
panic("timeout exceeded")
}
}
}()
wg.Wait()
}