aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/asset/type.go
blob: a9f55ebe7b2c216f659b7361cee0e7fe63260af9 (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
// Copyright 2022 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 asset

import (
	"github.com/google/syzkaller/dashboard/dashapi"
	"github.com/google/syzkaller/sys/targets"
)

type TypeDescription struct {
	AllowMultiple     bool
	GetTitle          QueryTypeTitle
	ContentType       string
	ContentEncoding   string
	ReportingPrio     int // the smaller, the higher the asset is on the list during reporting
	NoReporting       bool
	customCompressor  Compressor
	preserveExtension bool
}

var assetTypes = map[dashapi.AssetType]*TypeDescription{
	dashapi.BootableDisk: {
		GetTitle:      constTitle("disk image"),
		ReportingPrio: 1,
	},
	dashapi.NonBootableDisk: {
		GetTitle:      constTitle("disk image (non-bootable)"),
		ReportingPrio: 2,
	},
	dashapi.KernelObject: {
		GetTitle: func(target *targets.Target) string {
			if target != nil && target.KernelObject != "" {
				return target.KernelObject
			}
			return "kernel object"
		},
		ReportingPrio: 3,
	},
	dashapi.KernelImage: {
		GetTitle:      constTitle("kernel image"),
		ReportingPrio: 4,
	},
	dashapi.HTMLCoverageReport: {
		GetTitle:          constTitle("coverage report(html)"),
		AllowMultiple:     true,
		ContentType:       "text/html",
		ContentEncoding:   "gzip", // We do want to decompress than right in the browser.
		NoReporting:       true,
		customCompressor:  gzipCompressor,
		preserveExtension: true,
	},
	dashapi.MountInRepro: {
		GetTitle:      constTitle("mounted in repro"),
		ReportingPrio: 5,
		// It feels that such images are very well compressible, so we can just use
		// the omnipresent gzip compression.
		customCompressor: gzipCompressor,
	},
}

type QueryTypeTitle func(*targets.Target) string

func constTitle(title string) QueryTypeTitle {
	return func(*targets.Target) string {
		return title
	}
}

func GetTypeDescription(assetType dashapi.AssetType) *TypeDescription {
	return assetTypes[assetType]
}