...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "time"
23 )
24
25
26
27
28
29 type ProjectVulnerabilitiesService struct {
30 client *Client
31 }
32
33
34
35
36 type ProjectVulnerability struct {
37 AuthorID int `json:"author_id"`
38 Confidence string `json:"confidence"`
39 CreatedAt *time.Time `json:"created_at"`
40 Description string `json:"description"`
41 DismissedAt *time.Time `json:"dismissed_at"`
42 DismissedByID int `json:"dismissed_by_id"`
43 DueDate *time.Time `json:"due_date"`
44 Finding *Finding `json:"finding"`
45 ID int `json:"id"`
46 LastEditedAt *time.Time `json:"last_edited_at"`
47 LastEditedByID int `json:"last_edited_by_id"`
48 Project *Project `json:"project"`
49 ProjectDefaultBranch string `json:"project_default_branch"`
50 ReportType string `json:"report_type"`
51 ResolvedAt *time.Time `json:"resolved_at"`
52 ResolvedByID int `json:"resolved_by_id"`
53 ResolvedOnDefaultBranch bool `json:"resolved_on_default_branch"`
54 Severity string `json:"severity"`
55 StartDate *time.Time `json:"start_date"`
56 State string `json:"state"`
57 Title string `json:"title"`
58 UpdatedAt *time.Time `json:"updated_at"`
59 UpdatedByID int `json:"updated_by_id"`
60 }
61
62
63
64
65 type Finding struct {
66 Confidence string `json:"confidence"`
67 CreatedAt *time.Time `json:"created_at"`
68 ID int `json:"id"`
69 LocationFingerprint string `json:"location_fingerprint"`
70 MetadataVersion string `json:"metadata_version"`
71 Name string `json:"name"`
72 PrimaryIdentifierID int `json:"primary_identifier_id"`
73 ProjectFingerprint string `json:"project_fingerprint"`
74 ProjectID int `json:"project_id"`
75 RawMetadata string `json:"raw_metadata"`
76 ReportType string `json:"report_type"`
77 ScannerID int `json:"scanner_id"`
78 Severity string `json:"severity"`
79 UpdatedAt *time.Time `json:"updated_at"`
80 UUID string `json:"uuid"`
81 VulnerabilityID int `json:"vulnerability_id"`
82 }
83
84
85
86
87
88
89 type ListProjectVulnerabilitiesOptions struct {
90 ListOptions
91 }
92
93
94
95
96
97 func (s *ProjectVulnerabilitiesService) ListProjectVulnerabilities(pid interface{}, opt *ListProjectVulnerabilitiesOptions, options ...RequestOptionFunc) ([]*ProjectVulnerability, *Response, error) {
98 project, err := parseID(pid)
99 if err != nil {
100 return nil, nil, err
101 }
102 u := fmt.Sprintf("projects/%s/vulnerabilities", PathEscape(project))
103
104 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
105 if err != nil {
106 return nil, nil, err
107 }
108
109 var p []*ProjectVulnerability
110 resp, err := s.client.Do(req, &p)
111 if err != nil {
112 return nil, resp, err
113 }
114
115 return p, resp, nil
116 }
117
118
119
120
121
122
123 type CreateVulnerabilityOptions struct {
124 FindingID *int `url:"finding_id,omitempty" json:"finding_id,omitempty"`
125 }
126
127
128
129
130
131 func (s *ProjectVulnerabilitiesService) CreateVulnerability(pid interface{}, opt *CreateVulnerabilityOptions, options ...RequestOptionFunc) (*ProjectVulnerability, *Response, error) {
132 project, err := parseID(pid)
133 if err != nil {
134 return nil, nil, err
135 }
136 u := fmt.Sprintf("projects/%s/vulnerabilities", PathEscape(project))
137
138 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
139 if err != nil {
140 return nil, nil, err
141 }
142
143 p := new(ProjectVulnerability)
144 resp, err := s.client.Do(req, p)
145 if err != nil {
146 return nil, resp, err
147 }
148
149 return p, resp, nil
150 }
151
View as plain text