puppet 5.5.6 → 5.5.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Gemfile.lock +12 -12
  4. data/Rakefile +9 -0
  5. data/lib/puppet/application.rb +5 -0
  6. data/lib/puppet/application/apply.rb +1 -0
  7. data/lib/puppet/application/master.rb +9 -7
  8. data/lib/puppet/application/script.rb +1 -1
  9. data/lib/puppet/defaults.rb +51 -31
  10. data/lib/puppet/etc.rb +20 -0
  11. data/lib/puppet/file_serving/fileset.rb +1 -1
  12. data/lib/puppet/functions.rb +123 -0
  13. data/lib/puppet/functions/new.rb +37 -53
  14. data/lib/puppet/functions/warning.rb +1 -1
  15. data/lib/puppet/loaders.rb +1 -0
  16. data/lib/puppet/parser/functions.rb +3 -1
  17. data/lib/puppet/parser/functions/sprintf.rb +12 -1
  18. data/lib/puppet/pops/evaluator/runtime3_converter.rb +16 -0
  19. data/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
  20. data/lib/puppet/pops/issues.rb +8 -0
  21. data/lib/puppet/pops/loader/loader.rb +2 -2
  22. data/lib/puppet/pops/loader/loader_paths.rb +3 -1
  23. data/lib/puppet/pops/loader/module_loaders.rb +1 -1
  24. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
  25. data/lib/puppet/pops/loaders.rb +5 -21
  26. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  27. data/lib/puppet/pops/parser/lexer2.rb +1 -1
  28. data/lib/puppet/pops/validation/checker4_0.rb +31 -6
  29. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  30. data/lib/puppet/property/keyvalue.rb +70 -8
  31. data/lib/puppet/provider/aix_object.rb +483 -0
  32. data/lib/puppet/provider/exec.rb +54 -57
  33. data/lib/puppet/provider/group/aix.rb +40 -115
  34. data/lib/puppet/provider/group/pw.rb +4 -8
  35. data/lib/puppet/provider/group/windows_adsi.rb +7 -4
  36. data/lib/puppet/provider/nameservice.rb +1 -25
  37. data/lib/puppet/provider/nameservice/directoryservice.rb +5 -3
  38. data/lib/puppet/provider/package/portage.rb +2 -2
  39. data/lib/puppet/provider/package/windows.rb +2 -2
  40. data/lib/puppet/provider/package/windows/exe_package.rb +3 -10
  41. data/lib/puppet/provider/package/zypper.rb +1 -1
  42. data/lib/puppet/provider/service/launchd.rb +19 -3
  43. data/lib/puppet/provider/service/windows.rb +49 -40
  44. data/lib/puppet/provider/user/aix.rb +180 -246
  45. data/lib/puppet/provider/user/windows_adsi.rb +9 -1
  46. data/lib/puppet/resource/catalog.rb +1 -5
  47. data/lib/puppet/type/augeas.rb +1 -1
  48. data/lib/puppet/type/exec.rb +16 -14
  49. data/lib/puppet/type/file.rb +2 -2
  50. data/lib/puppet/type/file/source.rb +9 -5
  51. data/lib/puppet/type/group.rb +65 -23
  52. data/lib/puppet/type/k5login.rb +2 -2
  53. data/lib/puppet/type/notify.rb +1 -1
  54. data/lib/puppet/type/package.rb +3 -6
  55. data/lib/puppet/type/resources.rb +12 -2
  56. data/lib/puppet/type/schedule.rb +8 -1
  57. data/lib/puppet/type/selboolean.rb +2 -2
  58. data/lib/puppet/type/selmodule.rb +3 -4
  59. data/lib/puppet/type/service.rb +2 -5
  60. data/lib/puppet/type/tidy.rb +1 -1
  61. data/lib/puppet/type/user.rb +15 -20
  62. data/lib/puppet/type/yumrepo.rb +2 -2
  63. data/lib/puppet/type/zone.rb +2 -2
  64. data/lib/puppet/util.rb +7 -3
  65. data/lib/puppet/util/execution.rb +15 -1
  66. data/lib/puppet/util/posix.rb +15 -0
  67. data/lib/puppet/util/storage.rb +12 -0
  68. data/lib/puppet/util/windows.rb +4 -2
  69. data/lib/puppet/util/windows/adsi.rb +235 -205
  70. data/lib/puppet/util/windows/process.rb +23 -3
  71. data/lib/puppet/util/windows/security.rb +14 -0
  72. data/lib/puppet/util/windows/service.rb +977 -0
  73. data/lib/puppet/util/windows/user.rb +3 -5
  74. data/lib/puppet/version.rb +1 -1
  75. data/locales/ja/puppet.po +705 -374
  76. data/locales/puppet.pot +485 -261
  77. data/man/man5/puppet.conf.5 +36 -15
  78. data/man/man8/puppet-agent.8 +1 -1
  79. data/man/man8/puppet-apply.8 +1 -1
  80. data/man/man8/puppet-ca.8 +1 -1
  81. data/man/man8/puppet-catalog.8 +1 -1
  82. data/man/man8/puppet-cert.8 +1 -1
  83. data/man/man8/puppet-certificate.8 +1 -1
  84. data/man/man8/puppet-certificate_request.8 +1 -1
  85. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  86. data/man/man8/puppet-config.8 +1 -1
  87. data/man/man8/puppet-describe.8 +1 -1
  88. data/man/man8/puppet-device.8 +1 -1
  89. data/man/man8/puppet-doc.8 +1 -1
  90. data/man/man8/puppet-epp.8 +1 -1
  91. data/man/man8/puppet-facts.8 +1 -1
  92. data/man/man8/puppet-filebucket.8 +1 -1
  93. data/man/man8/puppet-generate.8 +1 -1
  94. data/man/man8/puppet-help.8 +1 -1
  95. data/man/man8/puppet-key.8 +1 -1
  96. data/man/man8/puppet-lookup.8 +1 -1
  97. data/man/man8/puppet-man.8 +1 -1
  98. data/man/man8/puppet-master.8 +1 -1
  99. data/man/man8/puppet-module.8 +1 -1
  100. data/man/man8/puppet-node.8 +1 -1
  101. data/man/man8/puppet-parser.8 +1 -1
  102. data/man/man8/puppet-plugin.8 +1 -1
  103. data/man/man8/puppet-report.8 +1 -1
  104. data/man/man8/puppet-resource.8 +1 -1
  105. data/man/man8/puppet-script.8 +1 -1
  106. data/man/man8/puppet-status.8 +1 -1
  107. data/man/man8/puppet.8 +2 -2
  108. data/spec/fixtures/unit/provider/aix_object/aix_colon_list_real_world_input.out +1 -0
  109. data/spec/fixtures/unit/provider/aix_object/aix_colon_list_real_world_output.out +1 -0
  110. data/spec/fixtures/unit/provider/user/aix/aix_passwd_file.out +32 -0
  111. data/spec/integration/parser/collection_spec.rb +4 -8
  112. data/spec/integration/provider/service/windows_spec.rb +5 -5
  113. data/spec/integration/type/file_spec.rb +6 -6
  114. data/spec/integration/util/windows/adsi_spec.rb +6 -5
  115. data/spec/integration/util/windows/security_spec.rb +10 -7
  116. data/spec/integration/util/windows/user_spec.rb +37 -17
  117. data/spec/spec_helper.rb +0 -1
  118. data/spec/unit/application/apply_spec.rb +41 -2
  119. data/spec/unit/application/master_spec.rb +7 -0
  120. data/spec/unit/application_spec.rb +21 -3
  121. data/spec/unit/defaults_spec.rb +20 -0
  122. data/spec/unit/etc_spec.rb +25 -0
  123. data/spec/unit/file_serving/fileset_spec.rb +11 -11
  124. data/spec/unit/gettext/config_spec.rb +1 -1
  125. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +6 -6
  126. data/spec/unit/pops/loaders/loaders_spec.rb +40 -7
  127. data/spec/unit/pops/parser/parse_heredoc_spec.rb +16 -0
  128. data/spec/unit/pops/validator/validator_spec.rb +129 -10
  129. data/spec/unit/property/keyvalue_spec.rb +97 -6
  130. data/spec/unit/provider/aix_object_spec.rb +805 -0
  131. data/spec/unit/provider/group/aix_spec.rb +57 -0
  132. data/spec/unit/provider/group/pw_spec.rb +0 -6
  133. data/spec/unit/provider/group/windows_adsi_spec.rb +34 -35
  134. data/spec/unit/provider/nameservice/directoryservice_spec.rb +2 -2
  135. data/spec/unit/provider/package/windows/exe_package_spec.rb +3 -3
  136. data/spec/unit/provider/package/windows_spec.rb +4 -4
  137. data/spec/unit/provider/service/launchd_spec.rb +19 -0
  138. data/spec/unit/provider/service/windows_spec.rb +71 -78
  139. data/spec/unit/provider/user/aix_spec.rb +162 -116
  140. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  141. data/spec/unit/resource/catalog_spec.rb +2 -2
  142. data/spec/unit/ssl/certificate_authority_spec.rb +0 -1
  143. data/spec/unit/type/group_spec.rb +111 -13
  144. data/spec/unit/type/resources_spec.rb +18 -0
  145. data/spec/unit/util/execution_spec.rb +77 -0
  146. data/spec/unit/util/posix_spec.rb +28 -0
  147. data/spec/unit/util/storage_spec.rb +107 -0
  148. data/spec/unit/util/windows/adsi_spec.rb +108 -13
  149. data/spec/unit/util/windows/service_spec.rb +669 -0
  150. metadata +17 -5
  151. data/lib/puppet/provider/aixobject.rb +0 -392
  152. data/spec/unit/provider/aixobject_spec.rb +0 -101
