Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / manifests / fragment.pp
1 # @summary
2 #   Manages a fragment of text to be compiled into a file.
3 #
4 # @param content
5 #   Supplies the content of the fragment. Note: You must supply either a content parameter or a source parameter.
6 #
7 # @param order
8 #   Reorders your fragments within the destination file. Fragments that share the same order number are ordered by name. The string
9 #   option is recommended.
10 #
11 # @param source
12 #   Specifies a file to read into the content of the fragment. Note: You must supply either a content parameter or a source parameter.
13 #   Valid options: a string or an array, containing one or more Puppet URLs.
14 #
15 # @param target
16 #   Specifies the destination file of the fragment. Valid options: a string containing the path or title of the parent concat resource.
17 #
18 define concat::fragment(
19   String                             $target,
20   Optional[String]                   $content = undef,
21   Optional[Variant[String, Array]]   $source  = undef,
22   Variant[String, Integer]           $order   = '10',
23 ) {
24   $resource = 'Concat::Fragment'
25
26   if ($order =~ String and $order =~ /[:\n\/]/) {
27     fail(translate("%{_resource}['%{_title}']: 'order' cannot contain '/', ':', or '\\n'.", {'_resource' => $resource, '_title' => $title}))
28   }
29
30   if ! ($content or $source) {
31     crit('No content, source or symlink specified')
32   } elsif ($content and $source) {
33     fail(translate("%{_resource}['%{_title}']: Can't use 'source' and 'content' at the same time.", {'_resource' => $resource, '_title' => $title}))
34   }
35
36   $safe_target_name = regsubst($target, '[\\\\/:~\n\s\+\*\(\)@]', '_', 'GM')
37
38   concat_fragment { $name:
39     target  => $target,
40     tag     => $safe_target_name,
41     order   => $order,
42     content => $content,
43     source  => $source,
44   }
45 }