-
Notifications
You must be signed in to change notification settings - Fork 900
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
HACK URI::Generic.build to allow a IPv6 host value. #2172
HACK URI::Generic.build to allow a IPv6 host value. #2172
Conversation
@@ -0,0 +1,39 @@ | |||
require "spec_helper" | |||
|
|||
$:.push(File.expand_path(File.join(File.dirname(__FILE__), %w{.. .. .. util extensions}))) |
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.
You shouldn't need this. require 'util/miq-uri'
should be sufficient for this spec
Looks good to me. Why is this WIP? |
Ok, so it's not technically WIP but I'm not really pleased with it though. I'd like to have this hack yell at us to remove it when it's not needed anymore although I don't know how to do that. Also, it feels like a lot of code to monkey patch one method. The alternative is to re-implement the whole of URI::Generic initialize in a monkey patch and hope that the code within that method doesn't change. I was hoping this code would give someone an idea on a better implementation. |
Can you just throw an else on the outer if and just do a ruby warning or puts something? |
It's when we move to a ruby 2.0.0 patchlevel that's guaranteed to be >= 643 (rpm based ruby is currently 353 with backports of security fixes) or ruby 2.1.6/2.2.0+ on all appliances/dev machines. I'm afraid it's going to be uselessly noisy if I do it in an outside if/else. |
# uri = URI::HTTPS.build(:host => "::1", :path => "/sdk") | ||
# uri.to_s # => "https://[::1]/sdk" | ||
# | ||
if RUBY_VERSION.start_with?("2.1") || (RUBY_VERSION == "2.0.0" && RUBY_PATCHLEVEL < 643) |
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.
Rather than doing explicit version checking, we could do:
def supports_ipv6_on_build?
URI::HTTPS.build(:host => "::1", :path => "/sdk")
true
rescue URI::InvalidComponentError
false
end
if !supports_ipv6_on_build?
# etc
Then we don't have to update this when the 2.1 backport lands.
It's a temporary workaround until ruby/ruby#765 is readily available. As of this writing, ruby 2.0.0p643 and ruby 2.2.0 have this fixed. Ruby 2.1.5, and ruby 2.0.0p598 and lower don't have this fixed and NEED this hack. Ruby 2.0: https://bugs.ruby-lang.org/issues/10873 (backported and in p643) Ruby 2.1: https://bugs.ruby-lang.org/issues/10875 (backported and not released yet) Ruby 2.2: https://bugs.ruby-lang.org/issues/10874 (backported and in 2.2.0) Workaround before this hack: ```ruby # Don't pass :host => "::1" to .build as it throws URI::InvalidComponentError uri = URI::HTTPS.build(:path => "/sdk") uri.hostname = "::1" uri.to_s # => "https://[::1]/sdk" ``` After this hack the caller doesn't need to know to use [::1] or hostname= method: ```ruby uri = URI::HTTPS.build(:host => "::1", :path => "/sdk") uri.to_s # => "https://[::1]/sdk" ```
0b36065
to
aa33f55
Compare
Checked commit jrafanie@aa33f55 with rubocop 0.27.1 lib/spec/util/extensions/miq-uri_spec.rb
lib/util/extensions/miq-uri.rb
|
@@ -0,0 +1,38 @@ | |||
require "spec_helper" | |||
|
|||
require 'util/extensions/miq-uri' |
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.
Thanks @Fryguy, fixed here.
@jrafanie Did you still want to add the "yelling at us to remove the patch" code? |
@Fryguy we can't easily do it since upstream will constantly yell while downstream wouldn't. I'll have to remember somehow. |
BUMP @Fryguy @tenderlove please review/merge... to clarify... upstream appliances now use ruby 2.0.0p643(a fixed ruby), some developers may also be using a ruby that would have this fixed, meanwhile, downstream appliances most likely won't be at a "fixed" ruby version for months, therefore yelling at developers would be useless because we still need this hack... until we don't. |
HACK URI::Generic.build to allow a IPv6 host value.
The backport in ManageIQ#2172 enables us to use the fixed syntax now.
It's a temporary workaround until ruby/ruby#765 is
readily available. As of this writing, ruby 2.0.0p643 and ruby 2.2.0 have this fixed.
Ruby 2.1.5, and ruby 2.0.0p598 and lower don't have this fixed and NEED this hack.
Ruby 2.0: https://bugs.ruby-lang.org/issues/10873 (backported and in p643)
Ruby 2.1: https://bugs.ruby-lang.org/issues/10875 (backported and not released yet)
Ruby 2.2: https://bugs.ruby-lang.org/issues/10874 (backported and in 2.2.0)
Workaround before this hack:
After this hack the caller doesn't need to know to use [::1] or hostname= method:
This enables us to use the fixed URI::Generic.build API now and clean up 60c8f7f, 01cb19a, 5cf1f30, e806c46 and any other place we may do this in the future.
cc @matthewd @tenderlove @Fryguy @blomquisg @abonas