github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/initializer/ca/config/ca.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 config
    20  
    21  import (
    22  	"path/filepath"
    23  )
    24  
    25  func (c *Config) ParseCABlock() (map[string][]byte, error) {
    26  	log.Info("Parsing CA block")
    27  
    28  	if c.caCrypto == nil {
    29  		c.caCrypto = map[string][]byte{}
    30  	}
    31  
    32  	certFile := c.ServerConfig.CAConfig.CA.Certfile
    33  	keyFile := c.ServerConfig.CAConfig.CA.Keyfile
    34  
    35  	if certFile == "" && keyFile == "" {
    36  		return nil, nil
    37  	}
    38  
    39  	err := c.HandleCertInput(certFile, "cert.pem", c.caCrypto)
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  	c.ServerConfig.CAConfig.CA.Certfile = filepath.Join(c.HomeDir, "cert.pem")
    44  
    45  	err = c.HandleKeyInput(keyFile, "key.pem", c.caCrypto)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	c.ServerConfig.CAConfig.CA.Keyfile = filepath.Join(c.HomeDir, "key.pem")
    50  
    51  	chainFile := c.ServerConfig.CAConfig.CA.Chainfile
    52  	if chainFile != "" {
    53  		err := c.HandleCertInput(chainFile, "chain.pem", c.caCrypto)
    54  		if err != nil {
    55  			return nil, err
    56  		}
    57  		c.ServerConfig.CAConfig.CA.Chainfile = filepath.Join(c.HomeDir, "chain.pem")
    58  	}
    59  
    60  	return c.caCrypto, nil
    61  }
    62  
    63  func (c *Config) CAMountPath() {
    64  	c.ServerConfig.CAConfig.CA.Keyfile = filepath.Join(c.MountPath, "key.pem")
    65  	c.ServerConfig.CAConfig.CA.Certfile = filepath.Join(c.MountPath, "cert.pem")
    66  
    67  	chainFile := c.ServerConfig.CAConfig.CA.Chainfile
    68  	if chainFile != "" {
    69  		c.ServerConfig.CAConfig.CA.Chainfile = filepath.Join(c.MountPath, "chain.pem")
    70  	}
    71  }