Skip to content

Commit 594bb32

Browse files
Dorin-Pleavamihaibuzgau
authored andcommitted
(MODULES-10246) Proxy settings allow empty string
This PR enables the Yum Repo Core to accept an empty string as proxy setting, to bypass any global proxy settings when accessing the repository. In case of EL 8, '_none_' will be replaced with '' (empty string).
1 parent 31c1736 commit 594bb32

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

lib/puppet/type/yumrepo.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,25 @@
304304

305305
newproperty(:proxy) do
306306
desc "URL of a proxy server that Yum should use when accessing this repository.
307-
This attribute can also be set to `'_none_'`, which will make Yum bypass any
308-
global proxy settings when accessing this repository.
307+
This attribute can also be set to '_none_' (or '' for EL >= 8 only),
308+
which will make Yum bypass any global proxy settings when accessing this repository.
309309
#{ABSENT_DOC}"
310310

311311
newvalues(%r{.*}, :absent)
312312
validate do |value|
313313
next if value.to_s =~ %r{^(absent|_none_)$}
314-
parsed = URI.parse(value)
314+
next if value.to_s.empty? && Facter.value(:operatingsystemmajrelease).to_i >= 8
315315

316+
parsed = URI.parse(value)
316317
unless VALID_SCHEMES.include?(parsed.scheme)
317318
raise _('Must be a valid URL')
318319
end
319320
end
321+
322+
munge do |value|
323+
return '' if Facter.value(:operatingsystemmajrelease).to_i >= 8 && value.to_s == '_none_'
324+
value.to_s
325+
end
320326
end
321327

322328
newproperty(:proxy_username) do

spec/unit/type/yumrepo_spec.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,37 @@
312312

313313
describe 'proxy' do
314314
it_behaves_like 'a yumrepo parameter that can be absent', :proxy
315+
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy
316+
315317
it 'accepts _none_' do
316318
described_class.new(
317319
name: 'puppetlabs',
318320
proxy: '_none_',
319321
)
320322
end
321-
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy
323+
324+
it 'accepts an empty string' do
325+
described_class.new(
326+
name: 'puppetlabs',
327+
proxy: '',
328+
)
329+
end
330+
331+
it "munges '_none_' to empty string for EL >= 8" do
332+
Facter.stubs(:value).with(:operatingsystemmajrelease).returns('8')
333+
instance = described_class.new(name: 'puppetlabs', proxy: '_none_')
334+
expect(instance[:proxy]).to eq ''
335+
end
336+
337+
it "does not munges '_none_' to empty string for EL < 8" do
338+
Facter.stubs(:value).with(:operatingsystemmajrelease).returns('7')
339+
instance = described_class.new(name: 'puppetlabs', proxy: '_none_')
340+
expect(instance[:proxy]).to eq '_none_'
341+
end
342+
343+
it 'does not raise any errors' do
344+
expect { described_class.new(name: 'puppetlabs', proxy: '') }.not_to raise_error
345+
end
322346
end
323347

324348
describe 'proxy_username' do

0 commit comments

Comments
 (0)