2021-02-03 21:09:17 +00:00
# frozen_string_literal: true
2018-06-04 12:06:07 +00:00
class DirectUploadsValidator
2020-09-09 21:08:33 +00:00
SUPPORTED_DIRECT_UPLOAD_PROVIDERS = [ ObjectStorage :: Config :: GOOGLE_PROVIDER ,
ObjectStorage :: Config :: AWS_PROVIDER ,
ObjectStorage :: Config :: AZURE_PROVIDER ] . freeze
2018-05-09 15:27:38 +00:00
2018-06-04 12:06:07 +00:00
ValidationError = Class . new ( StandardError )
2018-05-09 15:27:38 +00:00
2019-12-07 03:07:43 +00:00
def verify! ( uploader_type , object_store )
2018-06-04 12:06:07 +00:00
return unless object_store . enabled
return unless object_store . direct_upload
2019-12-07 03:07:43 +00:00
raise ValidationError , " Object storage is configured for ' #{ uploader_type } ', but the 'connection' section is missing " unless object_store . key? ( 'connection' )
provider = object_store . connection & . provider . to_s
raise ValidationError , " No provider configured for ' #{ uploader_type } '. #{ supported_provider_text } " if provider . blank?
2021-10-19 21:12:08 +00:00
return if provider_supported? ( provider )
2019-12-07 03:07:43 +00:00
raise ValidationError , " Object storage provider ' #{ provider } ' is not supported " \
" when 'direct_upload' is used for ' #{ uploader_type } '. #{ supported_provider_text } "
end
2020-08-20 06:10:17 +00:00
private
2021-10-19 21:12:08 +00:00
def provider_supported? ( provider )
SUPPORTED_DIRECT_UPLOAD_PROVIDERS . include? ( provider )
2020-08-20 06:10:17 +00:00
end
2019-12-07 03:07:43 +00:00
def supported_provider_text
2020-08-20 06:10:17 +00:00
" Only #{ SUPPORTED_DIRECT_UPLOAD_PROVIDERS . to_sentence } are supported. "
2018-06-04 12:06:07 +00:00
end
2018-05-09 15:27:38 +00:00
end
2018-06-04 12:06:07 +00:00
DirectUploadsValidator . new . tap do | validator |
2019-12-07 03:07:43 +00:00
CONFIGS = {
artifacts : Gitlab . config . artifacts ,
2020-08-20 06:10:17 +00:00
lfs : Gitlab . config . lfs ,
uploads : Gitlab . config . uploads
2019-12-07 03:07:43 +00:00
} . freeze
CONFIGS . each do | uploader_type , uploader |
validator . verify! ( uploader_type , uploader . object_store )
2018-06-04 12:06:07 +00:00
end
end