2016-04-02 18:10:28 +05:30
|
|
|
require 'base64'
|
|
|
|
require 'json'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class Workhorse
|
2016-06-02 11:05:42 +05:30
|
|
|
SEND_DATA_HEADER = 'Gitlab-Workhorse-Send-Data'
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
class << self
|
2016-06-16 23:09:34 +05:30
|
|
|
def git_http_ok(repository, user)
|
|
|
|
{
|
|
|
|
'GL_ID' => Gitlab::GlId.gl_id(user),
|
|
|
|
'RepoPath' => repository.path_to_repo,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def send_git_blob(repository, blob)
|
2016-06-02 11:05:42 +05:30
|
|
|
params = {
|
2016-04-02 18:10:28 +05:30
|
|
|
'RepoPath' => repository.path_to_repo,
|
|
|
|
'BlobId' => blob.id,
|
|
|
|
}
|
|
|
|
|
|
|
|
[
|
2016-06-02 11:05:42 +05:30
|
|
|
SEND_DATA_HEADER,
|
2016-06-16 23:09:34 +05:30
|
|
|
"git-blob:#{encode(params)}"
|
2016-04-02 18:10:28 +05:30
|
|
|
]
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def send_git_archive(repository, ref:, format:)
|
2016-06-02 11:05:42 +05:30
|
|
|
format ||= 'tar.gz'
|
|
|
|
format.downcase!
|
2016-06-16 23:09:34 +05:30
|
|
|
params = repository.archive_metadata(ref, Gitlab.config.gitlab.repository_downloads_path, format)
|
2016-06-02 11:05:42 +05:30
|
|
|
raise "Repository or ref not found" if params.empty?
|
|
|
|
|
|
|
|
[
|
|
|
|
SEND_DATA_HEADER,
|
2016-06-16 23:09:34 +05:30
|
|
|
"git-archive:#{encode(params)}"
|
2016-06-02 11:05:42 +05:30
|
|
|
]
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
def send_git_diff(repository, diff_refs)
|
|
|
|
params = {
|
|
|
|
'RepoPath' => repository.path_to_repo,
|
2016-08-24 12:49:21 +05:30
|
|
|
'ShaFrom' => diff_refs.start_sha,
|
|
|
|
'ShaTo' => diff_refs.head_sha
|
2016-06-16 23:09:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
[
|
|
|
|
SEND_DATA_HEADER,
|
|
|
|
"git-diff:#{encode(params)}"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
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
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
protected
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def encode(hash)
|
|
|
|
Base64.urlsafe_encode64(JSON.dump(hash))
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|