lib/onering/api.rb in onering-client-0.0.73 vs lib/onering/api.rb in onering-client-0.0.74
- old
+ new
@@ -4,10 +4,11 @@
#
# Don't cry for me...I'm already dead.
#
module OpenSSL
module SSL
+ remove_const :VERIFY_PEER
VERIFY_PEER = VERIFY_NONE
end
end
require 'yaml'
@@ -56,9 +57,39 @@
@_plugins = {}
@_connection_options = options
# load and merge all config file sources
_load_config(@_connection_options[:configfile], @_connection_options.get(:config, {}))
+
+ # source interface specified
+ # !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !!
+ # Due to certain versions of Ruby's Net::HTTP not allowing you explicitly
+ # specify the source IP/interface to use, this horrific monkey patch is
+ # necessary, if not right.
+ #
+ # If at least some of your code doesn't make you feel bottomless shame
+ # then you aren't coding hard enough.
+ #
+ if options.get('config.source').is_a?(String)
+ if options.get('config.source') =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/
+ # insert firing pin into the hack
+ TCPSocket.instance_eval do
+ (class << self; self; end).instance_eval do
+ alias_method :_stock_open, :open
+ attr_writer :_hack_local_ip
+
+ define_method(:open) do |conn_address, conn_port|
+ _stock_open(conn_address, conn_port, @_hack_local_ip)
+ end
+ end
+ end
+
+ # arm the hack
+ TCPSocket._hack_local_ip = options.get('config.source')
+ else
+ raise "Invalid source IP address #{options.get('config.source')}"
+ end
+ end
# set API connectivity details
Onering::API.base_uri @_config.get(:url, DEFAULT_BASE)
# add default parameters
\ No newline at end of file