/
installer_std_controller.go
63 lines (50 loc) · 1.5 KB
/
installer_std_controller.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
// +build !client
// +build !agent
package cli
import (
"fmt"
"os"
gofig "github.com/akutz/gofig/types"
"github.com/akutz/gotil"
"github.com/rexray/rexray/libstorage/api/context"
apitypes "github.com/rexray/rexray/libstorage/api/types"
"github.com/rexray/rexray/util"
)
func installSelfCert(
ctx apitypes.Context,
config gofig.Config) error {
certPath := config.GetString(apitypes.ConfigTLSCertFile)
keyPath := config.GetString(apitypes.ConfigTLSKeyFile)
if gotil.FileExists(certPath) && gotil.FileExists(keyPath) {
ctx.WithFields(map[string]interface{}{
"certFile": certPath,
"keyFile": keyPath,
}).Debug("not creating certs; files already exist")
return nil
}
pathConfig := context.MustPathConfig(ctx)
certPath = pathConfig.DefaultTLSCertFile
keyPath = pathConfig.DefaultTLSKeyFile
if gotil.FileExists(certPath) && gotil.FileExists(keyPath) {
ctx.WithFields(map[string]interface{}{
"certFile": certPath,
"keyFile": keyPath,
}).Debug("not creating certs; files already exist")
return nil
}
host, err := os.Hostname()
if err != nil {
return fmt.Errorf("get hostname for cert failed: %v", err)
}
ctx.WithFields(map[string]interface{}{
"host": host,
"certFile": certPath,
"keyFile": keyPath,
}).Debug("creating certs")
fmt.Println("generating self-signed certificate...")
if err := util.CreateSelfCert(ctx, certPath, keyPath, host); err != nil {
return fmt.Errorf("cert generation failed: %v", err)
}
fmt.Printf(" %s\n %s\n", certPath, keyPath)
return nil
}