aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/reporting_external.go
blob: 3bfc5f4458782ef9d195beff77d16b9f9a565d2f (plain)
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
// 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"
	"errors"

	"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, req *dashapi.PollBugsRequest) (any, error) {
	if stop, err := emergentlyStopped(c); err != nil || stop {
		return &dashapi.PollBugsResponse{}, 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, req *dashapi.PollNotificationsRequest) (
	any, error) {
	if stop, err := emergentlyStopped(c); err != nil || stop {
		return &dashapi.PollNotificationsResponse{}, err
	}
	notifs := reportingPollNotifications(c, req.Type)
	resp := &dashapi.PollNotificationsResponse{
		Notifications: notifs,
	}
	return resp, nil
}

func apiReportingPollClosed(c context.Context, req *dashapi.PollClosedRequest) (any, error) {
	if stop, err := emergentlyStopped(c); err != nil || stop {
		return &dashapi.PollClosedResponse{}, 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, req *dashapi.BugUpdate) (any, error) {
	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, req *dashapi.TestPatchRequest) (any, error) {
	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
}