Newer
Older
"forge.grandlyon.com/gestion-des-assemblees/elections/internal/auth"
"forge.grandlyon.com/gestion-des-assemblees/elections/internal/models"
"forge.grandlyon.com/gestion-des-assemblees/elections/pkg/middlewares"
"forge.grandlyon.com/systemes-dinformation/project-template/sdk-go/pkg/common"
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
)
// RootMux represents the main controller of the application
type RootMux struct {
Mux http.Handler
Manager *auth.Manager
}
// CreateRootMux creates a RootMux
func CreateRootMux(port int, staticDir string) RootMux {
hostname := os.Getenv("HOSTNAME")
// Create the main handler
mainMux := http.NewServeMux()
// ALL USERS API ENDPOINTS
// Authentication endpoints
m := auth.NewManager()
mainMux.HandleFunc("/OAuth2Login", m.HandleOAuth2Login)
mainMux.Handle("/OAuth2Callback", m.HandleOAuth2Callback())
mainMux.HandleFunc("/Logout", m.HandleLogout)
mainMux.HandleFunc("/Login", m.HandleInMemoryLogin)
// Bank API endpoints
dh := models.NewDataHandler()
mainMux.HandleFunc("/api/", dh.ProcessAPI)
// Common API endpoints
commonMux := http.NewServeMux()
mainMux.Handle("/api/common/WhoAmI", auth.ValidateAuthMiddleware(auth.WhoAmI(), []string{"*"}, false))
commonMux.HandleFunc("/Share", auth.GetShareToken)
mainMux.Handle("/api/common/", http.StripPrefix("/api/common", auth.ValidateAuthMiddleware(commonMux, []string{"*"}, true)))
// ADMIN API ENDPOINTS
adminMux := http.NewServeMux()
adminMux.HandleFunc("/users/", auth.ProcessUsers)
mainMux.Handle("/api/admin/", http.StripPrefix("/api/admin", auth.ValidateAuthMiddleware(adminMux, []string{"ADMIN"}, true)))
// Serve static files falling back to serving index.html
mainMux.Handle("/", middlewares.NoCache(http.FileServer(&common.FallBackWrapper{Assets: http.Dir(staticDir)})))
// Put it together into the main handler
mux := http.NewServeMux()
mux.Handle(hostname+"/", middlewares.WebSecurity(mainMux, "*."+hostname+":* *.mapbox.com *.grandlyon.com ", false))