remove legacy functions
[puppet-modules/puppetlabs-apt.git] / manifests / setting.pp
1 define apt::setting (
2   Variant[String, Integer, Array] $priority           = 50,
3   Optional[Enum['file', 'present', 'absent']] $ensure = file,
4   Optional[String] $source                            = undef,
5   Optional[String] $content                           = undef,
6   Boolean $notify_update                              = true,
7 ) {
8
9   if $content and $source {
10     fail('apt::setting cannot have both content and source')
11   }
12
13   if !$content and !$source {
14     fail('apt::setting needs either of content or source')
15   }
16
17   $title_array = split($title, '-')
18   $setting_type = $title_array[0]
19   $base_name = join(delete_at($title_array, 0), '-')
20
21   assert_type(Pattern[/\Aconf\z/, /\Apref\z/, /\Alist\z/], $setting_type) |$a, $b| {
22     fail("apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
23   }
24
25   if $priority !~ Integer {
26     # need this to allow zero-padded priority.
27     assert_type(Pattern[/^\d+$/], $priority) |$a, $b| {
28       fail('apt::setting priority must be an integer or a zero-padded integer')
29     }
30   }
31
32   if ($setting_type == 'list') or ($setting_type == 'pref') {
33     $_priority = ''
34   } else {
35     $_priority = $priority
36   }
37
38   $_path = $::apt::config_files[$setting_type]['path']
39   $_ext  = $::apt::config_files[$setting_type]['ext']
40
41   if $notify_update {
42     $_notify = Class['apt::update']
43   } else {
44     $_notify = undef
45   }
46
47   file { "${_path}/${_priority}${base_name}${_ext}":
48     ensure  => $ensure,
49     owner   => 'root',
50     group   => 'root',
51     mode    => '0644',
52     content => $content,
53     source  => $source,
54     notify  => $_notify,
55   }
56 }