|
1 | 1 | /*
|
2 |
| -Copyright IBM Corp. 2016 All Rights Reserved. |
| 2 | +Copyright IBM Corp. All Rights Reserved. |
3 | 3 |
|
4 |
| -Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| -you may not use this file except in compliance with the License. |
6 |
| -You may obtain a copy of the License at |
7 |
| -
|
8 |
| - http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| -
|
10 |
| -Unless required by applicable law or agreed to in writing, software |
11 |
| -distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| -See the License for the specific language governing permissions and |
14 |
| -limitations under the License. |
| 4 | +SPDX-License-Identifier: Apache-2.0 |
15 | 5 | */
|
16 | 6 |
|
17 | 7 | package policies
|
18 | 8 |
|
19 | 9 | import (
|
| 10 | + "bytes" |
20 | 11 | "fmt"
|
21 | 12 |
|
22 | 13 | cb "github.com/hyperledger/fabric/protos/common"
|
23 | 14 |
|
24 | 15 | "github.com/golang/protobuf/proto"
|
| 16 | + "github.com/op/go-logging" |
25 | 17 | )
|
26 | 18 |
|
27 | 19 | type implicitMetaPolicy struct {
|
28 | 20 | threshold int
|
29 | 21 | subPolicies []Policy
|
| 22 | + |
| 23 | + // Only used for logging |
| 24 | + managers map[string]*ManagerImpl |
| 25 | + subPolicyName string |
30 | 26 | }
|
31 | 27 |
|
32 | 28 | // NewPolicy creates a new policy based on the policy bytes
|
@@ -61,14 +57,36 @@ func newImplicitMetaPolicy(data []byte, managers map[string]*ManagerImpl) (*impl
|
61 | 57 | }
|
62 | 58 |
|
63 | 59 | return &implicitMetaPolicy{
|
64 |
| - subPolicies: subPolicies, |
65 |
| - threshold: threshold, |
| 60 | + subPolicies: subPolicies, |
| 61 | + threshold: threshold, |
| 62 | + managers: managers, |
| 63 | + subPolicyName: definition.SubPolicy, |
66 | 64 | }, nil
|
67 | 65 | }
|
68 | 66 |
|
69 | 67 | // Evaluate takes a set of SignedData and evaluates whether this set of signatures satisfies the policy
|
70 | 68 | func (imp *implicitMetaPolicy) Evaluate(signatureSet []*cb.SignedData) error {
|
| 69 | + logger.Debugf("This is an implicit meta policy, it will trigger other policy evaluations, whose failures may be benign") |
71 | 70 | remaining := imp.threshold
|
| 71 | + |
| 72 | + defer func() { |
| 73 | + if remaining != 0 { |
| 74 | + // This log message may be large and expensive to construct, so worth checking the log level |
| 75 | + if logger.IsEnabledFor(logging.DEBUG) { |
| 76 | + var b bytes.Buffer |
| 77 | + b.WriteString(fmt.Sprintf("Evaluation Failed: Only %d policies were satisfied, but needed %d of [ ", remaining, imp.threshold)) |
| 78 | + for m := range imp.managers { |
| 79 | + b.WriteString(m) |
| 80 | + b.WriteString(".") |
| 81 | + b.WriteString(imp.subPolicyName) |
| 82 | + b.WriteString(" ") |
| 83 | + } |
| 84 | + b.WriteString("]") |
| 85 | + logger.Debugf(b.String()) |
| 86 | + } |
| 87 | + } |
| 88 | + }() |
| 89 | + |
72 | 90 | for _, policy := range imp.subPolicies {
|
73 | 91 | if policy.Evaluate(signatureSet) == nil {
|
74 | 92 | remaining--
|
|
0 commit comments