Class: Golem::Command::Auth
Overview
Command for authorization. Checks authenticated (via sshd) user’s access to given repository, if access granted creates repository if needed and calls git-shell.
Constant Summary collapse
- RE_CMD =
Regexp to check for git commands.
/\A\s*(git[ \-](upload-pack|upload-archive|receive-pack))\s+'([^.]+).git'/
Instance Method Summary collapse
-
#run(user = ENV['GOLEM_USER']) ⇒ Object
Run the command.
Methods inherited from Base
#command, #initialize, #verbose?
Constructor Details
This class inherits a constructor from Golem::Command::Base
Instance Method Details
#run(user = ENV['GOLEM_USER']) ⇒ Object
Run the command. Git command is read from ENV. Set environment variables (for hooks) and call git-shell if access granted.
10 11 12 13 14 15 16 17 |
# File 'lib/golem/command/auth.rb', line 10 def run(user = ENV['GOLEM_USER']) abort 'Please use git!' unless matches = (ENV['SSH_ORIGINAL_COMMAND'] || '').match(RE_CMD) cmd, subcmd, repo = matches[1, 3] abort 'You don\'t have permission!' unless Golem::Access.check(user, repo, subcmd) command(:create_repository, repo) unless File.directory?(Golem::Config.repository_path(repo)) set_env(user, repo) exec "git-shell", "-c", "#{cmd} '#{ENV['GOLEM_REPOSITORY_PATH']}'" end |