diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2019-02-11 17:23:03 +1100 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-02-14 12:56:56 +1100 |
commit | c2b101cc2d1f51a4968673756eecfb2e36bf682c (patch) | |
tree | 28ec983e58c4922196f9b1311942a6531dcf37a8 /lib | |
parent | 1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258 (diff) | |
download | gitlab-shell-c2b101cc2d1f51a4968673756eecfb2e36bf682c.tar.gz |
Provide expires_in for LFS if available57353-git-push-fails-on-large-lfs-files-where-the-push-take-a-long-time
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_lfs_authentication.rb | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/gitlab_lfs_authentication.rb b/lib/gitlab_lfs_authentication.rb index ccd6d69..574dc98 100644 --- a/lib/gitlab_lfs_authentication.rb +++ b/lib/gitlab_lfs_authentication.rb @@ -2,29 +2,42 @@ require 'base64' require 'json' class GitlabLfsAuthentication + # TODO: These don't need to be public attr_accessor :username, :lfs_token, :repository_http_path - def initialize(username, lfs_token, repository_http_path) + def initialize(username, lfs_token, repository_http_path, expires_in = nil) @username = username @lfs_token = lfs_token @repository_http_path = repository_http_path + @expires_in = expires_in end def self.build_from_json(json) values = JSON.parse(json) - new(values['username'], values['lfs_token'], values['repository_http_path']) + new(values['username'], + values['lfs_token'], + values['repository_http_path'], + values['expires_in']) rescue nil end + # Source: https://github.com/git-lfs/git-lfs/blob/master/docs/api/server-discovery.md#ssh + # def authentication_payload - authorization = { - header: { - Authorization: "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}" - }, - href: "#{repository_http_path}/info/lfs/" - } - - JSON.generate(authorization) + payload = { header: { Authorization: authorization }, href: href } + payload[:expires_in] = @expires_in if @expires_in + + JSON.generate(payload) + end + + private + + def authorization + "Basic #{Base64.strict_encode64("#{username}:#{lfs_token}")}" + end + + def href + "#{repository_http_path}/info/lfs" end end |