puppet 4.9.4-universal-darwin → 4.10.0-universal-darwin

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 (124) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +6 -0
  3. data/ext/project_data.yaml +2 -2
  4. data/lib/hiera/puppet_function.rb +1 -1
  5. data/lib/puppet.rb +1 -0
  6. data/lib/puppet/application.rb +14 -0
  7. data/lib/puppet/application/inspect.rb +3 -0
  8. data/lib/puppet/defaults.rb +12 -2
  9. data/lib/puppet/etc.rb +125 -0
  10. data/lib/puppet/face/help.rb +1 -1
  11. data/lib/puppet/functions.rb +49 -4
  12. data/lib/puppet/functions/eyaml_lookup_key.rb +12 -3
  13. data/lib/puppet/functions/hocon_data.rb +9 -0
  14. data/lib/puppet/functions/json_data.rb +9 -0
  15. data/lib/puppet/functions/yaml_data.rb +9 -0
  16. data/lib/puppet/indirector/file_bucket_file/file.rb +69 -22
  17. data/lib/puppet/indirector/key/file.rb +2 -1
  18. data/lib/puppet/indirector/ssl_file.rb +24 -3
  19. data/lib/puppet/module.rb +28 -22
  20. data/lib/puppet/network/http/compression.rb +2 -1
  21. data/lib/puppet/parser/compiler.rb +15 -38
  22. data/lib/puppet/parser/functions/hiera.rb +1 -1
  23. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  24. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  25. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  26. data/lib/puppet/parser/scope.rb +59 -17
  27. data/lib/puppet/pops/evaluator/callable_signature.rb +7 -0
  28. data/lib/puppet/pops/functions/dispatch.rb +18 -5
  29. data/lib/puppet/pops/functions/dispatcher.rb +7 -13
  30. data/lib/puppet/pops/issue_reporter.rb +1 -1
  31. data/lib/puppet/pops/issues.rb +84 -0
  32. data/lib/puppet/pops/loader/base_loader.rb +13 -5
  33. data/lib/puppet/pops/lookup/configured_data_provider.rb +8 -2
  34. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +109 -19
  35. data/lib/puppet/pops/lookup/data_hash_function_provider.rb +19 -4
  36. data/lib/puppet/pops/lookup/data_provider.rb +43 -29
  37. data/lib/puppet/pops/lookup/environment_data_provider.rb +1 -1
  38. data/lib/puppet/pops/lookup/explainer.rb +1 -0
  39. data/lib/puppet/pops/lookup/function_provider.rb +36 -11
  40. data/lib/puppet/pops/lookup/global_data_provider.rb +18 -5
  41. data/lib/puppet/pops/lookup/hiera_config.rb +203 -84
  42. data/lib/puppet/pops/lookup/interpolation.rb +21 -6
  43. data/lib/puppet/pops/lookup/invocation.rb +14 -9
  44. data/lib/puppet/pops/lookup/location_resolver.rb +27 -0
  45. data/lib/puppet/pops/lookup/lookup_adapter.rb +59 -6
  46. data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +9 -77
  47. data/lib/puppet/pops/lookup/module_data_provider.rb +27 -4
  48. data/lib/puppet/pops/parser/lexer2.rb +1 -1
  49. data/lib/puppet/pops/pcore.rb +3 -3
  50. data/lib/puppet/pops/types/p_object_type.rb +4 -6
  51. data/lib/puppet/pops/types/ruby_generator.rb +2 -2
  52. data/lib/puppet/pops/types/type_asserter.rb +3 -3
  53. data/lib/puppet/pops/types/type_mismatch_describer.rb +25 -7
  54. data/lib/puppet/pops/types/types.rb +20 -29
  55. data/lib/puppet/provider/exec.rb +4 -2
  56. data/lib/puppet/provider/nameservice.rb +8 -8
  57. data/lib/puppet/provider/selmodule/semodule.rb +20 -16
  58. data/lib/puppet/provider/service/src.rb +39 -39
  59. data/lib/puppet/provider/service/systemd.rb +1 -1
  60. data/lib/puppet/provider/user/aix.rb +7 -2
  61. data/lib/puppet/settings.rb +30 -17
  62. data/lib/puppet/ssl/base.rb +14 -1
  63. data/lib/puppet/ssl/certificate_authority.rb +4 -2
  64. data/lib/puppet/ssl/configuration.rb +4 -1
  65. data/lib/puppet/ssl/inventory.rb +10 -3
  66. data/lib/puppet/ssl/key.rb +7 -3
  67. data/lib/puppet/test/test_helper.rb +3 -0
  68. data/lib/puppet/type.rb +13 -1
  69. data/lib/puppet/type/exec.rb +16 -1
  70. data/lib/puppet/type/group.rb +17 -11
  71. data/lib/puppet/type/user.rb +3 -1
  72. data/lib/puppet/util.rb +1 -0
  73. data/lib/puppet/util/character_encoding.rb +95 -0
  74. data/lib/puppet/util/execution.rb +9 -6
  75. data/lib/puppet/util/reference.rb +4 -2
  76. data/lib/puppet/util/windows/file.rb +5 -1
  77. data/lib/puppet/version.rb +6 -2
  78. data/locales/config.yaml +1 -1
  79. data/locales/puppet.pot +18 -4
  80. data/spec/integration/ssl/autosign_spec.rb +18 -3
  81. data/spec/integration/ssl/key_spec.rb +104 -0
  82. data/spec/integration/type/user_spec.rb +13 -6
  83. data/spec/spec_helper.rb +7 -0
  84. data/spec/unit/application/inspect_spec.rb +9 -2
  85. data/spec/unit/data_providers/function_data_provider_spec.rb +2 -2
  86. data/spec/unit/etc_spec.rb +234 -0
  87. data/spec/unit/face/certificate_spec.rb +10 -2
  88. data/spec/unit/functions/dig_spec.rb +1 -1
  89. data/spec/unit/functions/hiera_spec.rb +40 -1
  90. data/spec/unit/functions/lookup_fixture_spec.rb +10 -10
  91. data/spec/unit/functions/lookup_spec.rb +1217 -357
  92. data/spec/unit/functions4_spec.rb +37 -1
  93. data/spec/unit/indirector/file_bucket_file/file_spec.rb +33 -2
  94. data/spec/unit/indirector/key/file_spec.rb +1 -1
  95. data/spec/unit/indirector/ssl_file_spec.rb +3 -3
  96. data/spec/unit/module_spec.rb +52 -59
  97. data/spec/unit/network/http/compression_spec.rb +39 -8
  98. data/spec/unit/parser/compiler_spec.rb +14 -0
  99. data/spec/unit/pops/loaders/loaders_spec.rb +21 -3
  100. data/spec/unit/pops/loaders/module_loaders_spec.rb +61 -0
  101. data/spec/unit/pops/lookup/context_spec.rb +56 -8
  102. data/spec/unit/pops/lookup/lookup_spec.rb +32 -1
  103. data/spec/unit/pops/parser/lexer2_spec.rb +8 -0
  104. data/spec/unit/pops/types/ruby_generator_spec.rb +48 -0
  105. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +12 -3
  106. data/spec/unit/pops/types/types_spec.rb +6 -7
  107. data/spec/unit/provider/nameservice_spec.rb +12 -12
  108. data/spec/unit/provider/package/pkg_spec.rb +2 -0
  109. data/spec/unit/provider/service/src_spec.rb +5 -0
  110. data/spec/unit/ssl/base_spec.rb +9 -0
  111. data/spec/unit/ssl/certificate_authority_spec.rb +2 -2
  112. data/spec/unit/ssl/certificate_request_attributes_spec.rb +6 -0
  113. data/spec/unit/ssl/certificate_request_spec.rb +1 -1
  114. data/spec/unit/ssl/certificate_spec.rb +1 -1
  115. data/spec/unit/ssl/configuration_spec.rb +11 -2
  116. data/spec/unit/ssl/inventory_spec.rb +27 -3
  117. data/spec/unit/ssl/key_spec.rb +7 -7
  118. data/spec/unit/type/exec_spec.rb +41 -4
  119. data/spec/unit/type/file_spec.rb +4 -1
  120. data/spec/unit/util/character_encoding_spec.rb +88 -0
  121. data/spec/unit/util/execution_spec.rb +12 -0
  122. data/spec/unit/version_spec.rb +4 -0
  123. metadata +3803 -3810
  124. data/tasks/i18n.rake +0 -20
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0990a3768dd95825390787a1f010b89522c915ba
4
+ data.tar.gz: c893ec1185978f42dd6af4bbc91690ee4abd7f91
5
+ SHA512:
6
+ metadata.gz: 2932dcb5a1419afd95b400aa072772e052c6124895f4f410ae55227efa36e63a261474771234134c5ee027b76e787f22837bd422f89eaea7ac7663ca5b256418
7
+ data.tar.gz: aac2f49dc7382c85727d4b4221a2b345f0328f1c6042a1fb01558f2e77afd6ae22116be19de81a2fe23e1803b9c373e79035953cd656cccecdca278982885515
data/Rakefile CHANGED
@@ -104,3 +104,9 @@ task(:commits) do
104
104
  end
