Skip to content

Commit 840a9b7

Browse files
authored
feat: Add repoMeta to Component type and allow component filtering (#46)
1 parent 71daa02 commit 840a9b7

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

component.go

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@ package dtrack
33
import (
44
"context"
55
"fmt"
6-
"net/http"
7-
86
"github.com/google/uuid"
7+
"net/http"
98
)
109

1110
type Component struct {
12-
UUID uuid.UUID `json:"uuid,omitempty"`
13-
Author string `json:"author,omitempty"`
14-
Publisher string `json:"publisher,omitempty"`
15-
Group string `json:"group,omitempty"`
16-
Name string `json:"name"`
17-
Version string `json:"version"`
18-
Classifier string `json:"classifier,omitempty"`
19-
FileName string `json:"filename,omitempty"`
20-
Extension string `json:"extension,omitempty"`
21-
MD5 string `json:"md5,omitempty"`
22-
SHA1 string `json:"sha1,omitempty"`
23-
SHA256 string `json:"sha256,omitempty"`
24-
SHA384 string `json:"sha384,omitempty"`
25-
SHA512 string `json:"sha512,omitempty"`
26-
SHA3_256 string `json:"sha3_256,omitempty"`
27-
SHA3_384 string `json:"sha3_384,omitempty"`
28-
SHA3_512 string `json:"sha3_512,omitempty"`
29-
BLAKE2b_256 string `json:"blake2b_256,omitempty"`
30-
BLAKE2b_384 string `json:"blake2b_384,omitempty"`
31-
BLAKE2b_512 string `json:"blake2b_512,omitempty"`
32-
BLAKE3 string `json:"blake3,omitempty"`
33-
CPE string `json:"cpe,omitempty"`
34-
PURL string `json:"purl,omitempty"`
35-
SWIDTagID string `json:"swidTagId,omitempty"`
36-
Internal bool `json:"isInternal,omitempty"`
37-
Description string `json:"description,omitempty"`
38-
Copyright string `json:"copyright,omitempty"`
39-
License string `json:"license,omitempty"`
40-
ResolvedLicense *License `json:"resolvedLicense,omitempty"`
41-
DirectDependencies string `json:"directDependencies,omitempty"`
42-
Notes string `json:"notes,omitempty"`
43-
ExternalReferences []ExternalReference `json:"externalReferences,omitempty"`
44-
Project *Project `json:"project,omitempty"`
11+
UUID uuid.UUID `json:"uuid,omitempty"`
12+
Author string `json:"author,omitempty"`
13+
Publisher string `json:"publisher,omitempty"`
14+
Group string `json:"group,omitempty"`
15+
Name string `json:"name"`
16+
Version string `json:"version"`
17+
Classifier string `json:"classifier,omitempty"`
18+
FileName string `json:"filename,omitempty"`
19+
Extension string `json:"extension,omitempty"`
20+
MD5 string `json:"md5,omitempty"`
21+
SHA1 string `json:"sha1,omitempty"`
22+
SHA256 string `json:"sha256,omitempty"`
23+
SHA384 string `json:"sha384,omitempty"`
24+
SHA512 string `json:"sha512,omitempty"`
25+
SHA3_256 string `json:"sha3_256,omitempty"`
26+
SHA3_384 string `json:"sha3_384,omitempty"`
27+
SHA3_512 string `json:"sha3_512,omitempty"`
28+
BLAKE2b_256 string `json:"blake2b_256,omitempty"`
29+
BLAKE2b_384 string `json:"blake2b_384,omitempty"`
30+
BLAKE2b_512 string `json:"blake2b_512,omitempty"`
31+
BLAKE3 string `json:"blake3,omitempty"`
32+
CPE string `json:"cpe,omitempty"`
33+
PURL string `json:"purl,omitempty"`
34+
SWIDTagID string `json:"swidTagId,omitempty"`
35+
Internal bool `json:"isInternal,omitempty"`
36+
Description string `json:"description,omitempty"`
37+
Copyright string `json:"copyright,omitempty"`
38+
License string `json:"license,omitempty"`
39+
ResolvedLicense *License `json:"resolvedLicense,omitempty"`
40+
DirectDependencies string `json:"directDependencies,omitempty"`
41+
Notes string `json:"notes,omitempty"`
42+
ExternalReferences []ExternalReference `json:"externalReferences,omitempty"`
43+
Project *Project `json:"project,omitempty"`
44+
RepositoryMeta *RepositoryMetaComponent `json:"repositoryMeta,omitempty"`
4545
}
4646

4747
type ExternalReference struct {
@@ -54,6 +54,11 @@ type ComponentService struct {
5454
client *Client
5555
}
5656

57+
type ComponentFilterOptions struct {
58+
OnlyOutdated bool
59+
OnlyDirect bool
60+
}
61+
5762
func (cs ComponentService) Get(ctx context.Context, componentUUID uuid.UUID) (c Component, err error) {
5863
req, err := cs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/component/%s", componentUUID))
5964
if err != nil {
@@ -64,8 +69,8 @@ func (cs ComponentService) Get(ctx context.Context, componentUUID uuid.UUID) (c
6469
return
6570
}
6671

67-
func (cs ComponentService) GetAll(ctx context.Context, projectUUID uuid.UUID, po PageOptions) (p Page[Component], err error) {
68-
req, err := cs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/component/project/%s", projectUUID), withPageOptions(po))
72+
func (cs ComponentService) GetAll(ctx context.Context, projectUUID uuid.UUID, po PageOptions, filterOptions ComponentFilterOptions) (p Page[Component], err error) {
73+
req, err := cs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/component/project/%s", projectUUID), withPageOptions(po), withComponentFilterOptions(filterOptions))
6974
if err != nil {
7075
return
7176
}
@@ -79,6 +84,20 @@ func (cs ComponentService) GetAll(ctx context.Context, projectUUID uuid.UUID, po
7984
return
8085
}
8186

87+
func withComponentFilterOptions(filterOptions ComponentFilterOptions) requestOption {
88+
return func(req *http.Request) error {
89+
query := req.URL.Query()
90+
if filterOptions.OnlyDirect {
91+
query.Set("onlyDirect", "true")
92+
}
93+
if filterOptions.OnlyOutdated {
94+
query.Set("onlyOutdated", "true")
95+
}
96+
req.URL.RawQuery = query.Encode()
97+
return nil
98+
}
99+
}
100+
82101
func (cs ComponentService) Create(ctx context.Context, projectUUID string, component Component) (c Component, err error) {
83102
req, err := cs.client.newRequest(ctx, http.MethodPut,
84103
fmt.Sprintf("/api/v1/component/project/%s", projectUUID),

repository.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ type Repository struct {
3939
}
4040

4141
type RepositoryMetaComponent struct {
42-
LatestVersion string `json:"latestVersion"`
42+
RepositoryType string `json:"repositoryType"`
43+
Namespace string `json:"namespace,omitempty"`
44+
Name string `json:"name"`
45+
LatestVersion string `json:"latestVersion"`
46+
Published int `json:"published"`
47+
LastCheck int `json:"lastCheck"`
4348
}
4449

4550
type RepositoryService struct {

0 commit comments

Comments
 (0)