-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set Correct policy while channel update #114
Set Correct policy while channel update #114
Conversation
eb84812
to
662028f
Compare
Signed-off-by: n0s09by <[email protected]>
662028f
to
3bb082c
Compare
* @return HashMap with role and the configuration policy | ||
*/ | ||
@Override | ||
public HashMap<String, Configtx.ConfigPolicy> getDefaultRolePolicy(String orgMSPId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] What do you think?
Looks like this can be a channel utility function and it can be moved to a different class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, created a class for channel utility and moved the functions to this class so it can be used anywhere.
|
||
return applicationPoliciesMap; | ||
} | ||
|
||
private ConfigPolicy setNewOrgPolicy(String newOrgName, String policyTarget) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] setNewOrgPolicy
setTypeOnePolicy
is not used and can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, Addressed.
Signed-off-by: n0s09by <[email protected]>
import org.hyperledger.fabric.protos.common.Policies; | ||
|
||
@Slf4j | ||
public class FabricChannelUtil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] @UtilityClass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
case FabricClientConstants.CHANNEL_CONFIG_POLICY_TYPE_ADMINS: | ||
mspRole = | ||
MspPrincipal.MSPRole.newBuilder() | ||
.setMspIdentifier(orgMSPId) | ||
.setRole(MspPrincipal.MSPRole.MSPRoleType.ADMIN) | ||
.build(); | ||
mspPrincipal = | ||
MspPrincipal.MSPPrincipal.newBuilder() | ||
.setPrincipal(mspRole.toByteString()) | ||
.setPrincipalClassification(MspPrincipal.MSPPrincipal.Classification.ROLE) | ||
.build(); | ||
mspPrincipals.add(mspPrincipal); | ||
break; | ||
case FabricClientConstants.CHANNEL_CONFIG_POLICY_TYPE_WRITERS: | ||
// any member who is an admin can write | ||
mspRole = | ||
MspPrincipal.MSPRole.newBuilder() | ||
.setMspIdentifier(orgMSPId) | ||
.setRole(MspPrincipal.MSPRole.MSPRoleType.ADMIN) | ||
.build(); | ||
mspPrincipal = | ||
MspPrincipal.MSPPrincipal.newBuilder() | ||
.setPrincipal(mspRole.toByteString()) | ||
.setPrincipalClassification(MspPrincipal.MSPPrincipal.Classification.ROLE) | ||
.build(); | ||
mspPrincipals.add(mspPrincipal); | ||
// any client can also write | ||
mspRole = | ||
MspPrincipal.MSPRole.newBuilder() | ||
.setMspIdentifier(orgMSPId) | ||
.setRole(MspPrincipal.MSPRole.MSPRoleType.CLIENT) | ||
.build(); | ||
mspPrincipal = | ||
MspPrincipal.MSPPrincipal.newBuilder() | ||
.setPrincipal(mspRole.toByteString()) | ||
.setPrincipalClassification(MspPrincipal.MSPPrincipal.Classification.ROLE) | ||
.build(); | ||
mspPrincipals.add(mspPrincipal); | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple fragments of duplicate code here. We can simplify this as
switch (policyFor) {
case FabricClientConstants.CHANNEL_CONFIG_POLICY_TYPE_ADMINS:
mspPrincipals.add(createPrincipal(orgMSPId, MspPrincipal.MSPRole.MSPRoleType.ADMIN));
break;
case FabricClientConstants.CHANNEL_CONFIG_POLICY_TYPE_WRITERS:
mspPrincipals.add(createPrincipal(orgMSPId, MspPrincipal.MSPRole.MSPRoleType.ADMIN));
mspPrincipals.add(createPrincipal(orgMSPId, MspPrincipal.MSPRole.MSPRoleType.CLIENT));
break;
.
.
// Other case statements
createPrinciple
would look like
private static MspPrincipal.MSPPrincipal createPrincipal(String mspId, MspPrincipal.MSPRole.MSPRoleType roleType) {
MspPrincipal.MSPRole mspRole = MspPrincipal.MSPRole.newBuilder()
.setMspIdentifier(mspId)
.setRole(roleType)
.build();
return MspPrincipal.MSPPrincipal.newBuilder()
.setPrincipal(mspRole.toByteString())
.setPrincipalClassification(MspPrincipal.MSPPrincipal.Classification.ROLE)
.build();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, Incorporated changes.
import org.hyperledger.fabric.protos.common.MspPrincipal; | ||
import org.hyperledger.fabric.protos.common.Policies; | ||
|
||
@Slf4j |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] you can safely remove this since nothing is being logged in this class, or can introduce log statements if required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, removed it.
@@ -44,25 +39,27 @@ public ConfigGroup buildWriteset(ConfigGroup readset, NewOrgParamsDTO organizati | |||
// Get existing organizations in the channel and set with as objects and their | |||
// version to prevent deletion or modification | |||
// Omitting existing groups results in their deletion. | |||
Map<String, ConfigGroup> organizations = new HashMap<>(); | |||
Map<String, ConfigGroup> existingOrganizations = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you. Please address open comments.
Signed-off-by: n0s09by <[email protected]>
Thanks Arun, Open comments has been addressed. |
The policy while channel update for the newly added organization is not correct.