puppet 4.7.1-universal-darwin → 4.8.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.
- data/Gemfile +0 -3
- data/MAINTAINERS +76 -0
- data/README.md +0 -6
- data/Rakefile +2 -2
- data/lib/puppet/agent.rb +3 -3
- data/lib/puppet/application/apply.rb +1 -1
- data/lib/puppet/configurer.rb +2 -2
- data/lib/puppet/data_providers.rb +1 -0
- data/lib/puppet/data_providers/data_adapter.rb +1 -0
- data/lib/puppet/data_providers/data_function_support.rb +1 -0
- data/lib/puppet/data_providers/function_env_data_provider.rb +1 -0
- data/lib/puppet/data_providers/function_module_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_config.rb +1 -0
- data/lib/puppet/data_providers/hiera_env_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_interpolate.rb +1 -0
- data/lib/puppet/data_providers/hiera_module_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_support.rb +1 -2
- data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -0
- data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -0
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/environments.rb +5 -2
- data/lib/puppet/face/catalog.rb +1 -1
- data/lib/puppet/face/epp.rb +57 -11
- data/lib/puppet/face/module/install.rb +6 -6
- data/lib/puppet/functions.rb +23 -24
- data/lib/puppet/functions/alert.rb +14 -0
- data/lib/puppet/functions/binary_file.rb +25 -0
- data/lib/puppet/functions/break.rb +22 -0
- data/lib/puppet/functions/contain.rb +33 -0
- data/lib/puppet/functions/crit.rb +14 -0
- data/lib/puppet/functions/debug.rb +14 -0
- data/lib/puppet/functions/emerg.rb +14 -0
- data/lib/puppet/functions/epp.rb +1 -1
- data/lib/puppet/functions/err.rb +14 -0
- data/lib/puppet/functions/find_file.rb +31 -0
- data/lib/puppet/functions/include.rb +21 -0
- data/lib/puppet/functions/info.rb +14 -0
- data/lib/puppet/functions/new.rb +1 -1
- data/lib/puppet/functions/next.rb +23 -0
- data/lib/puppet/functions/notice.rb +14 -0
- data/lib/puppet/functions/regsubst.rb +12 -16
- data/lib/puppet/functions/require.rb +37 -0
- data/lib/puppet/functions/return.rb +22 -0
- data/lib/puppet/functions/strftime.rb +35 -0
- data/lib/puppet/functions/warning.rb +14 -0
- data/lib/puppet/generate/models/type/type.rb +4 -0
- data/lib/puppet/generate/templates/type/pcore.erb +2 -1
- data/lib/puppet/indirector/face.rb +6 -1
- data/lib/puppet/network/http/error.rb +2 -2
- data/lib/puppet/network/http/handler.rb +2 -2
- data/lib/puppet/node/environment.rb +11 -0
- data/lib/puppet/parser/ast.rb +5 -0
- data/lib/puppet/parser/ast/pops_bridge.rb +17 -4
- data/lib/puppet/parser/compiler.rb +29 -1
- data/lib/puppet/parser/functions.rb +6 -0
- data/lib/puppet/parser/functions/assert_type.rb +1 -1
- data/lib/puppet/parser/functions/binary_file.rb +24 -0
- data/lib/puppet/parser/functions/break.rb +39 -0
- data/lib/puppet/parser/functions/contain.rb +7 -15
- data/lib/puppet/parser/functions/defined.rb +2 -2
- data/lib/puppet/parser/functions/dig.rb +1 -1
- data/lib/puppet/parser/functions/each.rb +1 -1
- data/lib/puppet/parser/functions/epp.rb +2 -2
- data/lib/puppet/parser/functions/filter.rb +1 -1
- data/lib/puppet/parser/functions/find_file.rb +28 -0
- data/lib/puppet/parser/functions/hiera.rb +4 -4
- data/lib/puppet/parser/functions/hiera_array.rb +1 -1
- data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
- data/lib/puppet/parser/functions/hiera_include.rb +1 -1
- data/lib/puppet/parser/functions/include.rb +4 -8
- data/lib/puppet/parser/functions/inline_epp.rb +1 -1
- data/lib/puppet/parser/functions/lest.rb +1 -1
- data/lib/puppet/parser/functions/lookup.rb +4 -2
- data/lib/puppet/parser/functions/map.rb +1 -1
- data/lib/puppet/parser/functions/match.rb +1 -1
- data/lib/puppet/parser/functions/new.rb +414 -18
- data/lib/puppet/parser/functions/next.rb +38 -0
- data/lib/puppet/parser/functions/reduce.rb +1 -1
- data/lib/puppet/parser/functions/regsubst.rb +4 -2
- data/lib/puppet/parser/functions/require.rb +4 -27
- data/lib/puppet/parser/functions/return.rb +71 -0
- data/lib/puppet/parser/functions/reverse_each.rb +1 -1
- data/lib/puppet/parser/functions/scanf.rb +13 -8
- data/lib/puppet/parser/functions/slice.rb +1 -1
- data/lib/puppet/parser/functions/split.rb +1 -1
- data/lib/puppet/parser/functions/step.rb +1 -1
- data/lib/puppet/parser/functions/strftime.rb +185 -0
- data/lib/puppet/parser/functions/then.rb +1 -1
- data/lib/puppet/parser/functions/type.rb +1 -1
- data/lib/puppet/parser/functions/with.rb +3 -3
- data/lib/puppet/parser/resource.rb +8 -5
- data/lib/puppet/parser/scope.rb +1 -1
- data/lib/puppet/plugins/configuration.rb +8 -0
- data/lib/puppet/plugins/data_providers.rb +1 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +7 -28
- data/lib/puppet/plugins/data_providers/registry.rb +1 -0
- data/lib/puppet/pops.rb +4 -0
- data/lib/puppet/pops/evaluator/access_operator.rb +36 -5
- data/lib/puppet/pops/evaluator/closure.rb +81 -12
- data/lib/puppet/pops/evaluator/compare_operator.rb +24 -1
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +29 -5
- data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +1 -1
- data/lib/puppet/pops/evaluator/runtime3_converter.rb +53 -62
- data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -6
- data/lib/puppet/pops/functions/dispatch.rb +9 -2
- data/lib/puppet/pops/functions/dispatcher.rb +3 -1
- data/lib/puppet/pops/functions/function.rb +19 -2
- data/lib/puppet/pops/issues.rb +9 -0
- data/lib/puppet/pops/label_provider.rb +2 -2
- data/lib/puppet/pops/loader/loader.rb +17 -0
- data/lib/puppet/pops/loader/static_loader.rb +0 -41
- data/lib/puppet/pops/lookup.rb +12 -0
- data/lib/puppet/pops/lookup/context.rb +86 -0
- data/lib/puppet/pops/lookup/explainer.rb +46 -6
- data/lib/puppet/pops/lookup/invocation.rb +19 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
- data/lib/puppet/pops/model/factory.rb +20 -8
- data/lib/puppet/pops/model/model_label_provider.rb +3 -0
- data/lib/puppet/pops/model/model_meta.rb +2 -0
- data/lib/puppet/pops/model/model_tree_dumper.rb +14 -0
- data/lib/puppet/pops/parser/egrammar.ra +11 -6
- data/lib/puppet/pops/parser/eparser.rb +1112 -1086
- data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
- data/lib/puppet/pops/pcore.rb +1 -0
- data/lib/puppet/pops/puppet_stack.rb +3 -3
- data/lib/puppet/pops/resource/param.rb +5 -1
- data/lib/puppet/pops/resource/resource_type_impl.rb +8 -4
- data/lib/puppet/pops/resource/resource_type_set.pcore +1 -0
- data/lib/puppet/pops/serialization/abstract_reader.rb +19 -2
- data/lib/puppet/pops/serialization/abstract_writer.rb +16 -3
- data/lib/puppet/pops/serialization/deserializer.rb +5 -1
- data/lib/puppet/pops/serialization/extension.rb +2 -0
- data/lib/puppet/pops/serialization/json.rb +76 -26
- data/lib/puppet/pops/serialization/serializer.rb +5 -1
- data/lib/puppet/pops/serialization/time_factory.rb +2 -1
- data/lib/puppet/pops/time/timespan.rb +718 -0
- data/lib/puppet/pops/time/timestamp.rb +148 -0
- data/lib/puppet/pops/types/p_binary_type.rb +220 -0
- data/lib/puppet/pops/types/p_object_type.rb +12 -6
- data/lib/puppet/pops/types/p_sensitive_type.rb +5 -1
- data/lib/puppet/pops/types/p_timespan_type.rb +141 -0
- data/lib/puppet/pops/types/p_timestamp_type.rb +69 -0
- data/lib/puppet/pops/types/string_converter.rb +62 -0
- data/lib/puppet/pops/types/type_asserter.rb +1 -1
- data/lib/puppet/pops/types/type_calculator.rb +17 -3
- data/lib/puppet/pops/types/type_factory.rb +35 -1
- data/lib/puppet/pops/types/type_formatter.rb +64 -11
- data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -61
- data/lib/puppet/pops/types/type_parser.rb +18 -4
- data/lib/puppet/pops/types/types.rb +98 -63
- data/lib/puppet/pops/validation.rb +9 -1
- data/lib/puppet/pops/validation/checker4_0.rb +7 -0
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/provider.rb +3 -6
- data/lib/puppet/provider/mcx/mcxcontent.rb +1 -1
- data/lib/puppet/provider/mount/parsed.rb +18 -4
- data/lib/puppet/provider/nameservice/directoryservice.rb +15 -7
- data/lib/puppet/provider/package/gem.rb +6 -1
- data/lib/puppet/provider/package/pip.rb +0 -1
- data/lib/puppet/provider/package/pkg.rb +5 -1
- data/lib/puppet/provider/package/pkgng.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +10 -0
- data/lib/puppet/provider/service/launchd.rb +1 -0
- data/lib/puppet/provider/user/directoryservice.rb +6 -6
- data/lib/puppet/provider/yumrepo/inifile.rb +1 -1
- data/lib/puppet/provider/zpool/zpool.rb +1 -1
- data/lib/puppet/resource.rb +54 -12
- data/lib/puppet/resource/capability_finder.rb +15 -9
- data/lib/puppet/resource/catalog.rb +25 -6
- data/lib/puppet/resource/type.rb +3 -1
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/settings/environment_conf.rb +12 -4
- data/lib/puppet/syntax_checkers/base64.rb +41 -0
- data/lib/puppet/syntax_checkers/json.rb +0 -2
- data/lib/puppet/transaction.rb +6 -0
- data/lib/puppet/transaction/additional_resource_generator.rb +5 -0
- data/lib/puppet/transaction/report.rb +7 -2
- data/lib/puppet/type.rb +2 -1
- data/lib/puppet/type/file/checksum.rb +1 -0
- data/lib/puppet/type/file/content.rb +4 -4
- data/lib/puppet/type/mount.rb +44 -0
- data/lib/puppet/type/ssh_authorized_key.rb +1 -1
- data/lib/puppet/type/tidy.rb +3 -0
- data/lib/puppet/type/user.rb +12 -6
- data/lib/puppet/util/log.rb +25 -0
- data/lib/puppet/util/plist.rb +8 -3
- data/lib/puppet/version.rb +1 -1
- data/lib/puppet_x.rb +7 -1
- data/spec/integration/application/apply_spec.rb +118 -0
- data/spec/integration/parser/compiler_spec.rb +28 -0
- data/spec/integration/parser/pcore_resource_spec.rb +40 -3
- data/spec/integration/provider/mount_spec.rb +2 -1
- data/spec/integration/util/windows/principal_spec.rb +2 -2
- data/spec/integration/util/windows/registry_spec.rb +4 -4
- data/spec/lib/puppet_spec/compiler.rb +5 -1
- data/spec/lib/puppet_spec/unindent.rb +5 -0
- data/spec/shared_contexts/types_setup.rb +6 -0
- data/spec/shared_examples/rhel_package_provider.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/agent_spec.rb +11 -0
- data/spec/unit/application/lookup_spec.rb +94 -3
- data/spec/unit/capability_spec.rb +22 -0
- data/spec/unit/configurer_spec.rb +8 -0
- data/spec/unit/face/epp_face_spec.rb +22 -3
- data/spec/unit/functions/assert_type_spec.rb +3 -3
- data/spec/unit/functions/binary_file_spec.rb +46 -0
- data/spec/unit/functions/break_spec.rb +89 -0
- data/spec/unit/{parser/functions → functions}/contain_spec.rb +68 -3
- data/spec/unit/functions/find_file_spec.rb +69 -0
- data/spec/unit/functions/include_spec.rb +175 -0
- data/spec/unit/functions/logging_spec.rb +54 -0
- data/spec/unit/functions/lookup_spec.rb +3 -3
- data/spec/unit/functions/new_spec.rb +105 -5
- data/spec/unit/functions/next_spec.rb +93 -0
- data/spec/unit/functions/require_spec.rb +83 -0
- data/spec/unit/functions/return_spec.rb +105 -0
- data/spec/unit/{parser/functions → functions}/shared.rb +14 -11
- data/spec/unit/functions/strftime_spec.rb +152 -0
- data/spec/unit/functions4_spec.rb +22 -0
- data/spec/unit/indirector/face_spec.rb +10 -2
- data/spec/unit/network/http/error_spec.rb +1 -2
- data/spec/unit/network/http/handler_spec.rb +6 -5
- data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_spec.rb +1 -1
- data/spec/unit/parser/functions/lookup_spec.rb +1 -1
- data/spec/unit/parser/functions/regsubst_spec.rb +1 -1
- data/spec/unit/parser/functions/split_spec.rb +1 -1
- data/spec/unit/pops/evaluator/access_ops_spec.rb +81 -1
- data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +170 -0
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +29 -4
- data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +112 -4
- data/spec/unit/pops/loaders/dependency_loader_spec.rb +12 -0
- data/spec/unit/pops/loaders/static_loader_spec.rb +0 -26
- data/spec/unit/pops/lookup/context_spec.rb +149 -0
- data/spec/unit/pops/parser/parse_functions_spec.rb +19 -0
- data/spec/unit/pops/parser/parse_lambda_spec.rb +19 -0
- data/spec/unit/pops/puppet_stack_spec.rb +1 -1
- data/spec/unit/pops/resource/resource_type_impl_spec.rb +74 -0
- data/spec/unit/pops/serialization/packer_spec.rb +34 -14
- data/spec/unit/pops/serialization/serialization_spec.rb +67 -5
- data/spec/unit/pops/time/timespan_spec.rb +121 -0
- data/spec/unit/pops/types/p_binary_type_spec.rb +243 -0
- data/spec/unit/pops/types/p_object_type_spec.rb +7 -7
- data/spec/unit/pops/types/p_sensitive_type_spec.rb +1 -1
- data/spec/unit/pops/types/p_timespan_type_spec.rb +273 -0
- data/spec/unit/pops/types/p_timestamp_type_spec.rb +311 -0
- data/spec/unit/pops/types/p_type_set_type_spec.rb +13 -13
- data/spec/unit/pops/types/ruby_generator_spec.rb +12 -12
- data/spec/unit/pops/types/string_converter_spec.rb +89 -0
- data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
- data/spec/unit/pops/types/type_calculator_spec.rb +113 -5
- data/spec/unit/pops/types/type_formatter_spec.rb +40 -0
- data/spec/unit/pops/types/type_mismatch_describer_spec.rb +49 -38
- data/spec/unit/pops/types/type_parser_spec.rb +87 -4
- data/spec/unit/pops/types/types_spec.rb +1 -1
- data/spec/unit/pops/validator/validator_spec.rb +23 -0
- data/spec/unit/provider/mount/parsed_spec.rb +47 -29
- data/spec/unit/provider/package/pkg_spec.rb +109 -99
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
- data/spec/unit/provider/user/aix_spec.rb +1 -1
- data/spec/unit/provider/user/directoryservice_spec.rb +101 -30
- data/spec/unit/resource/capability_finder_spec.rb +29 -7
- data/spec/unit/resource/catalog_spec.rb +127 -0
- data/spec/unit/ssl/certificate_request_spec.rb +1 -1
- data/spec/unit/transaction/additional_resource_generator_spec.rb +30 -0
- data/spec/unit/transaction/persistence_spec.rb +1 -6
- data/spec/unit/transaction/report_spec.rb +23 -0
- data/spec/unit/transaction_spec.rb +38 -0
- data/spec/unit/type/mount_spec.rb +5 -0
- data/spec/unit/util/plist_spec.rb +14 -2
- metadata +71 -12
- data/spec/integration/parser/functions/require_spec.rb +0 -43
- data/spec/unit/parser/functions/include_spec.rb +0 -55
- data/spec/unit/parser/functions/require_spec.rb +0 -68
@@ -92,13 +92,23 @@ class CompareOperator
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
def cmp_Timespan(a, b)
|
96
|
+
raise ArgumentError.new('Timespans are only comparable to Timespans, Integers, and Floats') unless b.is_a?(Time::Timespan) || b.is_a?(Integer) || b.is_a?(Float)
|
97
|
+
a <=> b
|
98
|
+
end
|
99
|
+
|
100
|
+
def cmp_Timestamp(a, b)
|
101
|
+
raise ArgumentError.new('Timestamps are only comparable to Timestamps, Integers, and Floats') unless b.is_a?(Time::Timestamp) || b.is_a?(Integer) || b.is_a?(Float)
|
102
|
+
a <=> b
|
103
|
+
end
|
104
|
+
|
95
105
|
def cmp_Version(a, b)
|
96
106
|
raise ArgumentError.new('Versions not comparable to non Versions') unless b.is_a?(Semantic::Version)
|
97
107
|
a <=> b
|
98
108
|
end
|
99
109
|
|
100
110
|
def cmp_Object(a, b)
|
101
|
-
raise ArgumentError.new('Only Strings, Numbers, and Versions are comparable')
|
111
|
+
raise ArgumentError.new('Only Strings, Numbers, Timespans, Timestamps, and Versions are comparable')
|
102
112
|
end
|
103
113
|
|
104
114
|
|
@@ -137,6 +147,19 @@ class CompareOperator
|
|
137
147
|
end
|
138
148
|
end
|
139
149
|
|
150
|
+
def include_Binary(a, b, scope)
|
151
|
+
case b
|
152
|
+
when Puppet::Pops::Types::PBinaryType::Binary
|
153
|
+
a.binary_buffer.include?(b.binary_buffer)
|
154
|
+
when String
|
155
|
+
a.binary_buffer.include?(b)
|
156
|
+
when Numeric
|
157
|
+
a.binary_buffer.bytes.include?(b)
|
158
|
+
else
|
159
|
+
false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
140
163
|
def include_Array(a, b, scope)
|
141
164
|
case b
|
142
165
|
when Regexp
|
@@ -117,6 +117,10 @@ class EvaluatorImpl
|
|
117
117
|
# call stack instead
|
118
118
|
fail(Issues::RUNTIME_ERROR, target, {:detail => e.message}, e.original || e)
|
119
119
|
|
120
|
+
rescue StopIteration => e
|
121
|
+
# Ensure these are not rescued as StandardError
|
122
|
+
raise e
|
123
|
+
|
120
124
|
rescue StandardError => e
|
121
125
|
# All other errors, use its message and call stack
|
122
126
|
fail(Issues::RUNTIME_ERROR, target, {:detail => e.message}, e)
|
@@ -407,7 +411,20 @@ class EvaluatorImpl
|
|
407
411
|
begin
|
408
412
|
if operator == :'%' && (left.is_a?(Float) || right.is_a?(Float))
|
409
413
|
# Deny users the fun of seeing severe rounding errors and confusing results
|
410
|
-
fail(Issues::OPERATOR_NOT_APPLICABLE, left_o, {:operator => operator, :left_value => left})
|
414
|
+
fail(Issues::OPERATOR_NOT_APPLICABLE, left_o, {:operator => operator, :left_value => left}) if left.is_a?(Float)
|
415
|
+
fail(Issues::OPERATOR_NOT_APPLICABLE_WHEN, left_o, {:operator => operator, :left_value => left, :right_value => right})
|
416
|
+
end
|
417
|
+
if right.is_a?(Time::TimeData) && !left.is_a?(Time::TimeData)
|
418
|
+
if operator == :'+' || operator == :'*' && right.is_a?(Time::Timespan)
|
419
|
+
# Switch places. Let the TimeData do the arithmetic
|
420
|
+
x = left
|
421
|
+
left = right
|
422
|
+
right = x
|
423
|
+
elsif operator == :'-' && right.is_a?(Time::Timespan)
|
424
|
+
left = Time::Timespan.new((left * Time::NSECS_PER_SEC).to_i)
|
425
|
+
else
|
426
|
+
fail(Issues::OPERATOR_NOT_APPLICABLE_WHEN, left_o, {:operator => operator, :left_value => left, :right_value => right})
|
427
|
+
end
|
411
428
|
end
|
412
429
|
result = left.send(operator, right)
|
413
430
|
rescue NoMethodError => e
|
@@ -618,9 +635,7 @@ class EvaluatorImpl
|
|
618
635
|
# Evaluates all statements and produces the last evaluated value
|
619
636
|
#
|
620
637
|
def eval_BlockExpression o, scope
|
621
|
-
|
622
|
-
o.statements.each {|s| r = evaluate(s, scope)}
|
623
|
-
r
|
638
|
+
o.statements.reduce(nil) {|memo, s| evaluate(s, scope)}
|
624
639
|
end
|
625
640
|
|
626
641
|
# Performs optimized search over case option values, lazily evaluating each
|
@@ -693,7 +708,16 @@ class EvaluatorImpl
|
|
693
708
|
end
|
694
709
|
|
695
710
|
def eval_Program(o, scope)
|
696
|
-
|
711
|
+
begin
|
712
|
+
file = o.locator.file
|
713
|
+
line = 0
|
714
|
+
# Add stack frame for "top scope" logic. See Puppet::Pops::PuppetStack
|
715
|
+
return Puppet::Pops::PuppetStack.stack(file, line, self, 'evaluate', [o.body, scope])
|
716
|
+
#evaluate(o.body, scope)
|
717
|
+
rescue Puppet::Pops::Evaluator::PuppetStopIteration => ex
|
718
|
+
# breaking out of a file level program is not allowed
|
719
|
+
raise Puppet::ParseError.new("break() from context where this is illegal", ex.file, ex.line)
|
720
|
+
end
|
697
721
|
end
|
698
722
|
|
699
723
|
# Produces Array[PAnyType], an array of resource references
|
@@ -16,7 +16,7 @@ require 'rgen/ecore/ecore'
|
|
16
16
|
# * Default is not accepted as being literal
|
17
17
|
# * Regular Expression is not accepted as being literal
|
18
18
|
# * Hash with non String keys
|
19
|
-
# * String with
|
19
|
+
# * String with interpolation
|
20
20
|
#
|
21
21
|
class Puppet::Pops::Evaluator::JsonStrictLiteralEvaluator
|
22
22
|
#include Puppet::Pops::Utils
|
@@ -15,7 +15,7 @@ class Runtime3Converter
|
|
15
15
|
# @return [Array] The converted values
|
16
16
|
#
|
17
17
|
def self.map_args(args, scope, undef_value)
|
18
|
-
|
18
|
+
@instance.map_args(args, scope, undef_value)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Converts 4x supported values to a 3x values. Same as calling Runtime3Converter.instance.convert(...)
|
@@ -26,13 +26,13 @@ class Runtime3Converter
|
|
26
26
|
# @return [Object] The converted value
|
27
27
|
#
|
28
28
|
def self.convert(o, scope, undef_value)
|
29
|
-
|
29
|
+
@instance.convert(o, scope, undef_value)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Returns the singleton instance of this class.
|
33
33
|
# @return [Runtime3Converter] The singleton instance
|
34
34
|
def self.instance
|
35
|
-
|
35
|
+
@instance
|
36
36
|
end
|
37
37
|
|
38
38
|
# Converts 4x supported values to a 3x values.
|
@@ -58,79 +58,41 @@ class Runtime3Converter
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def convert_NilClass(o, scope, undef_value)
|
61
|
-
undef_value
|
62
|
-
end
|
63
|
-
|
64
|
-
def convert2_NilClass(o, scope, undef_value)
|
65
|
-
:undef
|
61
|
+
@inner ? :undef : undef_value
|
66
62
|
end
|
67
63
|
|
68
64
|
def convert_String(o, scope, undef_value)
|
69
65
|
# although wasteful, needed because user code may mutate these strings in Resources
|
70
66
|
o.frozen? ? o.dup : o
|
71
67
|
end
|
72
|
-
alias convert2_String :convert_String
|
73
68
|
|
74
69
|
def convert_Object(o, scope, undef_value)
|
75
70
|
o
|
76
71
|
end
|
77
|
-
alias :convert2_Object :convert_Object
|
78
72
|
|
79
73
|
def convert_Array(o, scope, undef_value)
|
80
|
-
|
74
|
+
ic = @inner_converter
|
75
|
+
o.map {|x| ic.convert(x, scope, undef_value) }
|
81
76
|
end
|
82
|
-
alias :convert2_Array :convert_Array
|
83
77
|
|
84
78
|
def convert_Hash(o, scope, undef_value)
|
85
79
|
result = {}
|
86
|
-
|
80
|
+
ic = @inner_converter
|
81
|
+
o.each {|k,v| result[ic.convert(k, scope, undef_value)] = ic.convert(v, scope, undef_value) }
|
87
82
|
result
|
88
83
|
end
|
89
|
-
alias :convert2_Hash :convert_Hash
|
90
84
|
|
91
85
|
def convert_Iterator(o, scope, undef_value)
|
92
86
|
raise Puppet::Error, 'Use of an Iterator is not supported here'
|
93
87
|
end
|
94
|
-
alias :convert2_Iterator :convert_Iterator
|
95
|
-
|
96
|
-
def convert_Regexp(o, scope, undef_value)
|
97
|
-
# Puppet 3x cannot handle parameter values that are reqular expressions. Turn into regexp string in
|
98
|
-
# source form
|
99
|
-
o.inspect
|
100
|
-
end
|
101
|
-
alias :convert2_Regexp :convert_Regexp
|
102
|
-
|
103
|
-
def convert_SemVer(o, scope, undef_value)
|
104
|
-
# Puppet 3x cannot handle SemVers. Use the string form
|
105
|
-
o.to_s
|
106
|
-
end
|
107
|
-
alias :convert2_SemVer :convert_SemVer
|
108
|
-
|
109
|
-
def convert_SemVerRange(o, scope, undef_value)
|
110
|
-
# Puppet 3x cannot handle SemVerRanges. Use the string form
|
111
|
-
o.to_s
|
112
|
-
end
|
113
|
-
alias :convert2_SemVerRange :convert_SemVerRange
|
114
88
|
|
115
89
|
def convert_Symbol(o, scope, undef_value)
|
116
|
-
|
117
|
-
# Support :undef since it may come from a 3x structure
|
118
|
-
when :undef
|
119
|
-
undef_value # 3x wants undef as either empty string or :undef
|
120
|
-
else
|
121
|
-
o # :default, and all others are verbatim since they are new in future evaluator
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# The :undef symbol should not be converted when nested in arrays or hashes
|
126
|
-
def convert2_Symbol(o, scope, undef_value)
|
127
|
-
o
|
90
|
+
o == :undef && !@inner ? undef_value : o
|
128
91
|
end
|
129
92
|
|
130
93
|
def convert_PAnyType(o, scope, undef_value)
|
131
94
|
o
|
132
95
|
end
|
133
|
-
alias :convert2_PAnyType :convert_PAnyType
|
134
96
|
|
135
97
|
def convert_PCatalogEntryType(o, scope, undef_value)
|
136
98
|
# Since 4x does not support dynamic scoping, all names are absolute and can be
|
@@ -142,7 +104,6 @@ class Runtime3Converter
|
|
142
104
|
t = Runtime3ResourceSupport.find_resource_type(scope, t) unless t == 'class' || t == 'node'
|
143
105
|
Puppet::Resource.new(t, title)
|
144
106
|
end
|
145
|
-
alias :convert2_PCatalogEntryType :convert_PCatalogEntryType
|
146
107
|
|
147
108
|
# Produces an array with [type, title] from a PCatalogEntryType
|
148
109
|
# This method is used to produce the arguments for creation of reference resource instances
|
@@ -170,24 +131,54 @@ class Runtime3Converter
|
|
170
131
|
end
|
171
132
|
end
|
172
133
|
|
173
|
-
|
134
|
+
protected
|
174
135
|
|
175
|
-
def initialize
|
176
|
-
@
|
177
|
-
@
|
136
|
+
def initialize(inner = false)
|
137
|
+
@inner = inner
|
138
|
+
@inner_converter = inner ? self : self.class.new(true)
|
139
|
+
@convert_visitor = Puppet::Pops::Visitor.new(self, 'convert', 2, 2)
|
178
140
|
end
|
179
141
|
|
180
|
-
|
142
|
+
@instance = self.new
|
143
|
+
end
|
181
144
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
145
|
+
# A Ruby function written for the 3.x API cannot be expected to handle extended data types. This
|
146
|
+
# converter ensures that they are converted to String format
|
147
|
+
# @api private
|
148
|
+
class Runtime3FunctionArgumentConverter < Runtime3Converter
|
149
|
+
|
150
|
+
def convert_Regexp(o, scope, undef_value)
|
151
|
+
# Puppet 3x cannot handle parameter values that are reqular expressions. Turn into regexp string in
|
152
|
+
# source form
|
153
|
+
o.inspect
|
154
|
+
end
|
155
|
+
|
156
|
+
def convert_Version(o, scope, undef_value)
|
157
|
+
# Puppet 3x cannot handle SemVers. Use the string form
|
158
|
+
o.to_s
|
159
|
+
end
|
160
|
+
|
161
|
+
def convert_VersionRange(o, scope, undef_value)
|
162
|
+
# Puppet 3x cannot handle SemVerRanges. Use the string form
|
163
|
+
o.to_s
|
191
164
|
end
|
165
|
+
|
166
|
+
def convert_Binary(o, scope, undef_value)
|
167
|
+
# Puppet 3x cannot handle Binary. Use the string form
|
168
|
+
o.to_s
|
169
|
+
end
|
170
|
+
|
171
|
+
def convert_Timespan(o, scope, undef_value)
|
172
|
+
# Puppet 3x cannot handle Timespans. Use the string form
|
173
|
+
o.to_s
|
174
|
+
end
|
175
|
+
|
176
|
+
def convert_Timestamp(o, scope, undef_value)
|
177
|
+
# Puppet 3x cannot handle Timestamps. Use the string form
|
178
|
+
o.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
@instance = self.new
|
192
182
|
end
|
183
|
+
|
193
184
|
end
|
@@ -59,11 +59,19 @@ module Runtime3Support
|
|
59
59
|
# The error is not specific enough to allow catching it - need to check the actual message text.
|
60
60
|
# TODO: Improve the messy implementation in Scope.
|
61
61
|
#
|
62
|
+
if name == "server_facts"
|
63
|
+
if Puppet[:trusted_server_facts] || Puppet[:strict] == :error
|
64
|
+
fail(Issues::ILLEGAL_RESERVED_ASSIGNMENT, o, {:name => name} )
|
65
|
+
elsif Puppet[:strict] == :warning
|
66
|
+
file, line = extract_file_line(o)
|
67
|
+
msg = "Assignment to $server_facts is deprecated"
|
68
|
+
Puppet.warn_once(:deprecation, msg, msg, file, line)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
62
72
|
if scope.bound?(name)
|
63
73
|
if Puppet::Parser::Scope::RESERVED_VARIABLE_NAMES.include?(name)
|
64
74
|
fail(Issues::ILLEGAL_RESERVED_ASSIGNMENT, o, {:name => name} )
|
65
|
-
elsif name == "server_facts" && Puppet[:trusted_server_facts]
|
66
|
-
fail(Issues::ILLEGAL_RESERVED_ASSIGNMENT, o, {:name => name} )
|
67
75
|
else
|
68
76
|
fail(Issues::ILLEGAL_REASSIGNMENT, o, {:name => name} )
|
69
77
|
end
|
@@ -240,7 +248,7 @@ module Runtime3Support
|
|
240
248
|
# @param name [String] the name of the function (without the 'function_' prefix used by scope)
|
241
249
|
# @param args [Array] arguments, may be empty
|
242
250
|
# @param scope [Object] the (runtime specific) scope where evaluation takes place
|
243
|
-
# @raise ArgumentError 'unknown function' if the function does not exist
|
251
|
+
# @raise [ArgumentError] 'unknown function' if the function does not exist
|
244
252
|
#
|
245
253
|
def external_call_function(name, args, scope, &block)
|
246
254
|
# Call via 4x API if the function exists there
|
@@ -261,7 +269,7 @@ module Runtime3Support
|
|
261
269
|
|
262
270
|
# Arguments must be mapped since functions are unaware of the new and magical creatures in 4x.
|
263
271
|
# NOTE: Passing an empty string last converts nil/:undef to empty string
|
264
|
-
mapped_args =
|
272
|
+
mapped_args = Runtime3FunctionArgumentConverter.map_args(args, scope, '')
|
265
273
|
result = scope.send("function_#{name}", mapped_args, &block)
|
266
274
|
# Prevent non r-value functions from leaking their result (they are not written to care about this)
|
267
275
|
Puppet::Parser::Functions.rvalue?(name) ? result : nil
|
@@ -281,7 +289,7 @@ module Runtime3Support
|
|
281
289
|
|
282
290
|
# Arguments must be mapped since functions are unaware of the new and magical creatures in 4x.
|
283
291
|
# NOTE: Passing an empty string last converts nil/:undef to empty string
|
284
|
-
mapped_args =
|
292
|
+
mapped_args = Runtime3FunctionArgumentConverter.map_args(args, scope, '')
|
285
293
|
result = Puppet::Pops::PuppetStack.stack(file, line, scope, "function_#{name}", [mapped_args], &block)
|
286
294
|
# Prevent non r-value functions from leaking their result (they are not written to care about this)
|
287
295
|
Puppet::Parser::Functions.rvalue?(name) ? result : nil
|
@@ -299,7 +307,8 @@ module Runtime3Support
|
|
299
307
|
end
|
300
308
|
|
301
309
|
def convert(value, scope, undef_value)
|
302
|
-
Runtime3Converter.
|
310
|
+
converter = scope.environment.rich_data? ? Runtime3Converter.instance : Runtime3FunctionArgumentConverter.instance
|
311
|
+
converter.convert(value, scope, undef_value)
|
303
312
|
end
|
304
313
|
|
305
314
|
def create_resources(o, scope, virtual, exported, type_name, resource_titles, evaluated_parameters)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
module Puppet::Pops
|
2
|
+
module Functions
|
1
3
|
# Defines a connection between a implementation method and the signature that
|
2
4
|
# the method will handle.
|
3
5
|
#
|
@@ -5,7 +7,7 @@
|
|
5
7
|
# constructed using the DSL defined in {Puppet::Functions}.
|
6
8
|
#
|
7
9
|
# @api private
|
8
|
-
class
|
10
|
+
class Dispatch < Evaluator::CallableSignature
|
9
11
|
# @api public
|
10
12
|
attr_reader :type
|
11
13
|
# TODO: refactor to parameter_names since that makes it API
|
@@ -42,7 +44,10 @@ class Puppet::Pops::Functions::Dispatch < Puppet::Pops::Evaluator::CallableSigna
|
|
42
44
|
|
43
45
|
# @api private
|
44
46
|
def invoke(instance, calling_scope, args, &block)
|
45
|
-
instance.send(@method_name, *weave(calling_scope, args), &block)
|
47
|
+
result = instance.send(@method_name, *weave(calling_scope, args), &block)
|
48
|
+
return_type = @type.return_type
|
49
|
+
Types::TypeAsserter.assert_instance_of(nil, return_type, result) { "value returned from function '#{@method_name}'" } unless return_type.nil?
|
50
|
+
result
|
46
51
|
end
|
47
52
|
|
48
53
|
# @api private
|
@@ -83,3 +88,5 @@ class Puppet::Pops::Functions::Dispatch < Puppet::Pops::Evaluator::CallableSigna
|
|
83
88
|
end
|
84
89
|
end
|
85
90
|
end
|
91
|
+
end
|
92
|
+
end
|
@@ -32,7 +32,9 @@ class Puppet::Pops::Functions::Dispatcher
|
|
32
32
|
actual = tc.infer_set(block_given? ? args + [block] : args)
|
33
33
|
found = @dispatchers.find { |d| tc.callable?(d.type, actual) }
|
34
34
|
if found
|
35
|
-
|
35
|
+
catch(:next) do
|
36
|
+
found.invoke(instance, calling_scope, args, &block)
|
37
|
+
end
|
36
38
|
else
|
37
39
|
raise ArgumentError, Puppet::Pops::Types::TypeMismatchDescriber.describe_signatures(instance.class.name, @dispatchers, actual)
|
38
40
|
end
|
@@ -41,7 +41,24 @@ class Puppet::Pops::Functions::Function
|
|
41
41
|
#
|
42
42
|
# @api public
|
43
43
|
def call(scope, *args, &block)
|
44
|
-
|
44
|
+
begin
|
45
|
+
result = catch(:return) do
|
46
|
+
return self.class.dispatcher.dispatch(self, scope, args, &block)
|
47
|
+
end
|
48
|
+
return result.value
|
49
|
+
rescue Puppet::Pops::Evaluator::Next => jumper
|
50
|
+
begin
|
51
|
+
throw :next, jumper.value
|
52
|
+
rescue Puppet::Parser::Scope::UNCAUGHT_THROW_EXCEPTION => uncaught
|
53
|
+
raise Puppet::ParseError.new("next() from context where this is illegal", jumper.file, jumper.line)
|
54
|
+
end
|
55
|
+
rescue Puppet::Pops::Evaluator::Return => jumper
|
56
|
+
begin
|
57
|
+
throw :return, jumper
|
58
|
+
rescue Puppet::Parser::Scope::UNCAUGHT_THROW_EXCEPTION => uncaught
|
59
|
+
raise Puppet::ParseError.new("return() from context where this is illegal", jumper.file, jumper.line)
|
60
|
+
end
|
61
|
+
end
|
45
62
|
end
|
46
63
|
|
47
64
|
# Allows the implementation of a function to call other functions by name. The callable functions
|
@@ -109,7 +126,7 @@ class Puppet::Pops::Functions::Function
|
|
109
126
|
# Call via 3x API
|
110
127
|
# Arguments must be mapped since functions are unaware of the new and magical creatures in 4x.
|
111
128
|
# NOTE: Passing an empty string last converts nil/:undef to empty string
|
112
|
-
result = scope.send(func_3x, Puppet::Pops::Evaluator::
|
129
|
+
result = scope.send(func_3x, Puppet::Pops::Evaluator::Runtime3FunctionArgumentConverter.map_args(args, loader_scope, ''), &block)
|
113
130
|
|
114
131
|
# Prevent non r-value functions from leaking their result (they are not written to care about this)
|
115
132
|
Puppet::Parser::Functions.rvalue?(function_name) ? result : nil
|
data/lib/puppet/pops/issues.rb
CHANGED
@@ -255,6 +255,10 @@ module Issues
|
|
255
255
|
"Operator '#{operator}' is not applicable to #{label.a_an(left_value)}."
|
256
256
|
end
|
257
257
|
|
258
|
+
OPERATOR_NOT_APPLICABLE_WHEN = hard_issue :OPERATOR_NOT_APPLICABLE_WHEN, :operator, :left_value, :right_value do
|
259
|
+
"Operator '#{operator}' is not applicable to #{label.a_an(left_value)} when right side is #{label.a_an(right_value)}."
|
260
|
+
end
|
261
|
+
|
258
262
|
COMPARISON_NOT_POSSIBLE = hard_issue :COMPARISON_NOT_POSSIBLE, :operator, :left_value, :right_value, :detail do
|
259
263
|
"Comparison of: #{label(left_value)} #{operator} #{label(right_value)}, is not possible. Caused by '#{detail}'."
|
260
264
|
end
|
@@ -430,6 +434,11 @@ module Issues
|
|
430
434
|
"#{label.a_an_uc(left_value)}[] cannot use #{actual} where #{expected_text} expected"
|
431
435
|
end
|
432
436
|
|
437
|
+
BAD_STRING_SLICE_KEY_TYPE = issue :BAD_STRING_SLICE_KEY_TYPE, :left_value, :actual_type do
|
438
|
+
actual_type_text = "#{label.article(actual_type)} #{actual_type}"
|
439
|
+
"A substring operation does not accept #{actual_type_text} as a character index. Expected an Integer"
|
440
|
+
end
|
441
|
+
|
433
442
|
BAD_NOT_UNDEF_SLICE_TYPE = issue :BAD_NOT_UNDEF_SLICE_TYPE, :base_type, :actual do
|
434
443
|
"#{base_type}[] argument must be a Type or a String. Got #{actual}"
|
435
444
|
end
|