summaryrefslogtreecommitdiff
path: root/lib/gitlab_lfs_authentication.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab_lfs_authentication.rb')
-rw-r--r--lib/gitlab_lfs_authentication.rb14
1 files changed, 10 insertions, 4 deletions
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/"
}