@@ -51,16 +51,14 @@
51
51
  # The following sections show the arguments and conversion rules
52
52
  # per data type built into the Puppet Type System.
53
53
  #
54
- # Conversion to Optional[T] and NotUndef[T]
55
- # -----------------------------------------
54
+ # ### Conversion to Optional[T] and NotUndef[T]
56
55
  #
57
56
  # Conversion to these data types is the same as a conversion to the type argument `T`.
58
57
  # In the case of `Optional[T]` it is accepted that the argument to convert may be `undef`.
59
58
  # It is however not acceptable to give other arguments (than `undef`) that cannot be
60
59
  # converted to `T`.
61
60
  #
62
- # Conversion to Integer
63
- # ---------------------
61
+ # ### Conversion to Integer
64
62
  #
65
63
  # A new `Integer` can be created from `Integer`, `Float`, `Boolean`, and `String` values.
66
64
  # For conversion from `String` it is possible to specify the radix (base).
@@ -108,8 +106,7 @@
108
106
  # $a_number = Integer(-38, 10, true) # results in 38
109
107
  # ```
110
108
  #
111
- # Conversion to Float
112
- # -------------------
109
+ # ### Conversion to Float
113
110
  #
114
111
  # A new `Float` can be created from `Integer`, `Float`, `Boolean`, and `String` values.
