Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support alternate download endpoint urls #93

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ aws_s3(
server_side_encryption: ENV['S3_SERVER_SIDE_ENCRYPTION'], # Optional

endpoint: 'https://s3-us-west-1.amazonaws.com', # Optional, for buckets that require a specific endpoint
download_endpoint: 'https://example.com', # Optional, for alternate download endpoint
download_endpoint_replacement_regex: '^https?://[^/]*', # This is actually the default.

ipa: 'AppName.ipa', # Required (if not uploading an APK).
dsym: 'AppName.app.dSYM.zip', # Optional if you use `ipa` to build.

Expand Down
52 changes: 39 additions & 13 deletions lib/fastlane/plugin/aws_s3/actions/aws_s3_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def self.run(config)
params[:aws_profile] = config[:aws_profile]
params[:bucket] = config[:bucket]
params[:endpoint] = config[:endpoint]
params[:download_endpoint] = config[:download_endpoint]
params[:download_endpoint_replacement_regex] = config[:download_endpoint_replacement_regex]
params[:region] = config[:region]
params[:app_directory] = config[:app_directory]
params[:acl] = config[:acl]
Expand Down Expand Up @@ -128,14 +130,15 @@ def self.upload_ipa(s3_client, params, s3_region, s3_access_key, s3_secret_acces
version_template_params = params[:version_template_params] || {}
version_file_name = params[:version_file_name]
override_file_name = params[:override_file_name]

download_endpoint = params[:download_endpoint]
download_endpoint_replacement_regex = params[:download_endpoint_replacement_regex]
url_part = self.expand_path_with_substitutions_from_ipa_plist(ipa_file, s3_path)

ipa_file_basename = File.basename(ipa_file)
ipa_file_name = "#{url_part}#{override_file_name ? override_file_name : ipa_file_basename}"
ipa_file_data = File.open(ipa_file, 'rb')

ipa_url = self.upload_file(s3_client, s3_bucket, app_directory, ipa_file_name, ipa_file_data, acl, server_side_encryption)
ipa_url = self.upload_file(s3_client, s3_bucket, app_directory, ipa_file_name, ipa_file_data, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

# Setting action and environment variables
Actions.lane_context[SharedValues::S3_IPA_OUTPUT_PATH] = ipa_url
Expand All @@ -146,7 +149,7 @@ def self.upload_ipa(s3_client, params, s3_region, s3_access_key, s3_secret_acces
dsym_file_name = "#{url_part}#{dsym_file_basename}"
dsym_file_data = File.open(dsym_file, 'rb')

dsym_url = self.upload_file(s3_client, s3_bucket, app_directory, dsym_file_name, dsym_file_data, acl, server_side_encryption)
dsym_url = self.upload_file(s3_client, s3_bucket, app_directory, dsym_file_name, dsym_file_data, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

# Setting action and environment variables
Actions.lane_context[SharedValues::S3_DSYM_OUTPUT_PATH] = dsym_url
Expand Down Expand Up @@ -207,7 +210,7 @@ def self.upload_ipa(s3_client, params, s3_region, s3_access_key, s3_secret_acces
# plist uploading
#
#####################################
plist_url = self.upload_file(s3_client, s3_bucket, app_directory, plist_file_name, plist_render, acl, server_side_encryption)
plist_url = self.upload_file(s3_client, s3_bucket, app_directory, plist_file_name, plist_render, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

# Creates html from template
if html_template_path && File.exist?(html_template_path)
Expand Down Expand Up @@ -250,8 +253,8 @@ def self.upload_ipa(s3_client, params, s3_region, s3_access_key, s3_secret_acces

skip_html = params[:skip_html_upload]
html_file_name = "#{url_part}#{html_file_name}" if generate_html_in_folder
html_url = self.upload_file(s3_client, s3_bucket, app_directory, html_file_name, html_render, acl, server_side_encryption) unless skip_html
version_url = self.upload_file(s3_client, s3_bucket, app_directory, version_file_name, version_render, acl, server_side_encryption)
html_url = self.upload_file(s3_client, s3_bucket, app_directory, html_file_name, html_render, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex) unless skip_html
version_url = self.upload_file(s3_client, s3_bucket, app_directory, version_file_name, version_render, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

# Setting action and environment variables
Actions.lane_context[SharedValues::S3_PLIST_OUTPUT_PATH] = plist_url
Expand Down Expand Up @@ -283,8 +286,10 @@ def self.upload_xcarchive(s3_client, params, s3_region, s3_access_key, s3_secret
sh("zip -r '#{archive_zip}' '#{archive}'")
full_archive_zip_name = "#{url_part}#{archive_zip_name}"
archive_zip_data = File.open(archive_zip, 'rb')
download_endpoint = params[:download_endpoint]
download_endpoint_replacement_regex = params[:download_endpoint_replacement_regex]

archive_url = self.upload_file(s3_client, s3_bucket, app_directory, full_archive_zip_name, archive_zip_data, acl, server_side_encryption)
archive_url = self.upload_file(s3_client, s3_bucket, app_directory, full_archive_zip_name, archive_zip_data, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

Actions.lane_context[SharedValues::S3_XCARCHIVE_OUTPUT_PATH] = archive_url
ENV[SharedValues::S3_XCARCHIVE_OUTPUT_PATH.to_s] = archive_url
Expand All @@ -311,14 +316,16 @@ def self.upload_apk(s3_client, params, s3_region, s3_access_key, s3_secret_acces
version_template_params = params[:version_template_params] || {}
version_file_name = params[:version_file_name]
override_file_name = params[:override_file_name]
download_endpoint = params[:download_endpoint]
download_endpoint_replacement_regex = params[:download_endpoint_replacement_regex]

url_part = s3_path

apk_file_basename = File.basename(apk_file)
apk_file_name = "#{url_part}#{override_file_name ? override_file_name : apk_file_basename}"
apk_file_data = File.open(apk_file, 'rb')

apk_url = self.upload_file(s3_client, s3_bucket, app_directory, apk_file_name, apk_file_data, acl, server_side_encryption)
apk_url = self.upload_file(s3_client, s3_bucket, app_directory, apk_file_name, apk_file_data, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

# Setting action and environment variables
Actions.lane_context[SharedValues::S3_APK_OUTPUT_PATH] = apk_url
Expand Down Expand Up @@ -377,8 +384,8 @@ def self.upload_apk(s3_client, params, s3_region, s3_access_key, s3_secret_acces

skip_html = params[:skip_html_upload]
html_file_name = "#{url_part}#{html_file_name}" if generate_html_in_folder
html_url = self.upload_file(s3_client, s3_bucket, app_directory, html_file_name, html_render, acl, server_side_encryption) unless skip_html
version_url = self.upload_file(s3_client, s3_bucket, app_directory, version_file_name, version_render, acl, server_side_encryption)
html_url = self.upload_file(s3_client, s3_bucket, app_directory, html_file_name, html_render, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex) unless skip_html
version_url = self.upload_file(s3_client, s3_bucket, app_directory, version_file_name, version_render, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

Actions.lane_context[SharedValues::S3_HTML_OUTPUT_PATH] = html_url unless skip_html
ENV[SharedValues::S3_HTML_OUTPUT_PATH.to_s] = html_url unless skip_html
Expand Down Expand Up @@ -408,7 +415,9 @@ def self.upload_source(s3_client, params, s3_bucket, source_directory, s3_path,
zip_file_name = "#{url_part}source.zip"

output_path_data = File.open("#{output_file_path}", 'rb')
source_url = self.upload_file(s3_client, s3_bucket, app_directory, zip_file_name, output_path_data, acl, server_side_encryption)
download_endpoint = params[:download_endpoint]
download_endpoint_replacement_regex = params[:download_endpoint_replacement_regex]
source_url = self.upload_file(s3_client, s3_bucket, app_directory, zip_file_name, output_path_data, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

Actions.lane_context[SharedValues::S3_SOURCE_OUTPUT_PATH] = source_url
ENV[SharedValues::S3_SOURCE_OUTPUT_PATH.to_s] = source_url
Expand Down Expand Up @@ -500,7 +509,7 @@ def self.upload_folder(s3_client, params, s3_region, s3_access_key, s3_secret_ac



def self.upload_file(s3_client, bucket_name, app_directory, file_name, file_data, acl, server_side_encryption)
def self.upload_file(s3_client, bucket_name, app_directory, file_name, file_data, acl, server_side_encryption, download_endpoint, download_endpoint_replacement_regex)

if app_directory
file_name = "#{app_directory}/#{file_name}"
Expand All @@ -525,7 +534,14 @@ def self.upload_file(s3_client, bucket_name, app_directory, file_name, file_data
end

# Return public url
obj.public_url.to_s
url = obj.public_url.to_s

# if a download endpoint is provided, then swap it in before returning
if download_endpoint
url = url.gsub(Regexp.new(download_endpoint_replacement_regex), download_endpoint)
end

return url
end

#
Expand Down Expand Up @@ -685,6 +701,16 @@ def self.available_options
description: "The base endpoint for your S3 bucket",
optional: true,
default_value: nil),
FastlaneCore::ConfigItem.new(key: :download_endpoint,
env_name: "S3_DOWNLOAD_ENDPOINT",
description: "The endpoint for downloads from your S3 bucket",
optional: true,
default_value: nil),
FastlaneCore::ConfigItem.new(key: :download_endpoint_replacement_regex,
env_name: "S3_DOWNLOAD_ENDPOINT_REPLACEMENT_REGEX",
description: "A regex used to determine which part of the S3 URL to replace with S3_DOWNLOAD_ENDPOINT",
optional: true,
default_value: '^https?://[^/]*'),
FastlaneCore::ConfigItem.new(key: :override_file_name,
env_name: "",
description: "Optional override ipa/apk uploaded file name",
Expand Down