aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorRaymie Stata2013-09-24 01:34:28 -0700
committerAdam Vandenberg2013-09-24 20:43:34 -0700
commit694a9c2eed98419fda7e110cdabb9b4f815e7a10 (patch)
tree83bcabc21cf01339f2b92a522d62042ce92b33b4 /Library/Homebrew
parent8d0c8fd978506edb5cdca8c68e8e948087428fab (diff)
downloadbrew-694a9c2eed98419fda7e110cdabb9b4f815e7a10.tar.bz2
add S3DownloadStrategy
downloads tarballs from public and private S3 buckets Closes Homebrew/homebrew#22779. Signed-off-by: Adam Vandenberg <flangy@gmail.com>
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/download_strategy.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index f844b9f23..46d363496 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -254,6 +254,42 @@ class LocalBottleDownloadStrategy < CurlDownloadStrategy
end
end
+# 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.)
+class S3DownloadStrategy < CurlDownloadStrategy
+ 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'
+ rescue LoadError
+ onoe "Install the aws-sdk gem into the gem repo used by brew."
+ raise
+ end
+
+ if @url !~ %r[^https?://+([^.]+).s3.amazonaws.com/+(.+)$] then
+ raise "Bad S3 URL: " + @url
+ end
+ (bucket,key) = $1,$2
+
+ 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 s3url, '-C', downloaded_size, '-o', @temporary_path
+ end
+end
+
class SubversionDownloadStrategy < AbstractDownloadStrategy
def initialize name, resource
super