From 2d46b5fdfc2809c6b315e559f6371e7ceaea6bf1 Mon Sep 17 00:00:00 2001 From: Charles Billette Date: Mon, 16 Sep 2024 11:51:21 -0400 Subject: [PATCH] add header to dashboard --- web/server.go | 120 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 35 deletions(-) diff --git a/web/server.go b/web/server.go index 84b3819..5904c3c 100644 --- a/web/server.go +++ b/web/server.go @@ -6,11 +6,13 @@ import ( "log" "net/http" "os" + "strconv" + "time" "github.com/golang-jwt/jwt/v5" ) -const METABASE_SITE_URL = "http://34.170.245.114:3000" +const METABASE_SITE_URL = "http://metabase.streamingfast.io" var METABASE_SECRET_KEY = os.Getenv("SECRET_KEY") @@ -25,33 +27,41 @@ type PageData struct { } func handler(w http.ResponseWriter, r *http.Request) { + dashboard := 1 + dashboardString := r.URL.Query().Get("dashboard") + if dashboardString != "" { + d, err := strconv.Atoi(dashboardString) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + fmt.Printf("error: %v\n", err) + return + } + dashboard = d - iframeURL := r.URL.Query().Get("iframeUrl") - if iframeURL == "" { - iframeURL = "http://metabase.streamingfast.io/public/dashboard/3e029abe-66bf-4cad-895c-e39922f03927" } - //claims := CustomClaims{ - // Resource: map[string]int{"dashboard": 1}, - // Params: map[string]interface{}{}, - // RegisteredClaims: jwt.RegisteredClaims{ - // ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 10)), - // }, - //} - // - //if METABASE_SECRET_KEY == "" { - // panic("METABASE_SECRET_KEY not set") - //} - //fmt.Println("METABASE_SECRET_KEY: " + METABASE_SECRET_KEY) - //// Create a new token object - //token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - //secretKey := []byte(METABASE_SECRET_KEY) + + claims := CustomClaims{ + Resource: map[string]int{"dashboard": dashboard}, + Params: map[string]interface{}{}, + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 10)), + }, + } // - //tokenString, err := token.SignedString(secretKey) - //if err != nil { - // http.Error(w, err.Error(), http.StatusInternalServerError) - // fmt.Printf("error: %v\n", err) - // return - //} + if METABASE_SECRET_KEY == "" { + panic("METABASE_SECRET_KEY not set") + } + fmt.Println("METABASE_SECRET_KEY: " + METABASE_SECRET_KEY) + // Create a new token object + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) + secretKey := []byte(METABASE_SECRET_KEY) + + tokenString, err := token.SignedString(secretKey) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + fmt.Printf("error: %v\n", err) + return + } tmpl, err := template.New("webpage").Parse(tmpl) if err != nil { @@ -60,8 +70,9 @@ func handler(w http.ResponseWriter, r *http.Request) { return } - //iframeUrl := METABASE_SITE_URL + "/embed/dashboard/" + tokenString + "#bordered=true&titled=true" - // + iframeURL := METABASE_SITE_URL + "/embed/dashboard/" + tokenString + "#bordered=false&titled=false" + fmt.Println("iframeURL: " + iframeURL) + tmplData := PageData{ IFrameUrl: iframeURL, } @@ -72,6 +83,7 @@ func handler(w http.ResponseWriter, r *http.Request) { fmt.Printf("error: %v\n", err) return } + fmt.Println("Done rendering") } const tmpl = ` @@ -80,20 +92,58 @@ const tmpl = ` Hivemaper Dashboard + - + +
+
+ + Hivemaper Dashboard + + + + +
+ +
+ ` +//style="position:fixed; top:0px; left:0; bottom:100; right:0; width:100%; height:100%; border:none; margin-top:100px; padding:0; overflow:hidden; z-index:999999;" //const tmpl = ` // //