diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 228cfd921..b50ae317c 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -468,7 +468,8 @@ end # distribution. (It will work for public buckets as well.) class S3DownloadStrategy < CurlDownloadStrategy def _fetch - if @url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$} + if @url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$} && + @url !~ %r{^s3://([^.].*?)/(.+)$} raise "Bad S3 URL: " + @url end bucket = Regexp.last_match(1) @@ -1136,6 +1137,9 @@ class DownloadStrategyDetector SubversionDownloadStrategy when %r{^https?://(.+?\.)?sourceforge\.net/hgweb/} MercurialDownloadStrategy + when %r{^s3://} + require_aws_sdk + S3DownloadStrategy else CurlDownloadStrategy end diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index d5437c120..f3a68407e 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -275,6 +275,14 @@ describe DownloadStrategyDetector do it { is_expected.to eq(GitHubGitDownloadStrategy) } end + context "when given an S3 URL" do + let(:url) { "s3://bucket/homebrew/brew.tar.gz" } + it "returns S3DownloadStrategy" do + allow(DownloadStrategyDetector).to receive(:require_aws_sdk).and_return(true) + is_expected.to eq(S3DownloadStrategy) + end + end + context "when given strategy = S3DownloadStrategy" do let(:url) { "https://bkt.s3.amazonaws.com/key.tar.gz" } let(:strategy) { S3DownloadStrategy }