Skip to content

Commit

Permalink
(MODULES-10246) Proxy settings allow empty string
Browse files Browse the repository at this point in the history
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 6/7, backwards compatibility was achived by replacing
empty string with _none_.
  • Loading branch information
Dorin-Pleava committed Dec 13, 2019
1 parent 31c1736 commit ffd1db6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/puppet/type/yumrepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,26 @@

newproperty(:proxy) do
desc "URL of a proxy server that Yum should use when accessing this repository.
This attribute can also be set to `'_none_'`, which will make Yum bypass any
This attribute can also be set to `'_none_'` or `''`(empty string), which will make Yum bypass any
global proxy settings when accessing this repository.
#{ABSENT_DOC}"

newvalues(%r{.*}, :absent)
validate do |value|
next if value.to_s =~ %r{^(absent|_none_)$}
parsed = URI.parse(value)
next if value.to_s.empty?

parsed = URI.parse(value)
unless VALID_SCHEMES.include?(parsed.scheme)
raise _('Must be a valid URL')
end
end

# Munges empty string (option available starting with EL 8)
# Using '_none_' as backwards compatibility
munge do |value|
value.to_s.empty? ? '_none_' : value.to_s
end
end

newproperty(:proxy_username) do
Expand Down
19 changes: 18 additions & 1 deletion spec/unit/type/yumrepo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,30 @@

describe 'proxy' do
it_behaves_like 'a yumrepo parameter that can be absent', :proxy
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy

it 'accepts _none_' do
described_class.new(
name: 'puppetlabs',
proxy: '_none_',
)
end
it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy

it 'accepts an empty string' do
described_class.new(
name: 'puppetlabs',
proxy: '',
)
end

it 'munges empty string to \'_none_\' due to backwards compatibility' do
instance = described_class.new(name: 'puppetlabs', proxy: '')
expect(instance[:proxy]).to eq '_none_'
end

it 'does not raise any errors' do
expect { described_class.new(name: 'puppetlabs', proxy: '') }.not_to raise_error
end
end

describe 'proxy_username' do
Expand Down

0 comments on commit ffd1db6

Please sign in to comment.