@@ -0,0 +1,320 @@
1+From 3df6278a00d29a0941cf0142848fac8bfba09ebf Mon Sep 17 00:00:00 2001
2+From: =?UTF-8?q?Milan=20P=C3=A4ssler?= <me@pbb.lc>
3+Date: Tue, 19 May 2020 01:12:04 +0200
4+Subject: [PATCH] Revert "Allow gitlabshell config to be passed in through a
7+This reverts commit 14d8bae73b9e0d604c048d1cbcc1f4413c922bef.
9+ ruby/gitlab-shell/lib/gitlab_config.rb | 46 +++----
10+ ruby/gitlab-shell/lib/gitlab_init.rb | 10 +-
11+ ruby/gitlab-shell/spec/gitlab_config_spec.rb | 116 +++++-------------
12+ .../spec/gitlab_custom_hook_spec.rb | 2 +-
13+ ruby/gitlab-shell/spec/gitlab_logger_spec.rb | 2 +-
14+ ruby/gitlab-shell/spec/spec_helper.rb | 4 +
15+ 6 files changed, 54 insertions(+), 126 deletions(-)
17+diff --git a/ruby/gitlab-shell/lib/gitlab_config.rb b/ruby/gitlab-shell/lib/gitlab_config.rb
18+index 9020ff7f..19f03c34 100644
19+--- a/ruby/gitlab-shell/lib/gitlab_config.rb
20++++ b/ruby/gitlab-shell/lib/gitlab_config.rb
21+@@ -2,46 +2,44 @@ require 'yaml'
25+- fetch_from_config('secret_file', fetch_from_legacy_config('secret_file', File.join(ROOT_PATH, '.gitlab_shell_secret')))
26++ fetch_from_legacy_config('secret_file',File.join(ROOT_PATH, '.gitlab_shell_secret'))
29+ # Pass a default value because this is called from a repo's context; in which
30+ # case, the repo's hooks directory should be the default.
32+ def custom_hooks_dir(default: nil)
33+- fetch_from_config('custom_hooks_dir', fetch_from_legacy_config('custom_hooks_dir', File.join(ROOT_PATH, 'hooks')))
34++ fetch_from_legacy_config('custom_hooks_dir', File.join(ROOT_PATH, 'hooks'))
38+- fetch_from_config('gitlab_url', fetch_from_legacy_config('gitlab_url',"http://localhost:8080").sub(%r{/*$}, ''))
39++ fetch_from_legacy_config('gitlab_url',"http://localhost:8080").sub(%r{/*$}, '')
43+- fetch_from_config('http_settings', fetch_from_legacy_config('http_settings', {}))
44++ fetch_from_legacy_config('http_settings', {})
48+- log_path = Pathname.new(fetch_from_config('log_path', LOG_PATH))
49++ return File.join(LOG_PATH, 'gitlab-shell.log') unless LOG_PATH.empty?
51+- log_path = ROOT_PATH if log_path === ''
53+- return log_path.join('gitlab-shell.log')
54++ fetch_from_legacy_config('log_file', File.join(ROOT_PATH, 'gitlab-shell.log'))
58+- log_level = fetch_from_config('log_level', LOG_LEVEL)
60+- return log_level unless log_level.empty?
61++ return LOG_LEVEL unless LOG_LEVEL.empty?
64++ fetch_from_legacy_config('log_level', 'INFO')
68+- log_format = fetch_from_config('log_format', LOG_FORMAT)
69++ return LOG_FORMAT unless LOG_FORMAT.empty?
71+- return log_format unless log_format.empty?
72++ fetch_from_legacy_config('log_format', 'text')
76++ def metrics_log_file
77++ fetch_from_legacy_config('metrics_log_file', File.join(ROOT_PATH, 'gitlab-shell-metrics.log'))
81+@@ -53,6 +51,7 @@ class GitlabConfig
83+ log_level: log_level,
84+ log_format: log_format,
85++ metrics_log_file: metrics_log_file
89+@@ -62,23 +61,8 @@ class GitlabConfig
93+- def fetch_from_config(key, default)
96+- return default if value.nil? || value.empty?
102+- @config ||= JSON.parse(ENV.fetch('GITALY_GITLAB_SHELL_CONFIG', '{}'))
106+ # TODO: deprecate @legacy_config that is parsing the gitlab-shell config.yml
107+- legacy_file = ROOT_PATH.join('config.yml')
108+- return {} unless legacy_file.exist?
110+- @legacy_config ||= YAML.load_file(legacy_file)
111++ @legacy_config ||= YAML.load_file(File.join(ROOT_PATH, 'config.yml'))
114+diff --git a/ruby/gitlab-shell/lib/gitlab_init.rb b/ruby/gitlab-shell/lib/gitlab_init.rb
115+index 94913549..ce54e2d4 100644
116+--- a/ruby/gitlab-shell/lib/gitlab_init.rb
117++++ b/ruby/gitlab-shell/lib/gitlab_init.rb
119+ # GITLAB_SHELL_DIR has been deprecated
122+-ROOT_PATH = Pathname.new(ENV['GITALY_GITLAB_SHELL_DIR'] || ENV['GITLAB_SHELL_DIR'] || File.expand_path('..', __dir__)).freeze
123+-LOG_PATH = Pathname.new(ENV.fetch('GITALY_LOG_DIR', ROOT_PATH))
124+-LOG_LEVEL = ENV.fetch('GITALY_LOG_LEVEL', 'INFO')
125+-LOG_FORMAT = ENV.fetch('GITALY_LOG_FORMAT', 'text')
126++ROOT_PATH = ENV['GITALY_GITLAB_SHELL_DIR'] || ENV['GITLAB_SHELL_DIR'] || File.expand_path('..', __dir__)
127++LOG_PATH = ENV.fetch('GITALY_LOG_DIR', "")
128++LOG_LEVEL = ENV.fetch('GITALY_LOG_LEVEL', "")
129++LOG_FORMAT = ENV.fetch('GITALY_LOG_FORMAT', "")
131+ # We are transitioning parts of gitlab-shell into the gitaly project. In
132+ # gitaly, GITALY_EMBEDDED will be true.
133+diff --git a/ruby/gitlab-shell/spec/gitlab_config_spec.rb b/ruby/gitlab-shell/spec/gitlab_config_spec.rb
134+index b0f12381..6de0cd08 100644
135+--- a/ruby/gitlab-shell/spec/gitlab_config_spec.rb
136++++ b/ruby/gitlab-shell/spec/gitlab_config_spec.rb
138+ require_relative 'spec_helper'
139+ require_relative '../lib/gitlab_config'
142+ describe GitlabConfig do
143+ let(:config) { GitlabConfig.new }
144++ let(:config_data) { {} }
146+- context "without ENV['GITALY_GITLAB_SHELL_CONFIG'] is passed in" do
147+- let(:config_data) { {} }
148++ before { expect(YAML).to receive(:load_file).and_return(config_data) }
150+- before { expect(YAML).to receive(:load_file).and_return(config_data) }
151++ describe '#gitlab_url' do
152++ let(:url) { 'http://test.com' }
154+- describe '#gitlab_url' do
155+- let(:url) { 'http://test.com' }
156++ subject { config.gitlab_url }
158+- subject { config.gitlab_url }
159++ before { config_data['gitlab_url'] = url }
161+- before { config_data['gitlab_url'] = url }
162++ it { is_expected.not_to be_empty }
163++ it { is_expected.to eq(url) }
165+- it { is_expected.not_to be_empty }
166+- it { is_expected.to eq(url) }
168+- context 'remove trailing slashes' do
169+- before { config_data['gitlab_url'] = url + '//' }
171+- it { is_expected.to eq(url) }
175+- describe '#secret_file' do
176+- subject { config.secret_file }
177++ context 'remove trailing slashes' do
178++ before { config_data['gitlab_url'] = url + '//' }
180+- it 'returns ".gitlab_shell_secret" by default' do
181+- is_expected.to eq(File.join(File.expand_path('..', __dir__),'.gitlab_shell_secret'))
185+- describe '#fetch_from_legacy_config' do
186+- let(:key) { 'yaml_key' }
188+- where(:yaml_value, :default, :expected_value) do
198+- it 'returns the correct value' do
199+- config_data[key] = yaml_value
201+- expect(config.fetch_from_legacy_config(key, default)).to eq(expected_value)
204++ it { is_expected.to eq(url) }
208+- context "when ENV['GITALY_GITLAB_SHELL_CONFIG'] is passed in" do
209+- let(:config_data) { {'secret_file': 'path/to/secret/file',
210+- 'custom_hooks_dir': '/path/to/custom_hooks',
211+- 'gitlab_url': 'http://localhost:123454',
212+- 'http_settings': {'user': 'user_123', 'password':'password123', 'ca_file': '/path/to/ca_file', 'ca_path': 'path/to/ca_path'},
213+- 'log_path': '/path/to/log',
214+- 'log_level': 'myloglevel',
215+- 'log_format': 'log_format'} }
216++ describe '#log_format' do
217++ subject { config.log_format }
219+- before { allow(ENV).to receive(:fetch).with('GITALY_GITLAB_SHELL_CONFIG', '{}').and_return(config_data.to_json) }
221+- describe '#secret_file' do
222+- it 'returns the correct secret_file' do
223+- expect(config.secret_file).to eq(config_data[:secret_file])
227+- describe '#custom_hooks_dir' do
228+- it 'returns the correct custom_hooks_dir' do
229+- expect(config.custom_hooks_dir).to eq(config_data[:custom_hooks_dir])
233+- describe '#http_settings' do
234+- it 'returns the correct http_settings' do
235+- expect(config.http_settings).to eq(config_data[:http_settings].transform_keys(&:to_s))
237++ it 'returns "text" by default' do
238++ is_expected.to eq('text')
242+- describe '#gitlab_url' do
243+- it 'returns the correct gitlab_url' do
244+- expect(config.gitlab_url).to eq(config_data[:gitlab_url])
247++ describe '#fetch_from_legacy_config' do
248++ let(:key) { 'yaml_key' }
250+- describe '#log_path' do
251+- it 'returns the correct log_path' do
252+- expect(config.log_file).to eq(Pathname.new(File.join(config_data[:log_path], 'gitlab-shell.log')))
254++ where(:yaml_value, :default, :expected_value) do
263+- describe '#log_level' do
264+- it 'returns the correct log_level' do
265+- expect(config.log_level).to eq(config_data[:log_level])
269++ it 'returns the correct value' do
270++ config_data[key] = yaml_value
272+- describe '#log_format' do
273+- it 'returns the correct log_format' do
274+- expect(config.log_format).to eq(config_data[:log_format])
275++ expect(config.fetch_from_legacy_config(key, default)).to eq(expected_value)
279+diff --git a/ruby/gitlab-shell/spec/gitlab_custom_hook_spec.rb b/ruby/gitlab-shell/spec/gitlab_custom_hook_spec.rb
280+index c19b90f8..50865331 100644
281+--- a/ruby/gitlab-shell/spec/gitlab_custom_hook_spec.rb
282++++ b/ruby/gitlab-shell/spec/gitlab_custom_hook_spec.rb
283+@@ -99,7 +99,7 @@ describe GitlabCustomHook do
284+ FileUtils.symlink(File.join(tmp_root_path, 'hooks'), File.join(tmp_repo_path, 'hooks'))
285+ FileUtils.symlink(File.join(ROOT_PATH, 'config.yml.example'), File.join(tmp_root_path, 'config.yml'))
287+- stub_const('ROOT_PATH', Pathname.new(tmp_root_path))
288++ stub_const('ROOT_PATH', tmp_root_path)
292+diff --git a/ruby/gitlab-shell/spec/gitlab_logger_spec.rb b/ruby/gitlab-shell/spec/gitlab_logger_spec.rb
293+index 0523a4cc..0da64735 100644
294+--- a/ruby/gitlab-shell/spec/gitlab_logger_spec.rb
295++++ b/ruby/gitlab-shell/spec/gitlab_logger_spec.rb
296+@@ -142,7 +142,7 @@ describe GitlabLogger do
297+ test_logger_status = system('bin/test-logger', msg)
298+ expect(test_logger_status).to eq(true)
300+- grep_status = system('grep', '-q', '-e', msg, GitlabConfig.new.log_file.to_s)
301++ grep_status = system('grep', '-q', '-e', msg, GitlabConfig.new.log_file)
302+ expect(grep_status).to eq(true)
305+diff --git a/ruby/gitlab-shell/spec/spec_helper.rb b/ruby/gitlab-shell/spec/spec_helper.rb
306+index 684f87b1..be5ff9c6 100644
307+--- a/ruby/gitlab-shell/spec/spec_helper.rb
308++++ b/ruby/gitlab-shell/spec/spec_helper.rb
309+@@ -10,4 +10,8 @@ Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
310+ RSpec.configure do |config|
311+ config.run_all_when_everything_filtered = true
312+ config.filter_run :focus
314++ config.before(:each) do
315++ stub_const('ROOT_PATH', File.expand_path('..', __dir__))