summaryrefslogtreecommitdiff
path: root/lib/gitlab_lfs_authentication.rb
blob: 196cdd7456a82f7e2fd0f549a57836becdc68976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'base64'
require 'json'

class GitlabLfsAuthentication
  attr_accessor :username, :lfs_token, :repository_http_path

  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) rescue nil
    self.new(values['username'], values['lfs_token'], values['repository_http_path'])
  end

  def authentication_payload
    authorization = {
      header: {
        Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}"
      },
      href: "#{repository_http_path}/info/lfs/"
    }

    JSON.generate(authorization)
  end
end