-
Notifications
You must be signed in to change notification settings - Fork 149
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
Move to explicit method call for Basic Auth credentials in push client #242
Conversation
2ae084f
to
e7111cd
Compare
|
||
@http = Net::HTTP.new(@uri.host, @uri.port) | ||
@http.use_ssl = (@uri.scheme == 'https') | ||
@http.open_timeout = kwargs[:open_timeout] if kwargs[:open_timeout] | ||
@http.read_timeout = kwargs[:read_timeout] if kwargs[:read_timeout] | ||
end | ||
|
||
def basic_auth(user, password) |
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 went with the same method name as Net::HTTP
as it seems like a reasonable one, though I'd also be open to something like set_basic_auth
to make it clearer if you'd prefer.
lib/prometheus/client/push.rb
Outdated
def validate_no_basic_auth!(uri) | ||
if uri.user || uri.password | ||
raise ArgumentError, <<~EOF | ||
Setting Basic Auth credentials in the gateway URL is not supported, please call the `basic_auth` method |
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.
Driveby 😄 maybe a quick usage example here that a developer could just copy-paste?
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.
That's a really good idea. Just added it in!
Also hi Nick 👋🏻
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.
Beautiful error message
79d119d
to
9ab21cd
Compare
While URLs do support passing Basic Auth credentials using the `http://user:password@example.com/` syntax, the username and password in that syntax have to follow the usual rules for URL encoding of characters per RFC 3986 (https://datatracker.ietf.org/doc/html/rfc3986#section-2.1). Rather than place the burden of correctly performing that encoding on users of this gem, we decided to have a separate method for supplying Basic Auth credentials, with no requirement to URL encode the characters in them. Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
9ab21cd
to
3a70f73
Compare
While URLs do support passing Basic Auth credentials using the
http://user:password@example.com/
syntax, the username and password inthat syntax have to follow the usual rules for URL encoding of
characters per RFC 3986
(https://datatracker.ietf.org/doc/html/rfc3986#section-2.1).
Rather than place the burden of correctly performing that encoding on
users of this gem, we decided to have a separate method for supplying
Basic Auth credentials, with no requirement to URL encode the characters
in them.
Since the tests around HTTP requests are extremely heavily mocked, I tested this locally with a real pushgateway configured with one user with
@
in the password and another with:
in it, as well as a more boring password that only used basic latin alphabet characters. All three worked.Maybe at some point we should have some integration tests, but that feels like its own piece of work.
Fixes #170