summaryrefslogtreecommitdiff
path: root/lib/api/internal.rb
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-08-30 13:38:22 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-09-15 12:21:00 -0500
commit48f1a61fd5c6aac395be0ce5d59aee61bbb69fe9 (patch)
tree1cc737a70838d527d2e089d938474057877f695f /lib/api/internal.rb
parentcb85cf1f0a7047c485d7b29b2792b8965e270898 (diff)
downloadgitlab-ce-48f1a61fd5c6aac395be0ce5d59aee61bbb69fe9.tar.gz
Refactored LFS auth logic when using SSH to use its own API endpoint `/lfs_authenticate` and added tests.
Diffstat (limited to 'lib/api/internal.rb')
-rw-r--r--lib/api/internal.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 760f69663ab..1b3388347a8 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -69,12 +69,26 @@ module API
else
project.repository.path_to_repo
end
+ end
+
+ response
+ end
+
+ post "/lfs_authenticate" do
+ status 200
+
+ key = Key.find(params[:key_id])
+ user = key.user
- # Return HTTP full path, so that gitlab-shell has this information
- # ready for git-lfs-authenticate
- response[:repository_http_path] = project.http_url_to_repo
+ if user
+ token = Gitlab::LfsToken.new(user).generate
+ response = { username: user.username, lfs_token: token }
+ else
+ token = Gitlab::LfsToken.new(key).generate
+ response = { username: "lfs-deploy-key-#{key.id}", lfs_token: token }
end
+ response[:repository_http_path] = project.http_url_to_repo
response
end
@@ -87,15 +101,7 @@ module API
#
get "/discover" do
key = Key.find(params[:key_id])
- user = key.user
-
- if user
- token = Gitlab::LfsToken.new(user).set_token
- { name: user.name, username: user.username, lfs_token: token }
- else
- token = Gitlab::LfsToken.new(key).set_token
- { username: "lfs-deploy-key-#{key.id}", lfs_token: token }
- end
+ present key.user, with: Entities::UserSafe
end
get "/check" do