github.com/lzy4123/fabric@v2.1.1+incompatible/internal/peer/common/ordererenv.go (about) 1 /* 2 Copyright IBM Corp. 2016-2017 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 package common 7 8 import ( 9 "time" 10 11 "github.com/spf13/cobra" 12 "github.com/spf13/viper" 13 ) 14 15 var ( 16 OrderingEndpoint string 17 tlsEnabled bool 18 clientAuth bool 19 caFile string 20 keyFile string 21 certFile string 22 ordererTLSHostnameOverride string 23 connTimeout time.Duration 24 ) 25 26 // SetOrdererEnv adds orderer-specific settings to the global Viper environment 27 func SetOrdererEnv(cmd *cobra.Command, args []string) { 28 // read in the legacy logging level settings and, if set, 29 // notify users of the FABRIC_LOGGING_SPEC env variable 30 var loggingLevel string 31 if viper.GetString("logging_level") != "" { 32 loggingLevel = viper.GetString("logging_level") 33 } else { 34 loggingLevel = viper.GetString("logging.level") 35 } 36 if loggingLevel != "" { 37 mainLogger.Warning("CORE_LOGGING_LEVEL is no longer supported, please use the FABRIC_LOGGING_SPEC environment variable") 38 } 39 // set the orderer environment from flags 40 viper.Set("orderer.tls.rootcert.file", caFile) 41 viper.Set("orderer.tls.clientKey.file", keyFile) 42 viper.Set("orderer.tls.clientCert.file", certFile) 43 viper.Set("orderer.address", OrderingEndpoint) 44 viper.Set("orderer.tls.serverhostoverride", ordererTLSHostnameOverride) 45 viper.Set("orderer.tls.enabled", tlsEnabled) 46 viper.Set("orderer.tls.clientAuthRequired", clientAuth) 47 viper.Set("orderer.client.connTimeout", connTimeout) 48 } 49 50 // AddOrdererFlags adds flags for orderer-related commands 51 func AddOrdererFlags(cmd *cobra.Command) { 52 flags := cmd.PersistentFlags() 53 54 flags.StringVarP(&OrderingEndpoint, "orderer", "o", "", "Ordering service endpoint") 55 flags.BoolVarP(&tlsEnabled, "tls", "", false, "Use TLS when communicating with the orderer endpoint") 56 flags.BoolVarP(&clientAuth, "clientauth", "", false, 57 "Use mutual TLS when communicating with the orderer endpoint") 58 flags.StringVarP(&caFile, "cafile", "", "", 59 "Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint") 60 flags.StringVarP(&keyFile, "keyfile", "", "", 61 "Path to file containing PEM-encoded private key to use for mutual TLS "+ 62 "communication with the orderer endpoint") 63 flags.StringVarP(&certFile, "certfile", "", "", 64 "Path to file containing PEM-encoded X509 public key to use for "+ 65 "mutual TLS communication with the orderer endpoint") 66 flags.StringVarP(&ordererTLSHostnameOverride, "ordererTLSHostnameOverride", 67 "", "", "The hostname override to use when validating the TLS connection to the orderer.") 68 flags.DurationVarP(&connTimeout, "connTimeout", 69 "", 3*time.Second, "Timeout for client to connect") 70 }