forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
vex.go
42 lines (33 loc) · 1005 Bytes
/
vex.go
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
package dtrack
import (
"context"
"fmt"
"net/http"
"github.com/google/uuid"
)
type VEXService struct {
client *Client
}
type VEXUploadRequest struct {
ProjectUUID *uuid.UUID `json:"project,omitempty"`
ProjectName string `json:"projectName,omitempty"`
ProjectVersion string `json:"projectVersion,omitempty"`
VEX string `json:"vex"`
}
func (vs VEXService) ExportCycloneDX(ctx context.Context, projectUUID uuid.UUID) (vex string, err error) {
req, err := vs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/vex/cyclonedx/project/%s", projectUUID))
if err != nil {
return
}
req.Header.Set("Accept", "application/vnd.cyclonedx+json")
_, err = vs.client.doRequest(req, &vex)
return
}
func (vs VEXService) Upload(ctx context.Context, uploadReq VEXUploadRequest) (err error) {
req, err := vs.client.newRequest(ctx, http.MethodPut, "/api/v1/vex", withBody(uploadReq))
if err != nil {
return
}
_, err = vs.client.doRequest(req, nil)
return
}