forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
104 lines (82 loc) · 3.01 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package accesscontrol
import (
"errors"
"fmt"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
)
const (
invalidBuiltInRoleMessage = `built-in role [{{ .Public.builtInRole }}] is not valid`
assignmentEntityNotFoundMessage = `{{ .Public.assignment }} not found`
)
var (
ErrInvalidBuiltinRole = errutil.BadRequest("accesscontrol.invalidBuiltInRole").
MustTemplate(invalidBuiltInRoleMessage, errutil.WithPublic(invalidBuiltInRoleMessage))
ErrNoneRoleAssignment = errutil.BadRequest("accesscontrol.noneRoleAssignment", errutil.WithPublicMessage("none role cannot receive permissions"))
ErrAssignmentEntityNotFound = errutil.BadRequest("accesscontrol.assignmentEntityNotFound").
MustTemplate(assignmentEntityNotFoundMessage, errutil.WithPublic(assignmentEntityNotFoundMessage))
// Note: these are intended to be replaced by equivalent errutil implementations.
// Avoid creating new errors with errors.New and prefer errutil
ErrInvalidRequestBody = errors.New("invalid request body")
ErrFixedRolePrefixMissing = errors.New("fixed role should be prefixed with '" + FixedRolePrefix + "'")
ErrInvalidScope = errors.New("invalid scope")
ErrResolverNotFound = errors.New("no resolver found")
ErrPluginIDRequired = errors.New("plugin ID is required")
ErrRoleNotFound = errors.New("role not found")
ErrActionSetValidationFailed = errutil.ValidationFailed("accesscontrol.actionSetInvalid")
)
func ErrInvalidBuiltinRoleData(builtInRole string) errutil.TemplateData {
return errutil.TemplateData{
Public: map[string]any{
"builtInRole": builtInRole,
},
}
}
func ErrAssignmentEntityNotFoundData(assignment string) errutil.TemplateData {
return errutil.TemplateData{
Public: map[string]any{
"assignment": assignment,
},
}
}
type ErrorInvalidRole struct{}
func (e *ErrorInvalidRole) Error() string {
return "role is invalid"
}
type ErrorRoleNameMissing struct{}
func (e *ErrorRoleNameMissing) Error() string {
return "role has been defined without a name"
}
func (e *ErrorRoleNameMissing) Unwrap() error {
return &ErrorInvalidRole{}
}
type ErrorRolePrefixMissing struct {
Role string
Prefixes []string
}
func (e *ErrorRolePrefixMissing) Error() string {
return fmt.Sprintf("expected role '%s' to be prefixed with any of '%v'", e.Role, e.Prefixes)
}
func (e *ErrorRolePrefixMissing) Unwrap() error {
return &ErrorInvalidRole{}
}
type ErrorActionPrefixMissing struct {
Action string
Prefixes []string
}
func (e *ErrorActionPrefixMissing) Error() string {
return fmt.Sprintf("expected action '%s' to be prefixed with any of '%v'", e.Action, e.Prefixes)
}
func (e *ErrorActionPrefixMissing) Unwrap() error {
return &ErrorInvalidRole{}
}
type ErrorScopeTarget struct {
Action string
Scope string
ExpectedScope string
}
func (e *ErrorScopeTarget) Error() string {
return fmt.Sprintf("expected action '%s' to be scoped with '%v', found '%v'", e.Action, e.ExpectedScope, e.Scope)
}
func (e *ErrorScopeTarget) Unwrap() error {
return &ErrorInvalidRole{}
}