This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nscuro <[email protected]>
- Loading branch information
Showing
5 changed files
with
161 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,133 @@ | ||
package dtrack | ||
|
||
import "github.com/google/uuid" | ||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
type Vulnerability struct { | ||
UUID uuid.UUID `json:"uuid"` | ||
VulnID string `json:"vulnId"` | ||
Source string `json:"source"` | ||
Severity string `json:"severity"` | ||
UUID uuid.UUID `json:"uuid"` | ||
VulnID string `json:"vulnId"` | ||
Source string `json:"source"` | ||
|
||
Title string `json:"title"` | ||
SubTitle string `json:"subTitle"` | ||
Description string `json:"description"` | ||
Recommendation string `json:"recommendation"` | ||
References string `json:"references"` | ||
Credits string `json:"credits"` | ||
|
||
Created time.Time `json:"created"` | ||
Published time.Time `json:"published"` | ||
|
||
CWE CWE `json:"cwe"` | ||
CVSSV2BaseScore float64 `json:"cvssV2BaseScore"` | ||
CVSSV2ImpactSubScore float64 `json:"cvssV2ImpactSubScore"` | ||
CVSSV2ExploitabilitySubScore float64 `json:"cvssV2ExploitabilitySubScore"` | ||
CVSSV2Vector string `json:"cvssV2Vector"` | ||
CVSSV3BaseScore float64 `json:"cvssV3BaseScore"` | ||
CVSSV3ImpactSubScore float64 `json:"cvssV3ImpactSubScore"` | ||
CVSSV3ExploitabilitySubScore float64 `json:"cvssV3ExploitabilitySubScore"` | ||
CVSSV3Vector string `json:"cvssV3Vector"` | ||
Severity string `json:"severity"` | ||
|
||
VulnerableVersions string `json:"vulnerableVersions"` | ||
PatchedVersions string `json:"patchedVersions"` | ||
} | ||
|
||
type VulnerabilitiesPage struct { | ||
Vulnerabilities []Vulnerability | ||
TotalCount int | ||
} | ||
|
||
type CWE struct { | ||
ID int `json:"cweId"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type VulnerabilityService struct { | ||
client *Client | ||
} | ||
|
||
func (v VulnerabilityService) Get(ctx context.Context, vulnUUID uuid.UUID) (*Vulnerability, error) { | ||
req, err := v.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/vulnerability/%s", vulnUUID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var vulnerability Vulnerability | ||
_, err = v.client.doRequest(req, &vulnerability) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &vulnerability, nil | ||
} | ||
|
||
func (v VulnerabilityService) GetAllForComponent(ctx context.Context, componentUUID uuid.UUID, po PageOptions) (*VulnerabilitiesPage, error) { | ||
req, err := v.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/vulnerability/component/%s", componentUUID), withPageOptions(po)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var vulnerabilities []Vulnerability | ||
res, err := v.client.doRequest(req, &vulnerabilities) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &VulnerabilitiesPage{ | ||
Vulnerabilities: vulnerabilities, | ||
TotalCount: res.TotalCount, | ||
}, nil | ||
} | ||
|
||
func (v VulnerabilityService) GetAllForProject(ctx context.Context, projectUUID uuid.UUID, po PageOptions) (*VulnerabilitiesPage, error) { | ||
req, err := v.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/vulnerability/project/%s", projectUUID), withPageOptions(po)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var vulnerabilities []Vulnerability | ||
res, err := v.client.doRequest(req, &vulnerabilities) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &VulnerabilitiesPage{ | ||
Vulnerabilities: vulnerabilities, | ||
TotalCount: res.TotalCount, | ||
}, nil | ||
} | ||
|
||
func (v VulnerabilityService) Assign(ctx context.Context, vulnUUID, componentUUID uuid.UUID) error { | ||
req, err := v.client.newRequest(ctx, http.MethodPost, fmt.Sprintf("/api/v1/vulnerability/%s/component/%s", vulnUUID, componentUUID)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = v.client.doRequest(req, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (v VulnerabilityService) Unassign(ctx context.Context, vulnUUID, componentUUID uuid.UUID) error { | ||
req, err := v.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/vulnerability/%s/component/%s", vulnUUID, componentUUID)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = v.client.doRequest(req, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |