|
30 | 30 | # $i3 = regsubst($ipaddress,'^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$','\\3') |
31 | 31 | # ``` |
32 | 32 | dispatch :regsubst_string do |
33 | | - param 'Variant[Array[String],String]', :target |
| 33 | + param 'Variant[Array[Variant[String,Sensitive[String]]],Variant[String,Sensitive[String]]]', :target |
34 | 34 | param 'String', :pattern |
35 | 35 | param 'Variant[String,Hash[String,String]]', :replacement |
36 | 36 | optional_param 'Optional[Pattern[/^[GEIM]*$/]]', :flags |
|
67 | 67 | # $x = regsubst($ipaddress, /([0-9]+)/, '<\\1>', 'G') |
68 | 68 | # ``` |
69 | 69 | dispatch :regsubst_regexp do |
70 | | - param 'Variant[Array[String],String]', :target |
| 70 | + param 'Variant[Array[Variant[String,Sensitive[String]]],Variant[String,Sensitive[String]]]', :target |
71 | 71 | param 'Variant[Regexp,Type[Regexp]]', :pattern |
72 | 72 | param 'Variant[String,Hash[String,String]]', :replacement |
73 | 73 | optional_param 'Pattern[/^G?$/]', :flags |
@@ -95,7 +95,27 @@ def regsubst_regexp(target, pattern, replacement, flags = nil) |
95 | 95 | end |
96 | 96 |
|
97 | 97 | def inner_regsubst(target, re, replacement, op) |
98 | | - target.respond_to?(op) ? target.send(op, re, replacement) : target.collect { |e| e.send(op, re, replacement) } |
| 98 | + if target.respond_to?(:map) |
| 99 | + # this is an Array |
| 100 | + target.map do |item| |
| 101 | + if item.respond_to?(:unwrap) |
| 102 | + item = item.unwrap |
| 103 | + Puppet::Pops::Types::PSensitiveType::Sensitive.new( |
| 104 | + item.respond_to?(op) ? item.send(op, re, replacement) : item.collect { |e| e.send(op, re, replacement) } |
| 105 | + ) |
| 106 | + else |
| 107 | + item.respond_to?(op) ? item.send(op, re, replacement) : item.collect { |e| e.send(op, re, replacement) } |
| 108 | + end |
| 109 | + end |
| 110 | + elsif target.respond_to?(:unwrap) |
| 111 | + # this is a Sensitive |
| 112 | + target = target.unwrap |
| 113 | + target = target.respond_to?(op) ? target.send(op, re, replacement) : target.collect { |e| e.send(op, re, replacement) } |
| 114 | + Puppet::Pops::Types::PSensitiveType::Sensitive.new(target) |
| 115 | + else |
| 116 | + # this should be a String |
| 117 | + target.respond_to?(op) ? target.send(op, re, replacement) : target.collect { |e| e.send(op, re, replacement) } |
| 118 | + end |
99 | 119 | end |
100 | 120 | private :inner_regsubst |
101 | 121 | end |
0 commit comments