diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-08-29 14:41:39 -0500 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-09-06 12:06:45 -0500 |
commit | a64f174d83caddfd3fe31698b5b2fd7701b5a573 (patch) | |
tree | 8172013137ce1e28e527825a15e4066944a952bb /lib | |
parent | dbf374e10ad859a02ef69af53031e245913b6e65 (diff) | |
download | gitlab-shell-a64f174d83caddfd3fe31698b5b2fd7701b5a573.tar.gz |
Refactored JSON header generation to its own class and added tests for it
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_lfs_authentication.rb | 22 | ||||
-rw-r--r-- | lib/gitlab_shell.rb | 12 |
2 files changed, 24 insertions, 10 deletions
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 diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb index ab98a6e..87fa347 100644 --- a/lib/gitlab_shell.rb +++ b/lib/gitlab_shell.rb @@ -1,8 +1,7 @@ require 'shellwords' -require 'base64' -require 'json' require_relative 'gitlab_net' +require_relative 'gitlab_lfs_authentication' class GitlabShell class AccessDeniedError < StandardError; end @@ -195,14 +194,7 @@ class GitlabShell def lfs_authenticate return unless user - authorization = { - header: { - Authorization: "Basic #{Base64.strict_encode64("#{user['username']}:#{user['lfs_token']}")}" - }, - href: "#{repository_http_path}/info/lfs/" - } - - puts JSON.generate(authorization) + puts GitlabLfsAuthentication.new(user, repository_http_path).authenticate! end private |