Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove legacy functions #711

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifests/backports.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
}
}

if is_hash($pin) {
if $pin =~ Hash {
$_pin = $pin
} elsif is_numeric($pin) or is_string($pin) {
} elsif $pin =~ Numeric or $pin =~ String {
# apt::source defaults to pinning to origin, but we should pin to release
# for backports
$_pin = {
Expand Down
9 changes: 5 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
fail('This module only works on Debian or derivatives like Ubuntu')
}

$frequency_options = ['always','daily','weekly','reluctantly']

if $update['frequency'] {
validate_re($update['frequency'], $frequency_options)
assert_type(
Enum['always','daily','weekly','reluctantly'],
$update['frequency'],
)
}
if $update['timeout'] {
assert_type(Integer, $update['timeout'])
Expand Down Expand Up @@ -66,7 +67,7 @@
$_purge = merge($::apt::purge_defaults, $purge)

if $proxy['ensure'] {
validate_re($proxy['ensure'], ['file', 'present', 'absent'])
assert_type(Enum['file', 'present', 'absent'], $proxy['ensure'])
}
if $proxy['host'] {
assert_type(String, $proxy['host'])
Expand Down
11 changes: 8 additions & 3 deletions manifests/key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
Optional[String] $options = undef,
) {

validate_re($id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
assert_type(
Pattern[
/\A(0x)?[0-9a-fA-F]{8}\Z/,
/\A(0x)?[0-9a-fA-F]{16}\Z/,
/\A(0x)?[0-9a-fA-F]{40}\Z/,
], $id)

if $source {
validate_re($source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
assert_type(Pattern[/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/], $source)
}

if $server {
validate_re($server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
assert_type(Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/], $server)
}

case $ensure {
Expand Down
2 changes: 1 addition & 1 deletion manifests/pin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Read the manpage 'apt_preferences(5)', especially the chapter
# 'The Effect of APT Preferences' to understand the following logic
# and the difference between specific and general form
if is_array($packages) {
if $packages =~ Array {
$packages_string = join($packages, ' ')
} else {
$packages_string = $packages
Expand Down
10 changes: 7 additions & 3 deletions manifests/setting.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
$setting_type = $title_array[0]
$base_name = join(delete_at($title_array, 0), '-')

validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/], $setting_type) |$a, $b| {
fail("apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
}

unless is_integer($priority) {
if $priority !~ Integer {
# need this to allow zero-padded priority.
validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
assert_type(Pattern[/^\d+$/], $priority) |$a, $b| {
fail('apt::setting priority must be an integer or a zero-padded integer')
}
}

if ($setting_type == 'list') or ($setting_type == 'pref') {
Expand Down
33 changes: 16 additions & 17 deletions manifests/source.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# source.pp
# add an apt source
define apt::source(
Optional[String] $location = undef,
String $comment = $name,
String $ensure = present,
Optional[String] $release = undef,
String $repos = 'main',
Optional[Variant[Hash]] $include = {},
Optional[Variant[String, Hash]] $key = undef,
$pin = undef,
Optional[String] $architecture = undef,
Boolean $allow_unsigned = false,
Boolean $notify_update = true,
Optional[String] $location = undef,
String $comment = $name,
String $ensure = present,
Optional[String] $release = undef,
String $repos = 'main',
Optional[Variant[Hash]] $include = {},
Optional[Variant[String, Hash]] $key = undef,
Optional[Variant[Hash, Numeric, String]] $pin = undef,
Optional[String] $architecture = undef,
Boolean $allow_unsigned = false,
Boolean $notify_update = true,
) {

# This is needed for compat with 1.8.x
Expand All @@ -36,14 +36,13 @@
$includes = merge($::apt::include_defaults, $include)

if $key {
if is_hash($key) {
if $key =~ Hash {
unless $key['id'] {
fail('key hash must contain at least an id entry')
}
$_key = merge($::apt::source_key_defaults, $key)
} else {
validate_legacy(String, 'validate_string', $key)
$_key = { 'id' => $key }
$_key = { 'id' => assert_type(String[1], $key) }
}
}

Expand All @@ -66,9 +65,9 @@
}

if $pin {
if is_hash($pin) {
if $pin =~ Hash {
$_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
} elsif (is_numeric($pin) or is_string($pin)) {
} elsif ($pin =~ Numeric or $pin =~ String) {
$url_split = split($location, '[:\/]+')
$host = $url_split[1]
$_pin = {
Expand All @@ -85,7 +84,7 @@

# We do not want to remove keys when the source is absent.
if $key and ($ensure == 'present') {
if is_hash($_key) {
if $_key =~ Hash {
apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
ensure => present,
id => $_key['id'],
Expand Down
24 changes: 12 additions & 12 deletions spec/defines/key_compat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
end

it 'fails' do
expect { subject.call } .to raise_error(%r{does not match})
expect { subject.call } .to raise_error(%r{expects a match})
end
end

Expand All @@ -158,7 +158,7 @@
end

it 'fails' do
expect { subject.call } .to raise_error(%r{does not match})
expect { subject.call } .to raise_error(%r{expects a match})
end
end

Expand All @@ -170,7 +170,7 @@
end

it 'fails' do
expect { subject.call } .to raise_error(%r{does not match})
expect { subject.call } .to raise_error(%r{expects a match})
end
end
context 'exceed character url' do
Expand All @@ -181,7 +181,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect port number url' do
Expand All @@ -192,7 +192,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect protocol for url' do
Expand All @@ -203,7 +203,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'missing port number url' do
Expand All @@ -214,7 +214,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url ending with a dot' do
Expand All @@ -225,7 +225,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url begin with a dash' do
Expand All @@ -236,7 +236,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'invalid key' do
Expand All @@ -245,7 +245,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end

Expand All @@ -257,7 +257,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end

Expand All @@ -281,7 +281,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end

Expand Down
24 changes: 12 additions & 12 deletions spec/defines/key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
end

it 'fails' do
expect { subject.call } .to raise_error(%r{does not match})
expect { subject.call } .to raise_error(%r{expects a match})
end
end

Expand All @@ -163,7 +163,7 @@
end

it 'fails' do
expect { subject.call } .to raise_error(%r{does not match})
expect { subject.call } .to raise_error(%r{expects a match})
end
end

Expand All @@ -175,7 +175,7 @@
end

it 'fails' do
expect { subject.call } .to raise_error(%r{does not match})
expect { subject.call } .to raise_error(%r{expects a match})
end
end
context 'exceed character url' do
Expand All @@ -186,7 +186,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect port number url' do
Expand All @@ -197,7 +197,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'incorrect protocol for url' do
Expand All @@ -208,7 +208,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'missing port number url' do
Expand All @@ -219,7 +219,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url ending with a dot' do
Expand All @@ -230,7 +230,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'url begin with a dash' do
Expand All @@ -241,7 +241,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end
context 'invalid key' do
Expand All @@ -250,7 +250,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end

Expand All @@ -262,7 +262,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end

Expand All @@ -286,7 +286,7 @@
end

it 'fails' do
expect { subject.call }.to raise_error(%r{does not match})
expect { subject.call }.to raise_error(%r{expects a match})
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
it do
expect {
subject.call
}.to raise_error(Puppet::Error, %r{invalid value for pin})
}.to raise_error(Puppet::Error, %r{expects a value})
end
end

Expand Down