mirror of
https://github.com/kopia/kopia.git
synced 2026-01-21 21:07:51 -05:00
* server: reworked authn/authz Previously authentication was done as an wrapper handler and authorization was inlined. This change moves authn/authz handlers inside the server and implements separate authorization module that's individually tested. Also fixed an issue where server users were not able to see global or host-level policies. * PR feedback
37 lines
920 B
Go
37 lines
920 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/internal/serverapi"
|
|
)
|
|
|
|
type apiError struct {
|
|
httpErrorCode int
|
|
apiErrorCode serverapi.APIErrorCode
|
|
message string
|
|
}
|
|
|
|
func requestError(apiErrorCode serverapi.APIErrorCode, message string) *apiError {
|
|
return &apiError{http.StatusBadRequest, apiErrorCode, message}
|
|
}
|
|
|
|
func notFoundError(message string) *apiError {
|
|
return &apiError{http.StatusNotFound, serverapi.ErrorNotFound, message}
|
|
}
|
|
|
|
func accessDeniedError() *apiError {
|
|
return &apiError{http.StatusForbidden, serverapi.ErrorAccessDenied, "access is denied"}
|
|
}
|
|
|
|
func repositoryNotWritableError() *apiError {
|
|
return internalServerError(errors.Errorf("repository is not writable"))
|
|
}
|
|
|
|
func internalServerError(err error) *apiError {
|
|
return &apiError{http.StatusInternalServerError, serverapi.ErrorInternal, fmt.Sprintf("internal server error: %v", err)}
|
|
}
|