115
112
  # For conversion from `String` both float and integer formats are supported.
@@ -121,15 +118,13 @@
121
118
  # )
122
119
  # ```
123
120
  #
124
- #
125
121
  # * For an integer, the floating point fraction of `.0` is added to the value.
126
122
  # * A `Boolean` `true` is converted to 1.0, and a `false` to 0.0
127
123
  # * In `String` format, integer prefixes for hex and binary are understood (but not octal since
128
124
  # floating point in string format may start with a '0').
129
125
  # * When `abs` is set to `true`, the result will be an absolute floating point value.
130
126
  #
131
- # Conversion to Numeric
132
- # ---------------------
127
+ # ### Conversion to Numeric
133
128
  #
134
129
  # A new `Integer` or `Float` can be created from `Integer`, `Float`, `Boolean` and
135
130
  # `String` values.
@@ -158,12 +153,11 @@
158
153
  # $a_number = Numeric(-42, true) # results in 42
159
154
  # ```
160
155
  #
161
- # Conversion to Timespan
162
- # -------------------
156
+ # ### Conversion to Timespan
163
157
  #
164
158
  # A new `Timespan` can be created from `Integer`, `Float`, `String`, and `Hash` values. Several variants of the constructor are provided.
165
159
  #
166
- # #### Timespan from seconds
160
+ # **Timespan from seconds**
167
161
  #
