github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/orderer/config/v24/orderer.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 v24 20 21 import ( 22 "encoding/json" 23 "io/ioutil" 24 "strings" 25 26 commonapi "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common" 27 v24 "github.com/IBM-Blockchain/fabric-operator/pkg/apis/orderer/v24" 28 "github.com/IBM-Blockchain/fabric-operator/pkg/util/merge" 29 "github.com/pkg/errors" 30 "sigs.k8s.io/yaml" 31 ) 32 33 type Orderer struct { 34 v24.Orderer `json:",inline"` 35 } 36 37 func (o *Orderer) ToBytes() ([]byte, error) { 38 bytes, err := yaml.Marshal(o) 39 if err != nil { 40 return nil, err 41 } 42 43 return bytes, nil 44 } 45 46 func (o *Orderer) WriteToFile(path string) error { 47 bytes, err := yaml.Marshal(o) 48 if err != nil { 49 return err 50 } 51 52 err = ioutil.WriteFile(path, bytes, 0600) 53 if err != nil { 54 return err 55 } 56 57 return nil 58 } 59 60 func (o *Orderer) MergeWith(newConfig interface{}, usingHSMProxy bool) error { 61 newOrderer := newConfig.(*Orderer) 62 63 if newOrderer != nil { 64 err := merge.WithOverwrite(o, newConfig) 65 if err != nil { 66 return errors.Wrapf(err, "failed to merge orderer configuration overrides") 67 } 68 } 69 70 if o.UsingPKCS11() { 71 o.SetPKCS11Defaults(usingHSMProxy) 72 } 73 74 return nil 75 } 76 77 func (o *Orderer) DeepCopyInto(into *Orderer) { 78 b, err := json.Marshal(o) 79 if err != nil { 80 return 81 } 82 83 err = json.Unmarshal(b, into) 84 if err != nil { 85 return 86 } 87 } 88 89 func (o *Orderer) DeepCopy() *Orderer { 90 if o == nil { 91 return nil 92 } 93 out := new(Orderer) 94 o.DeepCopyInto(out) 95 return out 96 } 97 98 func (o *Orderer) UsingPKCS11() bool { 99 if o.General.BCCSP != nil { 100 if strings.ToLower(o.General.BCCSP.ProviderName) == "pkcs11" { 101 return true 102 } 103 } 104 return false 105 } 106 107 func (o *Orderer) SetPKCS11Defaults(usingHSMProxy bool) { 108 if o.General.BCCSP.PKCS11 == nil { 109 o.General.BCCSP.PKCS11 = &commonapi.PKCS11Opts{} 110 } 111 112 if usingHSMProxy { 113 o.General.BCCSP.PKCS11.Library = "/usr/local/lib/libpkcs11-proxy.so" 114 } 115 116 if o.General.BCCSP.PKCS11.HashFamily == "" { 117 o.General.BCCSP.PKCS11.HashFamily = "SHA2" 118 } 119 120 if o.General.BCCSP.PKCS11.SecLevel == 0 { 121 o.General.BCCSP.PKCS11.SecLevel = 256 122 } 123 } 124 125 func (o *Orderer) SetBCCSPLibrary(library string) { 126 if o.General.BCCSP.PKCS11 == nil { 127 o.General.BCCSP.PKCS11 = &commonapi.PKCS11Opts{} 128 } 129 130 o.General.BCCSP.PKCS11.Library = library 131 } 132 133 func (o *Orderer) SetDefaultKeyStore() { 134 // No-op 135 return 136 } 137 138 func (o *Orderer) GetBCCSPSection() *commonapi.BCCSP { 139 return o.General.BCCSP 140 }