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
/
metrics.go
162 lines (141 loc) · 7.24 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package dtrack
import (
"context"
"fmt"
"net/http"
"time"
"github.com/google/uuid"
)
type PortfolioMetrics struct {
FirstOccurrence int `json:"firstOccurrence"`
LastOccurrence int `json:"lastOccurrence"`
InheritedRiskScore float64 `json:"inheritedRiskScore"`
Vulnerabilities int `json:"vulnerabilities"`
VulnerableProjects int `json:"vulnerableProjects"`
VulnerableComponents int `json:"vulnerableComponents"`
Projects int `json:"projects"`
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 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
}
func (ms MetricsService) LatestPortfolioMetrics(ctx context.Context) (m PortfolioMetrics, err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, "/api/v1/metrics/portfolio/current")
if err != nil {
return
}
_, err = ms.client.doRequest(req, &m)
return
}
func (ms MetricsService) PortfolioMetricsSince(ctx context.Context, date time.Time) (m []PortfolioMetrics, err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/metrics/portfolio/since/%s", date.Format("20060102")))
if err != nil {
return
}
_, err = ms.client.doRequest(req, &m)
return
}
func (ms MetricsService) PortfolioMetricsSinceDays(ctx context.Context, days uint) (m []PortfolioMetrics, err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/metrics/portfolio/%d/days", days))
if err != nil {
return nil, err
}
_, err = ms.client.doRequest(req, &m)
return
}
func (ms MetricsService) RefreshPortfolioMetrics(ctx context.Context) (err error) {
req, err := ms.client.newRequest(ctx, http.MethodGet, "/api/v1/metrics/portfolio/refresh")
if err != nil {
return
}
_, 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
}