diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-08-30 13:37:09 -0500 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-09-06 12:11:17 -0500 |
commit | f53d09e1eb1323be9cd697813a6f47375c091f6a (patch) | |
tree | 42b1950e5a8f0a7d3f97cf37e1c279793fc7c30d /lib/gitlab_net.rb | |
parent | c16f7323bad61601df1ebe93475bd84aee532faf (diff) | |
download | gitlab-shell-f53d09e1eb1323be9cd697813a6f47375c091f6a.tar.gz |
Refactored LFS auth logic to use its own API endpoint.
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r-- | lib/gitlab_net.rb | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb index 42ff94c..994f8d5 100644 --- a/lib/gitlab_net.rb +++ b/lib/gitlab_net.rb @@ -6,6 +6,7 @@ require_relative 'gitlab_config' require_relative 'gitlab_logger' require_relative 'gitlab_access' require_relative 'gitlab_redis' +require_relative 'gitlab_lfs_authentication' require_relative 'httpunix' class GitlabNet @@ -15,15 +16,12 @@ class GitlabNet READ_TIMEOUT = 300 def check_access(cmd, repo, actor, changes, protocol) - project_name = repo.gsub("'", "") - project_name = project_name.gsub(/\.git\Z/, "") - project_name = project_name.gsub(/\A\//, "") changes = changes.join("\n") unless changes.kind_of?(String) params = { action: cmd, changes: changes, - project: project_name, + project: project_name(repo), protocol: protocol } @@ -39,7 +37,7 @@ class GitlabNet if resp.code == '200' GitAccessStatus.create_from_json(resp.body) else - GitAccessStatus.new(false, 'API is not accessible', nil, nil) + GitAccessStatus.new(false, 'API is not accessible', nil) end end @@ -49,6 +47,19 @@ class GitlabNet JSON.parse(resp.body) rescue nil end + def lfs_authenticate(key, repo) + params = { + project: project_name(repo), + key_id: key.gsub('key-', '') + } + + resp = post("#{host}/lfs_authenticate", params) + + if resp.code == '200' + GitlabLfsAuthentication.build_from_json(resp.body) + end + end + def broadcast_message resp = get("#{host}/broadcast_message") JSON.parse(resp.body) rescue {} @@ -107,6 +118,12 @@ class GitlabNet protected + def project_name(repo) + project_name = repo.gsub("'", "") + project_name = project_name.gsub(/\.git\Z/, "") + project_name.gsub(/\A\//, "") + end + def config @config ||= GitlabConfig.new end |