github.com/ewagmig/fabric@v2.1.1+incompatible/common/channelconfig/acls.go (about) 1 /* 2 Copyright State Street Corp. 2018 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package channelconfig 8 9 import ( 10 pb "github.com/hyperledger/fabric-protos-go/peer" 11 ) 12 13 // aclsProvider provides mappings for resource to policy names 14 type aclsProvider struct { 15 aclPolicyRefs map[string]string 16 } 17 18 func (ag *aclsProvider) PolicyRefForAPI(aclName string) string { 19 return ag.aclPolicyRefs[aclName] 20 } 21 22 // this translates policies to absolute paths if needed 23 func newAPIsProvider(acls map[string]*pb.APIResource) *aclsProvider { 24 aclPolicyRefs := make(map[string]string) 25 26 for key, acl := range acls { 27 if len(acl.PolicyRef) == 0 { 28 logger.Warningf("Policy reference for resource '%s' is specified, but empty, falling back to default", key) 29 continue 30 } 31 // If the policy is fully qualified, ie to /Channel/Application/Readers leave it alone 32 // otherwise, make it fully qualified referring to /Channel/Application/policyName 33 if acl.PolicyRef[0] != '/' { 34 aclPolicyRefs[key] = "/" + ChannelGroupKey + "/" + ApplicationGroupKey + "/" + acl.PolicyRef 35 } else { 36 aclPolicyRefs[key] = acl.PolicyRef 37 } 38 } 39 40 return &aclsProvider{ 41 aclPolicyRefs: aclPolicyRefs, 42 } 43 }