168
162
  # When a Float is used, the decimal part represents fractions of a second.
169
163
  #
@@ -173,7 +167,7 @@
173
167
  # )
174
168
  # ```
175
169
  #
176
- # #### Timespan from days, hours, minutes, seconds, and fractions of a second
170
+ # **Timespan from days, hours, minutes, seconds, and fractions of a second**
177
171
  #
178
172
  # The arguments can be passed separately in which case the first four, days, hours, minutes, and seconds are mandatory and the rest are optional.
179
173
  # All values may overflow and/or be negative. The internal 128-bit nano-second integer is calculated as:
@@ -206,7 +200,7 @@
206
200
  # )
207
201
  # ```
208
202
  #
209
- # #### Timespan from String and format directive patterns
203
+ # **Timespan from String and format directive patterns**
210
204
  #
211
205
  # The first argument is parsed using the format optionally passed as a string or array of strings. When an array is used, an attempt
212
206
  # will be made to parse the string using the first entry and then with each entry in succession until parsing succeeds. If the second
@@ -276,12 +270,11 @@
276
270
  # $duration = Timespan('10:03.5', '%M:%S.%N') # 10 minutes, 3 seconds, and 5 nano-seconds
277
271
  # ```
278
272
  #
279
- # Conversion to Timestamp
280
- # -------------------
273
+ # ### Conversion to Timestamp
281
274
  #
282
275
  # A new `Timestamp` can be created from `Integer`, `Float`, `String`, and `Hash` values. Several variants of the constructor are provided.
283
276
  #
284
- # #### Timestamp from seconds since epoch (1970-01-01 00:00:00 UTC)
277
+ # **Timestamp from seconds since epoch (1970-01-01 00:00:00 UTC)**
285
278
  #
286
279
  # When a Float is used, the decimal part represents fractions of a second.
287
280
  #
@@ -291,7 +284,7 @@
291
284
  # )
292
285
  # ```
293
286
  #
294
- # #### Timestamp from String and patterns consisting of format directives
287
+ # **Timestamp from String and patterns consisting of format directives**
295
288
  #
296
289
  # The first argument is parsed using the format optionally passed as a string or array of strings. When an array is used, an attempt
297
290
  # will be made to parse the string using the first entry and then with each entry in succession until parsing succeeds. If the second
@@ -470,9 +463,9 @@
470
463
  #
471
464
  # ```
472
465
  #
473
- # Conversion to Type
474
- # ------------------
475
- # A new `Type` can be create from its `String` representation.
466
+ # ### Conversion to Type
467
+ #
468
+ # A new `Type` can be created from its `String` representation.
476
469
  #
477
470
  # @example Creating a type from a string
478
471
  #
@@ -480,8 +473,7 @@
480
473
  # $t = Type.new('Integer[10]')
481
474
  # ```
482
475
  #
483
- # Conversion to String
484
- # --------------------
476
+ # ### Conversion to String
485
477
  #
486
478
  # Conversion to `String` is the most comprehensive conversion as there are many
487
479
  # use cases where a string representation is wanted. The defaults for the many options
