Commit 49cf9badbce730c053496306778b801d596658af

Authored by Dmitriy Zaporozhets
1 parent b698094d

Gitlab::ShellEnv added

lib/gitlab/backend/grack_auth.rb
@@ -32,8 +32,7 @@ module Grack @@ -32,8 +32,7 @@ module Grack
32 self.user = User.find_by_email(login) || User.find_by_username(login) 32 self.user = User.find_by_email(login) || User.find_by_username(login)
33 return false unless user.try(:valid_password?, password) 33 return false unless user.try(:valid_password?, password)
34 34
35 - # Set GL_ID env variable  
36 - ENV['GL_ID'] = "user-#{user.id}" 35 + Gitlab::ShellEnv.set_env(user)
37 end 36 end
38 37
39 # Git upload and receive 38 # Git upload and receive
lib/gitlab/backend/shell.rb
@@ -53,7 +53,6 @@ module Gitlab @@ -53,7 +53,6 @@ module Gitlab
53 system("/home/git/gitlab-shell/bin/gitlab-keys rm-key #{key_id} \"#{key_content}\"") 53 system("/home/git/gitlab-shell/bin/gitlab-keys rm-key #{key_id} \"#{key_content}\"")
54 end 54 end
55 55
56 -  
57 def url_to_repo path 56 def url_to_repo path
58 Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git" 57 Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
59 end 58 end
lib/gitlab/backend/shell_env.rb 0 → 100644
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +module Gitlab
  2 + # This module provide 2 methods
  3 + # to set specific ENV variabled for GitLab Shell
  4 + module ShellEnv
  5 + extend self
  6 +
  7 + def set_env(user)
  8 + # Set GL_ID env variable
  9 + ENV['GL_ID'] = "user-#{user.id}"
  10 + end
  11 +
  12 + def reset_env
  13 + # Reset GL_ID env variable
  14 + ENV['GL_ID'] = nil
  15 + end
  16 + end
  17 +end
lib/gitlab/satellite/action.rb
@@ -17,6 +17,8 @@ module Gitlab @@ -17,6 +17,8 @@ module Gitlab
17 # * Locks the satellite repo 17 # * Locks the satellite repo
18 # * Yields the prepared satellite repo 18 # * Yields the prepared satellite repo
19 def in_locked_and_timed_satellite 19 def in_locked_and_timed_satellite
  20 + Gitlab::ShellEnv.set_env(user)
  21 +
20 Grit::Git.with_timeout(options[:git_timeout]) do 22 Grit::Git.with_timeout(options[:git_timeout]) do
21 project.satellite.lock do 23 project.satellite.lock do
22 return yield project.satellite.repo 24 return yield project.satellite.repo
@@ -28,6 +30,8 @@ module Gitlab @@ -28,6 +30,8 @@ module Gitlab
28 rescue Grit::Git::GitTimeout => ex 30 rescue Grit::Git::GitTimeout => ex
29 Gitlab::GitLogger.error(ex.message) 31 Gitlab::GitLogger.error(ex.message)
30 return false 32 return false
  33 + ensure
  34 + Gitlab::ShellEnv.reset_env
31 end 35 end
32 36
33 # * Clears the satellite 37 # * Clears the satellite