match/lib/match/storage/s3_storage.rb in fastlane-2.150.3 vs match/lib/match/storage/s3_storage.rb in fastlane-2.151.0
- old
+ new
@@ -12,20 +12,22 @@
# Store the code signing identities on AWS S3
class S3Storage < Interface
attr_reader :s3_bucket
attr_reader :s3_region
attr_reader :s3_client
+ attr_reader :s3_object_prefix
attr_reader :readonly
attr_reader :username
attr_reader :team_id
attr_reader :team_name
def self.configure(params)
s3_region = params[:s3_region]
s3_access_key = params[:s3_access_key]
s3_secret_access_key = params[:s3_secret_access_key]
s3_bucket = params[:s3_bucket]
+ s3_object_prefix = params[:s3_object_prefix]
if params[:git_url].to_s.length > 0
UI.important("Looks like you still define a `git_url` somewhere, even though")
UI.important("you use S3 Storage. You can remove the `git_url`")
UI.important("from your Matchfile and Fastfile")
@@ -35,10 +37,11 @@
return self.new(
s3_region: s3_region,
s3_access_key: s3_access_key,
s3_secret_access_key: s3_secret_access_key,
s3_bucket: s3_bucket,
+ s3_object_prefix: s3_object_prefix,
readonly: params[:readonly],
username: params[:username],
team_id: params[:team_id],
team_name: params[:team_name]
)
@@ -46,17 +49,19 @@
def initialize(s3_region: nil,
s3_access_key: nil,
s3_secret_access_key: nil,
s3_bucket: nil,
+ s3_object_prefix: nil,
readonly: nil,
username: nil,
team_id: nil,
team_name: nil)
@s3_bucket = s3_bucket
@s3_region = s3_region
@s3_client = Fastlane::Helper::S3ClientHelper.new(access_key: s3_access_key, secret_access_key: s3_secret_access_key, region: s3_region)
+ @s3_object_prefix = s3_object_prefix.to_s
@readonly = readonly
@username = username
@team_id = team_id
@team_name = team_name
end
@@ -86,12 +91,14 @@
return if @working_directory && Dir.exist?(@working_directory)
# No existing working directory, creating a new one now
self.working_directory = Dir.mktmpdir
- s3_client.find_bucket!(s3_bucket).objects.each do |object|
- file_path = object.key # :team_id/path/to/file
+ s3_client.find_bucket!(s3_bucket).objects(prefix: s3_object_prefix).each do |object|
+ file_path = strip_s3_object_prefix(object.key) # :s3_object_prefix:team_id/path/to/file
+
+ # strip s3_prefix from file_path
download_path = File.join(self.working_directory, file_path)
FileUtils.mkdir_p(File.expand_path("..", download_path))
UI.verbose("Downloading file from S3 '#{file_path}' on bucket #{self.s3_bucket}")
@@ -111,16 +118,15 @@
# Those doesn't mean they're new, it might just be they're changed
# Either way, we'll upload them using the same technique
files_to_upload.each do |file_name|
# Go from
- # "/var/folders/px/bz2kts9n69g8crgv4jpjh6b40000gn/T/d20181026-96528-1av4gge/profiles/development/Development_me.mobileprovision"
+ # "/var/folders/px/bz2kts9n69g8crgv4jpjh6b40000gn/T/d20181026-96528-1av4gge/:team_id/profiles/development/Development_me.mobileprovision"
# to
- # "profiles/development/Development_me.mobileprovision"
+ # ":s3_object_prefix:team_id/profiles/development/Development_me.mobileprovision"
#
-
- target_path = sanitize_file_name(file_name)
+ target_path = s3_object_path(file_name)
UI.verbose("Uploading '#{target_path}' to S3 Storage...")
body = File.read(file_name)
acl = 'private'
s3_url = s3_client.upload_file(s3_bucket, target_path, body, acl)
@@ -128,11 +134,12 @@
end
end
def delete_files(files_to_delete: [], custom_message: nil)
files_to_delete.each do |file_name|
- target_path = sanitize_file_name(file_name)
+ target_path = s3_object_path(file_name)
+ UI.verbose("Deleting '#{target_path}' from S3 Storage...")
s3_client.delete_file(s3_bucket, target_path)
end
end
def skip_docs
@@ -149,9 +156,20 @@
def generate_matchfile_content(template: nil)
return "s3_bucket(\"#{self.s3_bucket}\")"
end
private
+
+ def s3_object_path(file_name)
+ santized = sanitize_file_name(file_name)
+ return santized if santized.start_with?(s3_object_prefix)
+
+ s3_object_prefix + santized
+ end
+
+ def strip_s3_object_prefix(object_path)
+ object_path.gsub(/^#{s3_object_prefix}/, "")
+ end
def sanitize_file_name(file_name)
file_name.gsub(self.working_directory + "/", "")
end