105
105
  end
106
106
 
107
+ begin
108
+ spec = Gem::Specification.find_by_name 'gettext-setup'
109
+ load "#{spec.gem_dir}/lib/tasks/gettext.rake"
110
+ GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))
111
+ rescue LoadError
112
+ end
@@ -45,7 +45,7 @@ gem_platform_dependencies:
45
45
  # Use of win32-security is deprecated
46
46
  win32-security: '= 0.2.5'
47
47
  win32-service: '= 0.8.8'
48
- minitar: '~> 0.5.4'
48
+ minitar: '~> 0.6.1'
49
49
  x64-mingw32:
50
50
  gem_runtime_dependencies:
51
51
  ffi: '~> 1.9.6'
@@ -56,7 +56,7 @@ gem_platform_dependencies:
56
56
  # Use of win32-security is deprecated
57
57
  win32-security: '= 0.2.5'
58
58
  win32-service: '= 0.8.8'
59
- minitar: '~> 0.5.4'
59
+ minitar: '~> 0.6.1'
60
60
  bundle_platforms:
61
61
  universal-darwin: all
62
62
  x86-mingw32: mingw
@@ -61,7 +61,7 @@ class Hiera::PuppetFunction < Puppet::Functions::InternalFunction
61
61
  def lookup(scope, key, default, has_default, override, &default_block)
