lib/gitauth/client.rb in brownbeagle-gitauth-0.0.1 vs lib/gitauth/client.rb in brownbeagle-gitauth-0.0.2

- old
+ new

@@ -23,57 +23,55 @@ class Client attr_accessor :user, :command def initialize(user_name, command) - GitAuth.logger.debug "Initializing client with command: '#{command}' and user name '#{user_name}'" + GitAuth.logger.debug "Initializing client with command: #{command.inspect} and user name #{user_name.inspect}" @callbacks = Hash.new { |h,k| h[k] = [] } - @user = GitAuth::Users.get(user_name.to_s.strip) + @user = GitAuth::User.get(user_name.to_s.strip) @command = command end - def on(command, &blk) - @callbacks[command.to_sym] << blk - end - - def execute_callback!(command) - @callbacks[command.to_sym].each { |c| c.call(self) } - end - def exit_with_error(error) GitAuth.logger.warn "Exiting with error: #{error}" $stderr.puts error exit! 1 end def run! if @user.nil? - execute_callback! :invalid_user + exit_with_error "An invalid user / key was used. Please ensure it is setup with GitAuth" elsif @command.to_s.strip.empty? - execute_callback! :invalid_command + if user.shell_accessible? + exec(ENV["SHELL"]) + else + exit_with_error "SSH_ORIGINAL_COMMAND is needed, mmmkay?" + end else command = Command.parse!(@command) - repo = Repo.get(extract_repo_name(command)) + repo = command.bad? ? nil : Repo.get(extract_repo_name(command)) if command.bad? - execute_callback! :bad_command + if user.shell_accessible? + exec(@command) + else + exit_with_error "A Bad Command Has Failed Ye, Thou Shalt Not Continue." + end elsif repo.nil? - execute_callback! :invalid_repository + exit_with_error "Ze repository you specified does not exist." elsif user.can_execute?(command, repo) - # We can go ahead. git_shell_argument = "#{command.verb} '#{repo.real_path}'" - # And execute that soab. GitAuth.logger.info "Running command: #{git_shell_argument} for user: #{@user.name}" exec("git-shell", "-c", git_shell_argument) else - execute_callback! :access_denied + exit_with_error "These are not the droids you are looking for" end end rescue Exception => e GitAuth.logger.fatal "Exception: #{e.class.name}: #{e.message}" e.backtrace.each do |l| GitAuth.logger.fatal " => #{l}" end - execute_callback! :fatal_error + exit_with_error "Holy crap, we've imploded cap'n!" end def self.start!(user, command) client = self.new(user, command) yield client if block_given? \ No newline at end of file