-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
82 lines (69 loc) · 2.48 KB
/
util.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package policies
import (
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
)
// ConfigPolicy defines a common representation for different *cb.ConfigPolicy values.
type ConfigPolicy interface {
// Key is the key this value should be stored in the *cb.ConfigGroup.Policies map.
Key() string
// Value is the backing policy implementation for this ConfigPolicy
Value() *cb.Policy
}
// StandardConfigValue implements the ConfigValue interface.
type StandardConfigPolicy struct {
key string
value *cb.Policy
}
// Key is the key this value should be stored in the *cb.ConfigGroup.Values map.
func (scv *StandardConfigPolicy) Key() string {
return scv.key
}
// Value is the *cb.Policy which should be stored as the *cb.ConfigPolicy.Policy.
func (scv *StandardConfigPolicy) Value() *cb.Policy {
return scv.value
}
func makeImplicitMetaPolicy(subPolicyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.Policy {
return &cb.Policy{
Type: int32(cb.Policy_IMPLICIT_META),
Value: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
Rule: rule,
SubPolicy: subPolicyName,
}),
}
}
// ImplicitMetaAllPolicy defines an implicit meta policy whose sub_policy and key is policyname with rule ALL.
func ImplicitMetaAllPolicy(policyName string) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_ALL),
}
}
// ImplicitMetaAnyPolicy defines an implicit meta policy whose sub_policy and key is policyname with rule ANY.
func ImplicitMetaAnyPolicy(policyName string) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_ANY),
}
}
// ImplicitMetaMajorityPolicy defines an implicit meta policy whose sub_policy and key is policyname with rule MAJORITY.
func ImplicitMetaMajorityPolicy(policyName string) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_MAJORITY),
}
}
// ImplicitMetaMajorityPolicy defines a policy with key policyName and the given signature policy.
func SignaturePolicy(policyName string, sigPolicy *cb.SignaturePolicyEnvelope) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: &cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Value: utils.MarshalOrPanic(sigPolicy),
},
}
}