Skip to content
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

Merged
merged 1 commit into from
Jul 7, 2017
Merged

Add marathon label to configure basic auth #1799

merged 1 commit into from
Jul 7, 2017

Conversation

nikore
Copy link
Contributor

@nikore nikore commented Jun 28, 2017

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

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments left.

func TestMarathonGetBasicAuth(t *testing.T) {
provider := &Provider{}

applications := []struct {
Copy link
Contributor

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.)

Copy link
Contributor Author

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

Copy link
Contributor

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.

},
}

for _, a := range applications {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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:

  1. Capture the loop variable like c := c.
  2. Pass an expressive description/test name as first parameter to t.Run().
  3. Call t.Parallel() first thing inside the body of t.Run().

If you're interested in a bit of background, I suggest this blog post.

Let me know if you have further questions!

for _, a := range applications {
actual := provider.getBasicAuth(a.application)
if !reflect.DeepEqual(actual, a.expected) {
t.Fatalf("expected %q, got %q", a.expected, actual)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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?

for _, a := range applications {
actual := provider.getBasicAuth(a.application)
if !reflect.DeepEqual(actual, a.expected) {
t.Fatalf("expected %q, got %q", a.expected, actual)
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grammar nit-picks:

  1. "Sets a Basic Auth" -> "Sets basic authentication"
  2. "the users test:test and test2:test2" -> "the usernames and passwords test:test and test2:test2, respectively"

Copy link
Contributor Author

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

Copy link
Contributor

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{},
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@timoreimann timoreimann left a 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
Copy link
Contributor

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{},
Copy link
Contributor

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.

func TestMarathonGetBasicAuth(t *testing.T) {
provider := &Provider{}

applications := []struct {
Copy link
Contributor

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.

},
}

for _, a := range applications {
Copy link
Contributor

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:

  1. Capture the loop variable like c := c.
  2. Pass an expressive description/test name as first parameter to t.Run().
  3. Call t.Parallel() first thing inside the body of t.Run().

If you're interested in a bit of background, I suggest this blog post.

Let me know if you have further questions!

for _, a := range applications {
actual := provider.getBasicAuth(a.application)
if !reflect.DeepEqual(actual, a.expected) {
t.Fatalf("expected %q, got %q", a.expected, actual)
Copy link
Contributor

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?

@timoreimann
Copy link
Contributor

timoreimann commented Jul 3, 2017

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 . :/

@ldez ldez requested a review from juliens July 6, 2017 23:09
Copy link
Contributor

@timoreimann timoreimann left a 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. 🎉

Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@ldez ldez left a 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.

Copy link
Contributor

@ldez ldez left a 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

@ldez ldez added this to the 1.4 milestone Jul 7, 2017
@ldez ldez merged commit 4dfbb6d into traefik:master Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants