debian-mirror-gitlab/app/models/uploads/fog.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Uploads
class Fog < Base
include ::Gitlab::Utils::StrongMemoize
def available?
object_store.enabled
end
def keys(relation)
return [] unless available?
relation.pluck(:path)
end
def delete_keys(keys)
2021-12-11 22:18:48 +05:30
keys.each { |key| delete_object(key) }
2019-02-15 15:39:39 +05:30
end
private
2021-12-11 22:18:48 +05:30
def delete_object(key)
2023-05-08 21:46:49 +05:30
return unless available?
connection.delete_object(bucket_name, object_key(key))
2021-12-11 22:18:48 +05:30
# So far, only GoogleCloudStorage raises an exception when the file is not found.
# Other providers support idempotent requests and does not raise an error
# when the file is missing.
rescue ::Google::Apis::ClientError => e
Gitlab::ErrorTracking.log_exception(e)
end
2019-02-15 15:39:39 +05:30
def object_store
Gitlab.config.uploads.object_store
end
def bucket_name
object_store.remote_directory
end
2023-05-08 21:46:49 +05:30
def object_key(key)
# We allow administrators to create "sub buckets" by setting a prefix.
# This makes it possible to deploy GitLab with only one object storage
# bucket. This mirrors the implementation in app/uploaders/object_storage.rb.
File.join([object_store.bucket_prefix, key].compact)
end
2019-02-15 15:39:39 +05:30
def connection
return unless available?
strong_memoize(:connection) do
::Fog::Storage.new(object_store.connection.to_hash.deep_symbolize_keys)
end
end
end
end