diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-28 18:38:16 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-09-28 18:38:16 +0300 |
commit | 5f971520a50d3bd7b3b565a673c185b00f0df680 (patch) | |
tree | f3200b170ec06b35841e6a5564bad5e278536bd0 /internal | |
parent | 08d70aef345f1811f13cc990529f5114ccf3a92e (diff) |
refactor: move acl to auth package and update function signature
Diffstat (limited to 'internal')
-rw-r--r-- | internal/acl/middleware.go | 25 | ||||
-rw-r--r-- | internal/acme/middleware.go | 2 | ||||
-rw-r--r-- | internal/auth/middleware.go | 20 |
3 files changed, 20 insertions, 27 deletions
diff --git a/internal/acl/middleware.go b/internal/acl/middleware.go deleted file mode 100644 index 119d0549..00000000 --- a/internal/acl/middleware.go +++ /dev/null @@ -1,25 +0,0 @@ -package acl - -import ( - "net/http" - - "gitlab.com/gitlab-org/gitlab-pages/internal/auth" - "gitlab.com/gitlab-org/gitlab-pages/internal/request" -) - -// NewMiddleware returns middleware which handle authorization -func NewMiddleware(handler http.Handler, a *auth.Auth) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - domain := request.GetDomain(r) - - // Only for projects that have access control enabled - if domain.IsAccessControlEnabled(r) { - // accessControlMiddleware - if a.CheckAuthentication(w, r, domain) { - return - } - } - - handler.ServeHTTP(w, r) - }) -} diff --git a/internal/acme/middleware.go b/internal/acme/middleware.go index fb6aa158..bbb2ef04 100644 --- a/internal/acme/middleware.go +++ b/internal/acme/middleware.go @@ -7,7 +7,7 @@ import ( ) // NewMiddleware returns middleware which handle ACME challenges -func NewMiddleware(handler http.Handler, m *Middleware) http.Handler { +func (m *Middleware) AcmeMiddleware(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { domain := request.GetDomain(r) diff --git a/internal/auth/middleware.go b/internal/auth/middleware.go index 263e48b8..4eb1e943 100644 --- a/internal/auth/middleware.go +++ b/internal/auth/middleware.go @@ -3,11 +3,12 @@ package auth import ( "net/http" + "gitlab.com/gitlab-org/gitlab-pages/internal/request" "gitlab.com/gitlab-org/gitlab-pages/internal/source" ) // NewMiddleware returns middleware which handles authentication requests -func NewMiddleware(handler http.Handler, a *Auth, s source.Source) http.Handler { +func (a *Auth) AuthenticationMiddleware(handler http.Handler, s source.Source) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if a.TryAuthenticate(w, r, s) { return @@ -16,3 +17,20 @@ func NewMiddleware(handler http.Handler, a *Auth, s source.Source) http.Handler handler.ServeHTTP(w, r) }) } + +// NewMiddleware returns middleware which handle authorization +func (a *Auth) AuthorizationMiddleware(handler http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + domain := request.GetDomain(r) + + // Only for projects that have access control enabled + if domain.IsAccessControlEnabled(r) { + // accessControlMiddleware + if a.CheckAuthentication(w, r, domain) { + return + } + } + + handler.ServeHTTP(w, r) + }) +} |