• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 syzkaller project authors. All rights reserved.
2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4package dash
5
6import (
7	"encoding/json"
8	"fmt"
9	"net/http"
10
11	"github.com/google/syzkaller/dashboard/dashapi"
12	"golang.org/x/net/context"
13	"google.golang.org/appengine/log"
14)
15
16// Interface with external reporting systems.
17// The external system is meant to poll for new bugs with apiReportingPoll,
18// and report back bug status updates with apiReportingUpdate.
19
20type ExternalConfig struct {
21	ID string
22}
23
24func (cfg *ExternalConfig) Type() string {
25	return cfg.ID
26}
27
28func apiReportingPollBugs(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
29	req := new(dashapi.PollBugsRequest)
30	if err := json.Unmarshal(payload, req); err != nil {
31		return nil, fmt.Errorf("failed to unmarshal request: %v", err)
32	}
33	reports := reportingPollBugs(c, req.Type)
34	resp := &dashapi.PollBugsResponse{
35		Reports: reports,
36	}
37	return resp, nil
38}
39
40func apiReportingPollClosed(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
41	req := new(dashapi.PollClosedRequest)
42	if err := json.Unmarshal(payload, req); err != nil {
43		return nil, fmt.Errorf("failed to unmarshal request: %v", err)
44	}
45	ids, err := reportingPollClosed(c, req.IDs)
46	if err != nil {
47		log.Errorf(c, "failed to poll closed bugs: %v", err)
48		return nil, err
49	}
50	resp := &dashapi.PollClosedResponse{
51		IDs: ids,
52	}
53	return resp, nil
54}
55
56func apiReportingUpdate(c context.Context, r *http.Request, payload []byte) (interface{}, error) {
57	req := new(dashapi.BugUpdate)
58	if err := json.Unmarshal(payload, req); err != nil {
59		return nil, fmt.Errorf("failed to unmarshal request: %v", err)
60	}
61	ok, reason, err := incomingCommand(c, req)
62	return &dashapi.BugUpdateReply{
63		OK:    ok,
64		Error: err != nil,
65		Text:  reason,
66	}, nil
67}
68