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 #48

Merged
merged 5 commits into from
Mar 25, 2021
Merged
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
54 changes: 39 additions & 15 deletions lib/fastlane/plugin/aws_s3/actions/aws_s3_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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 @@ -126,14 +128,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 @@ -144,7 +147,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 @@ -205,7 +208,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 @@ -246,8 +249,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 @@ -279,8 +282,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 @@ -307,14 +312,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 @@ -371,8 +378,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 @@ -402,7 +409,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 @@ -492,9 +501,7 @@ def self.upload_folder(s3_client, params, s3_region, s3_access_key, s3_secret_ac
end
end



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 @@ -519,7 +526,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 @@ -675,6 +689,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