From a64f174d83caddfd3fe31698b5b2fd7701b5a573 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 29 Aug 2016 14:41:39 -0500 Subject: Refactored JSON header generation to its own class and added tests for it --- lib/gitlab_lfs_authentication.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/gitlab_lfs_authentication.rb (limited to 'lib/gitlab_lfs_authentication.rb') diff --git a/lib/gitlab_lfs_authentication.rb b/lib/gitlab_lfs_authentication.rb new file mode 100644 index 0000000..b05da21 --- /dev/null +++ b/lib/gitlab_lfs_authentication.rb @@ -0,0 +1,22 @@ +require 'base64' +require 'json' + +class GitlabLfsAuthentication + attr_accessor :user, :repository_http_path + + def initialize(user, repository_http_path) + @user = user + @repository_http_path = repository_http_path + end + + def authenticate! + authorization = { + header: { + Authorization: "Basic #{Base64.strict_encode64("#{user['username']}:#{user['lfs_token']}")}" + }, + href: "#{repository_http_path}/info/lfs/" + } + + JSON.generate(authorization) + end +end -- cgit v1.2.1