diff --git a/cmd/root.go b/cmd/root.go index 898c27f..8e0245d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -113,6 +113,7 @@ func init() { {"ldap-base-dn", "", "LDAP base DN (e.g. dc=example,dc=com)."}, {"ldap-insecure", false, "Skip certificate verification for the LDAP server."}, {"ldap-search-filter", "(uid=%s)", "LDAP search filter for user lookup."}, + {"resources-dir", "/data/resources", "Path to a directory containing custom resources (e.g. background image)."}, } for _, opt := range configOptions { diff --git a/internal/bootstrap/app_bootstrap.go b/internal/bootstrap/app_bootstrap.go index 2dfc61d..f452f25 100644 --- a/internal/bootstrap/app_bootstrap.go +++ b/internal/bootstrap/app_bootstrap.go @@ -151,7 +151,9 @@ func (app *BootstrapApp) Setup() error { Domain: domain, }, authService, oauthBrokerService) - uiMiddleware := middleware.NewUIMiddleware() + uiMiddleware := middleware.NewUIMiddleware(middleware.UIMiddlewareConfig{ + ResourcesDir: app.Config.ResourcesDir, + }) zerologMiddleware := middleware.NewZerologMiddleware() middlewares = append(middlewares, contextMiddleware, uiMiddleware, zerologMiddleware) diff --git a/internal/config/config.go b/internal/config/config.go index 655b61a..48961d6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -55,6 +55,7 @@ type Config struct { LdapBaseDN string `mapstructure:"ldap-base-dn"` LdapInsecure bool `mapstructure:"ldap-insecure"` LdapSearchFilter string `mapstructure:"ldap-search-filter"` + ResourcesDir string `mapstructure:"resources-dir"` } type OAuthLabels struct { diff --git a/internal/middleware/ui_middlware.go b/internal/middleware/ui_middlware.go index b0fabde..cd886b4 100644 --- a/internal/middleware/ui_middlware.go +++ b/internal/middleware/ui_middlware.go @@ -10,14 +10,21 @@ import ( "github.com/gin-gonic/gin" ) +type UIMiddlewareConfig struct { + ResourcesDir string +} + type UIMiddleware struct { + Config UIMiddlewareConfig UIFS fs.FS UIFileServer http.Handler ResourcesFileServer http.Handler } -func NewUIMiddleware() *UIMiddleware { - return &UIMiddleware{} +func NewUIMiddleware(config UIMiddlewareConfig) *UIMiddleware { + return &UIMiddleware{ + Config: config, + } } func (m *UIMiddleware) Init() error { @@ -29,7 +36,7 @@ func (m *UIMiddleware) Init() error { m.UIFS = ui m.UIFileServer = http.FileServer(http.FS(ui)) - m.ResourcesFileServer = http.FileServer(http.Dir("/data/resources")) + m.ResourcesFileServer = http.FileServer(http.Dir(m.Config.ResourcesDir)) return nil } @@ -45,7 +52,7 @@ func (m *UIMiddleware) Middleware() gin.HandlerFunc { c.Next() return case "resources": - _, err := os.Stat("/data/resources/" + strings.TrimPrefix(c.Request.URL.Path, "/resources/")) + _, err := os.Stat(m.Config.ResourcesDir + strings.TrimPrefix(c.Request.URL.Path, "/resources/")) if os.IsNotExist(err) { c.Status(404)