git.iko.soy/typeable/nixpkgs
on master help sign in
gitaly: revert a commit that broke config loading
commite32bf64da083edd714605d0ed917c2a447b703bf authorMilan Pässler <mil@nyantec.com> dateMon 18 May 2020, 23:50 (6 years ago) parent47c8e52
2 files changed+324−1
pkgs/applications/version-management/gitlab/gitaly/0001-Revert-Allow-gitlabshell-config-to-be-passed-in-thro.patch+320 pkgs/applications/version-management/gitlab/gitaly/default.nix+4−1
pkgs/applications/version-management/gitlab/gitaly/0001-Revert-Allow-gitlabshell-config-to-be-passed-in-thro.patchnew file+320
@@ -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
5+ config variable"
6+
7+This reverts commit 14d8bae73b9e0d604c048d1cbcc1f4413c922bef.
8+---
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(-)
16+
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'
22+
23+ class GitlabConfig
24+ def secret_file
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'))
27+ end
28+
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.
31+ #
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'))
35+ end
36+
37+ def gitlab_url
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{/*$}, '')
40+ end
41+
42+ def http_settings
43+- fetch_from_config('http_settings', fetch_from_legacy_config('http_settings', {}))
44++ fetch_from_legacy_config('http_settings', {})
45+ end
46+
47+ def log_file
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?
50+
51+- log_path = ROOT_PATH if log_path === ''
52+-
53+- return log_path.join('gitlab-shell.log')
54++ fetch_from_legacy_config('log_file', File.join(ROOT_PATH, 'gitlab-shell.log'))
55+ end
56+
57+ def log_level
58+- log_level = fetch_from_config('log_level', LOG_LEVEL)
59+-
60+- return log_level unless log_level.empty?
61++ return LOG_LEVEL unless LOG_LEVEL.empty?
62+
63+- 'INFO'
64++ fetch_from_legacy_config('log_level', 'INFO')
65+ end
66+
67+ def log_format
68+- log_format = fetch_from_config('log_format', LOG_FORMAT)
69++ return LOG_FORMAT unless LOG_FORMAT.empty?
70+
71+- return log_format unless log_format.empty?
72++ fetch_from_legacy_config('log_format', 'text')
73++ end
74+
75+- 'text'
76++ def metrics_log_file
77++ fetch_from_legacy_config('metrics_log_file', File.join(ROOT_PATH, 'gitlab-shell-metrics.log'))
78+ end
79+
80+ def to_json
81+@@ -53,6 +51,7 @@ class GitlabConfig
82+ log_file: log_file,
83+ log_level: log_level,
84+ log_format: log_format,
85++ metrics_log_file: metrics_log_file
86+ }.to_json
87+ end
88+
89+@@ -62,23 +61,8 @@ class GitlabConfig
90+
91+ private
92+
93+- def fetch_from_config(key, default)
94+- value = config[key]
95+-
96+- return default if value.nil? || value.empty?
97+-
98+- value
99+- end
100+-
101+- def config
102+- @config ||= JSON.parse(ENV.fetch('GITALY_GITLAB_SHELL_CONFIG', '{}'))
103+- end
104+-
105+ def legacy_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?
109+-
110+- @legacy_config ||= YAML.load_file(legacy_file)
111++ @legacy_config ||= YAML.load_file(File.join(ROOT_PATH, 'config.yml'))
112+ end
113+ end
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
118+@@ -1,10 +1,8 @@
119+ # GITLAB_SHELL_DIR has been deprecated
120+-require 'pathname'
121+-
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', "")
130+
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
137+@@ -1,112 +1,54 @@
138+ require_relative 'spec_helper'
139+ require_relative '../lib/gitlab_config'
140+-require 'json'
141+
142+ describe GitlabConfig do
143+ let(:config) { GitlabConfig.new }
144++ let(:config_data) { {} }
145+
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) }
149+
150+- before { expect(YAML).to receive(:load_file).and_return(config_data) }
151++ describe '#gitlab_url' do
152++ let(:url) { 'http://test.com' }
153+
154+- describe '#gitlab_url' do
155+- let(:url) { 'http://test.com' }
156++ subject { config.gitlab_url }
157+
158+- subject { config.gitlab_url }
159++ before { config_data['gitlab_url'] = url }
160+
161+- before { config_data['gitlab_url'] = url }
162++ it { is_expected.not_to be_empty }
163++ it { is_expected.to eq(url) }
164+
165+- it { is_expected.not_to be_empty }
166+- it { is_expected.to eq(url) }
167+-
168+- context 'remove trailing slashes' do
169+- before { config_data['gitlab_url'] = url + '//' }
170+-
171+- it { is_expected.to eq(url) }
172+- end
173+- end
174+-
175+- describe '#secret_file' do
176+- subject { config.secret_file }
177++ context 'remove trailing slashes' do
178++ before { config_data['gitlab_url'] = url + '//' }
179+
180+- it 'returns ".gitlab_shell_secret" by default' do
181+- is_expected.to eq(File.join(File.expand_path('..', __dir__),'.gitlab_shell_secret'))
182+- end
183+- end
184+-
185+- describe '#fetch_from_legacy_config' do
186+- let(:key) { 'yaml_key' }
187+-
188+- where(:yaml_value, :default, :expected_value) do
189+- [
190+- ['a', 'b', 'a'],
191+- [nil, 'b', 'b'],
192+- ['a', nil, 'a'],
193+- [nil, {}, {}]
194+- ]
195+- end
196+-
197+- with_them do
198+- it 'returns the correct value' do
199+- config_data[key] = yaml_value
200+-
201+- expect(config.fetch_from_legacy_config(key, default)).to eq(expected_value)
202+- end
203+- end
204++ it { is_expected.to eq(url) }
205+ end
206+ end
207+
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 }
218+
219+- before { allow(ENV).to receive(:fetch).with('GITALY_GITLAB_SHELL_CONFIG', '{}').and_return(config_data.to_json) }
220+-
221+- describe '#secret_file' do
222+- it 'returns the correct secret_file' do
223+- expect(config.secret_file).to eq(config_data[:secret_file])
224+- end
225+- end
226+-
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])
230+- end
231+- end
232+-
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))
236+- end
237++ it 'returns "text" by default' do
238++ is_expected.to eq('text')
239+ end
240++ end
241+
242+- describe '#gitlab_url' do
243+- it 'returns the correct gitlab_url' do
244+- expect(config.gitlab_url).to eq(config_data[:gitlab_url])
245+- end
246+- end
247++ describe '#fetch_from_legacy_config' do
248++ let(:key) { 'yaml_key' }
249+
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')))
253+- end
254++ where(:yaml_value, :default, :expected_value) do
255++ [
256++ ['a', 'b', 'a'],
257++ [nil, 'b', 'b'],
258++ ['a', nil, 'a'],
259++ [nil, {}, {}]
260++ ]
261+ end
262+
263+- describe '#log_level' do
264+- it 'returns the correct log_level' do
265+- expect(config.log_level).to eq(config_data[:log_level])
266+- end
267+- end
268++ with_them do
269++ it 'returns the correct value' do
270++ config_data[key] = yaml_value
271+
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)
276+ end
277+ end
278+ end
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'))
286+
287+- stub_const('ROOT_PATH', Pathname.new(tmp_root_path))
288++ stub_const('ROOT_PATH', tmp_root_path)
289+ end
290+
291+ after do
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)
299+
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)
303+ end
304+ end
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
313++
314++ config.before(:each) do
315++ stub_const('ROOT_PATH', File.expand_path('..', __dir__))
316++ end
317+ end
318+--
319+2.26.2
320+
pkgs/applications/version-management/gitlab/gitaly/default.nix+4−1
@@ -40,7 +40,10 @@ in buildGoPackage rec {
4040
4141 # Fix a check which assumes that hook files are writeable by their
4242 # owner.
43− patches = [ ./fix-executable-check.patch ];
43+ patches = [
44+ ./fix-executable-check.patch
45+ ./0001-Revert-Allow-gitlabshell-config-to-be-passed-in-thro.patch
46+ ];
4447
4548 goPackagePath = "gitlab.com/gitlab-org/gitaly";
4649