Class: S3DownloadStrategy

Inherits:
CurlDownloadStrategy show all
Defined in:
Library/Homebrew/download_strategy.rb

Overview

S3DownloadStrategy downloads tarballs from AWS S3. To use it, add “:using => S3DownloadStrategy” to the URL section of your formula. This download strategy uses AWS access tokens (in the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) to sign the request. This strategy is good in a corporate setting, because it lets you use a private S3 bucket as a repo for internal distribution. (It will work for public buckets as well.)

Instance Attribute Summary

Attributes inherited from CurlDownloadStrategy

#mirrors, #tarball_path, #temporary_path

Attributes inherited from AbstractDownloadStrategy

#cached_location, #meta, #name, #resource, #shutup, #version

Instance Method Summary collapse

Methods inherited from CurlDownloadStrategy

#cached_location, #clear_cache, #fetch, #initialize

Methods inherited from AbstractFileDownloadStrategy

#stage

Methods inherited from AbstractDownloadStrategy

#clear_cache, #expand_safe_system_args, #fetch, #initialize, #ohai, #puts, #quiet_safe_system, #safe_system, #shutup!, #source_modified_time, #stage

Methods included from FileUtils

#make, mkdir, mktemp, #old_mkdir, #old_ruby, #ruby, #scons, #xcodebuild

Constructor Details

This class inherits a constructor from CurlDownloadStrategy

Instance Method Details

#_fetchObject



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'Library/Homebrew/download_strategy.rb', line 471

def _fetch
  # Put the aws gem requirement here (vs top of file) so it's only
  # a dependency of S3 users, not all Homebrew users
  require "rubygems"
  begin
    require "aws-sdk-v1"
  rescue LoadError
    onoe "Install the aws-sdk gem into the gem repo used by brew."
    raise
  end

  if @url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$}
    raise "Bad S3 URL: " + @url
  end
  bucket = Regexp.last_match(1)
  key = Regexp.last_match(2)

  ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"]
  ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"]

  obj = AWS::S3.new.buckets[bucket].objects[key]
  begin
    s3url = obj.url_for(:get)
  rescue AWS::Errors::MissingCredentialsError
    ohai "AWS credentials missing, trying public URL instead."
    s3url = obj.public_url
  end

  curl_download s3url, to: temporary_path
end