forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 1
/
apis.go
51 lines (40 loc) · 1.25 KB
/
apis.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
/*
Copyright IBM Corp. 2017 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package resourcesconfig
import (
cb "github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
)
// apisGroup represents the ConfigGroup names APIs off the resources group
type apisGroup struct {
apiPolicyRefs map[string]string
}
func (ag *apisGroup) PolicyRefForAPI(apiName string) string {
return ag.apiPolicyRefs[apiName]
}
func newAPIsGroup(group *cb.ConfigGroup) (*apisGroup, error) {
if len(group.Groups) > 0 {
return nil, errors.New("apis group does not support sub-groups")
}
apiPolicyRefs := make(map[string]string)
for key, value := range group.Values {
api := &pb.APIResource{}
if err := proto.Unmarshal(value.Value, api); err != nil {
return nil, err
}
// If the policy is fully qualified, ie to /Channel/Application/Readers leave it alone
// otherwise, make it fully qualified referring to /Resources/APIs/policyName
if '/' != api.PolicyRef[0] {
apiPolicyRefs[key] = "/" + RootGroupKey + "/" + APIsGroupKey + "/" + api.PolicyRef
} else {
apiPolicyRefs[key] = api.PolicyRef
}
}
return &apisGroup{
apiPolicyRefs: apiPolicyRefs,
}, nil
}