2018-12-14 11:51:37 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LfsDownloadObject
|
|
|
|
include ActiveModel::Validations
|
|
|
|
|
2021-07-07 14:08:30 -04:00
|
|
|
attr_accessor :oid, :size, :link, :headers
|
2018-12-14 11:51:37 -05:00
|
|
|
delegate :sanitized_url, :credentials, to: :sanitized_uri
|
|
|
|
|
|
|
|
validates :oid, format: { with: /\A\h{64}\z/ }
|
|
|
|
validates :size, numericality: { greater_than_or_equal_to: 0 }
|
|
|
|
validates :link, public_url: { protocols: %w(http https) }
|
2021-07-07 14:08:30 -04:00
|
|
|
validate :headers_must_be_hash
|
2018-12-14 11:51:37 -05:00
|
|
|
|
2021-07-07 14:08:30 -04:00
|
|
|
def initialize(oid:, size:, link:, headers: {})
|
2018-12-14 11:51:37 -05:00
|
|
|
@oid = oid
|
|
|
|
@size = size
|
|
|
|
@link = link
|
2021-07-07 14:08:30 -04:00
|
|
|
@headers = headers || {}
|
2018-12-14 11:51:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def sanitized_uri
|
|
|
|
@sanitized_uri ||= Gitlab::UrlSanitizer.new(link)
|
|
|
|
end
|
2021-07-07 14:08:30 -04:00
|
|
|
|
|
|
|
def has_authorization_header?
|
|
|
|
headers.keys.map(&:downcase).include?('authorization')
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def headers_must_be_hash
|
|
|
|
errors.add(:base, "headers must be a Hash") unless headers.is_a?(Hash)
|
|
|
|
end
|
2018-12-14 11:51:37 -05:00
|
|
|
end
|