forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporting_external.go
115 lines (106 loc) · 3.42 KB
/
reporting_external.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
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/google/syzkaller/dashboard/dashapi"
"google.golang.org/appengine/v2/log"
)
// Interface with external reporting systems.
// The external system is meant to poll for new bugs with apiReportingPoll,
// and report back bug status updates with apiReportingUpdate.
func apiReportingPollBugs(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
if stop, err := emergentlyStopped(c); err != nil || stop {
return &dashapi.PollBugsResponse{}, err
}
req := new(dashapi.PollBugsRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %w", err)
}
reports := reportingPollBugs(c, req.Type)
resp := &dashapi.PollBugsResponse{
Reports: reports,
}
jobs, err := pollCompletedJobs(c, req.Type)
if err != nil {
log.Errorf(c, "failed to poll jobs(bugs): %v", err)
}
resp.Reports = append(resp.Reports, jobs...)
return resp, nil
}
func apiReportingPollNotifications(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
if stop, err := emergentlyStopped(c); err != nil || stop {
return &dashapi.PollNotificationsResponse{}, err
}
req := new(dashapi.PollNotificationsRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %w", err)
}
notifs := reportingPollNotifications(c, req.Type)
resp := &dashapi.PollNotificationsResponse{
Notifications: notifs,
}
return resp, nil
}
func apiReportingPollClosed(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
if stop, err := emergentlyStopped(c); err != nil || stop {
return &dashapi.PollClosedResponse{}, err
}
req := new(dashapi.PollClosedRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %w", err)
}
ids, err := reportingPollClosed(c, req.IDs)
if err != nil {
return nil, err
}
resp := &dashapi.PollClosedResponse{
IDs: ids,
}
return resp, nil
}
func apiReportingUpdate(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
req := new(dashapi.BugUpdate)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %w", err)
}
if req.JobID != "" {
resp := &dashapi.BugUpdateReply{
OK: true,
Error: false,
}
if err := jobReported(c, req.JobID); err != nil {
log.Errorf(c, "failed to mark job reported: %v", err)
resp.Text = err.Error()
resp.Error = true
}
return resp, nil
}
ok, reason, err := incomingCommand(c, req)
return &dashapi.BugUpdateReply{
OK: ok,
Error: err != nil,
Text: reason,
}, nil
}
func apiNewTestJob(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
req := new(dashapi.TestPatchRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %w", err)
}
resp := &dashapi.TestPatchReply{}
err := handleExternalTestRequest(c, req)
if err != nil {
resp.ErrorText = err.Error()
var badTest *BadTestRequestError
if !errors.As(err, &badTest) {
// Log errors that are not related to the invalid input.
log.Errorf(c, "external patch posting error: %v", err)
}
}
return resp, nil
}