github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/syz-kcidb/kcidb.go (about) 1 // Copyright 2020 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 main 5 6 import ( 7 "context" 8 "encoding/json" 9 "flag" 10 "os" 11 12 "github.com/google/syzkaller/dashboard/dashapi" 13 "github.com/google/syzkaller/pkg/kcidb" 14 "github.com/google/syzkaller/pkg/tool" 15 ) 16 17 func main() { 18 const ( 19 origin = "syzbot" 20 projectID = "kernelci-production" 21 topicName = "playground_kernelci_new" 22 ) 23 var ( 24 flagRestURI = flag.String("rest", "", "REST API endpoint for KCIDB") 25 flagToken = flag.String("token", "", "KCIDB API token") 26 flagDashClient = flag.String("client", "", "dashboard client") 27 flagDashAddr = flag.String("addr", "", "dashboard address") 28 flagDashKey = flag.String("key", "", "dashboard API key") 29 flagBug = flag.String("bug", "", "bug ID to upload to KCIDB") 30 flagInput = flag.String("input", "", "input JSON file with bug report") 31 flagOutput = flag.String("output", "", "output JSON file for KCIDB data") 32 ) 33 flag.Parse() 34 35 var bug *dashapi.BugReport 36 37 // If input file is specified, read from file instead of calling API 38 if *flagInput != "" { 39 data, err := os.ReadFile(*flagInput) 40 if err != nil { 41 tool.Fail(err) 42 } 43 bug = &dashapi.BugReport{} 44 if err := json.Unmarshal(data, bug); err != nil { 45 tool.Fail(err) 46 } 47 } else { 48 // Original behavior: fetch from dashboard API 49 dash, err := dashapi.New(*flagDashClient, *flagDashAddr, *flagDashKey) 50 if err != nil { 51 tool.Fail(err) 52 } 53 bug, err = dash.LoadBug(*flagBug) 54 if err != nil { 55 tool.Fail(err) 56 } 57 } 58 59 kcidb.Validate = true 60 client, err := kcidb.NewClient(context.Background(), origin, *flagRestURI, *flagToken) 61 if err != nil { 62 tool.Fail(err) 63 } 64 defer client.Close() 65 66 // If output file is specified, write to file instead of submitting. 67 if *flagOutput != "" { 68 if err := client.PublishToFile(bug, *flagOutput); err != nil { 69 tool.Fail(err) 70 } 71 } else { 72 // Original behavior: submit to REST API 73 if err := client.Publish(bug); err != nil { 74 tool.Fail(err) 75 } 76 } 77 }