Class: Gitlab::Git::HookEnv
- Inherits:
-
Object
- Object
- Gitlab::Git::HookEnv
- Defined in:
- lib/gitlab/git/hook_env.rb
Overview
Ephemeral (per request) storage for environment variables that some Git commands need during internal API calls made from the Git pre-receive push hook.
See gitlab.com/gitlab-org/gitaly/-/blob/master/doc/object_quarantine.md#gitlab-and-git-object-quarantine for more information.
This class is thread-safe via RequestStore.
Constant Summary collapse
- ALLOWLISTED_VARIABLES =
%w[ GIT_OBJECT_DIRECTORY_RELATIVE GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE ].freeze
Class Method Summary collapse
- .all(gl_repository) ⇒ Object
- .allowlist_git_env(env) ⇒ Object
- .set(gl_repository, env) ⇒ Object
- .to_env_hash(gl_repository) ⇒ Object
Class Method Details
.all(gl_repository) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/gitlab/git/hook_env.rb', line 31 def self.all(gl_repository) return {} unless Gitlab::SafeRequestStore.active? h = Gitlab::SafeRequestStore.fetch(:gitlab_git_env) { {} } h.fetch(gl_repository, {}) end |
.allowlist_git_env(env) ⇒ Object
49 50 51 |
# File 'lib/gitlab/git/hook_env.rb', line 49 def self.allowlist_git_env(env) env.select { |key, _| ALLOWLISTED_VARIABLES.include?(key.to_s) }.with_indifferent_access end |
.set(gl_repository, env) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/git/hook_env.rb', line 22 def self.set(gl_repository, env) return unless Gitlab::SafeRequestStore.active? raise "missing gl_repository" if gl_repository.blank? Gitlab::SafeRequestStore[:gitlab_git_env] ||= {} Gitlab::SafeRequestStore[:gitlab_git_env][gl_repository] = allowlist_git_env(env) end |
.to_env_hash(gl_repository) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gitlab/git/hook_env.rb', line 38 def self.to_env_hash(gl_repository) env = {} all(gl_repository).compact.each do |key, value| value = value.join(File::PATH_SEPARATOR) if value.is_a?(Array) env[key.to_s] = value end env end |