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

Commit

Permalink
feat: add project metrics (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Best <[email protected]>

Signed-off-by: Rob Best <[email protected]>
  • Loading branch information
ribbybibby authored Dec 1, 2022
1 parent f55395e commit 50bc2f4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
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

0 comments on commit 50bc2f4

Please sign in to comment.