github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/asset/config.go (about) 1 // Copyright 2022 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 4 package asset 5 6 import ( 7 "fmt" 8 "strings" 9 10 "github.com/google/syzkaller/dashboard/dashapi" 11 ) 12 13 type Config struct { 14 // Debug mode forces syz-ci upload artifacts on each syz-manager restart and also forces 15 // it to produce more logs. 16 Debug bool `json:"debug"` 17 // Where to upload artifacts. 18 // If "gs://bucket/" is specified, assets will be stored in the corresponding GCS bucket. 19 // If "dummy://" is specified, assets will not be actually stored anywhere. May be helpful 20 // for debugging. 21 UploadTo string `json:"upload_to"` 22 // Perform asset deprecation from this instance. If several syz-ci's share a common stoage, 23 // it make sense to enable derprecation only on one of them. 24 DoDeprecation bool `json:"do_deprecation"` 25 // Make assets publicly available (note that it also might require special configuration 26 // on the storage backend's side). 27 PublicAccess bool `json:"public_access"` 28 // Some asset type-specific configurations. By default all asset types are enabled. 29 Assets map[dashapi.AssetType]TypeConfig `json:"assets"` 30 } 31 32 type TypeConfig struct { 33 Never bool `json:"never"` 34 // TODO: in future there'll also be `OnlyOn` and `NeverOn`, but so far we don't really need that. 35 // TODO: here will also go compression settings, should we ever want to make it configurable. 36 } 37 38 func (tc *TypeConfig) Validate() error { 39 return nil 40 } 41 42 func (c *Config) IsEnabled(assetType dashapi.AssetType) bool { 43 return !c.Assets[assetType].Never 44 } 45 46 func (c *Config) IsEmpty() bool { 47 return c == nil 48 } 49 50 func (c *Config) Validate() error { 51 for assetType, cfg := range c.Assets { 52 if GetTypeDescription(assetType) == nil { 53 return fmt.Errorf("invalid asset type: %s", assetType) 54 } 55 if err := cfg.Validate(); err != nil { 56 return fmt.Errorf("invalid config for %s: %w", assetType, err) 57 } 58 } 59 if c.UploadTo == "" && len(c.Assets) != 0 { 60 return fmt.Errorf("assets are specified, but upload_to is empty") 61 } 62 allowedFormats := []string{"gs://", "dummy://"} 63 if c.UploadTo != "" { 64 any := false 65 for _, prefix := range allowedFormats { 66 if strings.HasPrefix(c.UploadTo, prefix) { 67 any = true 68 } 69 } 70 if !any { 71 return fmt.Errorf("the currently supported upload destinations are: %v", allowedFormats) 72 } 73 } 74 return nil 75 }