forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization.go
129 lines (101 loc) · 3.35 KB
/
organization.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
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 config
import (
"fmt"
mspconfig "github.com/hyperledger/fabric/common/config/msp"
"github.com/hyperledger/fabric/msp"
mspprotos "github.com/hyperledger/fabric/protos/msp"
)
// Org config keys
const (
// MSPKey is value key for marshaled *mspconfig.MSPConfig
MSPKey = "MSP"
)
type OrganizationProtos struct {
MSP *mspprotos.MSPConfig
}
type OrganizationConfig struct {
*standardValues
protos *OrganizationProtos
organizationGroup *OrganizationGroup
msp msp.MSP
mspID string
}
// Config stores common configuration information for organizations
type OrganizationGroup struct {
*Proposer
*OrganizationConfig
name string
mspConfigHandler *mspconfig.MSPConfigHandler
}
// NewConfig creates an instnace of the organization Config
func NewOrganizationGroup(name string, mspConfigHandler *mspconfig.MSPConfigHandler) *OrganizationGroup {
og := &OrganizationGroup{
name: name,
mspConfigHandler: mspConfigHandler,
}
og.Proposer = NewProposer(og)
return og
}
// Name returns the name this org is referred to in config
func (og *OrganizationGroup) Name() string {
return og.name
}
// MSPID returns the MSP ID associated with this org
func (og *OrganizationGroup) MSPID() string {
return og.mspID
}
// NewGroup always errors
func (og *OrganizationGroup) NewGroup(name string) (ValueProposer, error) {
return nil, fmt.Errorf("Organization does not support subgroups")
}
// Allocate creates the proto resources neeeded for a proposal
func (og *OrganizationGroup) Allocate() Values {
return NewOrganizationConfig(og)
}
func NewOrganizationConfig(og *OrganizationGroup) *OrganizationConfig {
oc := &OrganizationConfig{
protos: &OrganizationProtos{},
organizationGroup: og,
}
var err error
oc.standardValues, err = NewStandardValues(oc.protos)
if err != nil {
logger.Panicf("Programming error: %s", err)
}
return oc
}
// Validate returns whether the configuration is valid
func (oc *OrganizationConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
return oc.validateMSP(tx)
}
func (oc *OrganizationConfig) Commit() {
oc.organizationGroup.OrganizationConfig = oc
}
func (oc *OrganizationConfig) validateMSP(tx interface{}) error {
var err error
logger.Debugf("Setting up MSP for org %s", oc.organizationGroup.name)
oc.msp, err = oc.organizationGroup.mspConfigHandler.ProposeMSP(tx, oc.protos.MSP)
if err != nil {
return err
}
oc.mspID, _ = oc.msp.GetIdentifier()
if oc.mspID == "" {
return fmt.Errorf("MSP for org %s has empty MSP ID", oc.organizationGroup.name)
}
if oc.organizationGroup.OrganizationConfig != nil && oc.organizationGroup.mspID != oc.mspID {
return fmt.Errorf("Organization %s attempted to change its MSP ID from %s to %s", oc.organizationGroup.name, oc.organizationGroup.mspID, oc.mspID)
}
return nil
}