Skip to content

Commit 3f60a93

Browse files
committed
Implement repository functions
Signed-off-by: bakito <[email protected]>
1 parent 4729b5e commit 3f60a93

File tree

5 files changed

+97
-5
lines changed

5 files changed

+97
-5
lines changed

finding_example_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package dtrack_test
33
import (
44
"context"
55

6-
"github.com/google/uuid"
7-
86
"github.com/DependencyTrack/client-go"
7+
"github.com/google/uuid"
98
)
109

1110
// This example demonstrates how to fetch all findings for a given project.

permission.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package dtrack
33
import (
44
"context"
55
"fmt"
6-
"github.com/google/uuid"
76
"net/http"
7+
8+
"github.com/google/uuid"
89
)
910

1011
type PermissionService struct {

project_property.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package dtrack
33
import (
44
"context"
55
"fmt"
6-
"github.com/google/uuid"
76
"net/http"
7+
8+
"github.com/google/uuid"
89
)
910

1011
type ProjectProperty struct {

repository.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,40 @@ package dtrack
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
7+
8+
"github.com/google/uuid"
9+
)
10+
11+
const (
12+
RepositoryTypeCargo = "CARGO"
13+
RepositoryTypeComposer = "COMPOSER"
14+
RepositoryTypeCpan = "CPAN"
15+
RepositoryTypeGem = "GEM"
16+
RepositoryTypeGoModules = "GO_MODULES"
17+
RepositoryTypeHex = "HEX"
18+
RepositoryTypeMaven = "MAVEN"
19+
RepositoryTypeNpm = "NPM"
20+
RepositoryTypeNuget = "NUGET"
21+
RepositoryTypePypi = "PYPI"
22+
RepositoryTypeUnsupported = "UNSUPPORTED"
623
)
724

25+
type RepositoryType string
26+
27+
type Repository struct {
28+
Type RepositoryType `json:"type"`
29+
Identifier string `json:"identifier"`
30+
Url string `json:"url"`
31+
ResolutionOrder int `json:"resolutionOrder"`
32+
Enabled bool `json:"enabled"`
33+
Internal bool `json:"internal"`
34+
Username string `json:"username,omitempty"`
35+
Password string `json:"password,omitempty"`
36+
UUID uuid.UUID `json:"uuid,omitempty"`
37+
}
38+
839
type RepositoryMetaComponent struct {
940
LatestVersion string `json:"latestVersion"`
1041
}
@@ -26,3 +57,62 @@ func (rs RepositoryService) GetMetaComponent(ctx context.Context, purl string) (
2657
_, err = rs.client.doRequest(req, &r)
2758
return
2859
}
60+
61+
func (rs RepositoryService) GetAll(ctx context.Context, po PageOptions) (p Page[Repository], err error) {
62+
req, err := rs.client.newRequest(ctx, http.MethodGet, "/api/v1/repository", withPageOptions(po))
63+
if err != nil {
64+
return
65+
}
66+
67+
res, err := rs.client.doRequest(req, &p.Items)
68+
if err != nil {
69+
return
70+
}
71+
72+
p.TotalCount = res.TotalCount
73+
return
74+
}
75+
76+
func (rs RepositoryService) GetByType(ctx context.Context, repoType RepositoryType, po PageOptions) (p Page[Repository], err error) {
77+
req, err := rs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/repository/%s", repoType), withPageOptions(po))
78+
if err != nil {
79+
return
80+
}
81+
82+
res, err := rs.client.doRequest(req, &p.Items)
83+
if err != nil {
84+
return
85+
}
86+
87+
p.TotalCount = res.TotalCount
88+
return
89+
}
90+
91+
func (rs RepositoryService) Create(ctx context.Context, repository Repository) (r Repository, err error) {
92+
req, err := rs.client.newRequest(ctx, http.MethodPut, "/api/v1/repository", withBody(repository))
93+
if err != nil {
94+
return
95+
}
96+
97+
_, err = rs.client.doRequest(req, &r)
98+
return
99+
}
100+
func (rs RepositoryService) Update(ctx context.Context, repository Repository) (r Repository, err error) {
101+
req, err := rs.client.newRequest(ctx, http.MethodPost, "/api/v1/repository", withBody(repository))
102+
if err != nil {
103+
return
104+
}
105+
106+
_, err = rs.client.doRequest(req, &r)
107+
return
108+
}
109+
110+
func (rs RepositoryService) Delete(ctx context.Context, id string) (err error) {
111+
req, err := rs.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/repository/%s", id))
112+
if err != nil {
113+
return
114+
}
115+
116+
_, err = rs.client.doRequest(req, nil)
117+
return
118+
}

vulnerability.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package dtrack
33
import (
44
"context"
55
"fmt"
6-
"github.com/google/uuid"
76
"net/http"
87
"strconv"
8+
9+
"github.com/google/uuid"
910
)
1011

1112
type Vulnerability struct {

0 commit comments

Comments
 (0)