2020-11-13 21:09:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Groups::DependencyProxyForContainersController < Groups::ApplicationController
|
2020-12-03 18:10:10 +00:00
|
|
|
include DependencyProxy::Auth
|
|
|
|
include DependencyProxy::GroupAccess
|
2020-11-13 21:09:31 +00:00
|
|
|
include SendFileUpload
|
|
|
|
|
|
|
|
before_action :ensure_token_granted!
|
|
|
|
before_action :ensure_feature_enabled!
|
|
|
|
|
|
|
|
attr_reader :token
|
|
|
|
|
2020-12-03 18:10:10 +00:00
|
|
|
feature_category :dependency_proxy
|
2020-11-13 21:09:31 +00:00
|
|
|
|
|
|
|
def manifest
|
2020-12-11 00:09:41 +00:00
|
|
|
result = DependencyProxy::FindOrCreateManifestService.new(group, image, tag, token).execute
|
2020-11-13 21:09:31 +00:00
|
|
|
|
|
|
|
if result[:status] == :success
|
2020-12-11 00:09:41 +00:00
|
|
|
send_upload(result[:manifest].file)
|
2020-11-13 21:09:31 +00:00
|
|
|
else
|
|
|
|
render status: result[:http_status], json: result[:message]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def blob
|
|
|
|
result = DependencyProxy::FindOrCreateBlobService
|
|
|
|
.new(group, image, token, params[:sha]).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
send_upload(result[:blob].file)
|
|
|
|
else
|
|
|
|
head result[:http_status]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def image
|
|
|
|
params[:image]
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag
|
|
|
|
params[:tag]
|
|
|
|
end
|
|
|
|
|
|
|
|
def dependency_proxy
|
|
|
|
@dependency_proxy ||=
|
|
|
|
group.dependency_proxy_setting || group.create_dependency_proxy_setting
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_feature_enabled!
|
|
|
|
render_404 unless dependency_proxy.enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_token_granted!
|
|
|
|
result = DependencyProxy::RequestTokenService.new(image).execute
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
@token = result[:token]
|
|
|
|
else
|
|
|
|
render status: result[:http_status], json: result[:message]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|