Skip to content

Commit

Permalink
fix ca credhub cert
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHlt committed Feb 8, 2019
1 parent 63ff921 commit f589f79
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *Server) Load() error {
if s.config.Name == "" {
return fmt.Errorf("You must define a name to your backend to not conflict with other backend in credhub.")
}
s.config.CredhubCaCert, err = s.getTlsFilePath(s.config.CredhubCaCert)
s.config.CredhubCaCert, err = s.getTlsPem(s.config.CredhubCaCert)
if err != nil {
return err
}
Expand Down Expand Up @@ -213,6 +213,18 @@ func (s Server) Run() error {
return http.ListenAndServe(servAddr, finalHandler)
}

func (s Server) getTlsPem(tlsConf string) (string, error) {
if tlsConf == "" {
return "", nil
}
_, err := os.Stat(tlsConf)
if err != nil {
return tlsConf, nil
}
b, err := ioutil.ReadFile(tlsConf)
return string(b), err
}

func (s Server) getTlsFilePath(tlsConf string) (string, error) {
if tlsConf == "" {
return "", nil
Expand All @@ -221,9 +233,6 @@ func (s Server) getTlsFilePath(tlsConf string) (string, error) {
if err == nil {
return tlsConf, nil
}
if !os.IsNotExist(err) {
return "", err
}
f, err := ioutil.TempFile("", "terraform-secure-backend")
if err != nil {
return "", err
Expand Down

0 comments on commit f589f79

Please sign in to comment.