File: gitlab_lfs_authentication.rb

package info (click to toggle)
gitlab-shell 8.4.3%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,468 kB
  • sloc: ruby: 3,812; sh: 82; makefile: 60
file content (30 lines) | stat: -rw-r--r-- 720 bytes parent folder | download
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
29
30
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)
    new(values['username'], values['lfs_token'], values['repository_http_path'])
  rescue
    nil
  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