From f53d09e1eb1323be9cd697813a6f47375c091f6a Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Tue, 30 Aug 2016 13:37:09 -0500 Subject: Refactored LFS auth logic to use its own API endpoint. --- lib/gitlab_lfs_authentication.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/gitlab_lfs_authentication.rb') diff --git a/lib/gitlab_lfs_authentication.rb b/lib/gitlab_lfs_authentication.rb index b05da21..4b36229 100644 --- a/lib/gitlab_lfs_authentication.rb +++ b/lib/gitlab_lfs_authentication.rb @@ -2,17 +2,23 @@ require 'base64' require 'json' class GitlabLfsAuthentication - attr_accessor :user, :repository_http_path + attr_accessor :username, :lfs_token, :repository_http_path - def initialize(user, repository_http_path) - @user = user + def initialize(username, lfs_token, repository_http_path) + @username = username + @lfs_token = lfs_token @repository_http_path = repository_http_path end + def self.build_from_json(json) + values = JSON.parse(json) + self.new(values['username'], values['lfs_token'], values['repository_http_path']) + end + def authenticate! authorization = { header: { - Authorization: "Basic #{Base64.strict_encode64("#{user['username']}:#{user['lfs_token']}")}" + Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}" }, href: "#{repository_http_path}/info/lfs/" } -- cgit v1.2.1