vchs / ruby_vcloud_sdk

Apache License 2.0
15 stars 16 forks source link

upload_catalog_media does not honor https_proxy env var #3

Open gberche-orange opened 10 years ago

gberche-orange commented 10 years ago

The following error is generated when using ruby_vcloud_sdk using cloudfoundry bosh:

The problem is that Net:HTTP only deals with http_proxy and not https_proxy as documented into http://ruby-doc.org/stdlib-2.1.0/libdoc/net/http/rdoc/Net/HTTP.html#method-c-new

Most vCloud URLs being HTTPS, the http requests fail to be transmitted over an HTTP proxy.

    Updating persistent disk            |oooooooo                | 4/11 00:07:52  ETA: 00:11:55/opt/rh/ruby193/root/usr/share/ruby/net/http.rb:762:in `initialize': getaddrinfo: Name or service not known (SocketError)

            from /opt/rh/ruby193/root/usr/share/ruby/net/http.rb:762:in `open'

            from /opt/rh/ruby193/root/usr/share/ruby/net/http.rb:762:in `block in connect'

            from /opt/rh/ruby193/root/usr/share/ruby/timeout.rb:54:in `timeout'

            from /opt/rh/ruby193/root/usr/share/ruby/timeout.rb:99:in `timeout'

            from /opt/rh/ruby193/root/usr/share/ruby/net/http.rb:762:in `connect'

            from /opt/rh/ruby193/root/usr/share/ruby/net/http.rb:755:in `do_start'

            from /opt/rh/ruby193/root/usr/share/ruby/net/http.rb:744:in `start'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/ruby_vcloud_sdk-0.4.8/lib/ruby_vcloud_sdk/connection/file_uploader.rb:9:in `upload'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/ruby_vcloud_sdk-0.4.8/lib/ruby_vcloud_sdk/connection/connection.rb:118:in `put_file'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/ruby_vcloud_sdk-0.4.8/lib/ruby_vcloud_sdk/client.rb:128:in `upload_catalog_media'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/cloud.rb:541:in `block in set_agent_env'

            from /opt/rh/ruby193/root/usr/share/ruby/tmpdir.rb:83:in `mktmpdir'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/cloud.rb:527:in `set_agent_env'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/cloud.rb:285:in `block (2 levels) in attach_disk'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/util.rb:9:in `call'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/util.rb:9:in `block in retry_operation'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/util.rb:7:in `times'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/util.rb:7:in `retry_operation'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/cloud.rb:268:in `block in attach_disk'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_common-1.1761.0/lib/common/thread_formatter.rb:46:in `with_thread_name'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_vcloud_cpi-0.4.9/lib/cloud/vcloud/cloud.rb:267:in `attach_disk'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:313:in `attach_disk'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:330:in `attach_missing_disk'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:345:in `update_persistent_disk'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:138:in `block in create'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:79:in `step'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:137:in `create'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:202:in `update'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:102:in `block in update_deployment'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:92:in `with_lifecycle'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/deployer/instance_manager.rb:102:in `update_deployment'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli_plugin_micro-1.1761.0/lib/bosh/cli/commands/micro.rb:182:in `perform'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli-1.1761.0/lib/cli/command_handler.rb:57:in `run'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli-1.1761.0/lib/cli/runner.rb:56:in `run'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli-1.1761.0/lib/cli/runner.rb:16:in `run'

            from /opt/rh/ruby193/root/usr/local/share/gems/gems/bosh_cli-1.1761.0/bin/bosh:7:in `<top (required)>'

            from /opt/rh/ruby193/root/usr/local/bin/bosh:23:in `load'

            from /opt/rh/ruby193/root/usr/local/bin/bosh:23:in `<main>'

Locally applied workaround in ruby_vcloud_sdk/lib/ruby_vcloud_sdk/connection/file_uploader.rb

       def create_connection(href)
          uri = URI::parse(href)

          proxy_uri = nil
          if uri.scheme == 'https'
            https_proxy = ENV['https_proxy']
            proxy_uri = URI.parse(https_proxy) unless https_proxy.nil?
          else
            #Uri supports also upper case envs and other richer variations
            proxy_uri = uri.find_proxy
          end
          if proxy_uri
            proxy_address = proxy_uri.hostname
            proxy_port = proxy_uri.port
          else
            proxy_address = nil
            proxy_port = nil
          end

          net = Net::HTTP.new(uri.host, uri.port, proxy_address, proxy_port, nil, nil)
          net.use_ssl = uri.is_a?(URI::HTTPS)
          net.verify_mode = OpenSSL::SSL::VERIFY_NONE if net.use_ssl?
          net
        end