6 Star 47 Fork 28

Hyperledger/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config_util.go 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. 2017 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package msp
import (
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
mspprotos "github.com/hyperledger/fabric/protos/msp"
"github.com/hyperledger/fabric/protos/utils"
logging "github.com/op/go-logging"
)
var logger = logging.MustGetLogger("configvalues/msp")
const (
// ReadersPolicyKey is the key used for the read policy
ReadersPolicyKey = "Readers"
// WritersPolicyKey is the key used for the read policy
WritersPolicyKey = "Writers"
// AdminsPolicyKey is the key used for the read policy
AdminsPolicyKey = "Admins"
// MSPKey is the org key used for MSP configuration
MSPKey = "MSP"
)
// TemplateGroupMSP creates an MSP ConfigValue at the given configPath
func TemplateGroupMSP(configPath []string, mspConfig *mspprotos.MSPConfig) *cb.ConfigGroup {
// check that the type for that MSP is supported
if mspConfig.Type != int32(msp.FABRIC) {
logger.Panicf("Setup error: unsupported msp type %d", mspConfig.Type)
}
// create the msp instance
mspInst, err := msp.NewBccspMsp()
if err != nil {
logger.Panicf("Creating the MSP manager failed, err %s", err)
}
// set it up
err = mspInst.Setup(mspConfig)
if err != nil {
logger.Panicf("Setting up the MSP manager failed, err %s", err)
}
// add the MSP to the map of pending MSPs
mspID, err := mspInst.GetIdentifier()
if err != nil {
logger.Panicf("Could not extract msp identifier, err %s", err)
}
memberPolicy := &cb.ConfigPolicy{
Policy: &cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Policy: utils.MarshalOrPanic(cauthdsl.SignedByMspMember(mspID)),
},
}
adminPolicy := &cb.ConfigPolicy{
Policy: &cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Policy: utils.MarshalOrPanic(cauthdsl.SignedByMspAdmin(mspID)),
},
}
result := cb.NewConfigGroup()
intermediate := result
for _, group := range configPath {
intermediate.Groups[group] = cb.NewConfigGroup()
intermediate = intermediate.Groups[group]
}
intermediate.Values[MSPKey] = &cb.ConfigValue{
Value: utils.MarshalOrPanic(mspConfig),
}
intermediate.Policies[AdminsPolicyKey] = adminPolicy
intermediate.Policies[ReadersPolicyKey] = memberPolicy
intermediate.Policies[WritersPolicyKey] = memberPolicy
return result
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hyperledger/fabric.git
git@gitee.com:hyperledger/fabric.git
hyperledger
fabric
fabric
v1.0.0-alpha

搜索帮助

0d507c66 1850385 C8b1a773 1850385