mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	chore(web): Improve error message for invalid SSL configuration
This commit is contained in:
		@@ -7,6 +7,8 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"gopkg.in/macaron.v1"
 | 
			
		||||
 | 
			
		||||
	"golang.org/x/sync/errgroup"
 | 
			
		||||
 | 
			
		||||
	"github.com/grafana/grafana/pkg/api"
 | 
			
		||||
@@ -89,7 +91,7 @@ func (g *GrafanaServerImpl) startHttpServer() {
 | 
			
		||||
	case setting.HTTP:
 | 
			
		||||
		err = http.ListenAndServe(listenAddr, m)
 | 
			
		||||
	case setting.HTTPS:
 | 
			
		||||
		err = http.ListenAndServeTLS(listenAddr, setting.CertFile, setting.KeyFile, m)
 | 
			
		||||
		err = ListenAndServeTLS(listenAddr, setting.CertFile, setting.KeyFile, m)
 | 
			
		||||
	default:
 | 
			
		||||
		g.log.Error("Invalid protocol", "protocol", setting.Protocol)
 | 
			
		||||
		g.Shutdown(1, "Startup failed")
 | 
			
		||||
@@ -113,6 +115,26 @@ func (g *GrafanaServerImpl) Shutdown(code int, reason string) {
 | 
			
		||||
	os.Exit(code)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ListenAndServeTLS(listenAddr, certfile, keyfile string, m *macaron.Macaron) error {
 | 
			
		||||
	if certfile == "" {
 | 
			
		||||
		return fmt.Errorf("cert_file cannot be empty when using HTTPS")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if keyfile == "" {
 | 
			
		||||
		return fmt.Errorf("cert_key cannot be empty when using HTTPS")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, err := os.Stat(setting.CertFile); os.IsNotExist(err) {
 | 
			
		||||
		return fmt.Errorf(`Cannot find SSL cert_file at %v`, setting.CertFile)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, err := os.Stat(setting.KeyFile); os.IsNotExist(err) {
 | 
			
		||||
		return fmt.Errorf(`Cannot find SSL key_file at %v`, setting.KeyFile)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return http.ListenAndServeTLS(listenAddr, setting.CertFile, setting.KeyFile, m)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// implement context.Context
 | 
			
		||||
func (g *GrafanaServerImpl) Deadline() (deadline time.Time, ok bool) {
 | 
			
		||||
	return g.context.Deadline()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user