2020-11-13 21:09:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DependencyProxy
|
|
|
|
class PullManifestService < DependencyProxy::BaseService
|
|
|
|
def initialize(image, tag, token)
|
|
|
|
@image = image
|
|
|
|
@tag = tag
|
|
|
|
@token = token
|
|
|
|
end
|
|
|
|
|
2020-12-11 00:09:41 +00:00
|
|
|
def execute_with_manifest
|
|
|
|
raise ArgumentError, 'Block must be provided' unless block_given?
|
|
|
|
|
2021-02-22 18:10:55 +00:00
|
|
|
response = Gitlab::HTTP.get(manifest_url, headers: auth_headers.merge(Accept: ::ContainerRegistry::Client::ACCEPTED_TYPES.join(',')))
|
2020-11-13 21:09:31 +00:00
|
|
|
|
|
|
|
if response.success?
|
2020-12-11 00:09:41 +00:00
|
|
|
file = Tempfile.new
|
|
|
|
|
|
|
|
begin
|
|
|
|
file.write(response)
|
|
|
|
file.flush
|
|
|
|
|
2021-02-22 18:10:55 +00:00
|
|
|
yield(success(file: file, digest: response.headers['docker-content-digest'], content_type: response.headers['content-type']))
|
2020-12-11 00:09:41 +00:00
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
file.unlink
|
|
|
|
end
|
2020-11-13 21:09:31 +00:00
|
|
|
else
|
2020-12-11 00:09:41 +00:00
|
|
|
yield(error(response.body, response.code))
|
2020-11-13 21:09:31 +00:00
|
|
|
end
|
|
|
|
rescue Timeout::Error => exception
|
|
|
|
error(exception.message, 599)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def manifest_url
|
|
|
|
registry.manifest_url(@image, @tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|