mirror of
https://github.com/kopia/kopia.git
synced 2026-01-26 23:38:04 -05:00
* fixed new gocritic violations * fixed new 'contextcheck' violations * fixed 'gosec' warnings * suppressed ireturn and varnamelen linters * fixed tenv violations, enabled building robustness tests on arm64 * fixed remaining linux failures * makefile: fixed 'lint-all' target when running on arm64 * linter: increase deadline * disable nilnil linter - to be enabled in separate PR
43 lines
972 B
Go
43 lines
972 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/kopia/kopia/internal/auth"
|
|
)
|
|
|
|
func requireUIUser(s *Server, r *http.Request) bool {
|
|
if s.authenticator == nil {
|
|
return true
|
|
}
|
|
|
|
user, _, _ := r.BasicAuth()
|
|
|
|
return user == s.options.UIUser
|
|
}
|
|
|
|
func anyAuthenticatedUser(s *Server, r *http.Request) bool {
|
|
return true
|
|
}
|
|
|
|
func handlerWillCheckAuthorization(s *Server, r *http.Request) bool {
|
|
return true
|
|
}
|
|
|
|
func requireContentAccess(level auth.AccessLevel) isAuthorizedFunc {
|
|
return func(s *Server, r *http.Request) bool {
|
|
return s.httpAuthorizationInfo(r.Context(), r).ContentAccessLevel() >= level
|
|
}
|
|
}
|
|
|
|
func hasManifestAccess(ctx context.Context, s *Server, r *http.Request, labels map[string]string, level auth.AccessLevel) bool {
|
|
return s.httpAuthorizationInfo(ctx, r).ManifestAccessLevel(labels) >= level
|
|
}
|
|
|
|
var (
|
|
_ isAuthorizedFunc = requireUIUser
|
|
_ isAuthorizedFunc = anyAuthenticatedUser
|
|
_ isAuthorizedFunc = handlerWillCheckAuthorization
|
|
)
|