Commit b83ab386 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

gitlab-shell base implementation

parent e620575d
config.yml
user: git
repos_path: "/home/git/repositories"
require 'open3' require 'open3'
require 'yaml'
class GitlabShell class GitlabShell
attr_accessor :username, :repo_name, :git_cmd attr_accessor :username, :repo_name, :git_cmd, :repos_path
def initialize def initialize
@username = ARGV.shift @username = ARGV.shift
@origin_cmd = ENV['SSH_ORIGINAL_COMMAND'] @origin_cmd = ENV['SSH_ORIGINAL_COMMAND']
@config = YAML.load_file(File.join(ROOT_PATH, 'config.yml'))
@repos_path = @config['repos_path']
end end
def exec def exec
if @origin_cmd if @origin_cmd
parse_cmd parse_cmd
return system("git-upload-pack /home/gip/repositories/#{@repo_name}") if git_cmds.include?(@git_cmd)
process_cmd
else
puts 'Not allowed command'
end
else else
puts "Welcome #{@username}!" puts "Welcome #{@username}!"
end end
...@@ -28,4 +36,9 @@ class GitlabShell ...@@ -28,4 +36,9 @@ class GitlabShell
def git_cmds def git_cmds
%w(git-upload-pack git-receive-pack git-upload-archive) %w(git-upload-pack git-receive-pack git-upload-archive)
end end
def process_cmd
repo_full_path = File.join(repos_path, repo_name)
system("#{@git_cmd} #{repo_full_path}")
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment