in scm_helper/libraries/s3.rb [5:49]
def self.parse_uri(uri)
components = URI.split(uri)
base_uri = URI::HTTP.new(*(components.take(5) + [nil] * 4))
remote_path = URI::HTTP.new(*([nil] * 5 + components.drop(5)))
virtual_host_match = base_uri.host.match(/\A(.+)\.s3(?:-website|.dualstack)?([-.](ap|ca|cn|eu|sa|us)-(.+-)\d|-external-1)?\.amazonaws\.com/i)
if virtual_host_match
bucket = virtual_host_match[1]
if virtual_host_match[2]
region = virtual_host_match[2][1..-1]
region = "us-east-1" if region == "external-1"
else
region = "us-east-1"
end
else
uri_path_components = remote_path.path.split("/").reject(&:empty?)
bucket = uri_path_components.shift
base_uri.path = "/#{bucket}"
remote_path.path = uri_path_components.join("/")
if base_uri.host == "s3.amazonaws.com"
region = "us-east-1"
elsif base_uri.host == "s3-external-1.amazonaws.com"
region = "us-east-1"
elsif base_uri.host == "s3-website.amazonaws.com"
region = "us-east-1"
elsif base_uri.host.start_with? "s3.dualstack"
region = base_uri.host.split('.')[2]
else
region = base_uri.host.sub(/^s3(?:-website)?[-.]/i, '').split('.')[0]
end
end
[bucket, remote_path.to_s.to_s.sub(%r{^/}, ""), base_uri.to_s.chomp("/"), region]
end