Class: Pod::Downloader::S3
- Inherits:
-
Http
- Object
- Http
- Pod::Downloader::S3
- Defined in:
- lib/cocoapods-s3-download/s3.rb
Instance Method Summary collapse
Instance Method Details
#download_file(full_filename) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cocoapods-s3-download/s3.rb', line 10 def download_file(full_filename) UI.puts("Generating an AWS S3 pre signed URL from: #{url}") original_url = url begin @url = presign_url(original_url) rescue URLNotFileFromAWSS3 UI.puts("#{url} not a S3 URL (https://{BUCKET}.s3.amazonaws.com/FileKey)") raise rescue Aws::Errors::MissingRegionError UI.puts("No AWS region was provided. Export a region on ENV['AWS_REGION'] or setup properly using https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html#aws-ruby-sdk-credentials-shared") raise rescue Aws::Sigv4::Errors::MissingCredentialsError UI.puts("No AWS credentials was provided. Export on ENV['AWS_ACCESS_KEY'] and ENV['AWS_SECRET_KEY'] or setup properly using https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html#aws-ruby-sdk-credentials-shared") raise end super(full_filename) end |
#presign_url(original_url) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cocoapods-s3-download/s3.rb', line 29 def presign_url(original_url) final_url = original_url bucket = nil key = nil begin uri = URI.parse(original_url) bucket = uri.host if bucket.slice!(".s3.amazonaws.com").nil? raise URLNotFileFromAWSS3 end key = uri.path[1..-1] rescue StandardError raise URLNotFileFromAWSS3 end if key.nil? || key.empty? raise URLNotFileFromAWSS3 end presigner = Aws::S3::Presigner.new final_url, _ = presigner.presigned_request( :get_object, bucket: bucket, key: key ) final_url end |