forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporting_external.go
87 lines (79 loc) · 2.52 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
// 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 (
"encoding/json"
"fmt"
"net/http"
"github.com/google/syzkaller/dashboard/dashapi"
"golang.org/x/net/context"
"google.golang.org/appengine/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) {
req := new(dashapi.PollBugsRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %v", 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: %v", err)
}
resp.Reports = append(resp.Reports, jobs...)
return resp, nil
}
func apiReportingPollNotifications(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
req := new(dashapi.PollNotificationsRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %v", 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) {
req := new(dashapi.PollClosedRequest)
if err := json.Unmarshal(payload, req); err != nil {
return nil, fmt.Errorf("failed to unmarshal request: %v", 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: %v", 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
}