1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 14:31:44 +01:00

chore(test): adds test for proxy mode (#2490)

This commit is contained in:
Amir Raminfar
2023-11-11 13:22:06 -08:00
committed by GitHub
parent 009529f20e
commit f8a9396f6e
8 changed files with 111 additions and 47 deletions

View File

@@ -26,16 +26,25 @@ const (
// Config is a struct for configuring the web service
type Config struct {
Base string
Addr string
Version string
Username string
Password string
Hostname string
NoAnalytics bool
Dev bool
AuthProvider AuthProvider
Authorizer Authorizer
Base string
Addr string
Version string
Username string
Password string
Hostname string
NoAnalytics bool
Dev bool
Authorization Authorization
}
type Authorization struct {
Provider AuthProvider
Authorizer Authorizer
}
type Authorizer interface {
AuthMiddleware(http.Handler) http.Handler
CreateToken(string, string) (string, error)
}
type handler struct {
@@ -56,11 +65,6 @@ type DockerClient interface {
Host() *docker.Host
}
type Authorizer interface {
AuthMiddleware(http.Handler) http.Handler
CreateToken(string, string) (string, error)
}
func CreateServer(clients map[string]DockerClient, content fs.FS, config Config) *http.Server {
handler := &handler{
clients: clients,
@@ -82,13 +86,17 @@ func createRouter(h *handler) *chi.Mux {
r.Use(cspHeaders)
}
if h.config.Authorization.Provider != NONE && h.config.Authorization.Authorizer == nil {
log.Panic("Authorization provider is set but no authorizer is provided")
}
r.Route(base, func(r chi.Router) {
if h.config.Authorizer != nil {
r.Use(h.config.Authorizer.AuthMiddleware)
if h.config.Authorization.Provider != NONE {
r.Use(h.config.Authorization.Authorizer.AuthMiddleware)
}
r.Group(func(r chi.Router) {
r.Group(func(r chi.Router) {
if h.config.AuthProvider != NONE {
if h.config.Authorization.Provider != NONE {
r.Use(auth.RequireAuthentication)
}
r.Use(authorizationRequired) // TODO remove this
@@ -109,7 +117,7 @@ func createRouter(h *handler) *chi.Mux {
})
})
if h.config.AuthProvider == SIMPLE {
if h.config.Authorization.Provider == SIMPLE {
r.Post("/api/token", h.createToken)
r.Delete("/api/token", h.deleteToken)
}