forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_errors.go
75 lines (68 loc) · 2.04 KB
/
path_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
package mock
import (
"context"
"errors"
"net/rpc"
"github.com/hashicorp/vault/helper/errutil"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
"github.com/hashicorp/vault/logical/plugin/pb"
)
// pathInternal is used to test viewing internal backend values. In this case,
// it is used to test the invalidate func.
func errorPaths(b *backend) []*framework.Path {
return []*framework.Path{
&framework.Path{
Pattern: "errors/rpc",
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathErrorRPCRead,
},
},
&framework.Path{
Pattern: "errors/kill",
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathErrorRPCRead,
},
},
&framework.Path{
Pattern: "errors/type",
Fields: map[string]*framework.FieldSchema{
"err_type": &framework.FieldSchema{Type: framework.TypeInt},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.CreateOperation: b.pathErrorRPCRead,
logical.UpdateOperation: b.pathErrorRPCRead,
},
},
}
}
func (b *backend) pathErrorRPCRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
errTypeRaw, ok := data.GetOk("err_type")
if !ok {
return nil, rpc.ErrShutdown
}
var err error
switch uint32(errTypeRaw.(int)) {
case pb.ErrTypeUnknown:
err = errors.New("test")
case pb.ErrTypeUserError:
err = errutil.UserError{Err: "test"}
case pb.ErrTypeInternalError:
err = errutil.InternalError{Err: "test"}
case pb.ErrTypeCodedError:
err = logical.CodedError(403, "test")
case pb.ErrTypeStatusBadRequest:
err = &logical.StatusBadRequest{Err: "test"}
case pb.ErrTypeUnsupportedOperation:
err = logical.ErrUnsupportedOperation
case pb.ErrTypeUnsupportedPath:
err = logical.ErrUnsupportedPath
case pb.ErrTypeInvalidRequest:
err = logical.ErrInvalidRequest
case pb.ErrTypePermissionDenied:
err = logical.ErrPermissionDenied
case pb.ErrTypeMultiAuthzPending:
err = logical.ErrMultiAuthzPending
}
return nil, err
}