lib/git_handler/session.rb in git_handler-0.2.1 vs lib/git_handler/session.rb in git_handler-0.2.2

- old
+ new

@@ -12,20 +12,22 @@ def initialize(config=nil) unless config.kind_of?(GitHandler::Configuration) raise SessionError, 'Configuration required!' end - unless File.exists?(config.home_path) - raise ConfigurationError, "Home path does not exist!" - end + if config.raise_errors == true + unless File.exists?(config.home_path) + raise ConfigurationError, "Home path does not exist!" + end - unless File.exists?(config.repos_path) - raise ConfigurationError, "Repositories path does not exist!" + unless File.exists?(config.repos_path) + raise ConfigurationError, "Repositories path does not exist!" + end end @config = config - @log = Logger.new(@config.log_path) + @log = Logger.new(@config.log_path) end # Execute session # # @param [Array] args session arguments @@ -49,14 +51,18 @@ :command => [command[:action], "'#{repo_path}'"].join(' '), :read => command[:read], :write => command[:write] ) - log_request(request) + if config.log == true + log_request(request) + end - unless File.exist?(request.repo_path) - raise SessionError, "Repository #{request.repo} does not exist!" + if config.raise_errors == true + unless File.exist?(request.repo_path) + raise SessionError, "Repository #{request.repo} does not exist!" + end end if block_given? # Pass all request information for custom processing # if no block is defined it will execute git-shell @@ -101,15 +107,17 @@ $stderr.puts("Request failed: #{reason}") exit(exit_status) end # Check if session environment is valid + # @return [Boolean] def valid_environment? env['USER'] == config.user && env['HOME'] == config.home_path end # Check if session request is valid + # @return [Boolean] def valid_request? if env.include_all?(['SSH_CLIENT', 'SSH_CONNECTION', 'SSH_ORIGINAL_COMMAND']) if valid_command?(env['SSH_ORIGINAL_COMMAND']) return true end @@ -117,10 +125,17 @@ false end private + # Log incoming request details + # @param req [Request] request instance + # + # Example output: + # I, [2012-10-19T22:54:11.402583 #4212] INFO -- : 10.0.0.1 "git-upload-pack 'PATH'" arg1 arg2 + # def log_request(req) - log.info("Request \"#{req.command}\" from #{req.remote_ip}. Args: #{req.args.join(' ')}") + message = [req.remote_ip, req.command, req.args.join(' ')].join(' ') + log.info(message) end end end \ No newline at end of file