|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2017 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package config |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + api "github.com/hyperledger/fabric/common/configvalues" |
| 23 | + "github.com/hyperledger/fabric/common/configvalues/msp" |
| 24 | +) |
| 25 | + |
| 26 | +const ( |
| 27 | + // ApplicationGroupKey is the group name for the Application config |
| 28 | + ApplicationGroupKey = "Application" |
| 29 | +) |
| 30 | + |
| 31 | +// ApplicationGroup represents the application config group |
| 32 | +type ApplicationGroup struct { |
| 33 | + *Proposer |
| 34 | + *ApplicationConfig |
| 35 | + mspConfig *msp.MSPConfigHandler |
| 36 | +} |
| 37 | + |
| 38 | +type ApplicationConfig struct { |
| 39 | + *standardValues |
| 40 | + |
| 41 | + applicationGroup *ApplicationGroup |
| 42 | + applicationOrgs map[string]api.ApplicationOrg |
| 43 | +} |
| 44 | + |
| 45 | +// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper |
| 46 | +func NewApplicationGroup(mspConfig *msp.MSPConfigHandler) *ApplicationGroup { |
| 47 | + ag := &ApplicationGroup{ |
| 48 | + mspConfig: mspConfig, |
| 49 | + } |
| 50 | + ag.Proposer = NewProposer(ag) |
| 51 | + |
| 52 | + return ag |
| 53 | +} |
| 54 | + |
| 55 | +func (ag *ApplicationGroup) NewGroup(name string) (api.ValueProposer, error) { |
| 56 | + return NewApplicationOrgConfig(name, ag.mspConfig), nil |
| 57 | +} |
| 58 | + |
| 59 | +// Allocate returns the |
| 60 | +func (ag *ApplicationGroup) Allocate() Values { |
| 61 | + return NewApplicationConfig(ag) |
| 62 | +} |
| 63 | + |
| 64 | +func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig { |
| 65 | + sv, err := NewStandardValues(&(struct{}{})) |
| 66 | + if err != nil { |
| 67 | + logger.Panicf("Programming error: %s", err) |
| 68 | + } |
| 69 | + |
| 70 | + return &ApplicationConfig{ |
| 71 | + applicationGroup: ag, |
| 72 | + |
| 73 | + // Currently there are no config values |
| 74 | + standardValues: sv, |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func (ac *ApplicationConfig) Validate(groups map[string]api.ValueProposer) error { |
| 79 | + ac.applicationOrgs = make(map[string]api.ApplicationOrg) |
| 80 | + var ok bool |
| 81 | + for key, value := range groups { |
| 82 | + ac.applicationOrgs[key], ok = value.(*ApplicationOrgConfig) |
| 83 | + if !ok { |
| 84 | + return fmt.Errorf("Application sub-group %s was not an ApplicationOrgGroup, actually %T", key, value) |
| 85 | + } |
| 86 | + } |
| 87 | + return nil |
| 88 | +} |
| 89 | + |
| 90 | +func (ac *ApplicationConfig) Commit() { |
| 91 | + ac.applicationGroup.ApplicationConfig = ac |
| 92 | +} |
| 93 | + |
| 94 | +// Organizations returns a map of org ID to ApplicationOrg |
| 95 | +func (ac *ApplicationConfig) Organizations() map[string]api.ApplicationOrg { |
| 96 | + return ac.applicationOrgs |
| 97 | +} |
0 commit comments