|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | Puppet::Parser::Functions.newfunction(:redact, doc: <<~DOC |
4 | | - This function will modify the catalog during compilation to remove the named |
5 | | - parameter from the class from which it was called. For example, if you wrote a |
6 | | - class named `foo` and called `redact('bar')` from within that class, then the |
7 | | - catalog would not record the value of `bar` that `foo` was called with. |
8 | | -
|
9 | | - ~~~ puppet |
10 | | - class foo($bar) { |
11 | | - # this call will display the proper output, but because it's not a resource |
12 | | - # the string won't exist in the catalog. |
13 | | - notice("Class['foo'] was called with param ${bar}") |
14 | | -
|
15 | | - # but the catalog won't record what the passed in param was. |
16 | | - redact('bar') |
17 | | - } |
18 | | -
|
19 | | - class { 'foo': |
20 | | - bar => 'this will not appear in the catalog', |
21 | | - } |
22 | | - ~~~ |
23 | | -
|
24 | | - **Warning**: If you use that parameter to declare other classes or resources, |
25 | | - then you must take further action to remove the parameter from those declarations! |
26 | | -
|
27 | | - This takes an optional second parameter of the value to replace the original |
28 | | - parameter declaration with. This parameter is required if the class declares |
29 | | - a type that is not `String` for the parameter you're redacting. |
30 | | - DOC |
31 | | - ) do |args| |
| 4 | + This function will modify the catalog during compilation to remove the named |
| 5 | + parameter from the class from which it was called. For example, if you wrote a |
| 6 | + class named `foo` and called `redact('bar')` from within that class, then the |
| 7 | + catalog would not record the value of `bar` that `foo` was called with. |
| 8 | +
|
| 9 | + ~~~ puppet |
| 10 | + class foo($bar) { |
| 11 | + # this call will display the proper output, but because it's not a resource |
| 12 | + # the string won't exist in the catalog. |
| 13 | + notice("Class['foo'] was called with param ${bar}") |
| 14 | +
|
| 15 | + # but the catalog won't record what the passed in param was. |
| 16 | + redact('bar') |
| 17 | + } |
| 18 | +
|
| 19 | + class { 'foo': |
| 20 | + bar => 'this will not appear in the catalog', |
| 21 | + } |
| 22 | + ~~~ |
| 23 | +
|
| 24 | + **Warning**: If you use that parameter to declare other classes or resources, |
| 25 | + then you must take further action to remove the parameter from those declarations! |
| 26 | +
|
| 27 | + This takes an optional second parameter of the value to replace the original |
| 28 | + parameter declaration with. This parameter is required if the class declares |
| 29 | + a type that is not `String` for the parameter you're redacting. |
| 30 | +DOC |
| 31 | +) do |args| |
32 | 32 | raise Puppet::ParseError, 'The redact function requires 1 or 2 arguments' unless [1, 2].include? args.size |
33 | 33 |
|
34 | 34 | param = args[0] |
|
0 commit comments