62
62
  unless Puppet[:strict] == :off
63
63
  Puppet.warn_once(:deprecation, self.class.name,
64
- "The function '#{self.class.name}' is deprecated in favor of using 'lookup'. See https://docs.puppet.com/puppet/#{Puppet.version}/reference/deprecated_language.html")
64
+ "The function '#{self.class.name}' is deprecated in favor of using 'lookup'. See https://docs.puppet.com/puppet/#{Puppet.minor_version}/reference/deprecated_language.html")
65
65
  end
66
66
  lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {})
67
67
  adapter = lookup_invocation.lookup_adapter
data/lib/puppet.rb CHANGED
@@ -48,6 +48,7 @@ end
48
48
  # @api public
49
49
  module Puppet
50
50
  require 'puppet/file_system'
51
+ require 'puppet/etc'
51
52
  require 'puppet/context'
52
53
  require 'puppet/environments'
53
54
 
@@ -322,6 +322,15 @@ class Application
322
322
  @options = {}
323
323
  end
324
324
 
325
+ # call in setup of subclass to deprecate an application
326
+ def deprecate
327
+ @deprecated = true
328
+ end
329
+
330
+ def deprecated?
331
+ @deprecated
332
+ end
333
+
325
334
  # Execute the application.
326
335
  # @api public
327
336
  # @return [void]
@@ -339,6 +348,11 @@ class Application
339
348
  exit_on_fail("initialize") { preinit }
340
349
  exit_on_fail("parse application options") { parse_options }
341
350
  exit_on_fail("prepare for execution") { setup }
351
+
352
+ if deprecated?
353
+ Puppet.deprecation_warning(_("`puppet %{name}` is deprecated and will be removed in a future release.") % { name: name })
354
+ end
355
+
342
356
  exit_on_fail("configure routes from #{Puppet[:route_file]}") { configure_indirector_routes }
