Class: Vagrant::Util::Downloader
- Inherits:
-
Object
- Object
- Vagrant::Util::Downloader
- Defined in:
- lib/vagrant-gsauth/extension/downloader.rb
Instance Method Summary collapse
- #execute_curl_with_gsauth(options, subprocess_options, &data_proc) ⇒ Object (also: #execute_curl)
- #gsauth_download(options, subprocess_options, &data_proc) ⇒ Object
Instance Method Details
#execute_curl_with_gsauth(options, subprocess_options, &data_proc) ⇒ Object Also known as: execute_curl
50 51 52 53 54 |
# File 'lib/vagrant-gsauth/extension/downloader.rb', line 50 def execute_curl_with_gsauth(, , &data_proc) @ui.clear_line if @ui gsauth_download(, , &data_proc) || (raise e) end |
#gsauth_download(options, subprocess_options, &data_proc) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-gsauth/extension/downloader.rb', line 12 def gsauth_download(, , &data_proc) # The URL sent to curl is always the last argument. We have to rely # on this implementation detail because we need to hook into both # HEAD and GET requests. url = .last gs_object = GSAuth::Util.get_object(url) return unless gs_object @logger.info("gsauth: Discovered GS URL: #{@source}") @logger.debug("gsauth: Bucket: #{gs_object.bucket}") @logger.debug("gsauth: Object: #{gs_object.name}") url.replace(gs_object.media_link) @logger.debug("gsauth: Media download link: #{gs_object.media_link}") auth_headers = GSAuth::Util. .insert(0, *auth_headers.map { |k, v| ['-H', "#{k}: #{v}"] }.flatten) execute_curl_without_gsauth(, , &data_proc) rescue Errors::DownloaderError => e if e. =~ /403 Forbidden/ e. << "\n\n" e. << I18n.t('vagrant_gsauth.errors.box_download_forbidden', bucket: gs_object && gs_object.bucket.name) end raise rescue Google::Apis::Error => e raise Errors::DownloaderError, message: e rescue ::Seahorse::Client::NetworkingError => e # Vagrant ignores download errors during e.g. box update checks # because an internet connection isn't necessary if the box is # already downloaded. Vagrant isn't expecting AWS's # Seahorse::Client::NetworkingError, so we cast it to the # DownloaderError Vagrant expects. raise Errors::DownloaderError, message: e end |