Load TLS config files from config path before stash home (#1678)

* Load tls files from config or home directory
* Update README
* Require both ssl files if either present
This commit is contained in:
WithoutPants
2021-08-31 19:37:45 +10:00
committed by GitHub
parent 1774a3600c
commit 709d7ce1cc
8 changed files with 84 additions and 65 deletions

View File

@@ -157,18 +157,11 @@ func (e MissingConfigError) Error() string {
return fmt.Sprintf("missing the following mandatory settings: %s", strings.Join(e.missingFields, ", "))
}
func HasTLSConfig() bool {
ret, _ := utils.FileExists(paths.GetSSLCert())
if ret {
ret, _ = utils.FileExists(paths.GetSSLKey())
}
return ret
}
type Instance struct {
cpuProfilePath string
isNewSystem bool
certFile string
keyFile string
sync.RWMutex
//deadlock.RWMutex // for deadlock testing/issues
}
@@ -192,6 +185,26 @@ func (i *Instance) SetConfigFile(fn string) {
viper.SetConfigFile(fn)
}
func (i *Instance) InitTLS() {
configDirectory := i.GetConfigPath()
tlsPaths := []string{
configDirectory,
paths.GetStashHomeDirectory(),
}
i.certFile = utils.FindInPaths(tlsPaths, "stash.crt")
i.keyFile = utils.FindInPaths(tlsPaths, "stash.key")
}
func (i *Instance) GetTLSFiles() (certFile, keyFile string) {
return i.certFile, i.keyFile
}
func (i *Instance) HasTLSConfig() bool {
certFile, keyFile := i.GetTLSFiles()
return certFile != "" && keyFile != ""
}
// GetCPUProfilePath returns the path to the CPU profile file to output
// profiling info to. This is set only via a commandline flag. Returns an
// empty string if not set.