summaryrefslogtreecommitdiff
path: root/lib/gitlab_shell.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-05 11:59:53 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-05 11:59:53 +0200
commit02f4cb520458ad336e67c259810359ebcdaedb59 (patch)
tree4780bb36ed4a500419406af7698bbce7947574d2 /lib/gitlab_shell.rb
parent43bdc5da612af265b3c06eec26c36f7dbd98329e (diff)
downloadgitlab-shell-02f4cb520458ad336e67c259810359ebcdaedb59.tar.gz
gitlab net
Diffstat (limited to 'lib/gitlab_shell.rb')
-rw-r--r--lib/gitlab_shell.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 0223ded..9167bac 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -1,13 +1,13 @@
require 'open3'
-require 'net/http'
require_relative 'gitlab_config'
+require_relative 'gitlab_net'
class GitlabShell
- attr_accessor :username, :repo_name, :git_cmd, :repos_path, :repo_name
+ attr_accessor :key_id, :repo_name, :git_cmd, :repos_path, :repo_name
def initialize
- @username = ARGV.shift
+ @key_id = ARGV.shift
@origin_cmd = ENV['SSH_ORIGINAL_COMMAND']
@repos_path = GitlabConfig.new.repos_path
end
@@ -17,7 +17,7 @@ class GitlabShell
parse_cmd
if git_cmds.include?(@git_cmd)
- ENV['GL_USER'] = @username
+ ENV['GL_USER'] = @key_id
if validate_access
process_cmd
@@ -26,7 +26,8 @@ class GitlabShell
puts 'Not allowed command'
end
else
- puts "Welcome #{@username}!"
+ user = api.discover(@key_id)
+ puts "Welcome to GitLab, #{user['name']}!"
end
end
@@ -49,10 +50,11 @@ class GitlabShell
def validate_access
@ref_name = 'master' # just hardcode it cause we dont know ref
- project_name = @repo_name.gsub("'", "")
- project_name = project_name.gsub(/\.git$/, "")
- url = "http://127.0.0.1:3000/api/v3/allowed?project=#{project_name}&username=#{@username}&action=#{@git_cmd}&ref=#{@ref_name}"
- resp = Net::HTTP.get_response(URI.parse(url))
- resp.code == '200' && resp.body == 'true'
+
+ api.allowed?(@git_cmd, @repo_name, @key_id, @ref_name)
+ end
+
+ def api
+ GitlabNet.new
end
end