-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add marathon label to configure basic auth #1799
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments left.
provider/marathon/marathon_test.go
Outdated
func TestMarathonGetBasicAuth(t *testing.T) { | ||
provider := &Provider{} | ||
|
||
applications := []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename applications
to cases
?
(I realize you likely just copied this from existing tests; which unfortunately did not pick a better name either.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue to keep the the style the same an in a different PR correct them all at once. Would be confusing to any one else giving a contribution why there are two styles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we run two or three different test styles in marathon_test.go
, things must already be pretty confusing. At this point, I'm only interested in reducing the amount of alignment effort new code brings along until I get my cleanup PR through.
We'll most likely move to cases
everywhere in the not-too-remote future, so it's okay to adjust accordingly in your PR.
provider/marathon/marathon_test.go
Outdated
}, | ||
} | ||
|
||
for _, a := range applications { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please turn this into a group of parallelized sub-tests given proper names? See some of the other Marathon tests where we already employ those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give me a direct example and I can try; this is literally the first goland code (besides basic hello world stuff) I have written; so this is mostly gibberish to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing: Here you go (from an in-flight PR of mine).
Key points:
- Capture the loop variable like
c := c
. - Pass an expressive description/test name as first parameter to
t.Run()
. - Call
t.Parallel()
first thing inside the body oft.Run()
.
If you're interested in a bit of background, I suggest this blog post.
Let me know if you have further questions!
provider/marathon/marathon_test.go
Outdated
for _, a := range applications { | ||
actual := provider.getBasicAuth(a.application) | ||
if !reflect.DeepEqual(actual, a.expected) { | ||
t.Fatalf("expected %q, got %q", a.expected, actual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the expected, actual
order to match the check order one line above, and also to be in line with the preferred order in Go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it should also be fixed here https://github.com/containous/traefik/blob/master/provider/marathon/marathon_test.go#L1371
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! Would you mind taking care of it?
provider/marathon/marathon_test.go
Outdated
for _, a := range applications { | ||
actual := provider.getBasicAuth(a.application) | ||
if !reflect.DeepEqual(actual, a.expected) { | ||
t.Fatalf("expected %q, got %q", a.expected, actual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you've converted the tests into sub-tests, please don't forget to use t.Errorf
instead of t.Fatalf
.
docs/toml.md
Outdated
@@ -1022,6 +1022,7 @@ Labels can be used on containers to override default behaviour: | |||
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend. | |||
- `traefik.frontend.priority=10`: override default frontend priority | |||
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`. | |||
- `traefik.frontend.auth.basic=test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0`: Sets a Basic Auth for that frontend with the users test:test and test2:test2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grammar nit-picks:
- "Sets a Basic Auth" -> "Sets basic authentication"
- "the users test:test and test2:test2" -> "the usernames and passwords test:test and test2:test2, respectively"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to grammar nit-pick then this line should be changed as well since I directly copy pasted it to here https://github.com/containous/traefik/blame/master/docs/toml.md#L915
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree -- please do.
@@ -99,6 +99,7 @@ func TestMarathonLoadConfig(t *testing.T) { | |||
`frontend-test`: { | |||
Backend: "backend-test", | |||
PassHostHeader: true, | |||
BasicAuth: []string{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the unaffected tests fail if we do not add empty BasicAuth
slices?
We should not extend them unless it's required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes its required; all of the tests failed given how they just blind compare the structs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha.
We could still extract the empty BasicAuth
(and EntryPoints
, for that matter) into the test body. I'll take care of that in my cleanup PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment responses. :-)
docs/toml.md
Outdated
@@ -1022,6 +1022,7 @@ Labels can be used on containers to override default behaviour: | |||
- `traefik.frontend.passHostHeader=true`: forward client `Host` header to the backend. | |||
- `traefik.frontend.priority=10`: override default frontend priority | |||
- `traefik.frontend.entryPoints=http,https`: assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`. | |||
- `traefik.frontend.auth.basic=test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0`: Sets a Basic Auth for that frontend with the users test:test and test2:test2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree -- please do.
@@ -99,6 +99,7 @@ func TestMarathonLoadConfig(t *testing.T) { | |||
`frontend-test`: { | |||
Backend: "backend-test", | |||
PassHostHeader: true, | |||
BasicAuth: []string{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha.
We could still extract the empty BasicAuth
(and EntryPoints
, for that matter) into the test body. I'll take care of that in my cleanup PR.
provider/marathon/marathon_test.go
Outdated
func TestMarathonGetBasicAuth(t *testing.T) { | ||
provider := &Provider{} | ||
|
||
applications := []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we run two or three different test styles in marathon_test.go
, things must already be pretty confusing. At this point, I'm only interested in reducing the amount of alignment effort new code brings along until I get my cleanup PR through.
We'll most likely move to cases
everywhere in the not-too-remote future, so it's okay to adjust accordingly in your PR.
provider/marathon/marathon_test.go
Outdated
}, | ||
} | ||
|
||
for _, a := range applications { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing: Here you go (from an in-flight PR of mine).
Key points:
- Capture the loop variable like
c := c
. - Pass an expressive description/test name as first parameter to
t.Run()
. - Call
t.Parallel()
first thing inside the body oft.Run()
.
If you're interested in a bit of background, I suggest this blog post.
Let me know if you have further questions!
provider/marathon/marathon_test.go
Outdated
for _, a := range applications { | ||
actual := provider.getBasicAuth(a.application) | ||
if !reflect.DeepEqual(actual, a.expected) { | ||
t.Fatalf("expected %q, got %q", a.expected, actual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! Would you mind taking care of it?
Note to myself: Answering to review comments by another review apparently produces duplicate comments; at least, that's what it looks like on the UI . :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks a lot for your contribution. 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the base of the PR from v1.3
branch to master
branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the job.
LGTM
Description
Adding in support for configuring basic auth via a marathon label; there are similar functions in docker and the rancher providers.
This addresses the marathon part of #1465