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