diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-10 09:02:34 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-10 09:02:34 -0700 |
commit | 79c58482962bd7ddd4979a4afcd178f697fe84fa (patch) | |
tree | b39538ed8086aa229ee68dddfd9436d0dcab65c0 /lib/gitlab_shell.rb | |
parent | 45881f17d06c860c8fe6a0b0441a847a63b75783 (diff) | |
parent | 45b3a3a7cda1296682a2054abf89c95a55c78f0f (diff) | |
download | gitlab-shell-79c58482962bd7ddd4979a4afcd178f697fe84fa.tar.gz |
Merge pull request #56 from smashwilson/36-logger
Logger
Diffstat (limited to 'lib/gitlab_shell.rb')
-rw-r--r-- | lib/gitlab_shell.rb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb index 7a9e3df..01ef4a1 100644 --- a/lib/gitlab_shell.rb +++ b/lib/gitlab_shell.rb @@ -8,7 +8,9 @@ class GitlabShell def initialize @key_id = /key-[0-9]+/.match(ARGV.join).to_s @origin_cmd = ENV['SSH_ORIGINAL_COMMAND'] - @repos_path = GitlabConfig.new.repos_path + @config = GitlabConfig.new + @repos_path = @config.repos_path + @user_tried = false end def exec @@ -20,13 +22,18 @@ class GitlabShell if validate_access process_cmd + else + message = "gitlab-shell: Access denied for git command <#{@origin_cmd}> by #{log_username}." + $logger.warn message + $stderr.puts "Access denied." end else + message = "gitlab-shell: Attempt to execute disallowed command <#{@origin_cmd}> by #{log_username}." + $logger.warn message puts 'Not allowed command' end else - user = api.discover(@key_id) - puts "Welcome to GitLab, #{user && user['name'] || 'Anonymous'}!" + puts "Welcome to GitLab, #{username}!" end end @@ -44,7 +51,9 @@ class GitlabShell def process_cmd repo_full_path = File.join(repos_path, repo_name) - exec_cmd "#{@git_cmd} #{repo_full_path}" + cmd = "#{@git_cmd} #{repo_full_path}" + $logger.info "gitlab-shell: executing git command <#{cmd}> for #{log_username}." + exec_cmd(cmd) end def validate_access @@ -58,4 +67,23 @@ class GitlabShell def api GitlabNet.new end + + def user + # Can't use "@user ||=" because that will keep hitting the API when @user is really nil! + if @user_tried + @user + else + @user_tried = true + @user = api.discover(@key_id) + end + end + + def username + user && user['name'] || 'Anonymous' + end + + # User identifier to be used in log messages. + def log_username + @config.audit_usernames ? username : "user with key #{@key_id}" + end end |