2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DependencyProxy
|
|
|
|
class PullManifestService < DependencyProxy::BaseService
|
|
|
|
def initialize(image, tag, token)
|
|
|
|
@image = image
|
|
|
|
@tag = tag
|
|
|
|
@token = token
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def execute_with_manifest
|
|
|
|
raise ArgumentError, 'Block must be provided' unless block_given?
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
response = Gitlab::HTTP.get(manifest_url, headers: auth_headers.merge(Accept: ::ContainerRegistry::Client::ACCEPTED_TYPES.join(',')))
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
if response.success?
|
2021-02-22 17:27:13 +05:30
|
|
|
file = Tempfile.new
|
|
|
|
|
|
|
|
begin
|
2021-10-27 15:23:28 +05:30
|
|
|
file.write(response.body)
|
2021-02-22 17:27:13 +05:30
|
|
|
file.flush
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
yield(
|
|
|
|
success(
|
|
|
|
file: file,
|
|
|
|
digest: response.headers[DependencyProxy::Manifest::DIGEST_HEADER],
|
|
|
|
content_type: response.headers['content-type']
|
|
|
|
)
|
|
|
|
)
|
2021-02-22 17:27:13 +05:30
|
|
|
ensure
|
|
|
|
file.close
|
|
|
|
file.unlink
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
else
|
2021-02-22 17:27:13 +05:30
|
|
|
yield(error(response.body, response.code))
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
rescue Timeout::Error => exception
|
|
|
|
error(exception.message, 599)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def manifest_url
|
|
|
|
registry.manifest_url(@image, @tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|