Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 1af99f4

Browse files
committed
config: display an error message and abort if user cert missing
1 parent 5bdfe7d commit 1af99f4

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

cmd/root.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,24 @@ func init() {
112112
ourCAPool := x509.NewCertPool()
113113
chainFile, err := ioutil.ReadFile(viper.GetString("certs.cachain"))
114114
if err != nil {
115-
fmt.Println(err)
115+
log.Fatal(err)
116116
}
117117
ok := ourCAPool.AppendCertsFromPEM(chainFile)
118118
if !ok {
119-
fmt.Println("Error when loading certificate chain file")
119+
log.Fatal("Error when loading certificate chain file")
120+
}
121+
122+
// TODO: Check if the client certificate file is present
123+
certFile := viper.GetString("certs.cert")
124+
if _, err = os.Stat(certFile); err != nil {
125+
log.Fatalf("Please download your client certificate from DBHub.io, then update the configuration " +
126+
"file '%s' with its path", cfgFile)
120127
}
121128

122129
// Load a client certificate file
123-
cert, err := tls.LoadX509KeyPair(viper.GetString("certs.cert"), viper.GetString("certs.cert"))
130+
cert, err := tls.LoadX509KeyPair(certFile, certFile)
124131
if err != nil {
125-
fmt.Println(err)
132+
log.Fatal(err)
126133
}
127134

128135
// Load our self signed CA Cert chain, and set TLS1.2 as minimum
@@ -139,7 +146,7 @@ func init() {
139146
var email string
140147
certUser, email, _, err = getUserAndServer()
141148
if err != nil {
142-
fmt.Println(err)
149+
log.Fatal(err)
143150
}
144151
viper.Set("user.email", email)
145152
}

0 commit comments

Comments
 (0)