284ed39e30
Use Gitlab-Workhorse-Send-Data to send entry ## What does this MR do? Use Gitlab-Workhorse-Send-Data to send entry: Closes #19224, Closes #19128 Also requires this MR to work: https://gitlab.com/gitlab-org/gitlab-workhorse/merge_requests/53 ## Are there points in the code the reviewer needs to double check? Do we have a test for this? ## Why was this MR needed? This way gitlab-workhorse does not have to call any API. See merge request !5094
85 lines
1.9 KiB
Ruby
85 lines
1.9 KiB
Ruby
require 'base64'
|
|
require 'json'
|
|
|
|
module Gitlab
|
|
class Workhorse
|
|
SEND_DATA_HEADER = 'Gitlab-Workhorse-Send-Data'
|
|
|
|
class << self
|
|
def git_http_ok(repository, user)
|
|
{
|
|
'GL_ID' => Gitlab::GlId.gl_id(user),
|
|
'RepoPath' => repository.path_to_repo,
|
|
}
|
|
end
|
|
|
|
def send_git_blob(repository, blob)
|
|
params = {
|
|
'RepoPath' => repository.path_to_repo,
|
|
'BlobId' => blob.id,
|
|
}
|
|
|
|
[
|
|
SEND_DATA_HEADER,
|
|
"git-blob:#{encode(params)}"
|
|
]
|
|
end
|
|
|
|
def send_git_archive(repository, ref:, format:)
|
|
format ||= 'tar.gz'
|
|
format.downcase!
|
|
params = repository.archive_metadata(ref, Gitlab.config.gitlab.repository_downloads_path, format)
|
|
raise "Repository or ref not found" if params.empty?
|
|
|
|
[
|
|
SEND_DATA_HEADER,
|
|
"git-archive:#{encode(params)}"
|
|
]
|
|
end
|
|
|
|
def send_git_diff(repository, diff_refs)
|
|
params = {
|
|
'RepoPath' => repository.path_to_repo,
|
|
'ShaFrom' => diff_refs.start_sha,
|
|
'ShaTo' => diff_refs.head_sha
|
|
}
|
|
|
|
[
|
|
SEND_DATA_HEADER,
|
|
"git-diff:#{encode(params)}"
|
|
]
|
|
end
|
|
|
|
def send_git_patch(repository, diff_refs)
|
|
params = {
|
|
'RepoPath' => repository.path_to_repo,
|
|
'ShaFrom' => diff_refs.start_sha,
|
|
'ShaTo' => diff_refs.head_sha
|
|
}
|
|
|
|
[
|
|
SEND_DATA_HEADER,
|
|
"git-format-patch:#{encode(params)}"
|
|
]
|
|
end
|
|
|
|
def send_artifacts_entry(build, entry)
|
|
params = {
|
|
'Archive' => build.artifacts_file.path,
|
|
'Entry' => Base64.encode64(entry.path)
|
|
}
|
|
|
|
[
|
|
SEND_DATA_HEADER,
|
|
"artifacts-entry:#{encode(params)}"
|
|
]
|
|
end
|
|
|
|
protected
|
|
|
|
def encode(hash)
|
|
Base64.urlsafe_encode64(JSON.dump(hash))
|
|
end
|
|
end
|
|
end
|
|
end
|