mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00

* implement OIDC middleware * auth code cleanup * allow override allowed_user in middleware, fix typos * fix tests and callbackURL * update next release docs * fix OIDC middleware not working with Authentik * feat: add groups support for OIDC claims (#41) Allow users to specify allowed groups in the env and use it to inspect the claims. This performs a logical AND of users and groups (additive). * merge feat/oidc-middleware (#49) * api: enrich provider statistifcs * fix: docker monitor now uses container status * Feat/auto schemas (#48) * use auto generated schemas * go version bump and dependencies upgrade * clarify some error messages --------- Co-authored-by: yusing <yusing@6uo.me> * cleanup some loadbalancer code * api: cleanup websocket code * api: add /v1/health/ws for health bubbles on dashboard * feat: experimental memory logger and logs api for WebUI --------- Co-authored-by: yusing <yusing@6uo.me> --------- Co-authored-by: yusing <yusing@6uo.me> Co-authored-by: Peter Olds <peter@olds.co>
51 lines
2.1 KiB
Go
51 lines
2.1 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
v1 "github.com/yusing/go-proxy/internal/api/v1"
|
|
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
|
"github.com/yusing/go-proxy/internal/api/v1/favicon"
|
|
config "github.com/yusing/go-proxy/internal/config/types"
|
|
"github.com/yusing/go-proxy/internal/utils/strutils"
|
|
)
|
|
|
|
type ServeMux struct{ *http.ServeMux }
|
|
|
|
func (mux ServeMux) HandleFunc(methods, endpoint string, handler http.HandlerFunc) {
|
|
for _, m := range strutils.CommaSeperatedList(methods) {
|
|
mux.ServeMux.HandleFunc(m+" "+endpoint, handler)
|
|
}
|
|
}
|
|
|
|
func NewHandler(cfg config.ConfigInstance) http.Handler {
|
|
mux := ServeMux{http.NewServeMux()}
|
|
mux.HandleFunc("GET", "/v1", v1.Index)
|
|
mux.HandleFunc("GET", "/v1/version", v1.GetVersion)
|
|
mux.HandleFunc("POST", "/v1/reload", useCfg(cfg, v1.Reload))
|
|
mux.HandleFunc("GET", "/v1/list", auth.RequireAuth(useCfg(cfg, v1.List)))
|
|
mux.HandleFunc("GET", "/v1/list/{what}", auth.RequireAuth(useCfg(cfg, v1.List)))
|
|
mux.HandleFunc("GET", "/v1/list/{what}/{which}", auth.RequireAuth(useCfg(cfg, v1.List)))
|
|
mux.HandleFunc("GET", "/v1/file/{type}/{filename}", auth.RequireAuth(v1.GetFileContent))
|
|
mux.HandleFunc("POST,PUT", "/v1/file/{type}/{filename}", auth.RequireAuth(v1.SetFileContent))
|
|
mux.HandleFunc("GET", "/v1/schema/{filename...}", v1.GetSchemaFile)
|
|
mux.HandleFunc("GET", "/v1/stats", useCfg(cfg, v1.Stats))
|
|
mux.HandleFunc("GET", "/v1/stats/ws", useCfg(cfg, v1.StatsWS))
|
|
mux.HandleFunc("GET", "/v1/health/ws", useCfg(cfg, v1.HealthWS))
|
|
mux.HandleFunc("GET", "/v1/logs/ws", useCfg(cfg, v1.LogsWS()))
|
|
mux.HandleFunc("GET", "/v1/favicon/{alias}", auth.RequireAuth(favicon.GetFavIcon))
|
|
|
|
defaultAuth := auth.GetDefaultAuth()
|
|
if defaultAuth != nil {
|
|
mux.HandleFunc("GET", "/v1/auth/redirect", defaultAuth.RedirectLoginPage)
|
|
mux.HandleFunc("GET,POST", "/v1/auth/callback", defaultAuth.LoginCallbackHandler)
|
|
mux.HandleFunc("GET,POST", "/v1/auth/logout", auth.LogoutCallbackHandler(defaultAuth))
|
|
}
|
|
return mux
|
|
}
|
|
|
|
func useCfg(cfg config.ConfigInstance, handler func(cfg config.ConfigInstance, w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
handler(cfg, w, r)
|
|
}
|
|
}
|