@@ -524,7 +516,7 @@
524
516
  # Note that all data type supports the formats `s` and `p` with the meaning "default string representation" and
525
517
  # "default programmatic string representation" (which for example means that a String is quoted in 'p' format).
526
518
  #
527
- # ### Signatures of String conversion
519
+ # **Signatures of String conversion**
528
520
  #
529
521
  # ```puppet
530
522
  # type Format = Pattern[/^%([\s\+\-#0\[\{<\(\|]*)([1-9][0-9]*)?(?:\.([0-9]+))?([a-zA-Z])/]
@@ -582,7 +574,7 @@
582
574
  # The given formats are merged with the default formats, and matching of values to convert against format is based on
583
575
  # the specificity of the mapped type; for example, different formats can be used for short and long arrays.
584
576
  #
585
- # ### Integer to String
577
+ # **Integer to String**
586
578
  #
587
579
  # | Format | Integer Formats
588
580
  # | ------ | ---------------
@@ -597,7 +589,7 @@
597
589
  #
598
590
  # Defaults to `d`.
599
591
  #
600
- # ### Float to String
592
+ # **Float to String**
601
593
  #
602
594
  # | Format | Float formats
603
595
  # | ------ | -------------
@@ -611,7 +603,7 @@
611
603
  #
612
604
  # Defaults to `p`.
613
605
  #
614
- # ### String to String
606
+ # **String to String**
615
607
  #
616
608
  # | Format | String
617
609
  # | ------ | ------
@@ -625,7 +617,7 @@
625
617
  #
626
618
  # Defaults to `s` at top level and `p` inside array or hash.
627
619
  #
628
- # ### Boolean to String
620
+ # **Boolean to String**
629
621
  #
630
622
  # | Format | Boolean Formats
631
623
  # | ---- | -------------------
@@ -636,14 +628,14 @@
636
628
  # | s | String 'true' / 'false'.
637
629
  # | p | String 'true' / 'false'.
638
630
  #
639
- # ### Regexp to String
631
+ # **Regexp to String**
640
632
  #
641
633
  # | Format | Regexp Formats
642
634
  # | ---- | --------------
643
635
  # | s | No delimiters, quoted if alternative flag `#` is used.
644
636
  # | p | Delimiters `/ /`.
645
637
  #
646
- # ### Undef to String
638
+ # **Undef to String**
647
639
  #
648
640
  # | Format | Undef formats
649
641
  # | ------ | -------------
@@ -656,7 +648,7 @@
656
648
  # | V | String 'N/A'.
657
649
  # | u | String 'undef', or 'undefined' if alternative `#` flag is used.
658
650
  #
659
- # ### Default value to String
651
+ # **Default value to String**
660
652
  #
661
653
  # | Format | Default formats
662
654
  # | ------ | ---------------
@@ -664,7 +656,7 @@
664
656
  # | s | Same as d.
665
657
  # | p | Same as d.
666
658
  #
667
- # ### Binary value to String
659
+ # **Binary value to String**
668
660
  #
669
661
  # | Format | Default formats
670
662
  # | ------ | ---------------
@@ -681,7 +673,7 @@
681
673
  # as hex escaped characters on the form `\\xHH` where `H` is a hex digit.
682
674
  # * The width and precision values are applied to the text part only in `%p` format.
683
675
  #
684
- # ### Array & Tuple to String
676
+ # **Array & Tuple to String**
685
677
  #
686
678
  # | Format | Array/Tuple Formats
687
679
  # | ------ | -------------
@@ -696,7 +688,7 @@
696
688
  # it is taken as the maximum allowed length of a sequence of elements (not including delimiters). If this max length
697
689
  # is exceeded, each element will be indented.
698
690
  #
699
- # ### Hash & Struct to String
691
+ # **Hash & Struct to String**
700
692
  #
701
693
  # | Format | Hash/Struct Formats
702
694
  # | ------ | -------------
@@ -710,14 +702,14 @@
710
702
  #
