Skip to content

Commit

Permalink
Add a new protocol
Browse files Browse the repository at this point in the history
Co-authored-by: Gérald Croës <gerald@containo.us>
  • Loading branch information
2 people authored and traefiker committed Mar 14, 2019
1 parent 0ca2149 commit 4a68d29
Show file tree
Hide file tree
Showing 231 changed files with 6,890 additions and 4,390 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ _(But if you'd rather configure some of your routes manually, Traefik supports t
- Supports multiple load balancing algorithms
- Provides HTTPS to your microservices by leveraging [Let's Encrypt](https://letsencrypt.org) (wildcard certificates support)
- Circuit breakers, retry
- High Availability with cluster mode (beta)
- See the magic through its clean web UI
- Websocket, HTTP/2, GRPC ready
- Provides metrics (Rest, Prometheus, Datadog, Statsd, InfluxDB)
Expand Down
26 changes: 2 additions & 24 deletions anonymize/anonymize_config_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package anonymize

import (
"crypto/tls"
"os"
"testing"
"time"

"github.com/containous/flaeg/parse"
"github.com/containous/traefik/acme"
"github.com/containous/traefik/config/static"
"github.com/containous/traefik/provider"
"github.com/containous/traefik/provider/acme"
acmeprovider "github.com/containous/traefik/provider/acme"
"github.com/containous/traefik/provider/file"
traefiktls "github.com/containous/traefik/tls"
Expand Down Expand Up @@ -45,14 +44,6 @@ func TestDo_globalConfiguration(t *testing.T) {
IdleTimeout: parse.Duration(111 * time.Second),
},
},
TLS: &traefiktls.TLS{
MinVersion: "foo MinVersion",
CipherSuites: []string{"foo CipherSuites 1", "foo CipherSuites 2", "foo CipherSuites 3"},
ClientCA: traefiktls.ClientCA{
Files: traefiktls.FilesOrContents{"foo ClientCAFiles 1", "foo ClientCAFiles 2", "foo ClientCAFiles 3"},
Optional: false,
},
},
ProxyProtocol: &static.ProxyProtocol{
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
},
Expand All @@ -66,20 +57,12 @@ func TestDo_globalConfiguration(t *testing.T) {
IdleTimeout: parse.Duration(111 * time.Second),
},
},
TLS: &traefiktls.TLS{
MinVersion: "fii MinVersion",
CipherSuites: []string{"fii CipherSuites 1", "fii CipherSuites 2", "fii CipherSuites 3"},
ClientCA: traefiktls.ClientCA{
Files: traefiktls.FilesOrContents{"fii ClientCAFiles 1", "fii ClientCAFiles 2", "fii ClientCAFiles 3"},
Optional: false,
},
},
ProxyProtocol: &static.ProxyProtocol{
TrustedIPs: []string{"127.0.0.1/32", "192.168.0.1"},
},
},
}
config.ACME = &acme.ACME{
config.ACME = &acme.Configuration{
Email: "acme Email",
Domains: []types.Domain{
{
Expand All @@ -88,16 +71,11 @@ func TestDo_globalConfiguration(t *testing.T) {
},
},
Storage: "Storage",
OnDemand: true,
OnHostRule: true,
CAServer: "CAServer",
EntryPoint: "EntryPoint",
DNSChallenge: &acmeprovider.DNSChallenge{Provider: "DNSProvider"},
ACMELogging: true,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
// ...
},
}
config.Providers = &static.Providers{
ProvidersThrottleDuration: parse.Duration(111 * time.Second),
Expand Down
4 changes: 2 additions & 2 deletions anonymize/anonymize_doOnJSON_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func Test_doOnJSON(t *testing.T) {
"DNSProvider": "",
"DelayDontCheckDNS": 0,
"ACMELogging": false,
"TLSConfig": null
"TLSOptions": null
},
"DefaultEntryPoints": [
"https",
Expand Down Expand Up @@ -141,7 +141,7 @@ func Test_doOnJSON(t *testing.T) {
"DNSProvider": "",
"DelayDontCheckDNS": 0,
"ACMELogging": false,
"TLSConfig": null
"TLSOptions": null
},
"DefaultEntryPoints": [
"https",
Expand Down
127 changes: 89 additions & 38 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,51 @@ type jsonRenderer interface {
}

// Append add api routes on a router
func (p Handler) Append(router *mux.Router) {
if p.Debug {
func (h Handler) Append(router *mux.Router) {
if h.Debug {
DebugHandler{}.Append(router)
}

router.Methods(http.MethodGet).Path("/api/providers").HandlerFunc(p.getProvidersHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}").HandlerFunc(p.getProviderHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/routers").HandlerFunc(p.getRoutersHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/routers/{router}").HandlerFunc(p.getRouterHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/middlewares").HandlerFunc(p.getMiddlewaresHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/middlewares/{middleware}").HandlerFunc(p.getMiddlewareHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/services").HandlerFunc(p.getServicesHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/services/{service}").HandlerFunc(p.getServiceHandler)
router.Methods(http.MethodGet).Path("/api/rawdata").HandlerFunc(h.getRawData)
router.Methods(http.MethodGet).Path("/api/providers").HandlerFunc(h.getProvidersHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}").HandlerFunc(h.getProviderHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/routers").HandlerFunc(h.getRoutersHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/routers/{router}").HandlerFunc(h.getRouterHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/middlewares").HandlerFunc(h.getMiddlewaresHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/middlewares/{middleware}").HandlerFunc(h.getMiddlewareHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/services").HandlerFunc(h.getServicesHandler)
router.Methods(http.MethodGet).Path("/api/providers/{provider}/services/{service}").HandlerFunc(h.getServiceHandler)

// FIXME stats
// health route
//router.Methods(http.MethodGet).Path("/health").HandlerFunc(p.getHealthHandler)

version.Handler{}.Append(router)

if p.Dashboard {
DashboardHandler{Assets: p.DashboardAssets}.Append(router)
if h.Dashboard {
DashboardHandler{Assets: h.DashboardAssets}.Append(router)
}
}

func (p Handler) getProvidersHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getRawData(rw http.ResponseWriter, request *http.Request) {
if h.CurrentConfigurations != nil {
currentConfigurations, ok := h.CurrentConfigurations.Get().(config.Configurations)
if !ok {
rw.WriteHeader(http.StatusOK)
return
}
err := templateRenderer.JSON(rw, http.StatusOK, currentConfigurations)
if err != nil {
log.FromContext(request.Context()).Error(err)
http.Error(rw, err.Error(), http.StatusInternalServerError)
}
}
}

func (h Handler) getProvidersHandler(rw http.ResponseWriter, request *http.Request) {
// FIXME handle currentConfiguration
if p.CurrentConfigurations != nil {
currentConfigurations, ok := p.CurrentConfigurations.Get().(config.Configurations)
if h.CurrentConfigurations != nil {
currentConfigurations, ok := h.CurrentConfigurations.Get().(config.Configurations)
if !ok {
rw.WriteHeader(http.StatusOK)
return
Expand All @@ -115,35 +131,40 @@ func (p Handler) getProvidersHandler(rw http.ResponseWriter, request *http.Reque
}
}

func (p Handler) getProviderHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getProviderHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

var routers []ResourceIdentifier
for name := range provider.Routers {
for name := range provider.HTTP.Routers {
routers = append(routers, ResourceIdentifier{
ID: name,
Path: "/api/providers/" + providerID + "/routers",
})
}

var services []ResourceIdentifier
for name := range provider.Services {
for name := range provider.HTTP.Services {
services = append(services, ResourceIdentifier{
ID: name,
Path: "/api/providers/" + providerID + "/services",
})
}

var middlewares []ResourceIdentifier
for name := range provider.Middlewares {
for name := range provider.HTTP.Middlewares {
middlewares = append(middlewares, ResourceIdentifier{
ID: name,
Path: "/api/providers/" + providerID + "/middlewares",
Expand All @@ -159,19 +180,24 @@ func (p Handler) getProviderHandler(rw http.ResponseWriter, request *http.Reques
}
}

func (p Handler) getRoutersHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getRoutersHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

var routers []RouterRepresentation
for name, router := range provider.Routers {
for name, router := range provider.HTTP.Routers {
routers = append(routers, RouterRepresentation{Router: router, ID: name})
}

Expand All @@ -182,19 +208,24 @@ func (p Handler) getRoutersHandler(rw http.ResponseWriter, request *http.Request
}
}

func (p Handler) getRouterHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getRouterHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]
routerID := mux.Vars(request)["router"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

router, ok := provider.Routers[routerID]
if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

router, ok := provider.HTTP.Routers[routerID]
if !ok {
http.NotFound(rw, request)
return
Expand All @@ -207,19 +238,24 @@ func (p Handler) getRouterHandler(rw http.ResponseWriter, request *http.Request)
}
}

func (p Handler) getMiddlewaresHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getMiddlewaresHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

var middlewares []MiddlewareRepresentation
for name, middleware := range provider.Middlewares {
for name, middleware := range provider.HTTP.Middlewares {
middlewares = append(middlewares, MiddlewareRepresentation{Middleware: middleware, ID: name})
}

Expand All @@ -230,19 +266,24 @@ func (p Handler) getMiddlewaresHandler(rw http.ResponseWriter, request *http.Req
}
}

func (p Handler) getMiddlewareHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getMiddlewareHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]
middlewareID := mux.Vars(request)["middleware"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

middleware, ok := provider.Middlewares[middlewareID]
if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

middleware, ok := provider.HTTP.Middlewares[middlewareID]
if !ok {
http.NotFound(rw, request)
return
Expand All @@ -255,19 +296,24 @@ func (p Handler) getMiddlewareHandler(rw http.ResponseWriter, request *http.Requ
}
}

func (p Handler) getServicesHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getServicesHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

var services []ServiceRepresentation
for name, service := range provider.Services {
for name, service := range provider.HTTP.Services {
services = append(services, ServiceRepresentation{Service: service, ID: name})
}

Expand All @@ -278,19 +324,24 @@ func (p Handler) getServicesHandler(rw http.ResponseWriter, request *http.Reques
}
}

func (p Handler) getServiceHandler(rw http.ResponseWriter, request *http.Request) {
func (h Handler) getServiceHandler(rw http.ResponseWriter, request *http.Request) {
providerID := mux.Vars(request)["provider"]
serviceID := mux.Vars(request)["service"]

currentConfigurations := p.CurrentConfigurations.Get().(config.Configurations)
currentConfigurations := h.CurrentConfigurations.Get().(config.Configurations)

provider, ok := currentConfigurations[providerID]
if !ok {
http.NotFound(rw, request)
return
}

service, ok := provider.Services[serviceID]
if provider.HTTP == nil {
http.NotFound(rw, request)
return
}

service, ok := provider.HTTP.Services[serviceID]
if !ok {
http.NotFound(rw, request)
return
Expand Down
Loading

0 comments on commit 4a68d29

Please sign in to comment.