Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Add project metrics #36

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"net/http"
"time"

"github.com/google/uuid"
)

type PortfolioMetrics struct {
Expand Down Expand Up @@ -42,6 +44,39 @@ type PortfolioMetrics struct {
PolicyViolationsOperationalUnaudited int `json:"policyViolationsOperationalUnaudited"`
}

type ProjectMetrics struct {
FirstOccurrence int `json:"firstOccurrence"`
LastOccurrence int `json:"lastOccurrence"`
InheritedRiskScore float64 `json:"inheritedRiskScore"`
Vulnerabilities int `json:"vulnerabilities"`
VulnerableComponents int `json:"vulnerableComponents"`
Components int `json:"components"`
Suppressed int `json:"suppressed"`
Critical int `json:"critical"`
High int `json:"high"`
Medium int `json:"medium"`
Low int `json:"low"`
Unassigned int `json:"unassigned"`
FindingsTotal int `json:"findingsTotal"`
FindingsAudited int `json:"findingsAudited"`
FindingsUnaudited int `json:"findingsUnaudited"`
PolicyViolationsTotal int `json:"policyViolationsTotal"`
PolicyViolationsFail int `json:"policyViolationsFail"`
PolicyViolationsWarn int `json:"policyViolationsWarn"`
PolicyViolationsInfo int `json:"policyViolationsInfo"`
PolicyViolationsAudited int `json:"policyViolationsAudited"`
PolicyViolationsUnaudited int `json:"policyViolationsUnaudited"`
PolicyViolationsSecurityTotal int `json:"policyViolationsSecurityTotal"`
PolicyViolationsSecurityAudited int `json:"policyViolationsSecurityAudited"`
PolicyViolationsSecurityUnaudited int `json:"policyViolationsSecurityUnaudited"`
PolicyViolationsLicenseTotal int `json:"policyViolationsLicenseTotal"`
PolicyViolationsLicenseAudited int `json:"policyViolationsLicenseAudited"`
PolicyViolationsLicenseUnaudited int `json:"policyViolationsLicenseUnaudited"`
PolicyViolationsOperationalTotal int `json:"policyViolationsOperationalTotal"`
PolicyViolationsOperationalAudited int `json:"policyViolationsOperationalAudited"`
PolicyViolationsOperationalUnaudited int `json:"policyViolationsOperationalUnaudited"`
}

type MetricsService struct {
client *Client
}
Expand Down Expand Up @@ -85,3 +120,43 @@ func (ms MetricsService) RefreshPortfolioMetrics(ctx context.Context) (err error
_, err = ms.client.doRequest(req, nil)
return
}

func (ms MetricsService) LatestProjectMetrics(ctx context.Context, projectUUID uuid.UUID) (m ProjectMetrics, err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/metrics/project/%s/current", projectUUID))
if err != nil {
return
}

_, err = ms.client.doRequest(req, &m)
return
}

func (ms MetricsService) ProjectMetricsSince(ctx context.Context, projectUUID uuid.UUID, date time.Time) (m []ProjectMetrics, err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/metrics/project/%s/since/%s", projectUUID, date.Format("20060102")))
if err != nil {
return
}

_, err = ms.client.doRequest(req, &m)
return
}

func (ms MetricsService) ProjectMetricsSinceDays(ctx context.Context, projectUUID uuid.UUID, days uint) (m []ProjectMetrics, err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/metrics/project/%s/days/%d", projectUUID, days))
if err != nil {
return nil, err
}

_, err = ms.client.doRequest(req, &m)
return
}

func (ms MetricsService) RefreshProjectMetrics(ctx context.Context, projectUUID uuid.UUID) (err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/metrics/project/%s/refresh", projectUUID))
if err != nil {
return
}

_, err = ms.client.doRequest(req, nil)
return
}
1 change: 1 addition & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Project struct {
Properties []ProjectProperty `json:"properties,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Active bool `json:"active"`
Metrics ProjectMetrics `json:"metrics"`
}

type ProjectService struct {
Expand Down