711
703
  # The alternate form flag `#` will format each hash key/value entry indented on a separate line.
712
704
  #
713
- # ### Type to String
705
+ # **Type to String**
714
706
  #
715
707
  # | Format | Array/Tuple Formats
716
708
  # | ------ | -------------
717
709
  # | s | The same as `p`, quoted if alternative flag `#` is used.
718
710
  # | p | Outputs the type in string form as specified by the Puppet Language.
719
711
  #
720
- # ### Flags
712
+ # **Flags**
721
713
  #
722
714
  # | Flag | Effect
723
715
  # | ------ | ------
@@ -728,8 +720,7 @@
728
720
  # | 0 | Pad with 0 instead of space for widths larger than value.
729
721
  # | <[({\| | Defines an enclosing pair <> [] () {} or \| \| when used with a container type.
730
722
  #
731
- # Conversion to Boolean
732
- # ---
723
+ # ### Conversion to Boolean
733
724
  #
734
725
  # Accepts a single value as argument:
735
726
  #
@@ -740,8 +731,7 @@
740
731
  # * `false` if 'false', 'no', 'n' (case independent compare)
741
732
  # * Boolean is already boolean and is simply returned
742
733
  #
743
- # Conversion to Array and Tuple
744
- # ---
734
+ # ### Conversion to Array and Tuple
745
735
  #
746
736
  # When given a single value as argument:
747
737
  #
@@ -751,7 +741,6 @@
751
741
  # * An `Iterable[T]` is turned into an array of `T` instances.
752
742
  # * A `Binary` is converted to an `Array[Integer[0,255]]` of byte values
753
743
  #
754
- #
755
744
  # When given a second Boolean argument:
756
745
  #
757
746
  # * if `true`, a value that is not already an array is returned as a one element array.
@@ -766,8 +755,7 @@
766
755
  # Conversion to a `Tuple` works exactly as conversion to an `Array`, only that the constructed array is
767
756
  # asserted against the given tuple type.
768
757
  #
769
- # Conversion to Hash and Struct
770
- # ---
758
+ # ### Conversion to Hash and Struct
771
759
  #
772
760
  # Accepts a single value as argument:
773
761
  #
@@ -806,8 +794,8 @@
806
794
  # Conversion to a `Struct` works exactly as conversion to a `Hash`, only that the constructed hash is
807
795
  # asserted against the given struct type.
808
796
  #
809
- # Conversion to a Regexp
810
- # ---
797
+ # ### Conversion to a Regexp
798
+ #
811
799
  # A `String` can be converted into a `Regexp`
812
800
  #
813
801
  # **Example**: Converting a String into a Regexp
@@ -819,8 +807,7 @@
819
807
  # }
820
808
  # ```
821
809
  #
822
- # Creating a SemVer
823
- # ---
810
+ # ### Creating a SemVer
824
811
  #
825
812
  # A SemVer object represents a single [Semantic Version](http://semver.org/).
826
813
  # It can be created from a String, individual values for its parts, or a hash specifying the value per part.
@@ -869,8 +856,7 @@
869
856
  # notice(SemVer('3.4.5') =~ $t) # true
870
857
  # ```
871
858
  #
872
- # Creating a SemVerRange
873
- # ---
859
+ # ### Creating a SemVerRange
874
860
  #
875
861
  # A `SemVerRange` object represents a range of `SemVer`. It can be created from
876
862
  # a `String`, or from two `SemVer` instances, where either end can be given as
@@ -906,8 +892,7 @@
906
892
  #
907
893
  # For examples of `SemVerRange` use see "Creating a SemVer"
908
894
  #
909
- # Creating a Binary
910
- # ---
895
+ # ### Creating a Binary
911
896
  #
912
897
  # A `Binary` object represents a sequence of bytes and it can be created from a String in Base64 format,
913
898
  # an Array containing byte values. A Binary can also be created from a Hash containing the value to convert to
