Files
kopia/internal/server/server_authz_checks.go
Jarek Kowalski 8a4ac4dec3 Upgraded linter to 1.43.0 (#1505)
* 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
2021-11-11 17:03:11 -08:00

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
)