-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.go
178 lines (162 loc) · 4.92 KB
/
configuration.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package filevault
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
)
// Config stores the configuration parameters for a filevault
type Config struct {
TLSCert, TLSKey string
DataRoot, KeyRoot, MetaRoot string
ProdSupportDir string
ProdSupportPubRing string
LogFile string
EmailFrom, EmailTo string
SMTPServer string
SMTPPort int
SecRing string
MasterKeyPassphrase string
MasterKeyFingerprint string
HTTPLog string
HtpasswdFile string
}
// Validate performs some sanity checks on configuration values
func (c Config) Validate() (err error) {
var fi os.FileInfo
// validate key fingerprint
_, err = HexStringToFingerprint(c.MasterKeyFingerprint)
if err != nil {
return
}
// validate TLSCert
if len(c.TLSCert) == 0 {
return errors.New("Missing config param: TLSCert")
}
fi, err = os.Stat(c.TLSCert)
if err != nil {
return fmt.Errorf("Config error in TLSCert '%s': %s", c.TLSCert, err)
}
if fi.IsDir() {
return fmt.Errorf("Config error in TLSCert '%s': expected file path, got directory", c.TLSCert)
}
// validate TLSKey
if len(c.TLSKey) == 0 {
return errors.New("Missing config param: TLSKey")
}
fi, err = os.Stat(c.TLSKey)
if err != nil {
return fmt.Errorf("Config error in TLSKey '%s': %s", c.TLSKey, err)
}
if fi.IsDir() {
return fmt.Errorf("Config error in TLSKey '%s': expected file path, got directory", c.TLSKey)
}
// validate SecRing
if len(c.SecRing) == 0 {
return errors.New("Missing config param: SecRing")
}
fi, err = os.Stat(c.SecRing)
if err != nil {
return fmt.Errorf("Config error in SecRing '%s': %s", c.SecRing, err)
}
if fi.IsDir() {
return fmt.Errorf("Config error in SecRing '%s': expected file path, got directory", c.SecRing)
}
// validate ProdSupportPubRing
if len(c.ProdSupportPubRing) == 0 {
return errors.New("Missing config param: ProdSupportPubRing")
}
fi, err = os.Stat(c.ProdSupportPubRing)
if err != nil {
return fmt.Errorf("Config error in ProdSupportPubRing '%s': %s", c.ProdSupportPubRing, err)
}
if fi.IsDir() {
return fmt.Errorf("Config error in ProdSupportPubRing '%s': expected file path, got directory", c.ProdSupportPubRing)
}
// validate DataRoot
if len(c.DataRoot) == 0 {
return errors.New("Missing config param: DataRoot")
}
fi, err = os.Stat(c.DataRoot)
if err != nil {
// doesn't exist... can we create it?
if err = os.MkdirAll(c.DataRoot, 0744); err != nil {
return fmt.Errorf("Config error in DataRoot '%s': %s", c.DataRoot, err)
}
} else {
if !fi.IsDir() {
return fmt.Errorf("Config error in DataRoot '%s': expected directory, got file path", c.DataRoot)
}
}
// validate ProdSupportDir
if len(c.ProdSupportDir) == 0 {
return errors.New("Missing config param: ProdSupportDir")
}
fi, err = os.Stat(c.ProdSupportDir)
if err != nil {
// doesn't exist... can we create it?
if err = os.MkdirAll(c.ProdSupportDir, 0744); err != nil {
return fmt.Errorf("Config error in ProdSupportDir '%s': %s", c.ProdSupportDir, err)
}
} else {
if !fi.IsDir() {
return fmt.Errorf("Config error in ProdSupportDir '%s': expected directory, got file path", c.ProdSupportDir)
}
}
// validate KeyRoot
if len(c.KeyRoot) == 0 {
return errors.New("Missing config param: KeyRoot")
}
fi, err = os.Stat(c.KeyRoot)
if err != nil {
// doesn't exist... can we create it?
if err = os.MkdirAll(c.KeyRoot, 0744); err != nil {
return fmt.Errorf("Config error in KeyRoot '%s': %s", c.KeyRoot, err)
}
} else {
if !fi.IsDir() {
return fmt.Errorf("Config error in KeyRoot '%s': expected directory, got file path", c.KeyRoot)
}
}
// validate MetaRoot
if len(c.MetaRoot) == 0 {
return errors.New("Missing config param: MetaRoot")
}
fi, err = os.Stat(c.MetaRoot)
if err != nil {
// doesn't exist... can we create it?
if err = os.MkdirAll(c.MetaRoot, 0744); err != nil {
return fmt.Errorf("Config error in MetaRoot '%s': %s", c.MetaRoot, err)
}
} else {
if !fi.IsDir() {
return fmt.Errorf("Config error in MetaRoot '%s': expected directory, got file path", c.MetaRoot)
}
}
// validate HTTPLog
if len(c.HTTPLog) > 0 {
fi, err = os.Stat(filepath.Dir(c.HTTPLog))
if err != nil {
// doesn't exist... can we create it?
if err = os.MkdirAll(filepath.Dir(c.HTTPLog), 0744); err != nil {
return fmt.Errorf("Config error in HTTPLog '%s': %s", c.HTTPLog, err)
}
}
}
// validate HtpasswdFile
if len(c.HtpasswdFile) == 0 {
return errors.New("Missing config param: HtpasswdFile")
}
fi, err = os.Stat(c.HtpasswdFile)
if err != nil {
return fmt.Errorf("Config error in HtpasswdFile '%s': %s", c.HtpasswdFile, err)
}
if fi.IsDir() {
return fmt.Errorf("Config error in HtpasswdFile '%s': expected file path, got directory", c.HtpasswdFile)
}
if len(c.MasterKeyPassphrase) == 0 {
log.Println("no passphrase specified for secure keyring")
}
return nil
}