forked from magicsong/sonargo
/
ce_service.go
126 lines (114 loc) · 5.61 KB
/
ce_service.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
// Get information on Compute Engine tasks.
package sonargo
import "net/http"
type CeService struct {
client *Client
}
type CeActivityObject struct {
Tasks []*Task `json:"tasks,omitempty"`
}
type CeComponentObject struct {
Current *Task `json:"current,omitempty"`
Queue []*Task `json:"queue,omitempty"`
}
type CeTaskObject struct {
Task *Task `json:"task,omitempty"`
}
type Task struct {
AnalysisID string `json:"analysisId,omitempty"`
Branch string `json:"branch,omitempty"`
BranchType string `json:"branchType,omitempty"`
ComponentID string `json:"componentId,omitempty"`
ComponentKey string `json:"componentKey,omitempty"`
ComponentName string `json:"componentName,omitempty"`
ComponentQualifier string `json:"componentQualifier,omitempty"`
ErrorMessage string `json:"errorMessage,omitempty"`
ErrorStacktrace string `json:"errorStacktrace,omitempty"`
ErrorType string `json:"errorType,omitempty"`
ExecutedAt string `json:"executedAt,omitempty"`
ExecutionTimeMs int64 `json:"executionTimeMs,omitempty"`
FinishedAt string `json:"finishedAt,omitempty"`
HasErrorStacktrace bool `json:"hasErrorStacktrace,omitempty"`
HasScannerContext bool `json:"hasScannerContext,omitempty"`
ID string `json:"id,omitempty"`
Logs bool `json:"logs,omitempty"`
Organization string `json:"organization,omitempty"`
ScannerContext string `json:"scannerContext,omitempty"`
StartedAt string `json:"startedAt,omitempty"`
Status string `json:"status,omitempty"`
SubmittedAt string `json:"submittedAt,omitempty"`
SubmitterLogin string `json:"submitterLogin,omitempty"`
TaskType string `json:"taskType,omitempty"`
Type string `json:"type,omitempty"`
WarningCount int `json:"warningCount,omitempty"`
Warnings []string `json:"warnings,omitempty"`
}
type CeActivityOption struct {
ComponentId string `url:"componentId,omitempty"` // Description:"Id of the component (project) to filter on",ExampleValue:"AU-TpxcA-iU5OvuD2FL0"
MaxExecutedAt string `url:"maxExecutedAt,omitempty"` // Description:"Maximum date of end of task processing (inclusive)",ExampleValue:"2017-10-19T13:00:00+0200"
MinSubmittedAt string `url:"minSubmittedAt,omitempty"` // Description:"Minimum date of task submission (inclusive)",ExampleValue:"2017-10-19T13:00:00+0200"
OnlyCurrents string `url:"onlyCurrents,omitempty"` // Description:"Filter on the last tasks (only the most recent finished task by project)",ExampleValue:""
Ps string `url:"ps,omitempty"` // Description:"Page size. Must be greater than 0 and less or equal than 1000",ExampleValue:"20"
Q string `url:"q,omitempty"` // Description:"Limit search to: <ul><li>component names that contain the supplied string</li><li>component keys that are exactly the same as the supplied string</li><li>task ids that are exactly the same as the supplied string</li></ul>Must not be set together with componentId",ExampleValue:"Apache"
Status string `url:"status,omitempty"` // Description:"Comma separated list of task statuses",ExampleValue:"IN_PROGRESS,SUCCESS"
Type string `url:"type,omitempty"` // Description:"Task type",ExampleValue:"REPORT"
}
// Activity Search for tasks.<br> Requires the system administration permission, or project administration permission if componentId is set.
func (s *CeService) Activity(opt *CeActivityOption) (v *CeActivityObject, resp *http.Response, err error) {
err = s.ValidateActivityOpt(opt)
if err != nil {
return
}
req, err := s.client.NewRequest("GET", "ce/activity", opt)
if err != nil {
return
}
v = new(CeActivityObject)
resp, err = s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return
}
type CeComponentOption struct {
Component string `url:"component,omitempty"` // Description:"",ExampleValue:"my_project"
ComponentId string `url:"componentId,omitempty"` // Description:"",ExampleValue:"AU-Tpxb--iU5OvuD2FLy"
}
// Component Get the pending tasks, in-progress tasks and the last executed task of a given component (usually a project).<br>Requires the following permission: 'Browse' on the specified component.<br>Either 'componentId' or 'component' must be provided.
func (s *CeService) Component(opt *CeComponentOption) (v *CeComponentObject, resp *http.Response, err error) {
err = s.ValidateComponentOpt(opt)
if err != nil {
return
}
req, err := s.client.NewRequest("GET", "ce/component", opt)
if err != nil {
return
}
v = new(CeComponentObject)
resp, err = s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return
}
type CeTaskOption struct {
AdditionalFields string `url:"additionalFields,omitempty"` // Description:"Comma-separated list of the optional fields to be returned in response.",ExampleValue:""
Id string `url:"id,omitempty"` // Description:"Id of task",ExampleValue:"AU-Tpxb--iU5OvuD2FLy"
}
// Task Give Compute Engine task details such as type, status, duration and associated component.<br />Requires 'Administer System' or 'Execute Analysis' permission.<br/>Since 6.1, field "logs" is deprecated and its value is always false.
func (s *CeService) Task(opt *CeTaskOption) (v *CeTaskObject, resp *http.Response, err error) {
err = s.ValidateTaskOpt(opt)
if err != nil {
return
}
req, err := s.client.NewRequest("GET", "ce/task", opt)
if err != nil {
return
}
v = new(CeTaskObject)
resp, err = s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return
}