Skip to content

Commit 555cc03

Browse files
authored
fix(dependency-track): verify project directly (#1930)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 5ffa3fb commit 555cc03

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

app/controlplane/plugins/core/dependency-track/v1/client/sbom.go

+14-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2023-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -136,20 +136,9 @@ func (d *SBOMUploader) Validate(ctx context.Context) error {
136136
}
137137

138138
// Check if the project or parent project exists
139-
var projectFound bool
140-
projects, err := listProjects(d.host, d.apiKey)
141-
if err != nil {
139+
if projectFound, err := projectExists(d.host, d.apiKey, existingProjectID); err != nil {
142140
return fmt.Errorf("checking that the project exists: %w", err)
143-
}
144-
145-
for _, p := range projects {
146-
if p.ID == existingProjectID {
147-
projectFound = true
148-
break
149-
}
150-
}
151-
152-
if !projectFound {
141+
} else if !projectFound {
153142
return fmt.Errorf("project with ID %q not found", existingProjectID)
154143
}
155144

@@ -310,45 +299,30 @@ func uploadSBOMRequest(host *url.URL, apiKey string, values map[string]io.Reader
310299
return resp, nil
311300
}
312301

313-
type listProjectsResponseItem struct {
314-
ID string `json:"uuid"`
315-
Name string
316-
}
317-
318-
type listProjectsResponse []listProjectsResponseItem
319-
320302
// We are listing projects instead of accessing a specific one to enable
321303
// son in the future listing and selection in the UI
322-
func listProjects(host *url.URL, apiKey string) (listProjectsResponse, error) {
323-
apiEndpoint := host.JoinPath("/api/v1/project")
304+
func projectExists(host *url.URL, apiKey string, projectID string) (bool, error) {
305+
apiEndpoint := host.JoinPath(fmt.Sprintf("/api/v1/project/%s", projectID))
324306

325307
req, err := http.NewRequest(http.MethodGet, apiEndpoint.String(), nil)
326308
if err != nil {
327-
return nil, err
309+
return false, err
328310
}
329311

330312
req.Header.Set("X-Api-Key", apiKey)
331313
// Submit the request
332314
res, err := http.DefaultClient.Do(req)
333315
if err != nil {
334-
return nil, err
316+
return false, err
335317
}
336318

337319
// Check the response
338-
if res.StatusCode != http.StatusOK {
339-
err = fmt.Errorf("bad status: %s", res.Status)
340-
return nil, err
341-
}
342-
343-
resBody, err := io.ReadAll(res.Body)
344-
if err != nil {
345-
return nil, err
346-
}
347-
348-
resp := make([]listProjectsResponseItem, 0)
349-
if err := json.Unmarshal(resBody, &resp); err != nil {
350-
return nil, err
320+
switch res.StatusCode {
321+
case http.StatusOK:
322+
return true, nil
323+
case http.StatusNotFound:
324+
return false, nil
325+
default:
326+
return false, fmt.Errorf("bad status: %s", res.Status)
351327
}
352-
353-
return resp, nil
354328
}

app/controlplane/plugins/core/dependency-track/v1/extension.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2023-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ func New(l log.Logger) (sdk.FanOut, error) {
7979
base, err := sdk.NewFanOut(
8080
&sdk.NewParams{
8181
ID: "dependency-track",
82-
Version: "1.4",
82+
Version: "1.6",
8383
Description: description,
8484
Logger: l,
8585
InputSchema: &sdk.InputSchema{

devel/integrations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Below you can find the list of currently available integrations. If you can't fi
1010

1111
| ID | Version | Description | Material Requirement |
1212
| --- | --- | --- | --- |
13-
| [dependency-track](https://github.com/chainloop-dev/chainloop/blob/main/app/controlplane/plugins/core/dependency-track/v1/README.md) | 1.4 | Send CycloneDX SBOMs to your Dependency-Track instance | SBOM_CYCLONEDX_JSON |
13+
| [dependency-track](https://github.com/chainloop-dev/chainloop/blob/main/app/controlplane/plugins/core/dependency-track/v1/README.md) | 1.6 | Send CycloneDX SBOMs to your Dependency-Track instance | SBOM_CYCLONEDX_JSON |
1414
| [discord-webhook](https://github.com/chainloop-dev/chainloop/blob/main/app/controlplane/plugins/core/discord-webhook/v1/README.md) | 1.1 | Send attestations to Discord | |
1515
| [guac](https://github.com/chainloop-dev/chainloop/blob/main/app/controlplane/plugins/core/guac/v1/README.md) | 1.0 | Export Attestation and SBOMs metadata to a blob storage backend so guacsec/guac can consume it | SBOM_CYCLONEDX_JSON, SBOM_SPDX_JSON |
1616
| [slack-webhook](https://github.com/chainloop-dev/chainloop/blob/main/app/controlplane/plugins/core/slack-webhook/v1/README.md) | 1.0 | Send attestations to Slack | |

0 commit comments

Comments
 (0)