vagrant-unbundled 1.8.4.2 → 1.8.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +52 -0
- data/Gemfile.lock +9 -7
- data/RELEASE.md +37 -14
- data/lib/vagrant/action/builtin/box_add.rb +3 -1
- data/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +5 -0
- data/lib/vagrant/box_collection.rb +2 -1
- data/lib/vagrant/bundler.rb +36 -1
- data/lib/vagrant/errors.rb +16 -8
- data/lib/vagrant/plugin/state_file.rb +8 -1
- data/lib/vagrant/util/platform.rb +1 -1
- data/plugins/guests/arch/cap/change_host_name.rb +13 -10
- data/plugins/guests/arch/cap/configure_networks.rb +11 -8
- data/plugins/guests/arch/cap/nfs.rb +35 -0
- data/plugins/guests/arch/cap/rsync.rb +16 -0
- data/plugins/guests/arch/cap/smb.rb +17 -0
- data/plugins/guests/arch/plugin.rb +28 -3
- data/plugins/guests/atomic/cap/change_host_name.rb +13 -10
- data/plugins/guests/atomic/plugin.rb +3 -3
- data/plugins/guests/{netbsd → bsd}/cap/halt.rb +2 -2
- data/plugins/guests/bsd/cap/nfs.rb +49 -0
- data/plugins/guests/bsd/cap/public_key.rb +65 -0
- data/plugins/guests/bsd/cap/virtualbox.rb +16 -0
- data/plugins/guests/bsd/guest.rb +9 -0
- data/plugins/guests/bsd/plugin.rb +40 -0
- data/plugins/guests/coreos/cap/change_host_name.rb +1 -1
- data/plugins/guests/coreos/plugin.rb +4 -4
- data/plugins/guests/darwin/cap/change_host_name.rb +4 -1
- data/plugins/guests/darwin/cap/configure_networks.rb +12 -5
- data/plugins/guests/darwin/cap/halt.rb +3 -1
- data/plugins/guests/darwin/cap/rsync.rb +7 -4
- data/plugins/guests/darwin/plugin.rb +13 -28
- data/plugins/guests/debian/cap/change_host_name.rb +14 -15
- data/plugins/guests/debian/cap/configure_networks.rb +2 -6
- data/plugins/guests/debian/cap/{nfs_client.rb → nfs.rb} +2 -1
- data/plugins/guests/debian/cap/rsync.rb +5 -6
- data/plugins/guests/debian/plugin.rb +8 -8
- data/plugins/guests/esxi/cap/mount_nfs_folder.rb +2 -2
- data/plugins/guests/esxi/plugin.rb +6 -6
- data/plugins/guests/fedora/cap/flavor.rb +1 -1
- data/plugins/guests/fedora/plugin.rb +2 -17
- data/plugins/guests/freebsd/cap/change_host_name.rb +2 -3
- data/plugins/guests/freebsd/cap/rsync.rb +7 -4
- data/plugins/guests/freebsd/plugin.rb +9 -29
- data/plugins/guests/funtoo/plugin.rb +3 -8
- data/plugins/guests/gentoo/cap/change_host_name.rb +21 -6
- data/plugins/guests/gentoo/cap/configure_networks.rb +35 -26
- data/plugins/guests/gentoo/plugin.rb +4 -4
- data/plugins/guests/linux/cap/choose_addressable_ip_addr.rb +2 -3
- data/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +31 -45
- data/plugins/guests/linux/cap/network_interfaces.rb +20 -0
- data/plugins/guests/linux/cap/nfs.rb +57 -0
- data/plugins/guests/linux/cap/public_key.rb +65 -0
- data/plugins/guests/linux/cap/rsync.rb +7 -4
- data/plugins/guests/linux/plugin.rb +30 -25
- data/plugins/guests/mint/plugin.rb +1 -1
- data/plugins/guests/netbsd/plugin.rb +10 -30
- data/plugins/guests/nixos/plugin.rb +5 -5
- data/plugins/guests/omnios/cap/change_host_name.rb +1 -1
- data/plugins/guests/omnios/plugin.rb +4 -4
- data/plugins/guests/openbsd/cap/change_host_name.rb +21 -3
- data/plugins/guests/openbsd/plugin.rb +10 -30
- data/plugins/guests/photon/cap/change_host_name.rb +1 -1
- data/plugins/guests/photon/plugin.rb +4 -4
- data/plugins/guests/pld/cap/change_host_name.rb +1 -1
- data/plugins/guests/pld/plugin.rb +4 -4
- data/plugins/guests/redhat/cap/change_host_name.rb +4 -3
- data/plugins/guests/redhat/cap/configure_networks.rb +1 -24
- data/plugins/guests/redhat/plugin.rb +7 -7
- data/plugins/guests/slackware/cap/change_host_name.rb +1 -1
- data/plugins/guests/slackware/cap/configure_networks.rb +1 -5
- data/plugins/guests/slackware/plugin.rb +3 -3
- data/plugins/guests/smartos/plugin.rb +12 -12
- data/plugins/guests/solaris/plugin.rb +14 -14
- data/plugins/guests/solaris11/plugin.rb +12 -12
- data/plugins/guests/suse/cap/change_host_name.rb +1 -1
- data/plugins/guests/suse/cap/configure_networks.rb +1 -5
- data/plugins/guests/suse/plugin.rb +8 -8
- data/plugins/guests/tinycore/cap/mount_nfs.rb +2 -2
- data/plugins/guests/tinycore/plugin.rb +7 -7
- data/plugins/guests/trisquel/plugin.rb +1 -1
- data/plugins/guests/ubuntu/guest.rb +1 -1
- data/plugins/guests/ubuntu/plugin.rb +1 -6
- data/plugins/guests/windows/plugin.rb +2 -2
- data/plugins/kernel_v2/config/vm.rb +8 -1
- data/plugins/providers/hyperv/scripts/get_vm_status.ps1 +25 -5
- data/plugins/providers/virtualbox/driver/meta.rb +1 -0
- data/plugins/providers/virtualbox/driver/version_5_1.rb +734 -0
- data/plugins/providers/virtualbox/plugin.rb +1 -0
- data/plugins/synced_folders/nfs/synced_folder.rb +10 -2
- data/plugins/synced_folders/rsync/helper.rb +11 -4
- data/scripts/{bintray_upload.sh → sign.sh} +0 -0
- data/templates/guests/arch/network_static.erb +3 -3
- data/templates/guests/arch/network_static6.erb +8 -0
- data/templates/guests/freebsd/network_static6.erb +6 -0
- data/templates/guests/funtoo/network_static6.erb +9 -0
- data/templates/guests/gentoo/network_dhcp.erb +1 -1
- data/templates/guests/gentoo/network_static.erb +4 -4
- data/templates/guests/gentoo/network_static6.erb +7 -0
- data/templates/guests/redhat/network_dhcp.erb +1 -1
- data/templates/guests/redhat/network_static.erb +4 -1
- data/templates/guests/{fedora → redhat}/network_static6.erb +5 -2
- data/templates/locales/en.yml +40 -6
- data/test/unit/plugins/guests/arch/cap/change_host_name_test.rb +6 -6
- data/test/unit/plugins/guests/arch/cap/configure_networks_test.rb +20 -15
- data/test/unit/plugins/guests/arch/cap/rsync_test.rb +30 -0
- data/test/unit/plugins/guests/arch/cap/smb_test.rb +38 -0
- data/test/unit/plugins/guests/atomic/cap/change_host_name_test.rb +9 -8
- data/test/unit/plugins/guests/{freebsd → bsd}/cap/halt_test.rb +11 -10
- data/test/unit/plugins/guests/{freebsd → bsd}/cap/insert_public_key_test.rb +7 -6
- data/test/unit/plugins/guests/bsd/cap/nfs_test.rb +68 -0
- data/test/unit/plugins/guests/coreos/cap/change_host_name_test.rb +5 -5
- data/test/unit/plugins/guests/darwin/cap/change_host_name_test.rb +5 -5
- data/test/unit/plugins/guests/darwin/cap/halt_test.rb +36 -0
- data/test/unit/plugins/guests/debian/cap/change_host_name_test.rb +3 -5
- data/test/unit/plugins/guests/debian/cap/configure_networks_test.rb +13 -9
- data/test/unit/plugins/guests/debian/cap/rsync_test.rb +3 -11
- data/test/unit/plugins/guests/freebsd/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/linux/cap/mount_nfs_test.rb +16 -3
- data/test/unit/plugins/guests/omnios/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/photon/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/pld/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb +4 -3
- data/test/unit/plugins/guests/redhat/cap/configure_networks_test.rb +17 -33
- data/test/unit/plugins/guests/slackware/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/slackware/cap/configure_networks_test.rb +8 -4
- data/test/unit/plugins/guests/suse/cap/change_host_name_test.rb +2 -2
- data/test/unit/plugins/guests/suse/cap/configure_networks_test.rb +13 -16
- data/test/unit/plugins/kernel_v2/config/vm_test.rb +10 -2
- data/test/unit/templates/guests/arch/network_static_test.rb +4 -2
- data/test/unit/templates/guests/gentoo/network_dhcp_test.rb +2 -2
- data/test/unit/templates/guests/gentoo/network_static_test.rb +10 -10
- data/test/unit/templates/guests/redhat/network_dhcp_test.rb +2 -2
- data/test/unit/templates/guests/redhat/network_static_test.rb +9 -9
- data/vagrant.gemspec +3 -3
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/CHANGELOG.md +1 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/CONTRIBUTING.md +38 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/LICENSE.txt +22 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/README.md +297 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/bin/listen +12 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/base.rb +141 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/bsd.rb +106 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/config.rb +26 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/darwin.rb +92 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/linux.rb +106 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/polling.rb +37 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter/windows.rb +98 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/adapter.rb +45 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/backend.rb +38 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/change.rb +76 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/cli.rb +65 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/directory.rb +87 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/config.rb +55 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/loop.rb +117 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/processor.rb +122 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/queue.rb +55 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/file.rb +80 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/fsm.rb +132 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/internals/thread_pool.rb +29 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/listener/config.rb +41 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/listener.rb +133 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/logger.rb +32 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/options.rb +23 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/queue_optimizer.rb +132 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record/entry.rb +64 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record/symlink_detector.rb +39 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/record.rb +118 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/silencer/controller.rb +48 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/silencer.rb +97 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/version.rb +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen.rb +57 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.gitignore +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.rspec +2 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.rubocop-disables.yml +384 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.rubocop.yml +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/.travis.yml +43 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/AUTHORS +98 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/Gemfile +11 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/LICENSE +21 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/README.md +667 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/Rakefile +132 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/bin/restclient +92 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/history.md +310 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/rest-client.rb +2 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/rest_client.rb +2 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/abstract_response.rb +226 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/exceptions.rb +244 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/params_array.rb +72 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/payload.rb +209 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/platform.rb +49 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/raw_response.rb +38 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/request.rb +904 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/resource.rb +168 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/response.rb +80 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/utils.rb +235 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/version.rb +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/windows/root_certs.rb +105 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient/windows.rb +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/lib/restclient.rb +184 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/rest-client.gemspec +31 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/rest-client.windows.gemspec +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/helpers.rb +22 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/_lib.rb +1 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/244b5494.0 +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/81b9768f.0 +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/README +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_digicert/digicert.crt +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/415660c1.0 +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/7651b327.0 +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/README +8 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/capath_verisign/verisign.crt +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/certs/digicert.crt +19 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/certs/verisign.crt +14 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/httpbin_spec.rb +86 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/integration_spec.rb +125 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/integration/request_spec.rb +127 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/spec_helper.rb +29 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/_lib.rb +1 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/abstract_response_spec.rb +145 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/exceptions_spec.rb +108 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/master_shake.jpg +0 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/params_array_spec.rb +36 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/payload_spec.rb +263 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/raw_response_spec.rb +18 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/request2_spec.rb +54 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/request_spec.rb +1265 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/resource_spec.rb +130 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/response_spec.rb +241 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/restclient_spec.rb +79 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/utils_spec.rb +147 -0
- data/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.0/spec/unit/windows/root_certs_spec.rb +22 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.gitignore +10 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.rspec +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.rubocop.yml +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/.travis.yml +11 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/LICENSE.txt +21 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/README.md +151 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/logger.rb +16 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/quiet.rb +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/ruby_version.rb +58 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/travis/ruby_version.rb +59 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/travis.rb +58 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/version.rb +3 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep/warning.rb +97 -0
- data/vendor/bundle/ruby/2.3.0/gems/ruby_dep-1.4.0/lib/ruby_dep.rb +2 -0
- data/vendor/bundle/ruby/2.3.0/specifications/listen-3.1.5.gemspec +44 -0
- data/vendor/bundle/ruby/2.3.0/specifications/rest-client-2.0.0.gemspec +60 -0
- data/vendor/bundle/ruby/2.3.0/specifications/ruby_dep-1.4.0.gemspec +34 -0
- data/version.txt +1 -1
- metadata +147 -44
- data/plugins/guests/darwin/cap/insert_public_key.rb +0 -33
- data/plugins/guests/darwin/cap/mount_nfs_folder.rb +0 -37
- data/plugins/guests/darwin/cap/remove_public_key.rb +0 -21
- data/plugins/guests/fedora/cap/change_host_name.rb +0 -29
- data/plugins/guests/fedora/cap/configure_networks.rb +0 -135
- data/plugins/guests/fedora/cap/network_scripts_dir.rb +0 -15
- data/plugins/guests/freebsd/cap/halt.rb +0 -16
- data/plugins/guests/freebsd/cap/insert_public_key.rb +0 -34
- data/plugins/guests/freebsd/cap/mount_nfs_folder.rb +0 -24
- data/plugins/guests/freebsd/cap/remove_public_key.rb +0 -21
- data/plugins/guests/funtoo/cap/change_host_name.rb +0 -17
- data/plugins/guests/linux/cap/insert_public_key.rb +0 -31
- data/plugins/guests/linux/cap/mount_nfs.rb +0 -50
- data/plugins/guests/linux/cap/nfs_client.rb +0 -11
- data/plugins/guests/linux/cap/remove_public_key.rb +0 -24
- data/plugins/guests/netbsd/cap/insert_public_key.rb +0 -21
- data/plugins/guests/netbsd/cap/mount_nfs_folder.rb +0 -17
- data/plugins/guests/netbsd/cap/remove_public_key.rb +0 -21
- data/plugins/guests/openbsd/cap/halt.rb +0 -16
- data/plugins/guests/openbsd/cap/insert_public_key.rb +0 -21
- data/plugins/guests/openbsd/cap/mount_nfs_folder.rb +0 -14
- data/plugins/guests/openbsd/cap/remove_public_key.rb +0 -21
- data/plugins/guests/ubuntu/cap/change_host_name.rb +0 -52
- data/templates/guests/fedora/network_dhcp.erb +0 -6
- data/templates/guests/fedora/network_static.erb +0 -16
- data/test/unit/plugins/guests/freebsd/cap/mount_nfs_folder_test.rb +0 -53
- data/test/unit/plugins/guests/ubuntu/cap/change_host_name_test.rb +0 -42
- data/test/unit/templates/guests/fedora/network_dhcp_test.rb +0 -21
- data/test/unit/templates/guests/fedora/network_static6_test.rb +0 -25
- data/test/unit/templates/guests/fedora/network_static_test.rb +0 -71
@@ -0,0 +1,72 @@
|
|
1
|
+
module RestClient
|
2
|
+
|
3
|
+
# The ParamsArray class is used to represent an ordered list of [key, value]
|
4
|
+
# pairs. Use this when you need to include a key multiple times or want
|
5
|
+
# explicit control over parameter ordering.
|
6
|
+
#
|
7
|
+
# Most of the request payload & parameter functions normally accept a Hash of
|
8
|
+
# keys => values, which does not allow for duplicated keys.
|
9
|
+
#
|
10
|
+
# @see RestClient::Utils.encode_query_string
|
11
|
+
# @see RestClient::Utils.flatten_params
|
12
|
+
#
|
13
|
+
class ParamsArray
|
14
|
+
include Enumerable
|
15
|
+
|
16
|
+
# @param array [Array<Array>] An array of parameter key,value pairs. These
|
17
|
+
# pairs may be 2 element arrays [key, value] or single element hashes
|
18
|
+
# {key => value}. They may also be single element arrays to represent a
|
19
|
+
# key with no value.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# >> ParamsArray.new([[:foo, 123], [:foo, 456], [:bar, 789]])
|
23
|
+
# This will be encoded as "foo=123&foo=456&bar=789"
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# >> ParamsArray.new({foo: 123, bar: 456})
|
27
|
+
# This is valid, but there's no reason not to just use the Hash directly
|
28
|
+
# instead of a ParamsArray.
|
29
|
+
#
|
30
|
+
#
|
31
|
+
def initialize(array)
|
32
|
+
@array = process_input(array)
|
33
|
+
end
|
34
|
+
|
35
|
+
def each(*args, &blk)
|
36
|
+
@array.each(*args, &blk)
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty?
|
40
|
+
@array.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def process_input(array)
|
46
|
+
array.map {|v| process_pair(v) }
|
47
|
+
end
|
48
|
+
|
49
|
+
# A pair may be:
|
50
|
+
# - A single element hash, e.g. {foo: 'bar'}
|
51
|
+
# - A two element array, e.g. ['foo', 'bar']
|
52
|
+
# - A one element array, e.g. ['foo']
|
53
|
+
#
|
54
|
+
def process_pair(pair)
|
55
|
+
case pair
|
56
|
+
when Hash
|
57
|
+
if pair.length != 1
|
58
|
+
raise ArgumentError.new("Bad # of fields for pair: #{pair.inspect}")
|
59
|
+
end
|
60
|
+
pair.to_a.fetch(0)
|
61
|
+
when Array
|
62
|
+
if pair.length > 2
|
63
|
+
raise ArgumentError.new("Bad # of fields for pair: #{pair.inspect}")
|
64
|
+
end
|
65
|
+
[pair.fetch(0), pair[1]]
|
66
|
+
else
|
67
|
+
# recurse, converting any non-array to an array
|
68
|
+
process_pair(pair.to_a)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
require 'mime/types'
|
6
|
+
|
7
|
+
module RestClient
|
8
|
+
module Payload
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def generate(params)
|
12
|
+
if params.is_a?(String)
|
13
|
+
Base.new(params)
|
14
|
+
elsif params.is_a?(Hash)
|
15
|
+
if params.delete(:multipart) == true || has_file?(params)
|
16
|
+
Multipart.new(params)
|
17
|
+
else
|
18
|
+
UrlEncoded.new(params)
|
19
|
+
end
|
20
|
+
elsif params.respond_to?(:read)
|
21
|
+
Streamed.new(params)
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def has_file?(params)
|
28
|
+
unless params.is_a?(Hash)
|
29
|
+
raise ArgumentError.new("Must pass Hash, not #{params.inspect}")
|
30
|
+
end
|
31
|
+
_has_file?(params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def _has_file?(obj)
|
35
|
+
case obj
|
36
|
+
when Hash, ParamsArray
|
37
|
+
obj.any? {|_, v| _has_file?(v) }
|
38
|
+
when Array
|
39
|
+
obj.any? {|v| _has_file?(v) }
|
40
|
+
else
|
41
|
+
obj.respond_to?(:path) && obj.respond_to?(:read)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Base
|
46
|
+
def initialize(params)
|
47
|
+
build_stream(params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_stream(params)
|
51
|
+
@stream = StringIO.new(params)
|
52
|
+
@stream.seek(0)
|
53
|
+
end
|
54
|
+
|
55
|
+
def read(*args)
|
56
|
+
@stream.read(*args)
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
result = read
|
61
|
+
@stream.seek(0)
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
def headers
|
66
|
+
{'Content-Length' => size.to_s}
|
67
|
+
end
|
68
|
+
|
69
|
+
def size
|
70
|
+
@stream.size
|
71
|
+
end
|
72
|
+
|
73
|
+
alias :length :size
|
74
|
+
|
75
|
+
def close
|
76
|
+
@stream.close unless @stream.closed?
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_s_inspect
|
80
|
+
to_s.inspect
|
81
|
+
end
|
82
|
+
|
83
|
+
def short_inspect
|
84
|
+
(size > 500 ? "#{size} byte(s) length" : to_s_inspect)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
class Streamed < Base
|
90
|
+
def build_stream(params = nil)
|
91
|
+
@stream = params
|
92
|
+
end
|
93
|
+
|
94
|
+
def size
|
95
|
+
if @stream.respond_to?(:size)
|
96
|
+
@stream.size
|
97
|
+
elsif @stream.is_a?(IO)
|
98
|
+
@stream.stat.size
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
alias :length :size
|
103
|
+
end
|
104
|
+
|
105
|
+
class UrlEncoded < Base
|
106
|
+
def build_stream(params = nil)
|
107
|
+
@stream = StringIO.new(Utils.encode_query_string(params))
|
108
|
+
@stream.seek(0)
|
109
|
+
end
|
110
|
+
|
111
|
+
def headers
|
112
|
+
super.merge({'Content-Type' => 'application/x-www-form-urlencoded'})
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class Multipart < Base
|
117
|
+
EOL = "\r\n"
|
118
|
+
|
119
|
+
def build_stream(params)
|
120
|
+
b = '--' + boundary
|
121
|
+
|
122
|
+
@stream = Tempfile.new("RESTClient.Stream.#{rand(1000)}")
|
123
|
+
@stream.binmode
|
124
|
+
@stream.write(b + EOL)
|
125
|
+
|
126
|
+
case params
|
127
|
+
when Hash, ParamsArray
|
128
|
+
x = Utils.flatten_params(params)
|
129
|
+
else
|
130
|
+
x = params
|
131
|
+
end
|
132
|
+
|
133
|
+
last_index = x.length - 1
|
134
|
+
x.each_with_index do |a, index|
|
135
|
+
k, v = * a
|
136
|
+
if v.respond_to?(:read) && v.respond_to?(:path)
|
137
|
+
create_file_field(@stream, k, v)
|
138
|
+
else
|
139
|
+
create_regular_field(@stream, k, v)
|
140
|
+
end
|
141
|
+
@stream.write(EOL + b)
|
142
|
+
@stream.write(EOL) unless last_index == index
|
143
|
+
end
|
144
|
+
@stream.write('--')
|
145
|
+
@stream.write(EOL)
|
146
|
+
@stream.seek(0)
|
147
|
+
end
|
148
|
+
|
149
|
+
def create_regular_field(s, k, v)
|
150
|
+
s.write("Content-Disposition: form-data; name=\"#{k}\"")
|
151
|
+
s.write(EOL)
|
152
|
+
s.write(EOL)
|
153
|
+
s.write(v)
|
154
|
+
end
|
155
|
+
|
156
|
+
def create_file_field(s, k, v)
|
157
|
+
begin
|
158
|
+
s.write("Content-Disposition: form-data;")
|
159
|
+
s.write(" name=\"#{k}\";") unless (k.nil? || k=='')
|
160
|
+
s.write(" filename=\"#{v.respond_to?(:original_filename) ? v.original_filename : File.basename(v.path)}\"#{EOL}")
|
161
|
+
s.write("Content-Type: #{v.respond_to?(:content_type) ? v.content_type : mime_for(v.path)}#{EOL}")
|
162
|
+
s.write(EOL)
|
163
|
+
while (data = v.read(8124))
|
164
|
+
s.write(data)
|
165
|
+
end
|
166
|
+
ensure
|
167
|
+
v.close if v.respond_to?(:close)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def mime_for(path)
|
172
|
+
mime = MIME::Types.type_for path
|
173
|
+
mime.empty? ? 'text/plain' : mime[0].content_type
|
174
|
+
end
|
175
|
+
|
176
|
+
def boundary
|
177
|
+
return @boundary if defined?(@boundary) && @boundary
|
178
|
+
|
179
|
+
# Use the same algorithm used by WebKit: generate 16 random
|
180
|
+
# alphanumeric characters, replacing `+` `/` with `A` `B` (included in
|
181
|
+
# the list twice) to round out the set of 64.
|
182
|
+
s = SecureRandom.base64(12)
|
183
|
+
s.tr!('+/', 'AB')
|
184
|
+
|
185
|
+
@boundary = '----RubyFormBoundary' + s
|
186
|
+
end
|
187
|
+
|
188
|
+
# for Multipart do not escape the keys
|
189
|
+
#
|
190
|
+
# Ostensibly multipart keys MAY be percent encoded per RFC 7578, but in
|
191
|
+
# practice no major browser that I'm aware of uses percent encoding.
|
192
|
+
#
|
193
|
+
# Further discussion of multipart encoding:
|
194
|
+
# https://github.com/rest-client/rest-client/pull/403#issuecomment-156976930
|
195
|
+
#
|
196
|
+
def handle_key key
|
197
|
+
key
|
198
|
+
end
|
199
|
+
|
200
|
+
def headers
|
201
|
+
super.merge({'Content-Type' => %Q{multipart/form-data; boundary=#{boundary}}})
|
202
|
+
end
|
203
|
+
|
204
|
+
def close
|
205
|
+
@stream.close!
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module RestClient
|
4
|
+
module Platform
|
5
|
+
# Return true if we are running on a darwin-based Ruby platform. This will
|
6
|
+
# be false for jruby even on OS X.
|
7
|
+
#
|
8
|
+
# @return [Boolean]
|
9
|
+
def self.mac_mri?
|
10
|
+
RUBY_PLATFORM.include?('darwin')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return true if we are running on Windows.
|
14
|
+
#
|
15
|
+
# @return [Boolean]
|
16
|
+
#
|
17
|
+
def self.windows?
|
18
|
+
# Ruby only sets File::ALT_SEPARATOR on Windows, and the Ruby standard
|
19
|
+
# library uses that to test what platform it's on.
|
20
|
+
!!File::ALT_SEPARATOR
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return true if we are running on jruby.
|
24
|
+
#
|
25
|
+
# @return [Boolean]
|
26
|
+
#
|
27
|
+
def self.jruby?
|
28
|
+
# defined on mri >= 1.9
|
29
|
+
RUBY_ENGINE == 'jruby'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.architecture
|
33
|
+
"#{RbConfig::CONFIG['host_os']} #{RbConfig::CONFIG['host_cpu']}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.ruby_agent_version
|
37
|
+
case RUBY_ENGINE
|
38
|
+
when 'jruby'
|
39
|
+
"jruby/#{JRUBY_VERSION} (#{RUBY_VERSION}p#{RUBY_PATCHLEVEL})"
|
40
|
+
else
|
41
|
+
"#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.default_user_agent
|
46
|
+
"rest-client/#{VERSION} (#{architecture}) #{ruby_agent_version}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RestClient
|
2
|
+
# The response from RestClient on a raw request looks like a string, but is
|
3
|
+
# actually one of these. 99% of the time you're making a rest call all you
|
4
|
+
# care about is the body, but on the occassion you want to fetch the
|
5
|
+
# headers you can:
|
6
|
+
#
|
7
|
+
# RestClient.get('http://example.com').headers[:content_type]
|
8
|
+
#
|
9
|
+
# In addition, if you do not use the response as a string, you can access
|
10
|
+
# a Tempfile object at res.file, which contains the path to the raw
|
11
|
+
# downloaded request body.
|
12
|
+
class RawResponse
|
13
|
+
|
14
|
+
include AbstractResponse
|
15
|
+
|
16
|
+
attr_reader :file, :request
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
"<RestClient::RawResponse @code=#{code.inspect}, @file=#{file.inspect}, @request=#{request.inspect}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(tempfile, net_http_res, request)
|
23
|
+
@net_http_res = net_http_res
|
24
|
+
@file = tempfile
|
25
|
+
@request = request
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
@file.open
|
30
|
+
@file.read
|
31
|
+
end
|
32
|
+
|
33
|
+
def size
|
34
|
+
File.size file
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,904 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'mime/types'
|
3
|
+
require 'cgi'
|
4
|
+
require 'netrc'
|
5
|
+
require 'set'
|
6
|
+
|
7
|
+
module RestClient
|
8
|
+
# This class is used internally by RestClient to send the request, but you can also
|
9
|
+
# call it directly if you'd like to use a method not supported by the
|
10
|
+
# main API. For example:
|
11
|
+
#
|
12
|
+
# RestClient::Request.execute(:method => :head, :url => 'http://example.com')
|
13
|
+
#
|
14
|
+
# Mandatory parameters:
|
15
|
+
# * :method
|
16
|
+
# * :url
|
17
|
+
# Optional parameters (have a look at ssl and/or uri for some explanations):
|
18
|
+
# * :headers a hash containing the request headers
|
19
|
+
# * :cookies may be a Hash{String/Symbol => String} of cookie values, an
|
20
|
+
# Array<HTTP::Cookie>, or an HTTP::CookieJar containing cookies. These
|
21
|
+
# will be added to a cookie jar before the request is sent.
|
22
|
+
# * :user and :password for basic auth, will be replaced by a user/password available in the :url
|
23
|
+
# * :block_response call the provided block with the HTTPResponse as parameter
|
24
|
+
# * :raw_response return a low-level RawResponse instead of a Response
|
25
|
+
# * :max_redirects maximum number of redirections (default to 10)
|
26
|
+
# * :proxy An HTTP proxy URI to use for this request. Any value here
|
27
|
+
# (including nil) will override RestClient.proxy.
|
28
|
+
# * :verify_ssl enable ssl verification, possible values are constants from
|
29
|
+
# OpenSSL::SSL::VERIFY_*, defaults to OpenSSL::SSL::VERIFY_PEER
|
30
|
+
# * :read_timeout and :open_timeout are how long to wait for a response and
|
31
|
+
# to open a connection, in seconds. Pass nil to disable the timeout.
|
32
|
+
# * :timeout can be used to set both timeouts
|
33
|
+
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file, :ssl_ca_path,
|
34
|
+
# :ssl_cert_store, :ssl_verify_callback, :ssl_verify_callback_warnings
|
35
|
+
# * :ssl_version specifies the SSL version for the underlying Net::HTTP connection
|
36
|
+
# * :ssl_ciphers sets SSL ciphers for the connection. See
|
37
|
+
# OpenSSL::SSL::SSLContext#ciphers=
|
38
|
+
# * :before_execution_proc a Proc to call before executing the request. This
|
39
|
+
# proc, like procs from RestClient.before_execution_procs, will be
|
40
|
+
# called with the HTTP request and request params.
|
41
|
+
class Request
|
42
|
+
|
43
|
+
attr_reader :method, :uri, :url, :headers, :payload, :proxy,
|
44
|
+
:user, :password, :read_timeout, :max_redirects,
|
45
|
+
:open_timeout, :raw_response, :processed_headers, :args,
|
46
|
+
:ssl_opts
|
47
|
+
|
48
|
+
# An array of previous redirection responses
|
49
|
+
attr_accessor :redirection_history
|
50
|
+
|
51
|
+
def self.execute(args, & block)
|
52
|
+
new(args).execute(& block)
|
53
|
+
end
|
54
|
+
|
55
|
+
# This is similar to the list now in ruby core, but adds HIGH for better
|
56
|
+
# compatibility (similar to Firefox) and moves AES-GCM cipher suites above
|
57
|
+
# DHE/ECDHE CBC suites (similar to Chromium).
|
58
|
+
# https://github.com/ruby/ruby/commit/699b209cf8cf11809620e12985ad33ae33b119ee
|
59
|
+
#
|
60
|
+
# This list will be used by default if the Ruby global OpenSSL default
|
61
|
+
# ciphers appear to be a weak list.
|
62
|
+
#
|
63
|
+
# TODO: either remove this code or always use it, since Ruby uses a decent
|
64
|
+
# cipher list in versions >= 2.0.
|
65
|
+
#
|
66
|
+
DefaultCiphers = %w{
|
67
|
+
!aNULL
|
68
|
+
!eNULL
|
69
|
+
!EXPORT
|
70
|
+
!SSLV2
|
71
|
+
!LOW
|
72
|
+
|
73
|
+
ECDHE-ECDSA-AES128-GCM-SHA256
|
74
|
+
ECDHE-RSA-AES128-GCM-SHA256
|
75
|
+
ECDHE-ECDSA-AES256-GCM-SHA384
|
76
|
+
ECDHE-RSA-AES256-GCM-SHA384
|
77
|
+
DHE-RSA-AES128-GCM-SHA256
|
78
|
+
DHE-DSS-AES128-GCM-SHA256
|
79
|
+
DHE-RSA-AES256-GCM-SHA384
|
80
|
+
DHE-DSS-AES256-GCM-SHA384
|
81
|
+
AES128-GCM-SHA256
|
82
|
+
AES256-GCM-SHA384
|
83
|
+
ECDHE-ECDSA-AES128-SHA256
|
84
|
+
ECDHE-RSA-AES128-SHA256
|
85
|
+
ECDHE-ECDSA-AES128-SHA
|
86
|
+
ECDHE-RSA-AES128-SHA
|
87
|
+
ECDHE-ECDSA-AES256-SHA384
|
88
|
+
ECDHE-RSA-AES256-SHA384
|
89
|
+
ECDHE-ECDSA-AES256-SHA
|
90
|
+
ECDHE-RSA-AES256-SHA
|
91
|
+
DHE-RSA-AES128-SHA256
|
92
|
+
DHE-RSA-AES256-SHA256
|
93
|
+
DHE-RSA-AES128-SHA
|
94
|
+
DHE-RSA-AES256-SHA
|
95
|
+
DHE-DSS-AES128-SHA256
|
96
|
+
DHE-DSS-AES256-SHA256
|
97
|
+
DHE-DSS-AES128-SHA
|
98
|
+
DHE-DSS-AES256-SHA
|
99
|
+
AES128-SHA256
|
100
|
+
AES256-SHA256
|
101
|
+
AES128-SHA
|
102
|
+
AES256-SHA
|
103
|
+
ECDHE-ECDSA-RC4-SHA
|
104
|
+
ECDHE-RSA-RC4-SHA
|
105
|
+
RC4-SHA
|
106
|
+
|
107
|
+
HIGH
|
108
|
+
+RC4
|
109
|
+
}.join(":")
|
110
|
+
|
111
|
+
# A set of weak default ciphers that we will override by default.
|
112
|
+
WeakDefaultCiphers = Set.new([
|
113
|
+
"ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW",
|
114
|
+
])
|
115
|
+
|
116
|
+
SSLOptionList = %w{client_cert client_key ca_file ca_path cert_store
|
117
|
+
version ciphers verify_callback verify_callback_warnings}
|
118
|
+
|
119
|
+
def inspect
|
120
|
+
"<RestClient::Request @method=#{@method.inspect}, @url=#{@url.inspect}>"
|
121
|
+
end
|
122
|
+
|
123
|
+
def initialize args
|
124
|
+
@method = normalize_method(args[:method])
|
125
|
+
@headers = (args[:headers] || {}).dup
|
126
|
+
if args[:url]
|
127
|
+
@url = process_url_params(normalize_url(args[:url]), headers)
|
128
|
+
else
|
129
|
+
raise ArgumentError, "must pass :url"
|
130
|
+
end
|
131
|
+
|
132
|
+
@user = @password = nil
|
133
|
+
parse_url_with_auth!(url)
|
134
|
+
|
135
|
+
# process cookie arguments found in headers or args
|
136
|
+
@cookie_jar = process_cookie_args!(@uri, @headers, args)
|
137
|
+
|
138
|
+
@payload = Payload.generate(args[:payload])
|
139
|
+
|
140
|
+
@user = args[:user] if args.include?(:user)
|
141
|
+
@password = args[:password] if args.include?(:password)
|
142
|
+
|
143
|
+
if args.include?(:timeout)
|
144
|
+
@read_timeout = args[:timeout]
|
145
|
+
@open_timeout = args[:timeout]
|
146
|
+
end
|
147
|
+
if args.include?(:read_timeout)
|
148
|
+
@read_timeout = args[:read_timeout]
|
149
|
+
end
|
150
|
+
if args.include?(:open_timeout)
|
151
|
+
@open_timeout = args[:open_timeout]
|
152
|
+
end
|
153
|
+
@block_response = args[:block_response]
|
154
|
+
@raw_response = args[:raw_response] || false
|
155
|
+
|
156
|
+
@proxy = args.fetch(:proxy) if args.include?(:proxy)
|
157
|
+
|
158
|
+
@ssl_opts = {}
|
159
|
+
|
160
|
+
if args.include?(:verify_ssl)
|
161
|
+
v_ssl = args.fetch(:verify_ssl)
|
162
|
+
if v_ssl
|
163
|
+
if v_ssl == true
|
164
|
+
# interpret :verify_ssl => true as VERIFY_PEER
|
165
|
+
@ssl_opts[:verify_ssl] = OpenSSL::SSL::VERIFY_PEER
|
166
|
+
else
|
167
|
+
# otherwise pass through any truthy values
|
168
|
+
@ssl_opts[:verify_ssl] = v_ssl
|
169
|
+
end
|
170
|
+
else
|
171
|
+
# interpret all falsy :verify_ssl values as VERIFY_NONE
|
172
|
+
@ssl_opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
|
173
|
+
end
|
174
|
+
else
|
175
|
+
# if :verify_ssl was not passed, default to VERIFY_PEER
|
176
|
+
@ssl_opts[:verify_ssl] = OpenSSL::SSL::VERIFY_PEER
|
177
|
+
end
|
178
|
+
|
179
|
+
SSLOptionList.each do |key|
|
180
|
+
source_key = ('ssl_' + key).to_sym
|
181
|
+
if args.has_key?(source_key)
|
182
|
+
@ssl_opts[key.to_sym] = args.fetch(source_key)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Set some other default SSL options, but only if we have an HTTPS URI.
|
187
|
+
if use_ssl?
|
188
|
+
|
189
|
+
# If there's no CA file, CA path, or cert store provided, use default
|
190
|
+
if !ssl_ca_file && !ssl_ca_path && !@ssl_opts.include?(:cert_store)
|
191
|
+
@ssl_opts[:cert_store] = self.class.default_ssl_cert_store
|
192
|
+
end
|
193
|
+
|
194
|
+
unless @ssl_opts.include?(:ciphers)
|
195
|
+
# If we're on a Ruby version that has insecure default ciphers,
|
196
|
+
# override it with our default list.
|
197
|
+
if WeakDefaultCiphers.include?(
|
198
|
+
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.fetch(:ciphers))
|
199
|
+
@ssl_opts[:ciphers] = DefaultCiphers
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
@tf = nil # If you are a raw request, this is your tempfile
|
205
|
+
@max_redirects = args[:max_redirects] || 10
|
206
|
+
@processed_headers = make_headers headers
|
207
|
+
@args = args
|
208
|
+
|
209
|
+
@before_execution_proc = args[:before_execution_proc]
|
210
|
+
end
|
211
|
+
|
212
|
+
def execute & block
|
213
|
+
# With 2.0.0+, net/http accepts URI objects in requests and handles wrapping
|
214
|
+
# IPv6 addresses in [] for use in the Host request header.
|
215
|
+
transmit uri, net_http_request_class(method).new(uri, processed_headers), payload, & block
|
216
|
+
ensure
|
217
|
+
payload.close if payload
|
218
|
+
end
|
219
|
+
|
220
|
+
# SSL-related options
|
221
|
+
def verify_ssl
|
222
|
+
@ssl_opts.fetch(:verify_ssl)
|
223
|
+
end
|
224
|
+
SSLOptionList.each do |key|
|
225
|
+
define_method('ssl_' + key) do
|
226
|
+
@ssl_opts[key.to_sym]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Return true if the request URI will use HTTPS.
|
231
|
+
#
|
232
|
+
# @return [Boolean]
|
233
|
+
#
|
234
|
+
def use_ssl?
|
235
|
+
uri.is_a?(URI::HTTPS)
|
236
|
+
end
|
237
|
+
|
238
|
+
# Extract the query parameters and append them to the url
|
239
|
+
#
|
240
|
+
# Look through the headers hash for a :params option (case-insensitive,
|
241
|
+
# may be string or symbol). If present and the value is a Hash or
|
242
|
+
# RestClient::ParamsArray, *delete* the key/value pair from the headers
|
243
|
+
# hash and encode the value into a query string. Append this query string
|
244
|
+
# to the URL and return the resulting URL.
|
245
|
+
#
|
246
|
+
# @param [String] url
|
247
|
+
# @param [Hash] headers An options/headers hash to process. Mutation
|
248
|
+
# warning: the params key may be removed if present!
|
249
|
+
#
|
250
|
+
# @return [String] resulting url with query string
|
251
|
+
#
|
252
|
+
def process_url_params(url, headers)
|
253
|
+
url_params = nil
|
254
|
+
|
255
|
+
# find and extract/remove "params" key if the value is a Hash/ParamsArray
|
256
|
+
headers.delete_if do |key, value|
|
257
|
+
if key.to_s.downcase == 'params' &&
|
258
|
+
(value.is_a?(Hash) || value.is_a?(RestClient::ParamsArray))
|
259
|
+
if url_params
|
260
|
+
raise ArgumentError.new("Multiple 'params' options passed")
|
261
|
+
end
|
262
|
+
url_params = value
|
263
|
+
true
|
264
|
+
else
|
265
|
+
false
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
# build resulting URL with query string
|
270
|
+
if url_params && !url_params.empty?
|
271
|
+
query_string = RestClient::Utils.encode_query_string(url_params)
|
272
|
+
|
273
|
+
if url.include?('?')
|
274
|
+
url + '&' + query_string
|
275
|
+
else
|
276
|
+
url + '?' + query_string
|
277
|
+
end
|
278
|
+
else
|
279
|
+
url
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# Render a hash of key => value pairs for cookies in the Request#cookie_jar
|
284
|
+
# that are valid for the Request#uri. This will not necessarily include all
|
285
|
+
# cookies if there are duplicate keys. It's safer to use the cookie_jar
|
286
|
+
# directly if that's a concern.
|
287
|
+
#
|
288
|
+
# @see Request#cookie_jar
|
289
|
+
#
|
290
|
+
# @return [Hash]
|
291
|
+
#
|
292
|
+
def cookies
|
293
|
+
hash = {}
|
294
|
+
|
295
|
+
@cookie_jar.cookies(uri).each do |c|
|
296
|
+
hash[c.name] = c.value
|
297
|
+
end
|
298
|
+
|
299
|
+
hash
|
300
|
+
end
|
301
|
+
|
302
|
+
# @return [HTTP::CookieJar]
|
303
|
+
def cookie_jar
|
304
|
+
@cookie_jar
|
305
|
+
end
|
306
|
+
|
307
|
+
# Render a Cookie HTTP request header from the contents of the @cookie_jar,
|
308
|
+
# or nil if the jar is empty.
|
309
|
+
#
|
310
|
+
# @see Request#cookie_jar
|
311
|
+
#
|
312
|
+
# @return [String, nil]
|
313
|
+
#
|
314
|
+
def make_cookie_header
|
315
|
+
return nil if cookie_jar.nil?
|
316
|
+
|
317
|
+
arr = cookie_jar.cookies(url)
|
318
|
+
return nil if arr.empty?
|
319
|
+
|
320
|
+
return HTTP::Cookie.cookie_value(arr)
|
321
|
+
end
|
322
|
+
|
323
|
+
# Process cookies passed as hash or as HTTP::CookieJar. For backwards
|
324
|
+
# compatibility, these may be passed as a :cookies option masquerading
|
325
|
+
# inside the headers hash. To avoid confusion, if :cookies is passed in
|
326
|
+
# both headers and Request#initialize, raise an error.
|
327
|
+
#
|
328
|
+
# :cookies may be a:
|
329
|
+
# - Hash{String/Symbol => String}
|
330
|
+
# - Array<HTTP::Cookie>
|
331
|
+
# - HTTP::CookieJar
|
332
|
+
#
|
333
|
+
# Passing as a hash:
|
334
|
+
# Keys may be symbols or strings. Values must be strings.
|
335
|
+
# Infer the domain name from the request URI and allow subdomains (as
|
336
|
+
# though '.example.com' had been set in a Set-Cookie header). Assume a
|
337
|
+
# path of '/'.
|
338
|
+
#
|
339
|
+
# RestClient::Request.new(url: 'http://example.com', method: :get,
|
340
|
+
# :cookies => {:foo => 'Value', 'bar' => '123'}
|
341
|
+
# )
|
342
|
+
#
|
343
|
+
# results in cookies as though set from the server by:
|
344
|
+
# Set-Cookie: foo=Value; Domain=.example.com; Path=/
|
345
|
+
# Set-Cookie: bar=123; Domain=.example.com; Path=/
|
346
|
+
#
|
347
|
+
# which yields a client cookie header of:
|
348
|
+
# Cookie: foo=Value; bar=123
|
349
|
+
#
|
350
|
+
# Passing as HTTP::CookieJar, which will be passed through directly:
|
351
|
+
#
|
352
|
+
# jar = HTTP::CookieJar.new
|
353
|
+
# jar.add(HTTP::Cookie.new('foo', 'Value', domain: 'example.com',
|
354
|
+
# path: '/', for_domain: false))
|
355
|
+
#
|
356
|
+
# RestClient::Request.new(..., :cookies => jar)
|
357
|
+
#
|
358
|
+
# @param [URI::HTTP] uri The URI for the request. This will be used to
|
359
|
+
# infer the domain name for cookies passed as strings in a hash. To avoid
|
360
|
+
# this implicit behavior, pass a full cookie jar or use HTTP::Cookie hash
|
361
|
+
# values.
|
362
|
+
# @param [Hash] headers The headers hash from which to pull the :cookies
|
363
|
+
# option. MUTATION NOTE: This key will be deleted from the hash if
|
364
|
+
# present.
|
365
|
+
# @param [Hash] args The options passed to Request#initialize. This hash
|
366
|
+
# will be used as another potential source for the :cookies key.
|
367
|
+
# These args will not be mutated.
|
368
|
+
#
|
369
|
+
# @return [HTTP::CookieJar] A cookie jar containing the parsed cookies.
|
370
|
+
#
|
371
|
+
def process_cookie_args!(uri, headers, args)
|
372
|
+
|
373
|
+
# Avoid ambiguity in whether options from headers or options from
|
374
|
+
# Request#initialize should take precedence by raising ArgumentError when
|
375
|
+
# both are present. Prior versions of rest-client claimed to give
|
376
|
+
# precedence to init options, but actually gave precedence to headers.
|
377
|
+
# Avoid that mess by erroring out instead.
|
378
|
+
if headers[:cookies] && args[:cookies]
|
379
|
+
raise ArgumentError.new(
|
380
|
+
"Cannot pass :cookies in Request.new() and in headers hash")
|
381
|
+
end
|
382
|
+
|
383
|
+
cookies_data = headers.delete(:cookies) || args[:cookies]
|
384
|
+
|
385
|
+
# return copy of cookie jar as is
|
386
|
+
if cookies_data.is_a?(HTTP::CookieJar)
|
387
|
+
return cookies_data.dup
|
388
|
+
end
|
389
|
+
|
390
|
+
# convert cookies hash into a CookieJar
|
391
|
+
jar = HTTP::CookieJar.new
|
392
|
+
|
393
|
+
(cookies_data || []).each do |key, val|
|
394
|
+
|
395
|
+
# Support for Array<HTTP::Cookie> mode:
|
396
|
+
# If key is a cookie object, add it to the jar directly and assert that
|
397
|
+
# there is no separate val.
|
398
|
+
if key.is_a?(HTTP::Cookie)
|
399
|
+
if val
|
400
|
+
raise ArgumentError.new("extra cookie val: #{val.inspect}")
|
401
|
+
end
|
402
|
+
|
403
|
+
jar.add(key)
|
404
|
+
next
|
405
|
+
end
|
406
|
+
|
407
|
+
if key.is_a?(Symbol)
|
408
|
+
key = key.to_s
|
409
|
+
end
|
410
|
+
|
411
|
+
# assume implicit domain from the request URI, and set for_domain to
|
412
|
+
# permit subdomains
|
413
|
+
jar.add(HTTP::Cookie.new(key, val, domain: uri.hostname.downcase,
|
414
|
+
path: '/', for_domain: true))
|
415
|
+
end
|
416
|
+
|
417
|
+
jar
|
418
|
+
end
|
419
|
+
|
420
|
+
# Generate headers for use by a request. Header keys will be stringified
|
421
|
+
# using `#stringify_headers` to normalize them as capitalized strings.
|
422
|
+
#
|
423
|
+
# The final headers consist of:
|
424
|
+
# - default headers from #default_headers
|
425
|
+
# - user_headers provided here
|
426
|
+
# - headers from the payload object (e.g. Content-Type, Content-Lenth)
|
427
|
+
# - cookie headers from #make_cookie_header
|
428
|
+
#
|
429
|
+
# @param [Hash] user_headers User-provided headers to include
|
430
|
+
#
|
431
|
+
# @return [Hash<String, String>] A hash of HTTP headers => values
|
432
|
+
#
|
433
|
+
def make_headers(user_headers)
|
434
|
+
headers = stringify_headers(default_headers).merge(stringify_headers(user_headers))
|
435
|
+
headers.merge!(@payload.headers) if @payload
|
436
|
+
|
437
|
+
# merge in cookies
|
438
|
+
cookies = make_cookie_header
|
439
|
+
if cookies && !cookies.empty?
|
440
|
+
if headers['Cookie']
|
441
|
+
warn('warning: overriding "Cookie" header with :cookies option')
|
442
|
+
end
|
443
|
+
headers['Cookie'] = cookies
|
444
|
+
end
|
445
|
+
|
446
|
+
headers
|
447
|
+
end
|
448
|
+
|
449
|
+
# The proxy URI for this request. If `:proxy` was provided on this request,
|
450
|
+
# use it over `RestClient.proxy`.
|
451
|
+
#
|
452
|
+
# Return false if a proxy was explicitly set and is falsy.
|
453
|
+
#
|
454
|
+
# @return [URI, false, nil]
|
455
|
+
#
|
456
|
+
def proxy_uri
|
457
|
+
if defined?(@proxy)
|
458
|
+
if @proxy
|
459
|
+
URI.parse(@proxy)
|
460
|
+
else
|
461
|
+
false
|
462
|
+
end
|
463
|
+
elsif RestClient.proxy_set?
|
464
|
+
if RestClient.proxy
|
465
|
+
URI.parse(RestClient.proxy)
|
466
|
+
else
|
467
|
+
false
|
468
|
+
end
|
469
|
+
else
|
470
|
+
nil
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
def net_http_object(hostname, port)
|
475
|
+
p_uri = proxy_uri
|
476
|
+
|
477
|
+
if p_uri.nil?
|
478
|
+
# no proxy set
|
479
|
+
Net::HTTP.new(hostname, port)
|
480
|
+
elsif !p_uri
|
481
|
+
# proxy explicitly set to none
|
482
|
+
Net::HTTP.new(hostname, port, nil, nil, nil, nil)
|
483
|
+
else
|
484
|
+
Net::HTTP.new(hostname, port,
|
485
|
+
p_uri.hostname, p_uri.port, p_uri.user, p_uri.password)
|
486
|
+
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
def net_http_request_class(method)
|
491
|
+
Net::HTTP.const_get(method.capitalize, false)
|
492
|
+
end
|
493
|
+
|
494
|
+
def net_http_do_request(http, req, body=nil, &block)
|
495
|
+
if body && body.respond_to?(:read)
|
496
|
+
req.body_stream = body
|
497
|
+
return http.request(req, nil, &block)
|
498
|
+
else
|
499
|
+
return http.request(req, body, &block)
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
# Normalize a URL by adding a protocol if none is present.
|
504
|
+
#
|
505
|
+
# If the string has no HTTP-like scheme (i.e. scheme followed by '//'), a
|
506
|
+
# scheme of 'http' will be added. This mimics the behavior of browsers and
|
507
|
+
# user agents like cURL.
|
508
|
+
#
|
509
|
+
# @param [String] url A URL string.
|
510
|
+
#
|
511
|
+
# @return [String]
|
512
|
+
#
|
513
|
+
def normalize_url(url)
|
514
|
+
url = 'http://' + url unless url.match(%r{\A[a-z][a-z0-9+.-]*://}i)
|
515
|
+
url
|
516
|
+
end
|
517
|
+
|
518
|
+
# Return a certificate store that can be used to validate certificates with
|
519
|
+
# the system certificate authorities. This will probably not do anything on
|
520
|
+
# OS X, which monkey patches OpenSSL in terrible ways to insert its own
|
521
|
+
# validation. On most *nix platforms, this will add the system certifcates
|
522
|
+
# using OpenSSL::X509::Store#set_default_paths. On Windows, this will use
|
523
|
+
# RestClient::Windows::RootCerts to look up the CAs trusted by the system.
|
524
|
+
#
|
525
|
+
# @return [OpenSSL::X509::Store]
|
526
|
+
#
|
527
|
+
def self.default_ssl_cert_store
|
528
|
+
cert_store = OpenSSL::X509::Store.new
|
529
|
+
cert_store.set_default_paths
|
530
|
+
|
531
|
+
# set_default_paths() doesn't do anything on Windows, so look up
|
532
|
+
# certificates using the win32 API.
|
533
|
+
if RestClient::Platform.windows?
|
534
|
+
RestClient::Windows::RootCerts.instance.to_a.uniq.each do |cert|
|
535
|
+
begin
|
536
|
+
cert_store.add_cert(cert)
|
537
|
+
rescue OpenSSL::X509::StoreError => err
|
538
|
+
# ignore duplicate certs
|
539
|
+
raise unless err.message == 'cert already in hash table'
|
540
|
+
end
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
cert_store
|
545
|
+
end
|
546
|
+
|
547
|
+
def self.decode content_encoding, body
|
548
|
+
if (!body) || body.empty?
|
549
|
+
body
|
550
|
+
elsif content_encoding == 'gzip'
|
551
|
+
Zlib::GzipReader.new(StringIO.new(body)).read
|
552
|
+
elsif content_encoding == 'deflate'
|
553
|
+
begin
|
554
|
+
Zlib::Inflate.new.inflate body
|
555
|
+
rescue Zlib::DataError
|
556
|
+
# No luck with Zlib decompression. Let's try with raw deflate,
|
557
|
+
# like some broken web servers do.
|
558
|
+
Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate body
|
559
|
+
end
|
560
|
+
else
|
561
|
+
body
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
def redacted_uri
|
566
|
+
if uri.password
|
567
|
+
sanitized_uri = uri.dup
|
568
|
+
sanitized_uri.password = 'REDACTED'
|
569
|
+
sanitized_uri
|
570
|
+
else
|
571
|
+
uri
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
def redacted_url
|
576
|
+
redacted_uri.to_s
|
577
|
+
end
|
578
|
+
|
579
|
+
def log_request
|
580
|
+
return unless RestClient.log
|
581
|
+
|
582
|
+
out = []
|
583
|
+
|
584
|
+
out << "RestClient.#{method} #{redacted_url.inspect}"
|
585
|
+
out << payload.short_inspect if payload
|
586
|
+
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
|
587
|
+
RestClient.log << out.join(', ') + "\n"
|
588
|
+
end
|
589
|
+
|
590
|
+
def log_response res
|
591
|
+
return unless RestClient.log
|
592
|
+
|
593
|
+
size = if @raw_response
|
594
|
+
File.size(@tf.path)
|
595
|
+
else
|
596
|
+
res.body.nil? ? 0 : res.body.size
|
597
|
+
end
|
598
|
+
|
599
|
+
RestClient.log << "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{size} bytes\n"
|
600
|
+
end
|
601
|
+
|
602
|
+
# Return a hash of headers whose keys are capitalized strings
|
603
|
+
def stringify_headers headers
|
604
|
+
headers.inject({}) do |result, (key, value)|
|
605
|
+
if key.is_a? Symbol
|
606
|
+
key = key.to_s.split(/_/).map(&:capitalize).join('-')
|
607
|
+
end
|
608
|
+
if 'CONTENT-TYPE' == key.upcase
|
609
|
+
result[key] = maybe_convert_extension(value.to_s)
|
610
|
+
elsif 'ACCEPT' == key.upcase
|
611
|
+
# Accept can be composed of several comma-separated values
|
612
|
+
if value.is_a? Array
|
613
|
+
target_values = value
|
614
|
+
else
|
615
|
+
target_values = value.to_s.split ','
|
616
|
+
end
|
617
|
+
result[key] = target_values.map { |ext|
|
618
|
+
maybe_convert_extension(ext.to_s.strip)
|
619
|
+
}.join(', ')
|
620
|
+
else
|
621
|
+
result[key] = value.to_s
|
622
|
+
end
|
623
|
+
result
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
def default_headers
|
628
|
+
{
|
629
|
+
:accept => '*/*',
|
630
|
+
:accept_encoding => 'gzip, deflate',
|
631
|
+
:user_agent => RestClient::Platform.default_user_agent,
|
632
|
+
}
|
633
|
+
end
|
634
|
+
|
635
|
+
private
|
636
|
+
|
637
|
+
# Parse the `@url` string into a URI object and save it as
|
638
|
+
# `@uri`. Also save any basic auth user or password as @user and @password.
|
639
|
+
# If no auth info was passed, check for credentials in a Netrc file.
|
640
|
+
#
|
641
|
+
# @param [String] url A URL string.
|
642
|
+
#
|
643
|
+
# @return [URI]
|
644
|
+
#
|
645
|
+
# @raise URI::InvalidURIError on invalid URIs
|
646
|
+
#
|
647
|
+
def parse_url_with_auth!(url)
|
648
|
+
uri = URI.parse(url)
|
649
|
+
|
650
|
+
if uri.hostname.nil?
|
651
|
+
raise URI::InvalidURIError.new("bad URI(no host provided): #{url}")
|
652
|
+
end
|
653
|
+
|
654
|
+
@user = CGI.unescape(uri.user) if uri.user
|
655
|
+
@password = CGI.unescape(uri.password) if uri.password
|
656
|
+
if !@user && !@password
|
657
|
+
@user, @password = Netrc.read[uri.hostname]
|
658
|
+
end
|
659
|
+
|
660
|
+
@uri = uri
|
661
|
+
end
|
662
|
+
|
663
|
+
def print_verify_callback_warnings
|
664
|
+
warned = false
|
665
|
+
if RestClient::Platform.mac_mri?
|
666
|
+
warn('warning: ssl_verify_callback return code is ignored on OS X')
|
667
|
+
warned = true
|
668
|
+
end
|
669
|
+
if RestClient::Platform.jruby?
|
670
|
+
warn('warning: SSL verify_callback may not work correctly in jruby')
|
671
|
+
warn('see https://github.com/jruby/jruby/issues/597')
|
672
|
+
warned = true
|
673
|
+
end
|
674
|
+
warned
|
675
|
+
end
|
676
|
+
|
677
|
+
# Parse a method and return a normalized string version.
|
678
|
+
#
|
679
|
+
# Raise ArgumentError if the method is falsy, but otherwise do no
|
680
|
+
# validation.
|
681
|
+
#
|
682
|
+
# @param method [String, Symbol]
|
683
|
+
#
|
684
|
+
# @return [String]
|
685
|
+
#
|
686
|
+
# @see net_http_request_class
|
687
|
+
#
|
688
|
+
def normalize_method(method)
|
689
|
+
raise ArgumentError.new('must pass :method') unless method
|
690
|
+
method.to_s.downcase
|
691
|
+
end
|
692
|
+
|
693
|
+
def transmit uri, req, payload, & block
|
694
|
+
|
695
|
+
# We set this to true in the net/http block so that we can distinguish
|
696
|
+
# read_timeout from open_timeout. Now that we only support Ruby 2.0+,
|
697
|
+
# this is only needed for Timeout exceptions thrown outside of Net::HTTP.
|
698
|
+
established_connection = false
|
699
|
+
|
700
|
+
setup_credentials req
|
701
|
+
|
702
|
+
net = net_http_object(uri.hostname, uri.port)
|
703
|
+
net.use_ssl = uri.is_a?(URI::HTTPS)
|
704
|
+
net.ssl_version = ssl_version if ssl_version
|
705
|
+
net.ciphers = ssl_ciphers if ssl_ciphers
|
706
|
+
|
707
|
+
net.verify_mode = verify_ssl
|
708
|
+
|
709
|
+
net.cert = ssl_client_cert if ssl_client_cert
|
710
|
+
net.key = ssl_client_key if ssl_client_key
|
711
|
+
net.ca_file = ssl_ca_file if ssl_ca_file
|
712
|
+
net.ca_path = ssl_ca_path if ssl_ca_path
|
713
|
+
net.cert_store = ssl_cert_store if ssl_cert_store
|
714
|
+
|
715
|
+
# We no longer rely on net.verify_callback for the main SSL verification
|
716
|
+
# because it's not well supported on all platforms (see comments below).
|
717
|
+
# But do allow users to set one if they want.
|
718
|
+
if ssl_verify_callback
|
719
|
+
net.verify_callback = ssl_verify_callback
|
720
|
+
|
721
|
+
# Hilariously, jruby only calls the callback when cert_store is set to
|
722
|
+
# something, so make sure to set one.
|
723
|
+
# https://github.com/jruby/jruby/issues/597
|
724
|
+
if RestClient::Platform.jruby?
|
725
|
+
net.cert_store ||= OpenSSL::X509::Store.new
|
726
|
+
end
|
727
|
+
|
728
|
+
if ssl_verify_callback_warnings != false
|
729
|
+
if print_verify_callback_warnings
|
730
|
+
warn('pass :ssl_verify_callback_warnings => false to silence this')
|
731
|
+
end
|
732
|
+
end
|
733
|
+
end
|
734
|
+
|
735
|
+
if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE
|
736
|
+
warn('WARNING: OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE')
|
737
|
+
warn('This dangerous monkey patch leaves you open to MITM attacks!')
|
738
|
+
warn('Try passing :verify_ssl => false instead.')
|
739
|
+
end
|
740
|
+
|
741
|
+
if defined? @read_timeout
|
742
|
+
if @read_timeout == -1
|
743
|
+
warn 'Deprecated: to disable timeouts, please use nil instead of -1'
|
744
|
+
@read_timeout = nil
|
745
|
+
end
|
746
|
+
net.read_timeout = @read_timeout
|
747
|
+
end
|
748
|
+
if defined? @open_timeout
|
749
|
+
if @open_timeout == -1
|
750
|
+
warn 'Deprecated: to disable timeouts, please use nil instead of -1'
|
751
|
+
@open_timeout = nil
|
752
|
+
end
|
753
|
+
net.open_timeout = @open_timeout
|
754
|
+
end
|
755
|
+
|
756
|
+
RestClient.before_execution_procs.each do |before_proc|
|
757
|
+
before_proc.call(req, args)
|
758
|
+
end
|
759
|
+
|
760
|
+
if @before_execution_proc
|
761
|
+
@before_execution_proc.call(req, args)
|
762
|
+
end
|
763
|
+
|
764
|
+
log_request
|
765
|
+
|
766
|
+
net.start do |http|
|
767
|
+
established_connection = true
|
768
|
+
|
769
|
+
if @block_response
|
770
|
+
net_http_do_request(http, req, payload, &@block_response)
|
771
|
+
else
|
772
|
+
res = net_http_do_request(http, req, payload) { |http_response|
|
773
|
+
fetch_body(http_response)
|
774
|
+
}
|
775
|
+
log_response res
|
776
|
+
process_result res, & block
|
777
|
+
end
|
778
|
+
end
|
779
|
+
rescue EOFError
|
780
|
+
raise RestClient::ServerBrokeConnection
|
781
|
+
rescue Net::OpenTimeout => err
|
782
|
+
raise RestClient::Exceptions::OpenTimeout.new(nil, err)
|
783
|
+
rescue Net::ReadTimeout => err
|
784
|
+
raise RestClient::Exceptions::ReadTimeout.new(nil, err)
|
785
|
+
rescue Timeout::Error, Errno::ETIMEDOUT => err
|
786
|
+
# handling for non-Net::HTTP timeouts
|
787
|
+
if established_connection
|
788
|
+
raise RestClient::Exceptions::ReadTimeout.new(nil, err)
|
789
|
+
else
|
790
|
+
raise RestClient::Exceptions::OpenTimeout.new(nil, err)
|
791
|
+
end
|
792
|
+
|
793
|
+
rescue OpenSSL::SSL::SSLError => error
|
794
|
+
# TODO: deprecate and remove RestClient::SSLCertificateNotVerified and just
|
795
|
+
# pass through OpenSSL::SSL::SSLError directly.
|
796
|
+
#
|
797
|
+
# Exceptions in verify_callback are ignored [1], and jruby doesn't support
|
798
|
+
# it at all [2]. RestClient has to catch OpenSSL::SSL::SSLError and either
|
799
|
+
# re-throw it as is, or throw SSLCertificateNotVerified based on the
|
800
|
+
# contents of the message field of the original exception.
|
801
|
+
#
|
802
|
+
# The client has to handle OpenSSL::SSL::SSLError exceptions anyway, so
|
803
|
+
# we shouldn't make them handle both OpenSSL and RestClient exceptions.
|
804
|
+
#
|
805
|
+
# [1] https://github.com/ruby/ruby/blob/89e70fe8e7/ext/openssl/ossl.c#L238
|
806
|
+
# [2] https://github.com/jruby/jruby/issues/597
|
807
|
+
|
808
|
+
if error.message.include?("certificate verify failed")
|
809
|
+
raise SSLCertificateNotVerified.new(error.message)
|
810
|
+
else
|
811
|
+
raise error
|
812
|
+
end
|
813
|
+
end
|
814
|
+
|
815
|
+
def setup_credentials(req)
|
816
|
+
req.basic_auth(user, password) if user && !headers.has_key?("Authorization")
|
817
|
+
end
|
818
|
+
|
819
|
+
def fetch_body(http_response)
|
820
|
+
if @raw_response
|
821
|
+
# Taken from Chef, which as in turn...
|
822
|
+
# Stolen from http://www.ruby-forum.com/topic/166423
|
823
|
+
# Kudos to _why!
|
824
|
+
@tf = Tempfile.new('rest-client.')
|
825
|
+
@tf.binmode
|
826
|
+
size, total = 0, http_response['Content-Length'].to_i
|
827
|
+
http_response.read_body do |chunk|
|
828
|
+
@tf.write chunk
|
829
|
+
size += chunk.size
|
830
|
+
if RestClient.log
|
831
|
+
if size == 0
|
832
|
+
RestClient.log << "%s %s done (0 length file)\n" % [@method, @url]
|
833
|
+
elsif total == 0
|
834
|
+
RestClient.log << "%s %s (zero content length)\n" % [@method, @url]
|
835
|
+
else
|
836
|
+
RestClient.log << "%s %s %d%% done (%d of %d)\n" % [@method, @url, (size * 100) / total, size, total]
|
837
|
+
end
|
838
|
+
end
|
839
|
+
end
|
840
|
+
@tf.close
|
841
|
+
@tf
|
842
|
+
else
|
843
|
+
http_response.read_body
|
844
|
+
end
|
845
|
+
http_response
|
846
|
+
end
|
847
|
+
|
848
|
+
def process_result res, & block
|
849
|
+
if @raw_response
|
850
|
+
# We don't decode raw requests
|
851
|
+
response = RawResponse.new(@tf, res, self)
|
852
|
+
else
|
853
|
+
decoded = Request.decode(res['content-encoding'], res.body)
|
854
|
+
response = Response.create(decoded, res, self)
|
855
|
+
end
|
856
|
+
|
857
|
+
if block_given?
|
858
|
+
block.call(response, self, res, & block)
|
859
|
+
else
|
860
|
+
response.return!(&block)
|
861
|
+
end
|
862
|
+
|
863
|
+
end
|
864
|
+
|
865
|
+
def parser
|
866
|
+
URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
867
|
+
end
|
868
|
+
|
869
|
+
# Given a MIME type or file extension, return either a MIME type or, if
|
870
|
+
# none is found, the input unchanged.
|
871
|
+
#
|
872
|
+
# >> maybe_convert_extension('json')
|
873
|
+
# => 'application/json'
|
874
|
+
#
|
875
|
+
# >> maybe_convert_extension('unknown')
|
876
|
+
# => 'unknown'
|
877
|
+
#
|
878
|
+
# >> maybe_convert_extension('application/xml')
|
879
|
+
# => 'application/xml'
|
880
|
+
#
|
881
|
+
# @param ext [String]
|
882
|
+
#
|
883
|
+
# @return [String]
|
884
|
+
#
|
885
|
+
def maybe_convert_extension(ext)
|
886
|
+
unless ext =~ /\A[a-zA-Z0-9_@-]+\z/
|
887
|
+
# Don't look up strings unless they look like they could be a file
|
888
|
+
# extension known to mime-types.
|
889
|
+
#
|
890
|
+
# There currently isn't any API public way to look up extensions
|
891
|
+
# directly out of MIME::Types, but the type_for() method only strips
|
892
|
+
# off after a period anyway.
|
893
|
+
return ext
|
894
|
+
end
|
895
|
+
|
896
|
+
types = MIME::Types.type_for(ext)
|
897
|
+
if types.empty?
|
898
|
+
ext
|
899
|
+
else
|
900
|
+
types.first.content_type
|
901
|
+
end
|
902
|
+
end
|
903
|
+
end
|
904
|
+
end
|