feat(temporal): expose ui under authentication

This commit is contained in:
Tine 2024-02-13 12:00:48 +01:00
parent e74322f296
commit b516c979b3
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
4 changed files with 55 additions and 1 deletions

View file

@ -54,6 +54,9 @@ func main() {
r.HandleFunc("/oauth2/callback", h.OAuth2CallbackGET).Methods("GET")
r.HandleFunc("/oauth2/logout", h.Authenticated(h.OAuth2LogoutGET)).Methods("GET")
// Temporal UI
r.PathPrefix("/temporal").HandlerFunc(h.Authenticated(h.Temporal))
// 404
r.PathPrefix("/").HandlerFunc(h.Error404).Methods("GET")

View file

@ -106,7 +106,7 @@ func frontendServer() {
Port: 8223,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
UIAssetPath: "",
PublicPath: "/temporal",
Codec: uiconfig.Codec{
Endpoint: "",
},
@ -121,6 +121,7 @@ func frontendServer() {
if err := server.Start(); err != nil {
panic(err)
}
server.Stop()
}
func main() {

View file

@ -19,6 +19,7 @@ var SettingsPages = []*components.Page{
{Path: "/settings", Title: "Overview"},
{Path: "/settings/healthchecks", Title: "Healthchecks"},
{Path: "/settings/workers", Title: "Workers"},
{Path: "/temporal", Title: "Temporal"},
{Path: "/oauth2/logout", Title: "Logout"},
}

View file

@ -0,0 +1,49 @@
package handlers
import (
"io"
"net/http"
)
var customTransport = http.DefaultTransport
func (h *BaseHandler) Temporal(w http.ResponseWriter, r *http.Request, user *AuthenticatedUser) {
// Create a new HTTP request with the same method, URL, and body as the original request
targetURL := r.URL
targetURL.Host = "localhost:8223"
targetURL.Scheme = "http"
proxyReq, err := http.NewRequest(r.Method, targetURL.String(), r.Body)
if err != nil {
http.Error(w, "Error creating proxy request", http.StatusInternalServerError)
return
}
// Copy the headers from the original request to the proxy request
for name, values := range r.Header {
for _, value := range values {
proxyReq.Header.Add(name, value)
}
}
// Send the proxy request using the custom transport
resp, err := customTransport.RoundTrip(proxyReq)
if err != nil {
http.Error(w, "Error sending proxy request", http.StatusInternalServerError)
return
}
defer resp.Body.Close()
// Copy the headers from the proxy response to the original response
for name, values := range resp.Header {
for _, value := range values {
w.Header().Add(name, value)
}
}
// Set the status code of the original response to the status code of the proxy response
w.WriteHeader(resp.StatusCode)
// Copy the body of the proxy response to the original response
io.Copy(w, resp.Body)
}