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
Support passing HTTP Auth credentials to event stream #142
Conversation
if err != nil { | ||
return err | ||
} | ||
if r.config.HTTPBasicAuthUser != "" { |
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'm not completely sure if HTTP Basic Auth supports empty usernames with non-empty passwords. When in doubt, we should probably extend the if condition by
|| r.config.HTTPBasicPassword != ""
Would you mind also writing some tests for the new functionality (and the various branches it contains)? Let me know if you need help. |
It also seems like the Debug part in your commit message isn't perfectly fitting. How about changing it to Support passing HTTP Auth credentials to event stream or something like that? |
@timoreimann Thanks for your advice。I will write some tests for my commit。 |
@anxueyan |
@timoreimann Sorry for long time to reply. Yes ,you are right, we should add if condition 1.The file client.go, It's also use the if condition "if r.config.HTTPBasicAuthUser != "" " in the function "func (r *marathonClient) apiCall(method, uri string, body, result interface{}) error " (line 247). why this place use this condition? |
@dmajere yes, It's need some help with unit tests. I met the problem mentioned above, and I don't know how to write a good unit tests. Here is an example, is what I write:
It's ok? if not ok ,how should I write? |
@anxueyan ` go func() {
cause we'll be able to return stream object that we'll be able to control in tests |
@anxueyan Regarding your questions:
|
@timoreimann The first question, I am confused why there is not add if condition
Yes, marathon not support password-less credentials or username-less credentials, More powerful evidence can be find in file HttpServer.scala . If you set empty password or empty username for HTTP credentials of marathon, it don't do certification. |
|
@timoreimann It's better to centralize the credentials logic on the request instance . 😊 |
@anxueyan The request instance is from the stdlib ( |
@anxueyan did you have a chance to try out @dmajere's suggested testing approach? Let us know if there's need for clarification, and feel free to push any intermediate results you may have at any point in time. Thanks! |
@timoreimann @anxueyan ... Since its very much related to issue #148 (auth+tls) .. and the PR donovanhide/eventsource#22 has been merged, perhaps we can clean both up with the below ... or similar .. url := fmt.Sprintf("%s/%s", marathon, marathonAPIEventStream)
// step: create a new request for the stream
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
// step: add any basic authentication (perhaps wrap this in a method)
if r.config.HTTPBasicAuthUser != "" && r.config.HTTPBasicPassword != "" {
request.SetBasicAuth(r.config.HTTPBasicAuthUser, r.config.HTTPBasicPassword)
}
// Try to connect to stream, reusing the http client settings
stream, err := eventsource.SubscribeWith("", r.httpClient, request)
if err != nil {
return err
} |
was fixed in PR #156 |
Support passing HTTP Auth credentials to event stream。