@@ -963,8 +948,7 @@
963
948
  # * Since 4.5.0
964
949
  # * Binary type since 4.8.0
965
950
  #
966
- # Creating an instance of a `Type` using the `Init` type.
967
- # -------
951
+ # ### Creating an instance of a `Type` using the `Init` type
968
952
  #
969
953
  # The type `Init[T]` describes a value that can be used when instantiating a type. When used as the first argument in a call to `new`, it
970
954
  # will dispatch the call to its contained type and optionally augment the parameter list with additional arguments.
@@ -1,4 +1,4 @@
1
- # Logs a message on the server at level `notice`.
1
+ # Logs a message on the server at level `warning`.
2
2
  Puppet::Functions.create_function(:warning, Puppet::Functions::InternalFunction) do
3
3
  # @param values The values to log.
4
4
  # @return [Undef]
@@ -13,6 +13,7 @@ module Puppet
13
13
  require 'puppet/pops/loader/static_loader'
14
14
  require 'puppet/pops/loader/runtime3_type_loader'
15
15
  require 'puppet/pops/loader/ruby_function_instantiator'
16
+ require 'puppet/pops/loader/ruby_legacy_function_instantiator'
16
17
  require 'puppet/pops/loader/ruby_data_type_instantiator'
17
18
  require 'puppet/pops/loader/puppet_function_instantiator'
18
19
  require 'puppet/pops/loader/type_definition_instantiator'
@@ -171,7 +171,9 @@ module Puppet::Parser::Functions
171
171
  elsif arity < 0 and args[0].size < (arity+1).abs
172
172
  raise ArgumentError, _("%{name}(): Wrong number of arguments given (%{arg_count} for minimum %{min_arg_count})") % { name: name, arg_count: args[0].size, min_arg_count: (arity+1).abs }
173
173
  end
174
- self.send(real_fname, args[0])
174
+ r = Puppet::Pops::Evaluator::Runtime3FunctionArgumentConverter.convert_return(self.send(real_fname, args[0]))
175
+ # avoid leaking aribtrary value if not being an rvalue function
176
+ options[:type] == :rvalue ? r : nil
175
177
  else
176
178
  raise ArgumentError, _("custom functions must be called with a single array that contains the arguments. For example, function_example([1]) instead of function_example(1)")
177
179
  end
