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

- old
+ new

@@ -6,13 +6,11 @@ attr_reader :args, :env, :config attr_reader :log # Initialize a new Session - # - # config - GitHandler::Configuration instance - # + # @param [Configuration] config an existing configuration instance def initialize(config=nil) unless config.kind_of?(GitHandler::Configuration) raise SessionError, 'Configuration required!' end @@ -26,16 +24,15 @@ @config = config @log = Logger.new(@config.log_path) end - # Execute session - # - # args - Command arguments - # env - Environment parameters - # run_git - Execute git shell if no block provided# - # + # Execute session + # + # @param [Array] args session arguments + # @param [Hash] env hash with environment variables, use ENV.to_hash.dup + # @param [Boolean] run_git execute git command if set to true def execute(args, env, run_git=true) @args = args @env = env raise SessionError, "Invalid environment" unless valid_environment? @@ -75,13 +72,16 @@ # if we need to pass this to another server # the process should replace itself with another ssh call: # exec("ssh", "git@TARGET", "#{args.join(' ')}") end - # Execute session in safe manner, catch all exceptions - # and terminate session - # + # Execute session with catch-all-exceptions wrapper + # terminates session on SessionError or Exception + # + # @param [Array] args session arguments + # @param [Hash] env hash with environment variables, use ENV.to_hash.dup + # @param [Boolean] run_git execute git command if set to true def execute_safe(args, env, run_git=true) begin execute(args, env, run_git) rescue GitHandler::SessionError => err # TODO: Some additional logging here @@ -92,28 +92,25 @@ end end # Terminate session execution # - # reason - Process termination reason message - # exit_status - Exit code (default: 1) - # + # @param [String] reason + # @param [Fixnum] exit_status def terminate(reason='', exit_status=1) logger.error("Session terminated. Reason: #{reason}") $stderr.puts("Request failed: #{reason}") exit(exit_status) end # Check if session environment is valid - # def valid_environment? env['USER'] == config.user && env['HOME'] == config.home_path end # Check if session request is valid - # def valid_request? - if env.keys_all?(['SSH_CLIENT', 'SSH_CONNECTION', 'SSH_ORIGINAL_COMMAND']) + if env.include_all?(['SSH_CLIENT', 'SSH_CONNECTION', 'SSH_ORIGINAL_COMMAND']) if valid_command?(env['SSH_ORIGINAL_COMMAND']) return true end end false \ No newline at end of file