summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-02-11 14:34:10 +1100
committerAsh McKenzie <amckenzie@gitlab.com>2019-02-11 15:49:36 +1100
commitc4f1e8ed1014d2dec07ad12bed398dfa5d2bc6e1 (patch)
treef3a7a4d11e8f6c01b8900c151752937e69ad292f
parent9ab268b9c1bc028d50dee7c126878aa1df389cfe (diff)
downloadgitlab-ce-c4f1e8ed1014d2dec07ad12bed398dfa5d2bc6e1.tar.gz
Move LFS auth hash creation into GitLab::LfsToken
-rw-r--r--lib/api/internal.rb8
-rw-r--r--lib/gitlab/lfs_token.rb8
-rw-r--r--spec/lib/gitlab/lfs_token_spec.rb14
3 files changed, 23 insertions, 7 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 9488b3469d9..ede84dba42d 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -117,13 +117,7 @@ module API
raise ActiveRecord::RecordNotFound.new("No key_id or user_id passed!")
end
- token_handler = Gitlab::LfsToken.new(actor)
-
- {
- username: token_handler.actor_name,
- lfs_token: token_handler.token,
- repository_http_path: project.http_url_to_repo
- }
+ Gitlab::LfsToken.new(actor).for_gitlab_shell(project.http_url_to_repo)
end
# rubocop: enable CodeReuse/ActiveRecord
diff --git a/lib/gitlab/lfs_token.rb b/lib/gitlab/lfs_token.rb
index 26b81847d37..1193277bee5 100644
--- a/lib/gitlab/lfs_token.rb
+++ b/lib/gitlab/lfs_token.rb
@@ -47,6 +47,14 @@ module Gitlab
user? ? :lfs_token : :lfs_deploy_token
end
+ def for_gitlab_shell(repository_http_path)
+ {
+ username: actor_name,
+ lfs_token: token,
+ repository_http_path: repository_http_path
+ }
+ end
+
private # rubocop:disable Lint/UselessAccessModifier
class HMACToken
diff --git a/spec/lib/gitlab/lfs_token_spec.rb b/spec/lib/gitlab/lfs_token_spec.rb
index b81f3be874f..b4d42a47263 100644
--- a/spec/lib/gitlab/lfs_token_spec.rb
+++ b/spec/lib/gitlab/lfs_token_spec.rb
@@ -226,4 +226,18 @@ describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do
end
end
end
+
+ describe '#for_gitlab_shell' do
+ let(:actor) { create(:user) }
+ let(:lfs_token) { described_class.new(actor) }
+ let(:repo_http_path) { 'http://localhost/user/repo.git' }
+
+ it 'returns a Hash desgined for gitlab-shell' do
+ hash = lfs_token.for_gitlab_shell(repo_http_path)
+
+ expect(hash[:username]).to eq(actor.username)
+ expect(hash[:repository_http_path]).to eq(repo_http_path)
+ expect(hash[:lfs_token]).to be_a String
+ end
+ end
end