debian-mirror-gitlab/lib/gitlab/git/env.rb

54 lines
1.3 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
# Gitaly note: JV: no RPC's here.
2017-08-17 22:00:37 +05:30
module Gitlab
module Git
# Ephemeral (per request) storage for environment variables that some Git
# commands may need.
#
# For example, in pre-receive hooks, new objects are put in a temporary
# $GIT_OBJECT_DIRECTORY. Without it set, the new objects cannot be retrieved
# (this would break push rules for instance).
#
# This class is thread-safe via RequestStore.
class Env
2018-03-17 18:26:18 +05:30
WHITELISTED_VARIABLES = %w[
2017-08-17 22:00:37 +05:30
GIT_OBJECT_DIRECTORY
2018-03-17 18:26:18 +05:30
GIT_OBJECT_DIRECTORY_RELATIVE
2017-08-17 22:00:37 +05:30
GIT_ALTERNATE_OBJECT_DIRECTORIES
2018-03-17 18:26:18 +05:30
GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE
2017-08-17 22:00:37 +05:30
].freeze
def self.set(env)
return unless RequestStore.active?
RequestStore.store[:gitlab_git_env] = whitelist_git_env(env)
end
def self.all
return {} unless RequestStore.active?
RequestStore.fetch(:gitlab_git_env) { {} }
end
2018-03-17 18:26:18 +05:30
def self.to_env_hash
env = {}
all.compact.each do |key, value|
value = value.join(File::PATH_SEPARATOR) if value.is_a?(Array)
env[key.to_s] = value
end
env
end
2017-08-17 22:00:37 +05:30
def self.[](key)
all[key]
end
def self.whitelist_git_env(env)
2018-03-17 18:26:18 +05:30
env.select { |key, _| WHITELISTED_VARIABLES.include?(key.to_s) }.with_indifferent_access
2017-08-17 22:00:37 +05:30
end
end
end
end