-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.go
More file actions
42 lines (35 loc) · 1.09 KB
/
Copy pathcustom.go
File metadata and controls
42 lines (35 loc) · 1.09 KB
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
package hyperacc
import (
"github.com/hyperledger/fabric-contract-api-go/v2/contractapi"
)
// CustomRule allows creating custom rules using a function
type CustomRule struct {
checkFunc func(ctx contractapi.TransactionContextInterface) error
name string
}
// Custom creates a custom rule based on a function
func Custom(name string, checkFunc func(ctx contractapi.TransactionContextInterface) error) *CustomRule {
return &CustomRule{
checkFunc: checkFunc,
name: name,
}
}
// Check executes the custom check function
func (r *CustomRule) Check(ctx contractapi.TransactionContextInterface) error {
return r.checkFunc(ctx)
}
// AlwaysDenyRule always denies access
type AlwaysDenyRule struct {
message string
}
// AlwaysDeny creates a rule that always denies access
func AlwaysDeny(message string) *AlwaysDenyRule {
return &AlwaysDenyRule{message: message}
}
// Check always returns an error (access denied)
func (r *AlwaysDenyRule) Check(ctx contractapi.TransactionContextInterface) error {
if r.message == "" {
return NewAccessError("access denied")
}
return NewAccessError(r.message)
}