summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2017-06-20 18:20:09 +0200
committerAhmad Sherif <me@ahmadsherif.com>2017-07-03 13:31:36 +0200
commitbc6494016dbb4948eb9d13a6127f3fc8cee8fcc4 (patch)
treea1444d2930256f18fc7b2432c3c584290e2c5ffa
parent65c2a5fe36eb47d803037a1e2b719be580635036 (diff)
downloadgitlab-ce-migrate-workhorse-send-blob-to-gitaly.tar.gz
Migrate Workhorse SendBlob to Gitalymigrate-workhorse-send-blob-to-gitaly
-rw-r--r--app/controllers/projects/avatars_controller.rb2
-rw-r--r--app/controllers/projects/raw_controller.rb2
-rw-r--r--app/helpers/workhorse_helper.rb4
-rw-r--r--lib/api/files.rb2
-rw-r--r--lib/api/helpers.rb4
-rw-r--r--lib/api/repositories.rb2
-rw-r--r--lib/api/v3/repositories.rb4
-rw-r--r--lib/gitlab/workhorse.rb33
8 files changed, 34 insertions, 19 deletions
diff --git a/app/controllers/projects/avatars_controller.rb b/app/controllers/projects/avatars_controller.rb
index 21a403f3765..3f80221c782 100644
--- a/app/controllers/projects/avatars_controller.rb
+++ b/app/controllers/projects/avatars_controller.rb
@@ -10,7 +10,7 @@ class Projects::AvatarsController < Projects::ApplicationController
return if cached_blob?
- send_git_blob @repository, @blob
+ send_git_blob @project, @repository.root_ref, @blob
else
render_404
end
diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb
index a02cc477e08..472abaf9dd0 100644
--- a/app/controllers/projects/raw_controller.rb
+++ b/app/controllers/projects/raw_controller.rb
@@ -18,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
if @blob.stored_externally?
send_lfs_object
else
- send_git_blob @repository, @blob
+ send_git_blob @project, @commit.id, @blob
end
else
render_404
diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb
index 88f374be1e5..46e73663e90 100644
--- a/app/helpers/workhorse_helper.rb
+++ b/app/helpers/workhorse_helper.rb
@@ -2,8 +2,8 @@
# Workhorse will also serve files when using `send_file`.
module WorkhorseHelper
# Send a Git blob through Workhorse
- def send_git_blob(repository, blob)
- headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))
+ def send_git_blob(project, revision, blob)
+ headers.store(*Gitlab::Workhorse.send_git_blob(project, revision, blob))
headers['Content-Disposition'] = 'inline'
headers['Content-Type'] = safe_content_type(blob)
head :ok # 'render nothing: true' messes up the Content-Type
diff --git a/lib/api/files.rb b/lib/api/files.rb
index 521287ee2b4..ff00d79da4a 100644
--- a/lib/api/files.rb
+++ b/lib/api/files.rb
@@ -63,7 +63,7 @@ module API
get ":id/repository/files/:file_path/raw" do
assign_file_vars!
- send_git_blob @repo, @blob
+ send_git_blob user_project, params[:ref], @blob
end
desc 'Get a file from the repository'
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 2c73a6fdc4e..639a8174caf 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -384,10 +384,10 @@ module API
Gitlab::Shell.secret_token
end
- def send_git_blob(repository, blob)
+ def send_git_blob(project, revision, blob)
env['api.format'] = :txt
content_type 'text/plain'
- header(*Gitlab::Workhorse.send_git_blob(repository, blob))
+ header(*Gitlab::Workhorse.send_git_blob(project, revision, blob))
end
def send_git_archive(repository, ref:, format:)
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 14d2bff9cb5..57e05feaafe 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -62,7 +62,7 @@ module API
get ':id/repository/blobs/:sha/raw' do
assign_blob_vars!
- send_git_blob @repo, @blob
+ send_git_blob user_project, params[:sha], @blob
end
desc 'Get a blob from the repository'
diff --git a/lib/api/v3/repositories.rb b/lib/api/v3/repositories.rb
index 0eaa0de2eef..5609b2ba5e7 100644
--- a/lib/api/v3/repositories.rb
+++ b/lib/api/v3/repositories.rb
@@ -49,7 +49,7 @@ module API
not_found! "Commit" unless commit
blob = Gitlab::Git::Blob.find(repo, commit.id, params[:filepath])
not_found! "File" unless blob
- send_git_blob repo, blob
+ send_git_blob user_project, commit.id, blob
end
desc 'Get a raw blob contents by blob sha'
@@ -64,7 +64,7 @@ module API
not_found! 'Blob'
end
not_found! 'Blob' unless blob
- send_git_blob repo, blob
+ send_git_blob user_project, params[:sha], blob
end
desc 'Get an archive of the repository'
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index f96ee69096d..4d74f74fe6e 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -26,10 +26,7 @@ module Gitlab
}
if Gitlab.config.gitaly.enabled
- server = {
- address: Gitlab::GitalyClient.address(project.repository_storage),
- token: Gitlab::GitalyClient.token(project.repository_storage)
- }
+ server = gitaly_server_hash(project)
params[:Repository] = repository.gitaly_repository.to_h
feature_enabled = case action.to_s
@@ -63,11 +60,22 @@ module Gitlab
{ TempPath: ArtifactUploader.artifacts_upload_path }
end
- def send_git_blob(repository, blob)
- params = {
- 'RepoPath' => repository.path_to_repo,
- 'BlobId' => blob.id
- }
+ def send_git_blob(project, revision, blob)
+ params = if Gitlab::GitalyClient.feature_enabled?(:project_raw_show) && blob.path.present?
+ {
+ 'GitalyServer' => gitaly_server_hash(project),
+ 'TreeEntryRequest' => {
+ repository: project.repository.gitaly_repository.to_h,
+ revision: Base64.strict_encode64(revision),
+ path: Base64.strict_encode64(blob.path)
+ }
+ }
+ else
+ {
+ 'RepoPath' => project.repository.path_to_repo,
+ 'BlobId' => blob.id
+ }
+ end
[
SEND_DATA_HEADER,
@@ -194,6 +202,13 @@ module Gitlab
def encode(hash)
Base64.urlsafe_encode64(JSON.dump(hash))
end
+
+ def gitaly_server_hash(project)
+ {
+ address: Gitlab::GitalyClient.address(project.repository_storage),
+ token: Gitlab::GitalyClient.token(project.repository_storage)
+ }
+ end
end
end
end