debian-mirror-gitlab/app/services/dependency_proxy/head_manifest_service.rb

32 lines
799 B
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module DependencyProxy
class HeadManifestService < DependencyProxy::BaseService
2021-04-17 20:07:23 +05:30
ACCEPT_HEADERS = ::ContainerRegistry::Client::ACCEPTED_TYPES.join(',')
2021-02-22 17:27:13 +05:30
def initialize(image, tag, token)
@image = image
@tag = tag
@token = token
end
def execute
2021-04-17 20:07:23 +05:30
response = Gitlab::HTTP.head(manifest_url, headers: auth_headers.merge(Accept: ACCEPT_HEADERS))
2021-02-22 17:27:13 +05:30
if response.success?
2021-04-17 20:07:23 +05:30
success(digest: response.headers['docker-content-digest'], content_type: response.headers['content-type'])
2021-02-22 17:27:13 +05:30
else
error(response.body, response.code)
end
rescue Timeout::Error => exception
error(exception.message, 599)
end
private
def manifest_url
registry.manifest_url(@image, @tag)
end
end
end