2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-08-10 17:27:25 +00:00
|
|
|
package logical
|
|
|
|
|
2018-07-11 19:45:09 +00:00
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrUnsupportedOperation is returned if the operation is not supported
|
|
|
|
// by the logical backend.
|
|
|
|
ErrUnsupportedOperation = errors.New("unsupported operation")
|
|
|
|
|
|
|
|
// ErrUnsupportedPath is returned if the path is not supported
|
|
|
|
// by the logical backend.
|
|
|
|
ErrUnsupportedPath = errors.New("unsupported path")
|
|
|
|
|
|
|
|
// ErrInvalidRequest is returned if the request is invalid
|
|
|
|
ErrInvalidRequest = errors.New("invalid request")
|
|
|
|
|
|
|
|
// ErrPermissionDenied is returned if the client is not authorized
|
|
|
|
ErrPermissionDenied = errors.New("permission denied")
|
|
|
|
|
2022-09-27 23:49:14 +00:00
|
|
|
// ErrInvalidCredentials is returned when the provided credentials are incorrect
|
|
|
|
// This is used internally for user lockout purposes. This is not seen externally.
|
|
|
|
// The status code returned does not change because of this error
|
|
|
|
ErrInvalidCredentials = errors.New("invalid credentials")
|
|
|
|
|
2018-07-11 19:45:09 +00:00
|
|
|
// ErrMultiAuthzPending is returned if the the request needs more
|
|
|
|
// authorizations
|
|
|
|
ErrMultiAuthzPending = errors.New("request needs further approval")
|
2018-08-28 20:59:02 +00:00
|
|
|
|
2018-09-18 20:26:06 +00:00
|
|
|
// ErrUpstreamRateLimited is returned when Vault receives a rate limited
|
2018-08-28 20:59:02 +00:00
|
|
|
// response from an upstream
|
|
|
|
ErrUpstreamRateLimited = errors.New("upstream rate limited")
|
2019-01-25 19:08:42 +00:00
|
|
|
|
|
|
|
// ErrPerfStandbyForward is returned when Vault is in a state such that a
|
|
|
|
// perf standby cannot satisfy a request
|
|
|
|
ErrPerfStandbyPleaseForward = errors.New("please forward to the active node")
|
2020-06-26 21:13:16 +00:00
|
|
|
|
|
|
|
// ErrLeaseCountQuotaExceeded is returned when a request is rejected due to a lease
|
|
|
|
// count quota being exceeded.
|
|
|
|
ErrLeaseCountQuotaExceeded = errors.New("lease count quota exceeded")
|
|
|
|
|
|
|
|
// ErrRateLimitQuotaExceeded is returned when a request is rejected due to a
|
|
|
|
// rate limit quota being exceeded.
|
|
|
|
ErrRateLimitQuotaExceeded = errors.New("rate limit quota exceeded")
|
2021-05-03 23:56:06 +00:00
|
|
|
|
|
|
|
// ErrUnrecoverable is returned when a request fails due to something that
|
|
|
|
// is likely to require manual intervention. This is a generic form of an
|
|
|
|
// unrecoverable error.
|
|
|
|
// e.g.: misconfigured or disconnected storage backend.
|
|
|
|
ErrUnrecoverable = errors.New("unrecoverable error")
|
2021-06-11 17:18:16 +00:00
|
|
|
|
|
|
|
// ErrMissingRequiredState is returned when a request can't be satisfied
|
|
|
|
// with the data in the local node's storage, based on the provided
|
|
|
|
// X-Vault-Index request header.
|
|
|
|
ErrMissingRequiredState = errors.New("required index state not present")
|
2021-07-29 17:21:40 +00:00
|
|
|
|
|
|
|
// Error indicating that the requested path used to serve a purpose in older
|
|
|
|
// versions, but the functionality has now been removed
|
|
|
|
ErrPathFunctionalityRemoved = errors.New("functionality on this path has been removed")
|
2018-07-11 19:45:09 +00:00
|
|
|
)
|
|
|
|
|
2015-08-10 17:27:25 +00:00
|
|
|
type HTTPCodedError interface {
|
2016-08-19 20:48:32 +00:00
|
|
|
Error() string
|
|
|
|
Code() int
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 20:29:59 +00:00
|
|
|
func CodedError(status int, msg string) HTTPCodedError {
|
|
|
|
return &codedError{
|
|
|
|
Status: status,
|
|
|
|
Message: msg,
|
|
|
|
}
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 20:08:44 +00:00
|
|
|
var _ HTTPCodedError = (*codedError)(nil)
|
|
|
|
|
2015-08-10 17:27:25 +00:00
|
|
|
type codedError struct {
|
2017-10-19 20:29:59 +00:00
|
|
|
Status int
|
|
|
|
Message string
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *codedError) Error() string {
|
2017-10-19 20:29:59 +00:00
|
|
|
return e.Message
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *codedError) Code() int {
|
2017-10-19 20:29:59 +00:00
|
|
|
return e.Status
|
2015-08-10 17:27:25 +00:00
|
|
|
}
|
2017-02-16 20:15:02 +00:00
|
|
|
|
|
|
|
// Struct to identify user input errors. This is helpful in responding the
|
|
|
|
// appropriate status codes to clients from the HTTP endpoints.
|
|
|
|
type StatusBadRequest struct {
|
|
|
|
Err string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementing error interface
|
|
|
|
func (s *StatusBadRequest) Error() string {
|
|
|
|
return s.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a new type declared to not cause potential compatibility problems if
|
2017-10-19 20:29:59 +00:00
|
|
|
// the logic around the CodedError changes; in particular for logical request
|
|
|
|
// paths it is basically ignored, and changing that behavior might cause
|
2019-03-19 13:32:45 +00:00
|
|
|
// unforeseen issues.
|
2017-02-16 20:15:02 +00:00
|
|
|
type ReplicationCodedError struct {
|
|
|
|
Msg string
|
|
|
|
Code int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ReplicationCodedError) Error() string {
|
|
|
|
return r.Msg
|
|
|
|
}
|
2018-09-18 03:03:00 +00:00
|
|
|
|
|
|
|
type KeyNotFoundError struct {
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *KeyNotFoundError) WrappedErrors() []error {
|
|
|
|
return []error{e.Err}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *KeyNotFoundError) Error() string {
|
|
|
|
return e.Err.Error()
|
|
|
|
}
|