-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess.go
More file actions
43 lines (35 loc) · 890 Bytes
/
access.go
File metadata and controls
43 lines (35 loc) · 890 Bytes
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
package hyperacc
import (
"github.com/hyperledger/fabric-contract-api-go/v2/contractapi"
)
// Rule interface for access rules
type Rule interface {
Check(ctx contractapi.TransactionContextInterface) error
}
// controller main structure for access control
type controller struct {
rules []Rule
}
// New creates a new instance of controller
func New(rules ...Rule) *controller {
return &controller{
rules: rules,
}
}
// Check checks all access rules
func (c *controller) Check(ctx contractapi.TransactionContextInterface) error {
if len(c.rules) == 0 {
return nil // No restrictions
}
for _, rule := range c.rules {
if err := rule.Check(ctx); err != nil {
return err
}
}
return nil
}
// CheckAccess helper function for access checking
func CheckAccess(ctx contractapi.TransactionContextInterface, rules ...Rule) error {
c := New(rules...)
return c.Check(ctx)
}