Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / concat / manifests / init.pp
1 # @summary
2 #   Manages a file, compiled from one or more text fragments.
3 #
4 # @example
5 #   concat { '/tmp/concat':
6 #     ensure => present,
7 #     owner  => 'root',
8 #     group  => 'root',
9 #     mode   => '0644',
10 #   }
11 #
12 # @param backup
13 #   Specifies whether (and how) to back up the destination file before overwriting it. Your value gets passed on to Puppet's native file
14 #   resource for execution. Valid options: true, false, or a string representing either a target filebucket or a filename extension
15 #   beginning with ".".
16 #
17 # @param ensure
18 #   Specifies whether the destination file should exist. Setting to 'absent' tells Puppet to delete the destination file if it exists, and
19 #   negates the effect of any other parameters.
20 #
21 # @param ensure_newline
22 #   Specifies whether to add a line break at the end of each fragment that doesn't already end in one.
23 #
24 # @param format
25 #   Specify what data type to merge the fragments as. Valid options: 'plain', 'yaml', 'json', 'json-array', 'json-pretty',
26 #   'json-array-pretty'.
27 #
28 # @param force
29 #   Specifies whether to merge data structures, keeping the values with higher order. Used when format is specified as a value other than
30 #   'plain'.
31 #
32 # @param group
33 #   Specifies a permissions group for the destination file. Valid options: a string containing a group name or integer containing a gid.
34 #
35 # @param mode
36 #   Specifies the permissions mode of the destination file. Valid options: a string containing a permission mode value in octal notation.
37 #
38 # @param order
39 #   Specifies a method for sorting your fragments by name within the destination file. You can override this setting for individual
40 #   fragments by adjusting the order parameter in their concat::fragment declarations.
41 #
42 # @param owner
43 #   Specifies the owner of the destination file. Valid options: a string containing a username or integer containing a uid.
44 #
45 # @param path
46 #   Specifies a destination file for the combined fragments.
47 #
48 # @param replace
49 #   Specifies whether to overwrite the destination file if it already exists.
50 #
51 # @param selinux_ignore_defaults
52 #   See the file type's selinux_ignore_defaults documentention:
53 #   https://docs.puppetlabs.com/references/latest/type.html#file-attribute-selinux_ignore_defaults
54 #
55 # @param selrange
56 #   See the file type's selrange documentention: https://docs.puppetlabs.com/references/latest/type.html#file-attribute-selrange
57 #
58 # @param selrole
59 #   See the file type's selrole documentention: https://docs.puppetlabs.com/references/latest/type.html#file-attribute-selrole
60 #
61 # @param seltype
62 #   See the file type's seltype documentention: https://docs.puppetlabs.com/references/latest/type.html#file-attribute-seltype
63 #
64 # @param seluser
65 #   See the file type's seluser documentention: https://docs.puppetlabs.com/references/latest/type.html#file-attribute-seluser
66 #
67 # @param show_diff
68 #   Specifies whether to set the show_diff parameter for the file resource. Useful for hiding secrets stored in hiera from insecure
69 #   reporting methods.
70 #
71 # @param validate_cmd
72 #   Specifies a validation command to apply to the destination file.
73 #
74 # @param warn
75 #   Specifies whether to add a header message at the top of the destination file. Valid options: the booleans true and false, or a string
76 #   to serve as the header.
77 #   If you set 'warn' to true, concat adds the following line with an order of 0:
78 #   `# This file is managed by Puppet. DO NOT EDIT.`
79 #   Before 2.0.0, this parameter would add a newline at the end of the warn message. To improve flexibilty, this was removed. Please add
80 #   it explicitly if you need it.
81 #
82 define concat(
83   Enum['present', 'absent']          $ensure                  = 'present',
84   Stdlib::Absolutepath               $path                    = $name,
85   Optional[Variant[String, Integer]] $owner                   = undef,
86   Optional[Variant[String, Integer]] $group                   = undef,
87   String                             $mode                    = '0644',
88   Variant[Boolean, String]           $warn                    = false,
89   Boolean                            $show_diff               = true,
90   Variant[Boolean, String]           $backup                  = 'puppet',
91   Boolean                            $replace                 = true,
92   Enum['alpha','numeric']            $order                   = 'alpha',
93   Boolean                            $ensure_newline          = false,
94   Optional[String]                   $validate_cmd            = undef,
95   Optional[Boolean]                  $selinux_ignore_defaults = undef,
96   Optional[String]                   $selrange                = undef,
97   Optional[String]                   $selrole                 = undef,
98   Optional[String]                   $seltype                 = undef,
99   Optional[String]                   $seluser                 = undef,
100   Optional[String]                   $format                  = 'plain',
101   Optional[Boolean]                  $force                   = false,
102 ) {
103
104   $safe_name            = regsubst($name, '[\\\\/:~\n\s\+\*\(\)@]', '_', 'G')
105   $default_warn_message = "# This file is managed by Puppet. DO NOT EDIT.\n"
106
107   case $warn {
108     true: {
109       $warn_message = $default_warn_message
110       $_append_header = true
111     }
112     false: {
113       $warn_message = ''
114       $_append_header = false
115     }
116     default: {
117       $warn_message = $warn
118       $_append_header = true
119     }
120   }
121
122   if $ensure == 'present' {
123     concat_file { $name:
124       tag                     => $safe_name,
125       path                    => $path,
126       owner                   => $owner,
127       group                   => $group,
128       mode                    => $mode,
129       selinux_ignore_defaults => $selinux_ignore_defaults,
130       selrange                => $selrange,
131       selrole                 => $selrole,
132       seltype                 => $seltype,
133       seluser                 => $seluser,
134       replace                 => $replace,
135       backup                  => $backup,
136       show_diff               => $show_diff,
137       order                   => $order,
138       ensure_newline          => $ensure_newline,
139       validate_cmd            => $validate_cmd,
140       format                  => $format,
141       force                   => $force,
142     }
143
144     if $_append_header {
145       concat_fragment { "${name}_header":
146         target  => $name,
147         tag     => $safe_name,
148         content => $warn_message,
149         order   => '0',
150       }
151     }
152   } else {
153     concat_file { $name:
154       ensure => $ensure,
155       tag    => $safe_name,
156       path   => $path,
157       backup => $backup,
158     }
159   }
160 }