343
357
  exit_on_fail("log runtime debug info") { log_runtime_environment }
344
358
  exit_on_fail("run") { run_command }
@@ -19,6 +19,7 @@ puppet-inspect(8) -- Send an inspection report
19
19
 
20
20
  SYNOPSIS
21
21
  --------
22
+ Note: this command is deprecated
22
23
 
23
24
  Prepares and submits an inspection report to the puppet master.
24
25
 
@@ -74,6 +75,8 @@ Copyright (c) 2011 Puppet Labs, LLC Licensed under the Apache 2.0 License
74
75
  end
75
76
 
76
77
  def setup
78
+ deprecate
79
+
77
80
  exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
78
81
 
79
82
  raise "Inspect requires reporting to be enabled. Set report=true in puppet.conf to enable reporting." unless Puppet[:report]
@@ -1692,11 +1692,21 @@ EOT
1692
1692
  :archive_files => {
1693
1693
  :type => :boolean,
1694
1694
  :default => false,
1695
- :desc => "During an inspect run, whether to archive files whose contents are audited to a file bucket.",
1695
+ :desc => "During an inspect run, whether to archive files whose contents are audited to a file bucket. Note that the `inspect` command is deprecated.",
1696
+ :hook => proc { |value|
1697
+ if Puppet[:strict] != :off
1698
+ Puppet.deprecation_warning(_("Setting 'archive_files' is deprecated. It will be removed in a future release along with the `inspect` command."))
1699
+ end
1700
+ }
1696
1701
  },
1697
1702
  :archive_file_server => {
1698
1703
  :default => "$server",
1699
- :desc => "During an inspect run, the file bucket server to archive files to if archive_files is set.",
1704
+ :desc => "During an inspect run, the file bucket server to archive files to if archive_files is set. Note that the `inspect` command is deprecated.",
1705
+ :hook => proc { |value|
1706
+ if Puppet[:strict] != :off
1707
+ Puppet.deprecation_warning(_("Setting 'archive_file_server' is deprecated. It will be removed in a future release along with the `inspect` command."))
1708
+ end
1709
+ }
1700
1710
  }
1701
1711
  )
1702
1712
 
