-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-6567] Move ACL resources deeper in tree
The ACL work preliminarily put all of the policy references and polici at the root level of the config tree. Because the peer resources tree is now intended to support more than ACLs, keeping these at the root level does not make sense. Instead, these need to be moved down into the tree. This CR moves the old resource policy references from /Resources to /Resources/APIs It also creates /Resources/PeerPolicies as a global location to declare policies which may be referenced both for API ACL purposes, as well as later by other parts of the resources tree. Change-Id: I5c8eeba0472f480ac88ddbf02a0a1a3d90092463 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Oct 12, 2017
1 parent
20b5503
commit 33e3fb6
Showing
8 changed files
with
169 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.Resource{} | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright IBM Corp. 2017 All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package resourcesconfig | ||
|
||
import ( | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// peerPoliciesGroup is a free-form group, which supports only policies | ||
type peerPoliciesGroup struct{} | ||
|
||
func newPeerPoliciesGroup(group *cb.ConfigGroup) (*peerPoliciesGroup, error) { | ||
return &peerPoliciesGroup{}, verifyNoMoreValues(group) | ||
} | ||
|
||
func verifyNoMoreValues(subGroup *cb.ConfigGroup) error { | ||
if len(subGroup.Values) > 0 { | ||
return errors.Errorf("sub-groups not allowed to have values") | ||
} | ||
for _, subGroup := range subGroup.Groups { | ||
if err := verifyNoMoreValues(subGroup); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters