class Golem::Command::Auth

Command for authorization. Checks authenticated (via sshd) user’s access to given repository, if access granted creates repository if needed and calls git-shell.

Constants

RE_CMD

Regexp to check for git commands.

USAGE

@private

Public Instance Methods

run(user = ENV['GOLEM_USER']) click to toggle source

Run the command. Git command is read from ENV. Set environment variables (for hooks) and call git-shell if access granted. @param [String] user the user to run as.

# 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

Private Instance Methods

set_env(user, repo) click to toggle source
# File lib/golem/command/auth.rb, line 20
def set_env(user, repo)
    {
        'GOLEM_USER' => user,
        'GOLEM_REPOSITORY_NAME' => repo,
        'GOLEM_REPOSITORY_PATH' => Golem::Config.repository_path(repo),
    }.each {|k, v| ENV[k] = v}
end