From a096284d0345834707a633d1c6d1bb3aa0424b6a Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Tue, 20 Mar 2018 16:46:00 -0400 Subject: [PATCH] DownloadStrategyDetector recognizes s3 URL scheme DownloadStrategyDetector now detects URLs with the s3:// prefix, e.g.: s3://my-bucket/path/to/key/tarball.tar.gz --- Library/Homebrew/download_strategy.rb | 6 +++++- Library/Homebrew/test/download_strategies_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 2b594c908..0c33aa5f4 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -473,7 +473,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) @@ -1141,6 +1142,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 b8b975e52..5980bf9e0 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -260,6 +260,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 }