/tls/ -- add internal usable flag to simplify logic when https needs to be booted up
This commit is contained in:
parent
ba103f9825
commit
3c374b5940
2
app.go
2
app.go
|
@ -179,7 +179,7 @@ func run(args options) {
|
||||||
address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.TLS.PortHTTPS))
|
address := net.JoinHostPort(config.BindHost, strconv.Itoa(config.TLS.PortHTTPS))
|
||||||
// validate current TLS config and update warnings (it could have been loaded from file)
|
// validate current TLS config and update warnings (it could have been loaded from file)
|
||||||
data := validateCertificates(config.TLS)
|
data := validateCertificates(config.TLS)
|
||||||
if data.WarningValidation != "" {
|
if !data.usable {
|
||||||
log.Fatal(data.WarningValidation)
|
log.Fatal(data.WarningValidation)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,9 @@ type tlsConfigStatus struct {
|
||||||
ValidKey bool `yaml:"-" json:"valid_key"`
|
ValidKey bool `yaml:"-" json:"valid_key"`
|
||||||
KeyType string `yaml:"-" json:"key_type,omitempty"`
|
KeyType string `yaml:"-" json:"key_type,omitempty"`
|
||||||
|
|
||||||
|
// is usable? set by validator
|
||||||
|
usable bool
|
||||||
|
|
||||||
// warnings
|
// warnings
|
||||||
Warning string `yaml:"-" json:"warning,omitempty"`
|
Warning string `yaml:"-" json:"warning,omitempty"`
|
||||||
WarningValidation string `yaml:"-" json:"warning_validation,omitempty"`
|
WarningValidation string `yaml:"-" json:"warning_validation,omitempty"`
|
||||||
|
|
|
@ -1088,7 +1088,7 @@ func handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
restartHTTPS := false
|
restartHTTPS := false
|
||||||
data = validateCertificates(data)
|
data = validateCertificates(data)
|
||||||
if data.WarningValidation == "" {
|
if data.usable {
|
||||||
if !reflect.DeepEqual(config.TLS.tlsConfigSettings, data.tlsConfigSettings) {
|
if !reflect.DeepEqual(config.TLS.tlsConfigSettings, data.tlsConfigSettings) {
|
||||||
log.Printf("tls config settings have changed, will restart HTTPS server")
|
log.Printf("tls config settings have changed, will restart HTTPS server")
|
||||||
restartHTTPS = true
|
restartHTTPS = true
|
||||||
|
@ -1259,6 +1259,7 @@ func validateCertificates(data tlsConfig) tlsConfig {
|
||||||
data.WarningValidation = fmt.Sprintf("Invalid certificate or key: %s", err)
|
data.WarningValidation = fmt.Sprintf("Invalid certificate or key: %s", err)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
data.usable = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in New Issue