data/lib/puppet/etc.rb ADDED
@@ -0,0 +1,125 @@
1
+ require 'puppet/util/character_encoding'
2
+ # Wrapper around Ruby Etc module allowing us to manage encoding in a single
3
+ # place.
4
+ # This represents a subset of Ruby's Etc module, only the methods required by Puppet.
5
+ # Etc returns strings in variable encoding depending on
6
+ # environment. For Puppet we specifically want UTF-8 as our input from the Etc
7
+ # module - which is our input for many resource instance 'is' values. The
8
+ # associated 'should' value will basically always be coming from Puppet in
9
+ # UTF-8. Etc is defined for Windows but calls to it return nil.
10
+ #
11
+ # We only use Etc for retrieving existing property values from the system. For
12
+ # setting property values, providers leverage system tools (i.e., `useradd`)
13
+ #
14
+ # @api private
15
+ module Puppet::Etc
16
+ class << self
17
+ # Etc::getgrent returns an Etc::Group struct object
18
+ # On first call opens /etc/group and returns parse of first entry. Each subsquent call
19
+ # returns new struct the next entry or nil if EOF. Call ::endgrent to close file.
20
+ def getgrent
21
+ convert_field_values_to_utf8!(::Etc.getgrent)
22
+ end
23
+
24
+ # closes handle to /etc/group file
25
+ def endgrent
26
+ ::Etc.endgrent
27
+ end
28
+
29
+ # effectively equivalent to IO#rewind of /etc/group
30
+ def setgrent
31
+ ::Etc.setgrent
32
+ end
33
+
34
+ # Etc::getpwent returns an Etc::Passwd struct object
35
+ # On first call opens /etc/passwd and returns parse of first entry. Each subsquent call
36
+ # returns new struct for the next entry or nil if EOF. Call ::endgrent to close file.
37
+ def getpwent
38
+ convert_field_values_to_utf8!(::Etc.getpwent)
39
+ end
40
+
41
+ # closes handle to /etc/passwd file
42
+ def endpwent
43
+ ::Etc.endpwent
44
+ end
45
+
46
+ #effectively equivalent to IO#rewind of /etc/passwd
47
+ def setpwent
48
+ ::Etc.setpwent
49
+ end
50
+
51
+ # Etc::getpwnam searches /etc/passwd file for an entry corresponding to
52
+ # username.
53
+ # returns an Etc::Passwd struct corresponding to the entry or raises
54
+ # ArgumentError if none
55
+ def getpwnam(username)
56
+ convert_field_values_to_utf8!(::Etc.getpwnam(username))
57
+ end
58
+
59
+ # Etc::getgrnam searches /etc/group file for an entry corresponding to groupname.
60
+ # returns an Etc::Group struct corresponding to the entry or raises
61
+ # ArgumentError if none
62
+ def getgrnam(groupname)
63
+ convert_field_values_to_utf8!(::Etc.getgrnam(groupname))
64
+ end
65
+
66
+ # Etc::getgrid searches /etc/group file for an entry corresponding to id.
67
+ # returns an Etc::Group struct corresponding to the entry or raises
68
+ # ArgumentError if none
69
+ def getgrgid(id)
70
+ convert_field_values_to_utf8!(::Etc.getgrgid(id))
71
+ end
72
+
73
+ # Etc::getpwuid searches /etc/passwd file for an entry corresponding to id.
74
+ # returns an Etc::Passwd struct corresponding to the entry or raises
75
+ # ArgumentError if none
76
+ def getpwuid(id)
77
+ convert_field_values_to_utf8!(::Etc.getpwuid(id))
78
+ end
79
+
80
+ private
81
+ # Utility method for converting the String values of a struct returned by
82
+ # the Etc module to UTF-8. Structs returned by the ruby Etc module contain
83
+ # members with fields of type String, Integer, or Array of Strings, so we
84
+ # handle these types. Otherwise ignore fields.
85
+ #
86
+ # NOTE: If a string cannot be converted to UTF-8, this leaves the original
87
+ # string string intact in the Struct.
88
+ #
89
+ # Warning! This is a destructive method - the struct passed is modified!
90
+ #
91
+ # @api private
92
+ # @param [Etc::Passwd or Etc::Group struct]
93
+ # @return [Etc::Passwd or Etc::Group struct] the original struct with values
94
+ # converted to UTF-8 if possible, or the original value intact if not
95
+ def convert_field_values_to_utf8!(struct)
96
+ return nil if struct.nil?
97
+ struct.each_with_index do |value, index|
98
+ if value.is_a?(String)
99
+ converted = Puppet::Util::CharacterEncoding.convert_to_utf_8!(value)
100
+ struct[index] = converted if !converted.nil?
101
+ elsif value.is_a?(Array)
102
+ struct[index] = convert_array_values_to_utf8!(value)
103
+ end
104
+ end
105
+ end
106
+
107
+ # Helper method for ::convert_field_values_to_utf8!
108
+ #
109
+ # Warning! This is a destructive method - the array passed is modified!
110
+ #
111
+ # @api private
112
+ # @param [Array] object containing String values to convert to UTF-8
113
+ # @return [Array] original Array with String values converted to UTF-8 if
114
+ # convertible, or original, unmodified values if not.
115
+ def convert_array_values_to_utf8!(string_array)
116
+ string_array.map! do |elem|
117
+ converted = Puppet::Util::CharacterEncoding.convert_to_utf_8!(elem)
118
+ converted.nil? ? elem : converted
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+
125
+
@@ -20,7 +20,7 @@ Puppet::Face.define(:help, '0.0.1') do
20
20
  $ puppet help
21
21
  EOT
22
22
 
23
- option _("--version VERSION") do
23
+ option "--version " + _("VERSION") do
24
24
  summary _("The version of the subcommand for which to show help.")
25
25
  end
26
26
 
@@ -46,6 +46,14 @@
46
46
  # specifies the method that should be called for that signature. When a
47
47
  # matching signature is found, the corresponding method is called.
48
48
  #
