puppet 4.7.1-x86-mingw32 → 4.8.0-x86-mingw32
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
@@ -134,12 +134,13 @@ class TypeParser
|
|
134
134
|
# @api private
|
135
135
|
def self.type_map
|
136
136
|
@type_map ||= {
|
137
|
-
|
138
|
-
|
137
|
+
'integer' => TypeFactory.integer,
|
138
|
+
'float' => TypeFactory.float,
|
139
139
|
'numeric' => TypeFactory.numeric,
|
140
140
|
'iterable' => TypeFactory.iterable,
|
141
141
|
'iterator' => TypeFactory.iterator,
|
142
142
|
'string' => TypeFactory.string,
|
143
|
+
'binary' => TypeFactory.binary,
|
143
144
|
'sensitive' => TypeFactory.sensitive,
|
144
145
|
'enum' => TypeFactory.enum,
|
145
146
|
'boolean' => TypeFactory.boolean,
|
@@ -167,10 +168,12 @@ class TypeParser
|
|
167
168
|
'typealias' => TypeFactory.type_alias,
|
168
169
|
'typereference' => TypeFactory.type_reference,
|
169
170
|
'typeset' => TypeFactory.type_set,
|
170
|
-
|
171
|
+
# A generic callable as opposed to one that does not accept arguments
|
171
172
|
'callable' => TypeFactory.all_callables,
|
172
173
|
'semver' => TypeFactory.sem_ver,
|
173
|
-
'semverrange' => TypeFactory.sem_ver_range
|
174
|
+
'semverrange' => TypeFactory.sem_ver_range,
|
175
|
+
'timestamp' => TypeFactory.timestamp,
|
176
|
+
'timespan' => TypeFactory.timespan
|
174
177
|
}
|
175
178
|
end
|
176
179
|
|
@@ -355,6 +358,9 @@ class TypeParser
|
|
355
358
|
|
356
359
|
when 'callable'
|
357
360
|
# 1..m parameters being types (last three optionally integer or literal default, and a callable)
|
361
|
+
if parameters.size > 1 && parameters[0].is_a?(Array)
|
362
|
+
raise_invalid_parameters_error('callable', '2 when first parameter is an array', parameters.size) unless parameters.size == 2
|
363
|
+
end
|
358
364
|
TypeFactory.callable(*parameters)
|
359
365
|
|
360
366
|
when 'struct'
|
@@ -478,6 +484,14 @@ class TypeParser
|
|
478
484
|
raise_invalid_parameters_error('Runtime', '2', parameters.size) unless parameters.size == 2
|
479
485
|
TypeFactory.runtime(*parameters)
|
480
486
|
|
487
|
+
when 'timespan'
|
488
|
+
raise_invalid_parameters_error('Timespan', '0 to 2', parameters.size) unless parameters.size <= 2
|
489
|
+
TypeFactory.timespan(*parameters)
|
490
|
+
|
491
|
+
when 'timestamp'
|
492
|
+
raise_invalid_parameters_error('Timestamp', '0 to 2', parameters.size) unless parameters.size <= 2
|
493
|
+
TypeFactory.timestamp(*parameters)
|
494
|
+
|
481
495
|
when 'semver'
|
482
496
|
raise_invalid_parameters_error('SemVer', '1 or more', parameters.size) unless parameters.size >= 1
|
483
497
|
TypeFactory.sem_ver(*parameters)
|
@@ -741,16 +741,9 @@ class PEnumType < PScalarType
|
|
741
741
|
end
|
742
742
|
end
|
743
743
|
|
744
|
+
# Abstract class that encapsulates behavior common to PNumericType and PAbstractTimeDataType
|
744
745
|
# @api public
|
745
|
-
|
746
|
-
class PNumericType < PScalarType
|
747
|
-
def self.register_ptype(loader, ir)
|
748
|
-
create_ptype(loader, ir, 'ScalarType',
|
749
|
-
'from' => { KEY_TYPE => PNumericType::DEFAULT, KEY_VALUE => :default },
|
750
|
-
'to' => { KEY_TYPE => PNumericType::DEFAULT, KEY_VALUE => :default }
|
751
|
-
)
|
752
|
-
end
|
753
|
-
|
746
|
+
class PAbstractRangeType < PScalarType
|
754
747
|
def initialize(from, to = Float::INFINITY)
|
755
748
|
from = -Float::INFINITY if from.nil? || from == :default
|
756
749
|
to = Float::INFINITY if to.nil? || to == :default
|
@@ -807,22 +800,44 @@ class PNumericType < PScalarType
|
|
807
800
|
def unbounded?
|
808
801
|
@from == -Float::INFINITY && @to == Float::INFINITY
|
809
802
|
end
|
803
|
+
end
|
804
|
+
|
805
|
+
# @api public
|
806
|
+
#
|
807
|
+
class PNumericType < PAbstractRangeType
|
808
|
+
def self.register_ptype(loader, ir)
|
809
|
+
create_ptype(loader, ir, 'ScalarType',
|
810
|
+
'from' => { KEY_TYPE => PNumericType::DEFAULT, KEY_VALUE => :default },
|
811
|
+
'to' => { KEY_TYPE => PNumericType::DEFAULT, KEY_VALUE => :default }
|
812
|
+
)
|
813
|
+
end
|
810
814
|
|
811
815
|
def self.new_function(_, loader)
|
812
816
|
@new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, loader) do
|
813
817
|
local_types do
|
814
|
-
type 'Convertible = Variant[Undef, Integer, Float, Boolean, String]'
|
815
|
-
type 'NamedArgs = Struct[{from => Convertible}]'
|
818
|
+
type 'Convertible = Variant[Undef, Integer, Float, Boolean, String, Timespan, Timestamp]'
|
819
|
+
type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
|
816
820
|
end
|
817
821
|
|
818
822
|
dispatch :from_args do
|
819
823
|
param 'Convertible', :from
|
824
|
+
optional_param 'Boolean', :abs
|
820
825
|
end
|
821
826
|
|
822
827
|
dispatch :from_hash do
|
823
828
|
param 'NamedArgs', :hash_args
|
824
829
|
end
|
825
|
-
|
830
|
+
|
831
|
+
def from_args(from, abs = false)
|
832
|
+
result = from_convertible(from)
|
833
|
+
abs ? result.abs : result
|
834
|
+
end
|
835
|
+
|
836
|
+
def from_hash(args_hash)
|
837
|
+
from_args(args_hash['from'], args_hash['abs'] || false)
|
838
|
+
end
|
839
|
+
|
840
|
+
def from_convertible(from)
|
826
841
|
case from
|
827
842
|
when NilClass
|
828
843
|
throw :undefined_value
|
@@ -830,6 +845,8 @@ class PNumericType < PScalarType
|
|
830
845
|
from
|
831
846
|
when Integer
|
832
847
|
from
|
848
|
+
when Time::TimeData
|
849
|
+
from.to_f
|
833
850
|
when TrueClass
|
834
851
|
1
|
835
852
|
when FalseClass
|
@@ -851,15 +868,9 @@ class PNumericType < PScalarType
|
|
851
868
|
raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Numeric")
|
852
869
|
end
|
853
870
|
end
|
854
|
-
|
855
|
-
def from_hash(args_hash)
|
856
|
-
from_args(args_hash['from'])
|
857
|
-
end
|
858
871
|
end
|
859
872
|
end
|
860
873
|
|
861
|
-
DEFAULT = PNumericType.new(-Float::INFINITY)
|
862
|
-
|
863
874
|
protected
|
864
875
|
|
865
876
|
# @api_private
|
@@ -868,6 +879,8 @@ class PNumericType < PScalarType
|
|
868
879
|
# If o min and max are within the range of t
|
869
880
|
@from <= o.numeric_from && @to >= o.numeric_to
|
870
881
|
end
|
882
|
+
|
883
|
+
DEFAULT = PNumericType.new(-Float::INFINITY)
|
871
884
|
end
|
872
885
|
|
873
886
|
# @api public
|
@@ -956,24 +969,34 @@ class PIntegerType < PNumericType
|
|
956
969
|
@@new_function ||= Puppet::Functions.create_loaded_function(:new, loader) do
|
957
970
|
local_types do
|
958
971
|
type 'Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]'
|
959
|
-
type 'Convertible = Variant[Undef,
|
960
|
-
type 'NamedArgs = Struct[{from => Convertible, Optional[radix] => Radix}]'
|
972
|
+
type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
|
973
|
+
type 'NamedArgs = Struct[{from => Convertible, Optional[radix] => Radix, Optional[abs] => Boolean}]'
|
961
974
|
end
|
962
975
|
|
963
976
|
dispatch :from_args do
|
964
977
|
param 'Convertible', :from
|
965
978
|
optional_param 'Radix', :radix
|
979
|
+
optional_param 'Boolean', :abs
|
966
980
|
end
|
967
981
|
|
968
982
|
dispatch :from_hash do
|
969
983
|
param 'NamedArgs', :hash_args
|
970
984
|
end
|
971
985
|
|
972
|
-
def from_args(from, radix = :default)
|
986
|
+
def from_args(from, radix = :default, abs = false)
|
987
|
+
result = from_convertible(from, radix)
|
988
|
+
abs ? result.abs : result
|
989
|
+
end
|
990
|
+
|
991
|
+
def from_hash(args_hash)
|
992
|
+
from_args(args_hash['from'], args_hash['radix'] || :default, args_hash['abs'] || false)
|
993
|
+
end
|
994
|
+
|
995
|
+
def from_convertible(from, radix)
|
973
996
|
case from
|
974
997
|
when NilClass
|
975
998
|
throw :undefined_value
|
976
|
-
when Float
|
999
|
+
when Float, Time::TimeData
|
977
1000
|
from.to_i
|
978
1001
|
when Integer
|
979
1002
|
from
|
@@ -1005,12 +1028,6 @@ class PIntegerType < PNumericType
|
|
1005
1028
|
end
|
1006
1029
|
end
|
1007
1030
|
|
1008
|
-
def from_hash(args_hash)
|
1009
|
-
from = args_hash['from']
|
1010
|
-
radix = args_hash['radix'] || :default
|
1011
|
-
from_args(from, radix)
|
1012
|
-
end
|
1013
|
-
|
1014
1031
|
def assert_radix(radix)
|
1015
1032
|
case radix
|
1016
1033
|
when 2, 8, 10, 16, :default
|
@@ -1062,19 +1079,29 @@ class PFloatType < PNumericType
|
|
1062
1079
|
def self.new_function(_, loader)
|
1063
1080
|
@new_function ||= Puppet::Functions.create_loaded_function(:new_float, loader) do
|
1064
1081
|
local_types do
|
1065
|
-
type 'Convertible = Variant[Undef,
|
1066
|
-
type 'NamedArgs = Struct[{from => Convertible}]'
|
1082
|
+
type 'Convertible = Variant[Undef, Numeric, Boolean, String, Timespan, Timestamp]'
|
1083
|
+
type 'NamedArgs = Struct[{from => Convertible, Optional[abs] => Boolean}]'
|
1067
1084
|
end
|
1068
1085
|
|
1069
1086
|
dispatch :from_args do
|
1070
1087
|
param 'Convertible', :from
|
1088
|
+
optional_param 'Boolean', :abs
|
1071
1089
|
end
|
1072
1090
|
|
1073
1091
|
dispatch :from_hash do
|
1074
1092
|
param 'NamedArgs', :hash_args
|
1075
1093
|
end
|
1076
1094
|
|
1077
|
-
def from_args(from)
|
1095
|
+
def from_args(from, abs = false)
|
1096
|
+
result = from_convertible(from)
|
1097
|
+
abs ? result.abs : result
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
def from_hash(args_hash)
|
1101
|
+
from_args(args_hash['from'], args_hash['abs'] || false)
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
def from_convertible(from)
|
1078
1105
|
case from
|
1079
1106
|
when NilClass
|
1080
1107
|
throw :undefined_value
|
@@ -1082,6 +1109,8 @@ class PFloatType < PNumericType
|
|
1082
1109
|
from
|
1083
1110
|
when Integer
|
1084
1111
|
Float(from)
|
1112
|
+
when Time::TimeData
|
1113
|
+
from.to_f
|
1085
1114
|
when TrueClass
|
1086
1115
|
1.0
|
1087
1116
|
when FalseClass
|
@@ -1113,10 +1142,6 @@ class PFloatType < PNumericType
|
|
1113
1142
|
raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Float")
|
1114
1143
|
end
|
1115
1144
|
end
|
1116
|
-
|
1117
|
-
def from_hash(args_hash)
|
1118
|
-
from_args(args_hash['from'])
|
1119
|
-
end
|
1120
1145
|
end
|
1121
1146
|
end
|
1122
1147
|
|
@@ -2052,6 +2077,9 @@ class PCallableType < PAnyType
|
|
2052
2077
|
)
|
2053
2078
|
end
|
2054
2079
|
|
2080
|
+
# @return [PAnyType] The type for the values returned by this callable. Returns `nil` if return value is unconstrained
|
2081
|
+
attr_reader :return_type
|
2082
|
+
|
2055
2083
|
# Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count
|
2056
2084
|
# @return [PTupleType] the tuple representing the parameter types
|
2057
2085
|
attr_reader :param_types
|
@@ -2063,16 +2091,19 @@ class PCallableType < PAnyType
|
|
2063
2091
|
attr_reader :block_type
|
2064
2092
|
|
2065
2093
|
# @param param_types [PTupleType]
|
2066
|
-
# @param block_type [PAnyType
|
2067
|
-
|
2094
|
+
# @param block_type [PAnyType]
|
2095
|
+
# @param return_type [PAnyType]
|
2096
|
+
def initialize(param_types, block_type = nil, return_type = nil)
|
2068
2097
|
@param_types = param_types
|
2069
2098
|
@block_type = block_type
|
2099
|
+
@return_type = return_type == PAnyType::DEFAULT ? nil : return_type
|
2070
2100
|
end
|
2071
2101
|
|
2072
2102
|
def accept(visitor, guard)
|
2073
2103
|
super
|
2074
2104
|
@param_types.accept(visitor, guard) unless @param_types.nil?
|
2075
2105
|
@block_type.accept(visitor, guard) unless @block_type.nil?
|
2106
|
+
@return_type.accept(visitor, guard) unless @return_type.nil?
|
2076
2107
|
end
|
2077
2108
|
|
2078
2109
|
def generalize
|
@@ -2081,7 +2112,8 @@ class PCallableType < PAnyType
|
|
2081
2112
|
else
|
2082
2113
|
params_t = @param_types.nil? ? nil : @param_types.generalize
|
2083
2114
|
block_t = @block_type.nil? ? nil : @block_type.generalize
|
2084
|
-
|
2115
|
+
return_t = @return_type.nil? ? nil : @return_type.generalize
|
2116
|
+
@param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t)
|
2085
2117
|
end
|
2086
2118
|
end
|
2087
2119
|
|
@@ -2091,7 +2123,8 @@ class PCallableType < PAnyType
|
|
2091
2123
|
else
|
2092
2124
|
params_t = @param_types.nil? ? nil : @param_types.normalize(guard)
|
2093
2125
|
block_t = @block_type.nil? ? nil : @block_type.normalize(guard)
|
2094
|
-
|
2126
|
+
return_t = @return_type.nil? ? nil : @return_type.normalize(guard)
|
2127
|
+
@param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t)
|
2095
2128
|
end
|
2096
2129
|
end
|
2097
2130
|
|
@@ -2106,7 +2139,7 @@ class PCallableType < PAnyType
|
|
2106
2139
|
end
|
2107
2140
|
|
2108
2141
|
def kind_of_callable?(optional=true, guard = nil)
|
2109
|
-
|
2142
|
+
true
|
2110
2143
|
end
|
2111
2144
|
|
2112
2145
|
# Returns the number of accepted arguments [min, max]
|
@@ -2134,29 +2167,30 @@ class PCallableType < PAnyType
|
|
2134
2167
|
end
|
2135
2168
|
|
2136
2169
|
def hash
|
2137
|
-
@param_types
|
2170
|
+
[@param_types, @block_type, @return_type].hash
|
2138
2171
|
end
|
2139
2172
|
|
2140
2173
|
def eql?(o)
|
2141
|
-
self.class == o.class && @param_types == o.param_types && @block_type == o.block_type
|
2174
|
+
self.class == o.class && @param_types == o.param_types && @block_type == o.block_type && @return_type == o.return_type
|
2142
2175
|
end
|
2143
2176
|
|
2144
2177
|
def resolve(type_parser, loader)
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
rparam_types.equal?(@param_types) && rblock_type.equal?(@block_type) ? self : self.class.new(rparam_types, rblock_type)
|
2178
|
+
params_t = @param_types.nil? ? nil : @param_types.resolve(type_parser, loader)
|
2179
|
+
block_t = @block_type.nil? ? nil : @block_type.resolve(type_parser, loader)
|
2180
|
+
return_t = @return_type.nil? ? nil : @return_type.resolve(type_parser, loader)
|
2181
|
+
@param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : self.class.new(params_t, block_t, return_t)
|
2150
2182
|
end
|
2151
2183
|
|
2152
|
-
DEFAULT = PCallableType.new(nil)
|
2184
|
+
DEFAULT = PCallableType.new(nil, nil, nil)
|
2153
2185
|
|
2154
2186
|
protected
|
2155
2187
|
|
2156
2188
|
# @api private
|
2157
2189
|
def _assignable?(o, guard)
|
2158
2190
|
return false unless o.is_a?(PCallableType)
|
2159
|
-
|
2191
|
+
return false unless @return_type.nil? || @return_type.assignable?(o.return_type || PAnyType::DEFAULT, guard)
|
2192
|
+
|
2193
|
+
# nil param_types and compatible return type means other Callable is assignable
|
2160
2194
|
return true if @param_types.nil?
|
2161
2195
|
|
2162
2196
|
# NOTE: these tests are made in reverse as it is calling the callable that is constrained
|
@@ -2190,7 +2224,7 @@ class PArrayType < PCollectionType
|
|
2190
2224
|
param_t = callable.param_types
|
2191
2225
|
block_t = callable.block_type
|
2192
2226
|
# does not support calling with a block, but have to check that callable is ok with missing block
|
2193
|
-
(param_t.nil? || param_t.assignable?(self, guard)) && (block_t.nil? || block_t.assignable(PUndefType::DEFAULT, guard))
|
2227
|
+
(param_t.nil? || param_t.assignable?(self, guard)) && (block_t.nil? || block_t.assignable?(PUndefType::DEFAULT, guard))
|
2194
2228
|
end
|
2195
2229
|
|
2196
2230
|
def generalize
|
@@ -2239,6 +2273,11 @@ class PArrayType < PCollectionType
|
|
2239
2273
|
from
|
2240
2274
|
when Hash
|
2241
2275
|
wrap ? [from] : from.to_a
|
2276
|
+
|
2277
|
+
when PBinaryType::Binary
|
2278
|
+
# For older rubies, the #bytes method returns an Enumerator that must be rolled out
|
2279
|
+
wrap ? [from] : from.binary_buffer.bytes.to_a
|
2280
|
+
|
2242
2281
|
else
|
2243
2282
|
if wrap
|
2244
2283
|
[from]
|
@@ -2556,9 +2595,11 @@ class PVariantType < PAnyType
|
|
2556
2595
|
types = swap_optionals(types)
|
2557
2596
|
types = merge_enums(types)
|
2558
2597
|
types = merge_patterns(types)
|
2559
|
-
types = merge_int_ranges(types)
|
2560
|
-
types = merge_float_ranges(types)
|
2561
2598
|
types = merge_version_ranges(types)
|
2599
|
+
types = merge_numbers(PIntegerType, types)
|
2600
|
+
types = merge_numbers(PFloatType, types)
|
2601
|
+
types = merge_numbers(PTimespanType, types)
|
2602
|
+
types = merge_numbers(PTimestampType, types)
|
2562
2603
|
|
2563
2604
|
if types.size == 1
|
2564
2605
|
types[0]
|
@@ -2685,18 +2726,9 @@ class PVariantType < PAnyType
|
|
2685
2726
|
end
|
2686
2727
|
|
2687
2728
|
# @api private
|
2688
|
-
def
|
2689
|
-
if array.size > 1
|
2690
|
-
parts = array.partition {|t| t.is_a?(PIntegerType) }
|
2691
|
-
ranges = parts[0]
|
2692
|
-
array = merge_ranges(ranges) + parts[1] if ranges.size > 1
|
2693
|
-
end
|
2694
|
-
array
|
2695
|
-
end
|
2696
|
-
|
2697
|
-
def merge_float_ranges(array)
|
2729
|
+
def merge_numbers(clazz, array)
|
2698
2730
|
if array.size > 1
|
2699
|
-
parts = array.partition {|t| t.is_a?(
|
2731
|
+
parts = array.partition {|t| t.is_a?(clazz) }
|
2700
2732
|
ranges = parts[0]
|
2701
2733
|
array = merge_ranges(ranges) + parts[1] if ranges.size > 1
|
2702
2734
|
end
|
@@ -3224,5 +3256,8 @@ require_relative 'p_sem_ver_type'
|
|
3224
3256
|
require_relative 'p_sem_ver_range_type'
|
3225
3257
|
require_relative 'p_sensitive_type'
|
3226
3258
|
require_relative 'p_type_set_type'
|
3259
|
+
require_relative 'p_timespan_type'
|
3260
|
+
require_relative 'p_timestamp_type'
|
3261
|
+
require_relative 'p_binary_type'
|
3227
3262
|
require_relative 'type_set_reference'
|
3228
3263
|
require_relative 'implementation_registry'
|
@@ -200,7 +200,15 @@ module Validation
|
|
200
200
|
# TODO: this support is questionable, it requires knowledge that :detail is special
|
201
201
|
arguments[:detail] ||= ''
|
202
202
|
|
203
|
-
if
|
203
|
+
# Accept an Error as semantic if it supports methods #file(), #line(), and #pos()
|
204
|
+
if semantic.is_a?(StandardError)
|
205
|
+
unless semantic.respond_to?(:file) && semantic.respond_to?(:line) && semantic.respond_to?(:pos)
|
206
|
+
raise Puppet::DevError("Issue #{issue.issue_code}: Cannot pass a #{semantic.class} as a semantic object when it does not support #pos(), #file() and #line()")
|
207
|
+
end
|
208
|
+
source_pos = semantic
|
209
|
+
file = semantic.file
|
210
|
+
|
211
|
+
elsif semantic.is_a?(Puppet::Parser::Resource)
|
204
212
|
source_pos = semantic
|
205
213
|
file = semantic.file
|
206
214
|
else
|
@@ -418,6 +418,7 @@ class Checker4_0 < Evaluator::LiteralEvaluator
|
|
418
418
|
|
419
419
|
def check_FunctionDefinition(o)
|
420
420
|
check_NamedDefinition(o)
|
421
|
+
internal_check_return_type(o)
|
421
422
|
internal_check_parameter_name_uniqueness(o)
|
422
423
|
end
|
423
424
|
|
@@ -437,6 +438,11 @@ class Checker4_0 < Evaluator::LiteralEvaluator
|
|
437
438
|
internal_check_no_idem_last(o)
|
438
439
|
end
|
439
440
|
|
441
|
+
def internal_check_return_type(o)
|
442
|
+
r = o.return_type
|
443
|
+
internal_check_type_ref(o, r) unless r.nil?
|
444
|
+
end
|
445
|
+
|
440
446
|
def internal_check_type_ref(o, r)
|
441
447
|
n = r.is_a?(Model::AccessExpression) ? r.left_expr : r
|
442
448
|
if n.is_a? Model::QualifiedReference
|
@@ -515,6 +521,7 @@ class Checker4_0 < Evaluator::LiteralEvaluator
|
|
515
521
|
|
516
522
|
def check_LambdaExpression(o)
|
517
523
|
internal_check_capture_last(o)
|
524
|
+
internal_check_return_type(o)
|
518
525
|
end
|
519
526
|
|
520
527
|
def check_LiteralList(o)
|