SSL frontend

This commit is contained in:
emile 2015-09-11 16:48:52 +02:00
parent 91f95f4fa2
commit cc88e28213
3 changed files with 19 additions and 13 deletions

View file

@ -1,12 +1,10 @@
# /træfɪk/ # /træfɪk/
* Logs
* Default configuration values * Default configuration values
* Retry with streams * Retry with streams
* Static files * Static files
* Licence * Licence
* Add traefik.indlude all/enabled policy * Add traefik.indlude all/enabled policy
* SSL frontend support
* SSL backends support * SSL backends support
* Consul support * Consul support
* README * README
@ -24,3 +22,5 @@
* ~~Weights~~ * ~~Weights~~
* ~~Filter traefik.enabled=false apps~~ * ~~Filter traefik.enabled=false apps~~
* ~~Filter no exposed port apps~~ * ~~Filter no exposed port apps~~
* ~~Logs~~
* ~~SSL frontend support~~

View file

@ -6,6 +6,7 @@ type GlobalConfiguration struct {
AccessLogsFile string AccessLogsFile string
TraefikLogsFile string TraefikLogsFile string
TraefikLogsStdout bool TraefikLogsStdout bool
CertFile, KeyFile string
LogLevel string LogLevel string
Docker *DockerProvider Docker *DockerProvider
File *FileProvider File *FileProvider

View file

@ -39,11 +39,12 @@ func main() {
if err != nil { if err != nil {
log.Fatal("Error getting level", err) log.Fatal("Error getting level", err)
} }
if (len(gloablConfiguration.TraefikLogsFile) > 0 ){
if (len(gloablConfiguration.TraefikLogsFile) > 0 ) {
fi, err := os.OpenFile(gloablConfiguration.TraefikLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) fi, err := os.OpenFile(gloablConfiguration.TraefikLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil { if err != nil {
log.Fatal("Error opening file", err) log.Fatal("Error opening file", err)
}else{ }else {
logBackend := logging.NewLogBackend(fi, "", 0) logBackend := logging.NewLogBackend(fi, "", 0)
logBackendFormatter := logging.NewBackendFormatter(logBackend, logging.GlogFormatter) logBackendFormatter := logging.NewBackendFormatter(logBackend, logging.GlogFormatter)
logBackendLeveled := logging.AddModuleLevel(logBackend) logBackendLeveled := logging.AddModuleLevel(logBackend)
@ -51,7 +52,7 @@ func main() {
backends = append(backends, logBackendFormatter) backends = append(backends, logBackendFormatter)
} }
} }
if (gloablConfiguration.TraefikLogsStdout){ if (gloablConfiguration.TraefikLogsStdout) {
logBackend := logging.NewLogBackend(os.Stdout, "", 0) logBackend := logging.NewLogBackend(os.Stdout, "", 0)
logBackendFormatter := logging.NewBackendFormatter(logBackend, format) logBackendFormatter := logging.NewBackendFormatter(logBackend, format)
logBackendLeveled := logging.AddModuleLevel(logBackend) logBackendLeveled := logging.AddModuleLevel(logBackend)
@ -131,7 +132,11 @@ func main() {
} }
go func() { go func() {
if (len(gloablConfiguration.CertFile) > 0 && len(gloablConfiguration.KeyFile) > 0) {
srv.ListenAndServeTLS(gloablConfiguration.CertFile, gloablConfiguration.KeyFile)
} else {
srv.ListenAndServe() srv.ListenAndServe()
}
}() }()
log.Notice("Started") log.Notice("Started")
<-srv.StopChan() <-srv.StopChan()
@ -145,13 +150,13 @@ func notFoundHandler(w http.ResponseWriter, r *http.Request) {
func LoadDefaultConfig(gloablConfiguration *GlobalConfiguration) *mux.Router { func LoadDefaultConfig(gloablConfiguration *GlobalConfiguration) *mux.Router {
router := mux.NewRouter() router := mux.NewRouter()
if (len(gloablConfiguration.AccessLogsFile) > 0 ){ if (len(gloablConfiguration.AccessLogsFile) > 0 ) {
fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil { if err != nil {
log.Fatal("Error opening file", err) log.Fatal("Error opening file", err)
} }
router.NotFoundHandler = handlers.CombinedLoggingHandler(fi, http.HandlerFunc(notFoundHandler)) router.NotFoundHandler = handlers.CombinedLoggingHandler(fi, http.HandlerFunc(notFoundHandler))
}else{ }else {
router.NotFoundHandler = http.HandlerFunc(notFoundHandler) router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
} }
return router return router
@ -159,13 +164,13 @@ func LoadDefaultConfig(gloablConfiguration *GlobalConfiguration) *mux.Router {
func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfiguration) *mux.Router { func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfiguration) *mux.Router {
router := mux.NewRouter() router := mux.NewRouter()
if (len(gloablConfiguration.AccessLogsFile) > 0 ){ if (len(gloablConfiguration.AccessLogsFile) > 0 ) {
fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil { if err != nil {
log.Fatal("Error opening file", err) log.Fatal("Error opening file", err)
} }
router.NotFoundHandler = handlers.CombinedLoggingHandler(fi, http.HandlerFunc(notFoundHandler)) router.NotFoundHandler = handlers.CombinedLoggingHandler(fi, http.HandlerFunc(notFoundHandler))
}else{ }else {
router.NotFoundHandler = http.HandlerFunc(notFoundHandler) router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
} }
backends := map[string]http.Handler{} backends := map[string]http.Handler{}
@ -193,13 +198,13 @@ func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfigu
log.Debug("Reusing backend", route.Backend) log.Debug("Reusing backend", route.Backend)
} }
for _, muxRoute := range newRoutes { for _, muxRoute := range newRoutes {
if (len(gloablConfiguration.AccessLogsFile) > 0 ){ if (len(gloablConfiguration.AccessLogsFile) > 0 ) {
fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil { if err != nil {
log.Fatal("Error opening file", err) log.Fatal("Error opening file", err)
} }
muxRoute.Handler(handlers.CombinedLoggingHandler(fi, backends[route.Backend])) muxRoute.Handler(handlers.CombinedLoggingHandler(fi, backends[route.Backend]))
}else{ }else {
muxRoute.Handler(backends[route.Backend]) muxRoute.Handler(backends[route.Backend])
} }
err := muxRoute.GetError() err := muxRoute.GetError()