|
5 | 5 | "net/http" |
6 | 6 | "os" |
7 | 7 | "time" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/damacus/iron-buckets/internal/handlers" |
10 | 11 | customMiddleware "github.com/damacus/iron-buckets/internal/middleware" |
@@ -41,7 +42,8 @@ func newServer(minioEndpoint string) *echo.Echo { |
41 | 42 | // Services |
42 | 43 | authService := services.NewAuthService() |
43 | 44 | minioFactory := &services.RealMinioFactory{} |
44 | | - authHandler := handlers.NewAuthHandler(authService, minioFactory, minioEndpoint) |
| 45 | + oidcEnabled := oidcEnabledFromEnv() |
| 46 | + authHandler := handlers.NewAuthHandler(authService, minioFactory, minioEndpoint, oidcEnabled) |
45 | 47 | usersHandler := handlers.NewUsersHandler(minioFactory) |
46 | 48 | groupsHandler := handlers.NewGroupsHandler(minioFactory) |
47 | 49 | bucketsHandler := handlers.NewBucketsHandler(minioFactory) |
@@ -69,16 +71,40 @@ func newServer(minioEndpoint string) *echo.Echo { |
69 | 71 | e.Renderer = renderer.New() |
70 | 72 |
|
71 | 73 | // Public Routes (auth middleware will skip these) |
| 74 | + registerPublicRoutes(e, authHandler, oidcEnabled) |
| 75 | + |
| 76 | + // Protected Routes |
| 77 | + registerProtectedRoutes(e, drivesHandler, dashboardHandler, usersHandler, groupsHandler, bucketsHandler, settingsHandler) |
| 78 | + |
| 79 | + return e |
| 80 | +} |
| 81 | + |
| 82 | +func oidcEnabledFromEnv() bool { |
| 83 | + return strings.EqualFold(os.Getenv("OIDC_ENABLED"), "true") |
| 84 | +} |
| 85 | + |
| 86 | +func registerPublicRoutes(e *echo.Echo, authHandler *handlers.AuthHandler, oidcEnabled bool) { |
72 | 87 | e.GET("/health", func(c echo.Context) error { |
73 | 88 | return c.String(http.StatusOK, "OK") |
74 | 89 | }) |
75 | 90 | e.GET("/login", authHandler.LoginPage) |
76 | 91 | e.POST("/login", authHandler.Login) |
77 | | - e.GET("/login/oauth", authHandler.LoginOIDC) |
78 | | - e.GET("/oauth/callback", authHandler.CallbackOIDC) |
| 92 | + if oidcEnabled { |
| 93 | + e.GET("/login/oauth", authHandler.LoginOIDC) |
| 94 | + e.GET("/oauth/callback", authHandler.CallbackOIDC) |
| 95 | + } |
79 | 96 | e.GET("/logout", authHandler.Logout) |
| 97 | +} |
80 | 98 |
|
81 | | - // Protected Routes |
| 99 | +func registerProtectedRoutes( |
| 100 | + e *echo.Echo, |
| 101 | + drivesHandler *handlers.DrivesHandler, |
| 102 | + dashboardHandler *handlers.DashboardHandler, |
| 103 | + usersHandler *handlers.UsersHandler, |
| 104 | + groupsHandler *handlers.GroupsHandler, |
| 105 | + bucketsHandler *handlers.BucketsHandler, |
| 106 | + settingsHandler *handlers.SettingsHandler, |
| 107 | +) { |
82 | 108 | e.GET("/", func(c echo.Context) error { |
83 | 109 | return c.Render(http.StatusOK, "dashboard", map[string]interface{}{ |
84 | 110 | "ActiveNav": "dashboard", |
@@ -153,6 +179,4 @@ func newServer(minioEndpoint string) *echo.Echo { |
153 | 179 | e.GET("/settings", settingsHandler.ShowSettings) |
154 | 180 | e.POST("/settings/restart", settingsHandler.RestartService) |
155 | 181 | e.GET("/settings/logs", settingsHandler.GetLogs) |
156 | | - |
157 | | - return e |
158 | 182 | } |
0 commit comments