aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2023-06-16 11:53:33 +0200
committerTaras Madan <tarasmadan@google.com>2023-06-19 16:42:56 +0200
commitf1f9726ad56cc48e47cc0fdef249052883d7d7ee (patch)
treeedee57e011efed74b7151b78277737c59c13ec9b
parentd521bc5692c2ea3fa25a1a2ae3190b18c0dfc181 (diff)
dashboard/app: prepare json generation code for extension
-rw-r--r--dashboard/app/main.go8
-rw-r--r--dashboard/app/public_json_api.go25
2 files changed, 21 insertions, 12 deletions
diff --git a/dashboard/app/main.go b/dashboard/app/main.go
index 4de600fc2..4c9c8c253 100644
--- a/dashboard/app/main.go
+++ b/dashboard/app/main.go
@@ -5,7 +5,6 @@ package main
import (
"bytes"
- "encoding/json"
"fmt"
"html/template"
"net/http"
@@ -1024,11 +1023,8 @@ func isJSONRequested(request *http.Request) bool {
return request.FormValue("json") == "1"
}
-func writeJSONVersionOf(writer http.ResponseWriter, bugPage *uiBugPage) error {
- data, err := json.MarshalIndent(
- GetExtAPIDescrForBugPage(bugPage),
- "",
- "\t")
+func writeJSONVersionOf(writer http.ResponseWriter, page interface{}) error {
+ data, err := GetJSONDescrFor(page)
if err != nil {
return err
}
diff --git a/dashboard/app/public_json_api.go b/dashboard/app/public_json_api.go
index 0832b7721..a4b630257 100644
--- a/dashboard/app/public_json_api.go
+++ b/dashboard/app/public_json_api.go
@@ -3,17 +3,19 @@
package main
+import "encoding/json"
+
// publicApiBugDescription is used to serve the /bug HTTP requests
// and provide JSON description of the BUG. Backward compatible.
-type PublicAPIBugDescription struct {
+type publicAPIBugDescription struct {
Version int `json:"version"`
Title string `json:"title,omitempty"`
// links to the discussions
Discussions []string `json:"discussions,omitempty"`
- Crashes []PublicAPICrashDescription `json:"crashes,omitempty"`
+ Crashes []publicAPICrashDescription `json:"crashes,omitempty"`
}
-type PublicAPICrashDescription struct {
+type publicAPICrashDescription struct {
SyzReproducer string `json:"syz-reproducer,omitempty"`
CReproducer string `json:"c-reproducer,omitempty"`
KernelConfig string `json:"kernel-config,omitempty"`
@@ -25,9 +27,9 @@ type PublicAPICrashDescription struct {
Architecture string `json:"architecture,omitempty"`
}
-func GetExtAPIDescrForBugPage(bugPage *uiBugPage) *PublicAPIBugDescription {
+func getExtAPIDescrForBugPage(bugPage *uiBugPage) *publicAPIBugDescription {
crash := bugPage.Crashes.Crashes[0]
- return &PublicAPIBugDescription{
+ return &publicAPIBugDescription{
Version: 1,
Title: bugPage.Bug.Title,
Discussions: func() []string {
@@ -36,7 +38,7 @@ func GetExtAPIDescrForBugPage(bugPage *uiBugPage) *PublicAPIBugDescription {
}
return []string{bugPage.Bug.ExternalLink}
}(),
- Crashes: []PublicAPICrashDescription{{
+ Crashes: []publicAPICrashDescription{{
SyzReproducer: crash.ReproSyzLink,
CReproducer: crash.ReproCLink,
KernelConfig: crash.KernelConfigLink,
@@ -49,3 +51,14 @@ func GetExtAPIDescrForBugPage(bugPage *uiBugPage) *PublicAPIBugDescription {
}},
}
}
+
+func GetJSONDescrFor(page interface{}) ([]byte, error) {
+ var res interface{}
+ switch i := page.(type) {
+ case *uiBugPage:
+ res = getExtAPIDescrForBugPage(i)
+ default:
+ return nil, ErrClientNotFound
+ }
+ return json.MarshalIndent(res, "", "\t")
+}