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
|
// Copyright 2025 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 api
import (
"context"
"net/url"
"strings"
"time"
)
type ReporterClient struct {
baseURL string
}
func NewReporterClient(url string) *ReporterClient {
return &ReporterClient{baseURL: strings.TrimRight(url, "/")}
}
type NextReportResp struct {
Report *SessionReport `json:"report"`
}
const LKMLReporter = "lkml"
func (client ReporterClient) GetNextReport(ctx context.Context, reporter string) (*NextReportResp, error) {
v := url.Values{}
v.Add("reporter", reporter)
return postJSON[any, NextReportResp](ctx, client.baseURL+"/reports?"+v.Encode(), nil)
}
// ConfirmReport should be called to mark a report as sent.
func (client ReporterClient) ConfirmReport(ctx context.Context, id string) error {
_, err := postJSON[any, any](ctx, client.baseURL+"/reports/"+id+"/confirm", nil)
return err
}
type UpstreamReportReq struct {
User string `json:"user"`
}
func (client ReporterClient) UpstreamReport(ctx context.Context, id string, req *UpstreamReportReq) error {
_, err := postJSON[UpstreamReportReq, any](ctx, client.baseURL+"/reports/"+id+"/upstream", req)
return err
}
func (client ReporterClient) InvalidateReport(ctx context.Context, id string) error {
_, err := postJSON[any, any](ctx, client.baseURL+"/reports/"+id+"/invalidate", nil)
return err
}
type RecordReplyReq struct {
MessageID string `json:"message_id"`
ReportID string `json:"report_id"`
// If ReportID is not set, InReplyTo will help identify the original report.
InReplyTo string `json:"in_reply_to"`
Reporter string `json:"reporter"`
Time time.Time `json:"time"`
}
type RecordReplyResp struct {
New bool `json:"new"`
ReportID string `json:"report_id"` // or empty, if no original message was found
}
func (client ReporterClient) RecordReply(ctx context.Context, req *RecordReplyReq) (*RecordReplyResp, error) {
return postJSON[RecordReplyReq, RecordReplyResp](ctx, client.baseURL+"/reports/record_reply", req)
}
type LastReplyResp struct {
Time time.Time `json:"time"`
}
// Returns nil if no reply has ever been recorded.
func (client ReporterClient) LastReply(ctx context.Context, reporter string) (*LastReplyResp, error) {
v := url.Values{}
v.Add("reporter", reporter)
return postJSON[any, LastReplyResp](ctx, client.baseURL+"/reports/last_reply?"+v.Encode(), nil)
}
|