Add marathon label to configure basic auth, similar to docker and rancher providers
This commit is contained in:
parent
c31b4c55c2
commit
4dfbb6d489
4 changed files with 62 additions and 5 deletions
|
@ -163,6 +163,7 @@ func (p *Provider) loadMarathonConfig() *types.Configuration {
|
|||
"hasHealthCheckLabels": p.hasHealthCheckLabels,
|
||||
"getHealthCheckPath": p.getHealthCheckPath,
|
||||
"getHealthCheckInterval": p.getHealthCheckInterval,
|
||||
"getBasicAuth": p.getBasicAuth,
|
||||
}
|
||||
|
||||
applications, err := p.marathonClient.Applications(nil)
|
||||
|
@ -485,6 +486,14 @@ func (p *Provider) getHealthCheckInterval(application marathon.Application) stri
|
|||
return ""
|
||||
}
|
||||
|
||||
func (p *Provider) getBasicAuth(application marathon.Application) []string {
|
||||
if basicAuth, ok := p.getLabel(application, "traefik.frontend.auth.basic"); ok {
|
||||
return strings.Split(basicAuth, ",")
|
||||
}
|
||||
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func processPorts(application marathon.Application, task marathon.Task) (int, error) {
|
||||
if portLabel, ok := (*application.Labels)[labelPort]; ok {
|
||||
port, err := strconv.Atoi(portLabel)
|
||||
|
|
|
@ -98,6 +98,7 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
`frontend-test`: {
|
||||
Backend: "backend-test",
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
EntryPoints: []string{},
|
||||
Routes: map[string]types.Route{
|
||||
`route-host-test`: {
|
||||
|
@ -151,6 +152,7 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
`frontend-testLoadBalancerAndCircuitBreaker.dot`: {
|
||||
Backend: "backend-testLoadBalancerAndCircuitBreaker.dot",
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
EntryPoints: []string{},
|
||||
Routes: map[string]types.Route{
|
||||
`route-host-testLoadBalancerAndCircuitBreaker.dot`: {
|
||||
|
@ -209,6 +211,7 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
`frontend-testMaxConn`: {
|
||||
Backend: "backend-testMaxConn",
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
EntryPoints: []string{},
|
||||
Routes: map[string]types.Route{
|
||||
`route-host-testMaxConn`: {
|
||||
|
@ -264,6 +267,7 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
`frontend-testMaxConnOnlySpecifyAmount`: {
|
||||
Backend: "backend-testMaxConnOnlySpecifyAmount",
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
EntryPoints: []string{},
|
||||
Routes: map[string]types.Route{
|
||||
`route-host-testMaxConnOnlySpecifyAmount`: {
|
||||
|
@ -316,6 +320,7 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
`frontend-testMaxConnOnlyExtractorFunc`: {
|
||||
Backend: "backend-testMaxConnOnlyExtractorFunc",
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
EntryPoints: []string{},
|
||||
Routes: map[string]types.Route{
|
||||
`route-host-testMaxConnOnlyExtractorFunc`: {
|
||||
|
@ -369,6 +374,7 @@ func TestMarathonLoadConfig(t *testing.T) {
|
|||
"frontend-testHealthCheck": {
|
||||
Backend: "backend-testHealthCheck",
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
EntryPoints: []string{},
|
||||
Routes: map[string]types.Route{
|
||||
"route-host-testHealthCheck": {
|
||||
|
@ -1368,7 +1374,7 @@ func TestMarathonGetEntryPoints(t *testing.T) {
|
|||
for _, a := range applications {
|
||||
actual := provider.getEntryPoints(a.application)
|
||||
|
||||
if !reflect.DeepEqual(actual, a.expected) {
|
||||
if !reflect.DeepEqual(a.expected, actual) {
|
||||
t.Fatalf("expected %#v, got %#v", a.expected, actual)
|
||||
}
|
||||
}
|
||||
|
@ -1800,3 +1806,41 @@ func TestParseIndex(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarathonGetBasicAuth(t *testing.T) {
|
||||
provider := &Provider{}
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
application marathon.Application
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
desc: "basic auth label is empty",
|
||||
application: marathon.Application{
|
||||
Labels: &map[string]string{}},
|
||||
expected: []string{},
|
||||
},
|
||||
{
|
||||
desc: "basic auth label is set with user:password",
|
||||
application: marathon.Application{
|
||||
Labels: &map[string]string{
|
||||
"traefik.frontend.auth.basic": "user:password",
|
||||
},
|
||||
},
|
||||
expected: []string{"user:password"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actual := provider.getBasicAuth(c.application)
|
||||
if !reflect.DeepEqual(c.expected, actual) {
|
||||
t.Errorf("expected %q, got %q", c.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue