|
|
@@ -3,7 +3,6 @@ package main
|
|
|
import (
|
|
|
"crypto/tls"
|
|
|
"crypto/x509"
|
|
|
- "encoding/json"
|
|
|
"encoding/pem"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
@@ -16,7 +15,6 @@ import (
|
|
|
"net/url"
|
|
|
"os"
|
|
|
"os/signal"
|
|
|
- "path/filepath"
|
|
|
"runtime/pprof"
|
|
|
"strings"
|
|
|
"time"
|
|
|
@@ -324,68 +322,6 @@ func tlsConfigFromInfo(info TLSInfo) (t TLSConfig, ok bool) {
|
|
|
return t, true
|
|
|
}
|
|
|
|
|
|
-func parseInfo(path string) *Info {
|
|
|
- file, err := os.Open(path)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- info := &Info{}
|
|
|
- defer file.Close()
|
|
|
-
|
|
|
- content, err := ioutil.ReadAll(file)
|
|
|
- if err != nil {
|
|
|
- fatalf("Unable to read info: %v", err)
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- if err = json.Unmarshal(content, &info); err != nil {
|
|
|
- fatalf("Unable to parse info: %v", err)
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- return info
|
|
|
-}
|
|
|
-
|
|
|
-// Get the server info from previous conf file
|
|
|
-// or from the user
|
|
|
-func getInfo(path string) *Info {
|
|
|
-
|
|
|
- // Read in the server info if available.
|
|
|
- infoPath := filepath.Join(path, "info")
|
|
|
-
|
|
|
- // Delete the old configuration if exist
|
|
|
- if force {
|
|
|
- logPath := filepath.Join(path, "log")
|
|
|
- confPath := filepath.Join(path, "conf")
|
|
|
- snapshotPath := filepath.Join(path, "snapshot")
|
|
|
- os.Remove(infoPath)
|
|
|
- os.Remove(logPath)
|
|
|
- os.Remove(confPath)
|
|
|
- os.RemoveAll(snapshotPath)
|
|
|
- }
|
|
|
-
|
|
|
- info := parseInfo(infoPath)
|
|
|
- if info != nil {
|
|
|
- fmt.Printf("Found node configuration in '%s'. Ignoring flags.\n", infoPath)
|
|
|
- return info
|
|
|
- }
|
|
|
-
|
|
|
- info = &argInfo
|
|
|
-
|
|
|
- // Write to file.
|
|
|
- content, _ := json.MarshalIndent(info, "", " ")
|
|
|
- content = []byte(string(content) + "\n")
|
|
|
- if err := ioutil.WriteFile(infoPath, content, 0644); err != nil {
|
|
|
- fatalf("Unable to write info to file: %v", err)
|
|
|
- }
|
|
|
-
|
|
|
- fmt.Printf("Wrote node configuration to '%s'.\n", infoPath)
|
|
|
-
|
|
|
- return info
|
|
|
-}
|
|
|
-
|
|
|
// newCertPool creates x509 certPool and corresponding Auth Type.
|
|
|
// If the given CAfile is valid, add the cert into the pool and verify the clients'
|
|
|
// certs against the cert in the pool.
|