Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jenting committed Dec 8, 2024
1 parent bac1c74 commit 35b9217
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ func main() {
})

log.Println("Proxy server running on :8081")
log.Fatal(http.ListenAndServe(":8081", nil))
srv := &http.Server{
Addr: ":8081",
Handler: nil, // default mux
ReadTimeout: 0, // Disable read timeout for long-running connections
WriteTimeout: 0, // Disable write timeout for streaming responses
IdleTimeout: 15 * time.Second, // Only applies to idle connections
}
log.Fatal(srv.ListenAndServe())
}

func loadRBACPolicyFromConfigMap(clientset *kubernetes.Clientset, namespace, configMapName string) (map[string][]string, map[string][]string) {
Expand Down Expand Up @@ -83,6 +90,15 @@ func createReverseProxy(target string) *httputil.ReverseProxy {
req.URL.Host = parsedURL.Host
req.Host = parsedURL.Host
},
FlushInterval: 100 * time.Millisecond, // Enable periodic flushing for streaming
ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
if r.Context().Err() == context.Canceled {
log.Printf("Client disconnected: %s", r.URL.Path)
} else {
log.Printf("Proxy error: %v (URL: %s)", err, r.URL.Path)
}
http.Error(w, "Error during proxying request", http.StatusBadGateway)
},
}
}

Expand All @@ -95,13 +111,13 @@ func handleRequest(w http.ResponseWriter, r *http.Request, proxy *httputil.Rever

payload, err := decodeJWTPayload(token)
if err != nil {
fmt.Printf("Failed to decode JWT payload: %v\n", err)
proxy.ServeHTTP(w, r)
return
}

email, _ := payload["email"].(string)
groups, _ := payload["groups"].([]string)

objectPatterns := resolveObjectPatterns(email, groups, userToObjectPatternMapping, groupToObjectPatternMapping)

resp := fetchApplicationsFromRedis(redisClient, objectPatterns)
Expand Down

0 comments on commit 35b9217

Please sign in to comment.