@@ -30,7 +30,18 @@ Puppet::Parser::Functions::newfunction(
30
30
  :doc => "Perform printf-style formatting of text.
31
31
 
32
32
  The first parameter is format string describing how the rest of the parameters should be formatted.
33
- See the documentation for the `Kernel::sprintf` function in Ruby for all the details."
33
+ See the documentation for the [`Kernel::sprintf` function](https://ruby-doc.org/core/Kernel.html)
34
+ in Ruby for details.
35
+
36
+ To use [named format](https://idiosyncratic-ruby.com/49-what-the-format.html) arguments, provide a
37
+ hash containing the target string values as the argument to be formatted. For example:
38
+
39
+ ```puppet
40
+ notice sprintf(\"%<x>s : %<y>d\", { 'x' => 'value is', 'y' => 42 })
41
+ ```
42
+
43
+ This statement produces a notice of `value is : 42`."
44
+
34
45
  ) do |args|
35
46
  fmt = args[0]
36
47
  args = args[1..-1]
@@ -196,6 +196,22 @@ class Runtime3FunctionArgumentConverter < Runtime3Converter
196
196
  o.to_s
197
197
  end
198
198
 
199
+ # Converts result back to 4.x by replacing :undef with nil in Array and Hash objects
200
+ #
201
+ def self.convert_return(val3x)
202
+ if val3x == :undef
203
+ nil
204
+ elsif val3x.is_a?(Array)
205
+ val3x.map {|v| convert_return(v) }
206
+ elsif val3x.is_a?(Hash)
207
+ hsh = {}
208
+ val3x.each_pair {|k,v| hsh[convert_return(k)] = convert_return(v)}
209
+ hsh
210
+ else
211
+ val3x
212
+ end
213
+ end
214
+
199
215
  @instance = self.new
200
216
  end
201
217
 
@@ -305,15 +305,14 @@ module Runtime3Support
305
305
  return Kernel.eval('_func.call(scope, *args, &block)'.freeze, Kernel.binding, file || '', line)
306
306
  end
307
307
  end
308
- # Call via 3x API if function exists there
308
+ # Call via 3x API if function exists there without having been autoloaded
309
309
  fail(Issues::UNKNOWN_FUNCTION, o, {:name => name}) unless Puppet::Parser::Functions.function(name)
310
310
 
311
311
  # Arguments must be mapped since functions are unaware of the new and magical creatures in 4x.
312
312
  # NOTE: Passing an empty string last converts nil/:undef to empty string
313
313
  mapped_args = Runtime3FunctionArgumentConverter.map_args(args, scope, '')
314
- result = Puppet::Pops::PuppetStack.stack(file, line, scope, "function_#{name}", [mapped_args], &block)
315
- # Prevent non r-value functions from leaking their result (they are not written to care about this)
316
- Puppet::Parser::Functions.rvalue?(name) ? result : nil
314
+ # The 3x function performs return value mapping and returns nil if it is not of rvalue type
315
+ Puppet::Pops::PuppetStack.stack(file, line, scope, "function_#{name}", [mapped_args], &block)
317
316
  end
318
317
 
319
318
  # The o is used for source reference
@@ -490,6 +490,14 @@ module Issues
490
490
  _("Unacceptable location. The name '%{name}' is unacceptable in file '%{file}'") % { name: name, file: file }
491
491
  end
492
492
 
493
+ ILLEGAL_TOP_CONSTRUCT_LOCATION = issue :ILLEGAL_TOP_CONSTRUCT_LOCATION do
494
+ if semantic.is_a?(Puppet::Pops::Model::NamedDefinition)
495
+ _("The %{value} '%{name}' is unacceptable as a top level construct in this location") % { name: semantic.name, value: label(semantic) }
496
+ else
497
+ _("This %{value} is unacceptable as a top level construct in this location") % { value: label(semantic) }
498
+ end
499
+ end
500
+
493
501
  CAPTURES_REST_NOT_LAST = hard_issue :CAPTURES_REST_NOT_LAST, :param_name do
494
502
  _("Parameter $%{param} is not last, and has 'captures rest'") % { param: param_name }
495
503
  end
@@ -29,7 +29,7 @@ class Loader
29
29
  attr_reader :loader_name
30
30
 
31
31
  # Describes the kinds of things that loaders can load
32
- LOADABLE_KINDS = [:func_4x, :func_4xpp, :datatype, :type_pp, :resource_type_pp, :plan, :task].freeze
32
+ LOADABLE_KINDS = [:func_4x, :func_4xpp, :func_3x, :datatype, :type_pp, :resource_type_pp, :plan, :task].freeze
33
33
 
34
34
  # @param [String] name the name of the loader. Must be unique among all loaders maintained by a {Loader} instance
35
35
  def initialize(loader_name)
@@ -107,7 +107,7 @@ class Loader
107
107
  #
108
108
  # @api private
109
109
  #
110
- def [] (typed_name)
110
+ def [](typed_name)
111
111
  if found = get_entry(typed_name)
112
112
  found.value
113
113
  else
@@ -25,7 +25,9 @@ module LoaderPaths
25
25
  if loader.loadables.include?(:func_4xpp)
26
26
  result << FunctionPathPP.new(loader)
27
27
  end
28
- # When wanted also add FunctionPath3x to load 3x functions
28
+ if loader.loadables.include?(:func_3x)
29
+ result << FunctionPath3x.new(loader)
30
+ end
29
31
  when :plan
30
32
  result << PlanPathPP.new(loader)
31
33
  when :task