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
|
// 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 service
import (
"context"
"errors"
"fmt"
"github.com/google/syzkaller/syz-cluster/pkg/api"
"github.com/google/syzkaller/syz-cluster/pkg/app"
"github.com/google/syzkaller/syz-cluster/pkg/db"
)
type BaseFindingService struct {
baseFindingRepo *db.BaseFindingRepository
buildRepo *db.BuildRepository
}
func NewBaseFindingService(env *app.AppEnvironment) *BaseFindingService {
return &BaseFindingService{
baseFindingRepo: db.NewBaseFindingRepository(env.Spanner),
buildRepo: db.NewBuildRepository(env.Spanner),
}
}
var ErrBuildNotFound = errors.New("build not found")
func (s *BaseFindingService) Upload(ctx context.Context, info *api.BaseFindingInfo) error {
finding, err := s.makeBaseFinding(ctx, info)
if err != nil {
return err
}
return s.baseFindingRepo.Save(ctx, finding)
}
func (s *BaseFindingService) Status(ctx context.Context, info *api.BaseFindingInfo) (
*api.BaseFindingStatus, error) {
finding, err := s.makeBaseFinding(ctx, info)
if err != nil {
return nil, err
}
exists, err := s.baseFindingRepo.Exists(ctx, finding)
if err != nil {
return nil, err
}
return &api.BaseFindingStatus{
Observed: exists,
}, nil
}
func (s *BaseFindingService) makeBaseFinding(ctx context.Context, info *api.BaseFindingInfo) (*db.BaseFinding, error) {
build, err := s.buildRepo.GetByID(ctx, info.BuildID)
if err != nil {
return nil, fmt.Errorf("failed to query build: %w", err)
} else if build == nil {
return nil, ErrBuildNotFound
}
return &db.BaseFinding{
CommitHash: build.CommitHash,
Config: build.ConfigName,
Arch: build.Arch,
Title: info.Title,
}, nil
}
|