github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/peer/peer.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package initializer 20 21 import ( 22 "fmt" 23 24 commonapi "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common" 25 "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config" 26 commonconfig "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config" 27 v1 "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v1" 28 "github.com/pkg/errors" 29 ) 30 31 type CoreConfig interface { 32 MergeWith(interface{}, bool) error 33 GetAddressOverrides() []v1.AddressOverride 34 ToBytes() ([]byte, error) 35 UsingPKCS11() bool 36 SetPKCS11Defaults(bool) 37 GetBCCSPSection() *commonapi.BCCSP 38 SetBCCSPLibrary(string) 39 } 40 41 type Peer struct { 42 Config CoreConfig 43 Cryptos *commonconfig.Cryptos 44 UsingHSMProxy bool 45 } 46 47 func (p *Peer) OverrideConfig(newConfig CoreConfig) (err error) { 48 log.Info("Overriding peer config values from spec") 49 err = p.Config.MergeWith(newConfig, p.UsingHSMProxy) 50 if err != nil { 51 return errors.Wrapf(err, "failed to merge override configuration") 52 } 53 54 return nil 55 } 56 57 func (p *Peer) GenerateCrypto() (*commonconfig.CryptoResponse, error) { 58 log.Info("Generating peer's crypto material") 59 if p.Cryptos != nil { 60 response, err := p.Cryptos.GenerateCryptoResponse() 61 if err != nil { 62 return nil, err 63 } 64 return response, nil 65 } 66 67 return &config.CryptoResponse{}, nil 68 } 69 70 func (p *Peer) GetConfig() CoreConfig { 71 return p.Config 72 } 73 74 func (p *Peer) DeliveryClientCrypto() map[string][]byte { 75 data := map[string][]byte{} 76 77 if p.Config != nil { 78 for i, addr := range p.Config.GetAddressOverrides() { 79 data[fmt.Sprintf("cert%d.pem", i)] = addr.GetCertBytes() 80 } 81 } 82 83 return data 84 }