49
+ # Special dispatches designed to create error messages for an argument mismatch
50
+ # can be added using the keyword `argument_mismatch` instead of `dispatch`. The
51
+ # method appointed by an `argument_mismatch` will be called with arguments
52
+ # just like a normal `dispatch` would, but the method must produce a string.
53
+ # The string is then used as the message in the `ArgumentError` that is raised
54
+ # when the method returns. A block parameter can be given, but it is not
55
+ # propagated in the method call.
56
+ #
49
57
  # Documentation for the function should be placed as comments to the
50
58
  # implementation method(s).
51
59
  #
@@ -73,6 +81,27 @@
73
81
  # end
74
82
  # end
75
83
  #
84
+ # @example Using an argument mismatch handler
85
+ # Puppet::Functions.create_function('math::min') do
86
+ # dispatch :numeric_min do
87
+ # param 'Numeric', :a
88
+ # param 'Numeric', :b
89
+ # end
90
+ #
91
+ # argument_mismatch :on_error do
92
+ # param 'Any', :a
93
+ # param 'Any', :b
94
+ # end
95
+ #
96
+ # def numeric_min(a, b)
97
+ # a <= b ? a : b
98
+ # end
99
+ #
100
+ # def on_error(a, b)
101
+ # 'both arguments must be of type Numeric'
102
+ # end
103
+ # end
104
+ #
76
105
  # Specifying Signatures
77
106
  # ---
78
107
  #
@@ -224,7 +253,7 @@ module Puppet::Functions
224
253
  simple_name = func_name.split(/::/)[-1]
225
254
  type, names = default_dispatcher(the_class, simple_name)
226
255
  last_captures_rest = (type.size_range[1] == Float::INFINITY)
227
- the_class.dispatcher.add_dispatch(type, simple_name, names, nil, nil, nil, last_captures_rest)
256
+ the_class.dispatcher.add(Puppet::Pops::Functions::Dispatch.new(type, simple_name, names, last_captures_rest))
228
257
  end
229
258
 
230
259
  # The function class is returned as the result of the create function method
@@ -285,7 +314,22 @@ module Puppet::Functions
285
314
  # @api public
286
315
  def self.dispatch(meth_name, &block)
287
316
  builder().instance_eval do
288
- dispatch(meth_name, &block)
317
+ dispatch(meth_name, false, &block)
318
+ end
319
+ end
320
+
321
+ # Like `dispatch` but used for a specific type of argument mismatch. Will not be include in the list of valid
322
+ # parameter overloads for the function.
323
+ #
324
+ # @param meth_name [Symbol] The name of the implementation method to call
325
+ # when the signature defined in the block matches the arguments to a call
326
+ # to the function.
327
+ # @return [Void]
328
+ #
329
+ # @api public
330
+ def self.argument_mismatch(meth_name, &block)
331
+ builder().instance_eval do
332
+ dispatch(meth_name, true, &block)
289
333
  end
290
334
  end
291
335
 
@@ -500,7 +544,7 @@ module Puppet::Functions
500
544
  end
501
545
 
502
546
  # @api private
503
- def dispatch(meth_name, &block)
547
+ def dispatch(meth_name, argument_mismatch_handler, &block)
504
548
  # an array of either an index into names/types, or an array with
505
549
  # injection information [type, name, injection_name] used when the call
506
550
  # is being made to weave injections into the given arguments.
@@ -514,9 +558,10 @@ module Puppet::Functions
514
558
  @block_type = nil
515
559
  @block_name = nil
516
560
  @return_type = nil
561
+ @argument_mismatch_hander = argument_mismatch_handler
517
562
  self.instance_eval &block
518
563
  callable_t = create_callable(@types, @block_type, @return_type, @min, @max)
519
- @dispatcher.add_dispatch(callable_t, meth_name, @names, @block_name, @injections, @weaving, @max == :default)
564
+ @dispatcher.add(Puppet::Pops::Functions::Dispatch.new(callable_t, meth_name, @names, @max == :default, @block_name, @injections, @weaving, @argument_mismatch_hander))
520
565
  end
521
566
 
522
567
  # Handles creation of a callable type from strings specifications of puppet
