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