github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/orderer/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 initializer
    20  
    21  import (
    22  	commonapi "github.com/IBM-Blockchain/fabric-operator/pkg/apis/common"
    23  	"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config"
    24  	commonconfig "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/config"
    25  	"github.com/pkg/errors"
    26  )
    27  
    28  type OrdererConfig interface {
    29  	MergeWith(interface{}, bool) error
    30  	ToBytes() ([]byte, error)
    31  	UsingPKCS11() bool
    32  	SetPKCS11Defaults(bool)
    33  	GetBCCSPSection() *commonapi.BCCSP
    34  	SetDefaultKeyStore()
    35  	SetBCCSPLibrary(string)
    36  }
    37  
    38  type Orderer struct {
    39  	Config        OrdererConfig
    40  	Cryptos       *commonconfig.Cryptos
    41  	UsingHSMProxy bool
    42  }
    43  
    44  func (o *Orderer) OverrideConfig(newConfig OrdererConfig) (err error) {
    45  	if newConfig == nil {
    46  		return nil
    47  	}
    48  
    49  	log.Info("Overriding orderer config values from spec")
    50  	err = o.Config.MergeWith(newConfig, o.UsingHSMProxy)
    51  	if err != nil {
    52  		return errors.Wrapf(err, "failed to merge override configuration")
    53  	}
    54  
    55  	return nil
    56  }
    57  
    58  func (o *Orderer) GenerateCrypto() (*commonconfig.CryptoResponse, error) {
    59  	log.Info("Generating orderer's crypto material")
    60  	if o.Cryptos != nil {
    61  		response, err := o.Cryptos.GenerateCryptoResponse()
    62  		if err != nil {
    63  			return nil, err
    64  		}
    65  		return response, nil
    66  	}
    67  
    68  	return &config.CryptoResponse{}, nil
    69  }
    70  
    71  func (o *Orderer) GetConfig() OrdererConfig {
    72  	return o.Config
    73  }