@@ -19,6 +19,13 @@ Puppet::Functions.create_function(:eyaml_lookup_key) do
19
19
  def eyaml_lookup_key(key, options, context)
20
20
  return context.cached_value(key) if context.cache_has_key(key)
21
21
 
22
+ # Can't do this with an argument_mismatch dispatcher since there is no way to declare a struct that at least
23
+ # contains some keys but may contain other arbitrary keys.
24
+ unless options.include?('path')
25
+ raise ArgumentError,
26
+ "'eyaml_lookup_key': one of 'path', 'paths' 'glob', 'globs' or 'mapped_paths' must be declared in hiera.yaml when using this lookup_key function"
27
+ end
28
+
22
29
  # nil key is used to indicate that the cache contains the raw content of the eyaml file
23
30
  raw_data = context.cached_value(nil)
24
31
  if raw_data.nil?
@@ -70,9 +77,11 @@ Puppet::Functions.create_function(:eyaml_lookup_key) do
70
77
  end
71
78
 
72
79
  def decrypt(data, context)
73
- return context.interpolate(data) unless encrypted?(data)
74
- tokens = Hiera::Backend::Eyaml::Parser::ParserFactory.hiera_backend_parser.parse(data)
75
- tokens.map(&:to_plain_text).join.chomp
80
+ if encrypted?(data)
81
+ tokens = Hiera::Backend::Eyaml::Parser::ParserFactory.hiera_backend_parser.parse(data)
82
+ data = tokens.map(&:to_plain_text).join.chomp
83
+ end
84
+ context.interpolate(data)
76
85
  end
77
86
 
78
87
  def encrypted?(data)
@@ -13,6 +13,11 @@ Puppet::Functions.create_function(:hocon_data) do
13
13
  param 'Puppet::LookupContext', :context
14
14
  end
15
15
 
16
+ argument_mismatch :missing_path do
17
+ param 'Hash', :options
18
+ param 'Puppet::LookupContext', :context
19
+ end
20
+
16
21
  def hocon_data(options, context)
17
22
  path = options['path']
18
23
  context.cached_file_data(path) do |content|
@@ -23,4 +28,8 @@ Puppet::Functions.create_function(:hocon_data) do
23
28
  end
24
29
  end
25
30
  end
31
+
32
+ def missing_path(options, context)
33
+ "one of 'path', 'paths' 'glob', 'globs' or 'mapped_paths' must be declared in hiera.yaml when using this data_hash function"
34
+ end
26
35
  end
@@ -6,6 +6,11 @@ Puppet::Functions.create_function(:json_data) do
6
6
  param 'Puppet::LookupContext', :context
7
7
  end
8
8
 
9
+ argument_mismatch :missing_path do
10
+ param 'Hash', :options
11
+ param 'Puppet::LookupContext', :context
12
+ end
13
+
9
14
  def json_data(options, context)
10
15
  path = options['path']
11
16
  context.cached_file_data(path) do |content|
@@ -17,4 +22,8 @@ Puppet::Functions.create_function(:json_data) do
17
22
  end
18
23
  end
19
24
  end
25
+
26
+ def missing_path(options, context)
27
+ "one of 'path', 'paths' 'glob', 'globs' or 'mapped_paths' must be declared in hiera.yaml when using this data_hash function"
28
+ end
20
29
  end
@@ -8,6 +8,11 @@ Puppet::Functions.create_function(:yaml_data) do
8
8
  param 'Puppet::LookupContext', :context
9
9
  end
10
10
 
11
+ argument_mismatch :missing_path do
12
+ param 'Hash', :options
13
+ param 'Puppet::LookupContext', :context
14
+ end
15
+
11
16
  def yaml_data(options, context)
12
17
  path = options['path']
13
18
  context.cached_file_data(path) do |content|
@@ -26,4 +31,8 @@ Puppet::Functions.create_function(:yaml_data) do
26
31
  end
27
32
  end
28
33
  end
34
+
35
+ def missing_path(options, context)
36
+ "one of 'path', 'paths' 'glob', 'globs' or 'mapped_paths' must be declared in hiera.yaml when using this data_hash function"
37
+ end
29
38
  end