diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /lib/object_storage | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'lib/object_storage')
-rw-r--r-- | lib/object_storage/config.rb | 36 | ||||
-rw-r--r-- | lib/object_storage/direct_upload.rb | 4 |
2 files changed, 38 insertions, 2 deletions
diff --git a/lib/object_storage/config.rb b/lib/object_storage/config.rb index f933d4e4866..0e6408b4917 100644 --- a/lib/object_storage/config.rb +++ b/lib/object_storage/config.rb @@ -2,6 +2,8 @@ module ObjectStorage class Config + include Gitlab::Utils::StrongMemoize + AWS_PROVIDER = 'AWS' AZURE_PROVIDER = 'AzureRM' GOOGLE_PROVIDER = 'Google' @@ -66,6 +68,36 @@ module ObjectStorage def provider credentials[:provider].to_s end + + # This method converts fog-aws parameters to an endpoint for the + # Workhorse S3 client. + def s3_endpoint + strong_memoize(:s3_endpoint) do + # We could omit this line and let the following code handle this, but + # this will ensure that working configurations that use `endpoint` + # will continue to work. + next credentials[:endpoint] if credentials[:endpoint].present? + + generate_s3_endpoint_from_credentials + end + end + + def generate_s3_endpoint_from_credentials + # fog-aws has special handling of the host, region, scheme, etc: + # https://github.com/fog/fog-aws/blob/c7a11ba377a76d147861d0e921eb1e245bc11b6c/lib/fog/aws/storage.rb#L440-L449 + # Rather than reimplement this, we derive it from a sample GET URL. + url = fog_connection.get_object_url(bucket, "tmp", nil) + uri = ::Addressable::URI.parse(url) + + return unless uri&.scheme && uri&.host + + endpoint = "#{uri.scheme}://#{uri.host}" + endpoint += ":#{uri.port}" if uri.port + endpoint + rescue ::URI::InvalidComponentError, ::Addressable::URI::InvalidURIError => e + Gitlab::ErrorTracking.track_exception(e) + nil + end # End AWS-specific options # Begin Azure-specific options @@ -91,6 +123,10 @@ module ObjectStorage end end + def fog_connection + @connection ||= ::Fog::Storage.new(credentials) + end + private # This returns a Hash of HTTP encryption headers to send along to S3. diff --git a/lib/object_storage/direct_upload.rb b/lib/object_storage/direct_upload.rb index 7f1c30e574d..9fb4b571e06 100644 --- a/lib/object_storage/direct_upload.rb +++ b/lib/object_storage/direct_upload.rb @@ -80,7 +80,7 @@ module ObjectStorage S3Config: { Bucket: bucket_name, Region: credentials[:region], - Endpoint: credentials[:endpoint], + Endpoint: config.s3_endpoint, PathStyle: config.use_path_style?, UseIamProfile: config.use_iam_profile?, ServerSideEncryption: config.server_side_encryption, @@ -229,7 +229,7 @@ module ObjectStorage end def connection - @connection ||= ::Fog::Storage.new(credentials) + config.fog_connection end end end |