Merge pull request #3967 from amancevice/s3-scheme

DownloadStrategyDetector recognizes s3 URL scheme
This commit is contained in:
Mike McQuaid 2018-03-25 10:01:31 +01:00 committed by GitHub
commit 46e6b33d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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 }