service_kiosk 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Vagrantfile +25 -0
- data/bin/kiosk +55 -0
- data/bin/start_kiosk.sh +3 -0
- data/lib/Procfile.kiosk +1 -0
- data/lib/internal_service.rb +59 -0
- data/lib/json-simple-1.1.1.jar +0 -0
- data/lib/kiosk.rb +57 -0
- data/lib/kiosks/logger/output_logger.rb +16 -0
- data/lib/mall.rb +77 -0
- data/lib/mallcop.rb +9 -0
- data/lib/remote_service.rb +61 -0
- data/lib/tasks/local_mall.rake +93 -0
- data/provision/bootstrap.sh +21 -0
- data/provision/manifests/default.pp +49 -0
- data/provision/modules/apt/CHANGELOG +83 -0
- data/provision/modules/apt/LICENSE +19 -0
- data/provision/modules/apt/Modulefile +14 -0
- data/provision/modules/apt/README.md +119 -0
- data/provision/modules/apt/Rakefile +1 -0
- data/provision/modules/apt/manifests/backports.pp +48 -0
- data/provision/modules/apt/manifests/builddep.pp +16 -0
- data/provision/modules/apt/manifests/conf.pp +18 -0
- data/provision/modules/apt/manifests/debian/testing.pp +21 -0
- data/provision/modules/apt/manifests/debian/unstable.pp +21 -0
- data/provision/modules/apt/manifests/force.pp +24 -0
- data/provision/modules/apt/manifests/init.pp +114 -0
- data/provision/modules/apt/manifests/key.pp +80 -0
- data/provision/modules/apt/manifests/params.pp +23 -0
- data/provision/modules/apt/manifests/pin.pp +48 -0
- data/provision/modules/apt/manifests/ppa.pp +49 -0
- data/provision/modules/apt/manifests/release.pp +17 -0
- data/provision/modules/apt/manifests/source.pp +83 -0
- data/provision/modules/apt/manifests/update.pp +9 -0
- data/provision/modules/apt/spec/classes/apt_spec.rb +129 -0
- data/provision/modules/apt/spec/classes/backports_spec.rb +71 -0
- data/provision/modules/apt/spec/classes/debian_testing_spec.rb +14 -0
- data/provision/modules/apt/spec/classes/debian_unstable_spec.rb +14 -0
- data/provision/modules/apt/spec/classes/params_spec.rb +13 -0
- data/provision/modules/apt/spec/classes/release_spec.rb +22 -0
- data/provision/modules/apt/spec/defines/builddep_spec.rb +18 -0
- data/provision/modules/apt/spec/defines/conf_spec.rb +57 -0
- data/provision/modules/apt/spec/defines/force_spec.rb +41 -0
- data/provision/modules/apt/spec/defines/key_spec.rb +123 -0
- data/provision/modules/apt/spec/defines/pin_spec.rb +58 -0
- data/provision/modules/apt/spec/defines/ppa_spec.rb +92 -0
- data/provision/modules/apt/spec/defines/source_spec.rb +158 -0
- data/provision/modules/apt/spec/fixtures/manifests/site.pp +0 -0
- data/provision/modules/apt/spec/spec_helper.rb +1 -0
- data/provision/modules/apt/templates/pin.pref.erb +5 -0
- data/provision/modules/apt/templates/source.list.erb +5 -0
- data/provision/modules/apt/tests/builddep.pp +2 -0
- data/provision/modules/apt/tests/debian/testing.pp +2 -0
- data/provision/modules/apt/tests/debian/unstable.pp +2 -0
- data/provision/modules/apt/tests/force.pp +7 -0
- data/provision/modules/apt/tests/init.pp +1 -0
- data/provision/modules/apt/tests/key.pp +5 -0
- data/provision/modules/apt/tests/params.pp +1 -0
- data/provision/modules/apt/tests/pin.pp +5 -0
- data/provision/modules/apt/tests/ppa.pp +4 -0
- data/provision/modules/apt/tests/release.pp +4 -0
- data/provision/modules/apt/tests/source.pp +29 -0
- data/provision/modules/stdlib/CHANGELOG +177 -0
- data/provision/modules/stdlib/LICENSE +19 -0
- data/provision/modules/stdlib/Modulefile +11 -0
- data/provision/modules/stdlib/README.markdown +929 -0
- data/provision/modules/stdlib/README_DEVELOPER.markdown +35 -0
- data/provision/modules/stdlib/RELEASE_PROCESS.markdown +24 -0
- data/provision/modules/stdlib/Rakefile +2 -0
- data/provision/modules/stdlib/lib/facter/pe_version.rb +53 -0
- data/provision/modules/stdlib/lib/facter/puppet_vardir.rb +26 -0
- data/provision/modules/stdlib/lib/facter/root_home.rb +19 -0
- data/provision/modules/stdlib/lib/facter/util/puppet_settings.rb +21 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/abs.rb +36 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/bool2num.rb +49 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/capitalize.rb +34 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/chomp.rb +35 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/chop.rb +37 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb +35 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/delete.rb +46 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/delete_at.rb +49 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/downcase.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/empty.rb +28 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb +24 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb +35 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/flatten.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb +46 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb +17 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/getvar.rb +26 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/grep.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb +52 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb +25 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb +25 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/has_key.rb +28 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/hash.rb +41 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_array.rb +22 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb +47 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_float.rb +27 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_hash.rb +22 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_integer.rb +27 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb +32 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb +27 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb +27 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/is_string.rb +26 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/join.rb +41 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb +47 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/keys.rb +26 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb +20 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/lstrip.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/max.rb +13 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/member.rb +44 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/merge.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/min.rb +13 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/num2bool.rb +40 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/parsejson.rb +24 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb +24 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/pick.rb +29 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/prefix.rb +45 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/range.rb +80 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/reject.rb +31 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/reverse.rb +28 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/rstrip.rb +32 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/shuffle.rb +46 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/size.rb +48 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/sort.rb +27 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/squeeze.rb +36 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/str2bool.rb +41 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb +32 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/strftime.rb +107 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/strip.rb +39 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/swapcase.rb +39 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/time.rb +49 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb +28 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/type.rb +50 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/unique.rb +51 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/upcase.rb +41 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/uriescape.rb +36 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb +56 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_array.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb +34 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_re.rb +40 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb +52 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/validate_string.rb +33 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/values.rb +39 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/values_at.rb +98 -0
- data/provision/modules/stdlib/lib/puppet/parser/functions/zip.rb +65 -0
- data/provision/modules/stdlib/lib/puppet/provider/file_line/ruby.rb +59 -0
- data/provision/modules/stdlib/lib/puppet/type/anchor.rb +41 -0
- data/provision/modules/stdlib/lib/puppet/type/file_line.rb +70 -0
- data/provision/modules/stdlib/manifests/init.pp +20 -0
- data/provision/modules/stdlib/manifests/stages.pp +43 -0
- data/provision/modules/stdlib/spec/functions/defined_with_params_spec.rb +37 -0
- data/provision/modules/stdlib/spec/functions/ensure_packages_spec.rb +42 -0
- data/provision/modules/stdlib/spec/functions/ensure_resource_spec.rb +40 -0
- data/provision/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb +8 -0
- data/provision/modules/stdlib/spec/monkey_patches/publicize_methods.rb +10 -0
- data/provision/modules/stdlib/spec/spec.opts +6 -0
- data/provision/modules/stdlib/spec/spec_helper.rb +28 -0
- data/provision/modules/stdlib/spec/unit/facter/pe_version_spec.rb +76 -0
- data/provision/modules/stdlib/spec/unit/facter/root_home_spec.rb +40 -0
- data/provision/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb +35 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb +25 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb +38 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb +23 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb +23 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb +33 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb +46 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb +37 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb +64 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb +39 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb +36 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb +42 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb +64 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb +39 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb +34 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb +40 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb +21 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb +23 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb +47 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb +23 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb +22 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb +34 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb +34 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb +20 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb +45 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb +18 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb +19 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb +29 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb +58 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb +43 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb +24 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +83 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb +38 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb +51 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb +43 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb +76 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb +48 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb +60 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb +38 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb +31 -0
- data/provision/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb +15 -0
- data/provision/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb +127 -0
- data/provision/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb +11 -0
- data/provision/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb +69 -0
- data/provision/modules/stdlib/spec/watchr.rb +86 -0
- data/provision/modules/stdlib/tests/file_line.pp +9 -0
- data/provision/modules/stdlib/tests/has_interface_with.pp +10 -0
- data/provision/modules/stdlib/tests/has_ip_address.pp +3 -0
- data/provision/modules/stdlib/tests/has_ip_network.pp +4 -0
- data/provision/modules/stdlib/tests/init.pp +1 -0
- metadata +291 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Puppet::Parser::Functions
|
|
2
|
+
|
|
3
|
+
newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
|
4
|
+
Load a YAML file containing an array, string, or hash, and return the data
|
|
5
|
+
in the corresponding native data type.
|
|
6
|
+
|
|
7
|
+
For example:
|
|
8
|
+
|
|
9
|
+
$myhash = loadyaml('/etc/puppet/data/myhash.yaml')
|
|
10
|
+
ENDHEREDOC
|
|
11
|
+
|
|
12
|
+
unless args.length == 1
|
|
13
|
+
raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
YAML.load_file(args[0])
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#
|
|
2
|
+
# lstrip.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Strips leading spaces to the left of a string.
|
|
8
|
+
EOS
|
|
9
|
+
) do |arguments|
|
|
10
|
+
|
|
11
|
+
raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " +
|
|
12
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
13
|
+
|
|
14
|
+
value = arguments[0]
|
|
15
|
+
klass = value.class
|
|
16
|
+
|
|
17
|
+
unless [Array, String].include?(klass)
|
|
18
|
+
raise(Puppet::ParseError, 'lstrip(): Requires either ' +
|
|
19
|
+
'array or string to work with')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if value.is_a?(Array)
|
|
23
|
+
# Numbers in Puppet are often string-encoded which is troublesome ...
|
|
24
|
+
result = value.collect { |i| i.is_a?(String) ? i.lstrip : i }
|
|
25
|
+
else
|
|
26
|
+
result = value.lstrip
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
return result
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Puppet::Parser::Functions
|
|
2
|
+
newfunction(:max, :type => :rvalue, :doc => <<-EOS
|
|
3
|
+
Returns the highest value of all arguments.
|
|
4
|
+
Requires at least one argument.
|
|
5
|
+
EOS
|
|
6
|
+
) do |args|
|
|
7
|
+
|
|
8
|
+
raise(Puppet::ParseError, "max(): Wrong number of arguments " +
|
|
9
|
+
"need at least one") if args.size == 0
|
|
10
|
+
|
|
11
|
+
return args.max
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#
|
|
2
|
+
# member.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
|
|
6
|
+
# TODO(Krzysztof Wilczynski): Support for strings and hashes too ...
|
|
7
|
+
|
|
8
|
+
module Puppet::Parser::Functions
|
|
9
|
+
newfunction(:member, :type => :rvalue, :doc => <<-EOS
|
|
10
|
+
This function determines if a variable is a member of an array.
|
|
11
|
+
|
|
12
|
+
*Examples:*
|
|
13
|
+
|
|
14
|
+
member(['a','b'], 'b')
|
|
15
|
+
|
|
16
|
+
Would return: true
|
|
17
|
+
|
|
18
|
+
member(['a','b'], 'c')
|
|
19
|
+
|
|
20
|
+
Would return: false
|
|
21
|
+
EOS
|
|
22
|
+
) do |arguments|
|
|
23
|
+
|
|
24
|
+
raise(Puppet::ParseError, "member(): Wrong number of arguments " +
|
|
25
|
+
"given (#{arguments.size} for 2)") if arguments.size < 2
|
|
26
|
+
|
|
27
|
+
array = arguments[0]
|
|
28
|
+
|
|
29
|
+
unless array.is_a?(Array)
|
|
30
|
+
raise(Puppet::ParseError, 'member(): Requires array to work with')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
item = arguments[1]
|
|
34
|
+
|
|
35
|
+
raise(Puppet::ParseError, 'member(): You must provide item ' +
|
|
36
|
+
'to search for within array given') if item.empty?
|
|
37
|
+
|
|
38
|
+
result = array.include?(item)
|
|
39
|
+
|
|
40
|
+
return result
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Puppet::Parser::Functions
|
|
2
|
+
newfunction(:merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
|
3
|
+
Merges two or more hashes together and returns the resulting hash.
|
|
4
|
+
|
|
5
|
+
For example:
|
|
6
|
+
|
|
7
|
+
$hash1 = {'one' => 1, 'two', => 2}
|
|
8
|
+
$hash2 = {'two' => 'dos', 'three', => 'tres'}
|
|
9
|
+
$merged_hash = merge($hash1, $hash2)
|
|
10
|
+
# The resulting hash is equivalent to:
|
|
11
|
+
# $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
|
|
12
|
+
|
|
13
|
+
When there is a duplicate key, the key in the rightmost hash will "win."
|
|
14
|
+
|
|
15
|
+
ENDHEREDOC
|
|
16
|
+
|
|
17
|
+
if args.length < 2
|
|
18
|
+
raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The hash we accumulate into
|
|
22
|
+
accumulator = Hash.new
|
|
23
|
+
# Merge into the accumulator hash
|
|
24
|
+
args.each do |arg|
|
|
25
|
+
unless arg.is_a?(Hash)
|
|
26
|
+
raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments"
|
|
27
|
+
end
|
|
28
|
+
accumulator.merge!(arg)
|
|
29
|
+
end
|
|
30
|
+
# Return the fully merged hash
|
|
31
|
+
accumulator
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Puppet::Parser::Functions
|
|
2
|
+
newfunction(:min, :type => :rvalue, :doc => <<-EOS
|
|
3
|
+
Returns the lowest value of all arguments.
|
|
4
|
+
Requires at least one argument.
|
|
5
|
+
EOS
|
|
6
|
+
) do |args|
|
|
7
|
+
|
|
8
|
+
raise(Puppet::ParseError, "min(): Wrong number of arguments " +
|
|
9
|
+
"need at least one") if args.size == 0
|
|
10
|
+
|
|
11
|
+
return args.min
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#
|
|
2
|
+
# num2bool.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
|
|
6
|
+
|
|
7
|
+
module Puppet::Parser::Functions
|
|
8
|
+
newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
|
|
9
|
+
This function converts a number into a true boolean. Zero becomes false. Numbers
|
|
10
|
+
higher then 0 become true.
|
|
11
|
+
EOS
|
|
12
|
+
) do |arguments|
|
|
13
|
+
|
|
14
|
+
raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " +
|
|
15
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
16
|
+
|
|
17
|
+
number = arguments[0]
|
|
18
|
+
|
|
19
|
+
# Only numbers allowed ...
|
|
20
|
+
unless number.match(/^\-?\d+$/)
|
|
21
|
+
raise(Puppet::ParseError, 'num2bool(): Requires integer to work with')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
result = case number
|
|
25
|
+
when /^0$/
|
|
26
|
+
false
|
|
27
|
+
when /^\-?\d+$/
|
|
28
|
+
# Numbers in Puppet are often string-encoded which is troublesome ...
|
|
29
|
+
number = number.to_i
|
|
30
|
+
# We yield true for any positive number and false otherwise ...
|
|
31
|
+
number > 0 ? true : false
|
|
32
|
+
else
|
|
33
|
+
raise(Puppet::ParseError, 'num2bool(): Unknown numeric format given')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
return result
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#
|
|
2
|
+
# parsejson.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
This function accepts JSON as a string and converts into the correct Puppet
|
|
8
|
+
structure.
|
|
9
|
+
EOS
|
|
10
|
+
) do |arguments|
|
|
11
|
+
|
|
12
|
+
if (arguments.size != 1) then
|
|
13
|
+
raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+
|
|
14
|
+
"given #{arguments.size} for 1")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
json = arguments[0]
|
|
18
|
+
|
|
19
|
+
# PSON is natively available in puppet
|
|
20
|
+
PSON.load(json)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#
|
|
2
|
+
# parseyaml.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
This function accepts YAML as a string and converts it into the correct
|
|
8
|
+
Puppet structure.
|
|
9
|
+
EOS
|
|
10
|
+
) do |arguments|
|
|
11
|
+
|
|
12
|
+
if (arguments.size != 1) then
|
|
13
|
+
raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+
|
|
14
|
+
"given #{arguments.size} for 1")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
require 'yaml'
|
|
18
|
+
|
|
19
|
+
YAML::load(arguments[0])
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Puppet::Parser::Functions
|
|
2
|
+
newfunction(:pick, :type => :rvalue, :doc => <<-EOS
|
|
3
|
+
|
|
4
|
+
This function is similar to a coalesce function in SQL in that it will return
|
|
5
|
+
the first value in a list of values that is not undefined or an empty string
|
|
6
|
+
(two things in Puppet that will return a boolean false value). Typically,
|
|
7
|
+
this function is used to check for a value in the Puppet Dashboard/Enterprise
|
|
8
|
+
Console, and failover to a default value like the following:
|
|
9
|
+
|
|
10
|
+
$real_jenkins_version = pick($::jenkins_version, '1.449')
|
|
11
|
+
|
|
12
|
+
The value of $real_jenkins_version will first look for a top-scope variable
|
|
13
|
+
called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
|
|
14
|
+
Enterprise Console are brought into Puppet as top-scope variables), and,
|
|
15
|
+
failing that, will use a default value of 1.449.
|
|
16
|
+
|
|
17
|
+
EOS
|
|
18
|
+
) do |args|
|
|
19
|
+
args = args.compact
|
|
20
|
+
args.delete(:undef)
|
|
21
|
+
args.delete(:undefined)
|
|
22
|
+
args.delete("")
|
|
23
|
+
if args[0].to_s.empty? then
|
|
24
|
+
fail "Must provide non empty value."
|
|
25
|
+
else
|
|
26
|
+
return args[0]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#
|
|
2
|
+
# prefix.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
This function applies a prefix to all elements in an array.
|
|
8
|
+
|
|
9
|
+
*Examles:*
|
|
10
|
+
|
|
11
|
+
prefix(['a','b','c'], 'p')
|
|
12
|
+
|
|
13
|
+
Will return: ['pa','pb','pc']
|
|
14
|
+
EOS
|
|
15
|
+
) do |arguments|
|
|
16
|
+
|
|
17
|
+
# Technically we support two arguments but only first is mandatory ...
|
|
18
|
+
raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
|
|
19
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
20
|
+
|
|
21
|
+
array = arguments[0]
|
|
22
|
+
|
|
23
|
+
unless array.is_a?(Array)
|
|
24
|
+
raise(Puppet::ParseError, 'prefix(): Requires array to work with')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
prefix = arguments[1] if arguments[1]
|
|
28
|
+
|
|
29
|
+
if prefix
|
|
30
|
+
unless prefix.is_a?(String)
|
|
31
|
+
raise(Puppet::ParseError, 'prefix(): Requires string to work with')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Turn everything into string same as join would do ...
|
|
36
|
+
result = array.collect do |i|
|
|
37
|
+
i = i.to_s
|
|
38
|
+
prefix ? prefix + i : i
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
return result
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#
|
|
2
|
+
# range.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
|
|
6
|
+
|
|
7
|
+
module Puppet::Parser::Functions
|
|
8
|
+
newfunction(:range, :type => :rvalue, :doc => <<-EOS
|
|
9
|
+
When given range in the form of (start, stop) it will extrapolate a range as
|
|
10
|
+
an array.
|
|
11
|
+
|
|
12
|
+
*Examples:*
|
|
13
|
+
|
|
14
|
+
range("0", "9")
|
|
15
|
+
|
|
16
|
+
Will return: [0,1,2,3,4,5,6,7,8,9]
|
|
17
|
+
|
|
18
|
+
range("00", "09")
|
|
19
|
+
|
|
20
|
+
Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to
|
|
21
|
+
integers automatically)
|
|
22
|
+
|
|
23
|
+
range("a", "c")
|
|
24
|
+
|
|
25
|
+
Will return: ["a","b","c"]
|
|
26
|
+
|
|
27
|
+
range("host01", "host10")
|
|
28
|
+
|
|
29
|
+
Will return: ["host01", "host02", ..., "host09", "host10"]
|
|
30
|
+
EOS
|
|
31
|
+
) do |arguments|
|
|
32
|
+
|
|
33
|
+
# We support more than one argument but at least one is mandatory ...
|
|
34
|
+
raise(Puppet::ParseError, "range(): Wrong number of " +
|
|
35
|
+
"arguments given (#{arguments.size} for 1)") if arguments.size < 1
|
|
36
|
+
|
|
37
|
+
if arguments.size > 1
|
|
38
|
+
start = arguments[0]
|
|
39
|
+
stop = arguments[1]
|
|
40
|
+
|
|
41
|
+
type = '..' # We select simplest type for Range available in Ruby ...
|
|
42
|
+
|
|
43
|
+
elsif arguments.size > 0
|
|
44
|
+
value = arguments[0]
|
|
45
|
+
|
|
46
|
+
if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/)
|
|
47
|
+
start = m[1]
|
|
48
|
+
stop = m[3]
|
|
49
|
+
|
|
50
|
+
type = m[2]
|
|
51
|
+
|
|
52
|
+
elsif value.match(/^.+$/)
|
|
53
|
+
raise(Puppet::ParseError, 'range(): Unable to compute range ' +
|
|
54
|
+
'from the value given')
|
|
55
|
+
else
|
|
56
|
+
raise(Puppet::ParseError, 'range(): Unknown format of range given')
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Check whether we have integer value if so then make it so ...
|
|
61
|
+
if start.match(/^\d+$/)
|
|
62
|
+
start = start.to_i
|
|
63
|
+
stop = stop.to_i
|
|
64
|
+
else
|
|
65
|
+
start = start.to_s
|
|
66
|
+
stop = stop.to_s
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
range = case type
|
|
70
|
+
when /^(\.\.|\-)$/ then (start .. stop)
|
|
71
|
+
when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
result = range.collect { |i| i } # Get them all ... Pokemon ...
|
|
75
|
+
|
|
76
|
+
return result
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#
|
|
2
|
+
# reject.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args|
|
|
7
|
+
This function searches through an array and rejects all elements that match
|
|
8
|
+
the provided regular expression.
|
|
9
|
+
|
|
10
|
+
*Examples:*
|
|
11
|
+
|
|
12
|
+
reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
|
|
13
|
+
|
|
14
|
+
Would return:
|
|
15
|
+
|
|
16
|
+
['bbb','ccc']
|
|
17
|
+
EOS
|
|
18
|
+
|
|
19
|
+
if (args.size != 2)
|
|
20
|
+
raise Puppet::ParseError,
|
|
21
|
+
"reject(): Wrong number of arguments given #{args.size} for 2"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
ary = args[0]
|
|
25
|
+
pattern = Regexp.new(args[1])
|
|
26
|
+
|
|
27
|
+
ary.reject { |e| e =~ pattern }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#
|
|
2
|
+
# reverse.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Reverses the order of a string or array.
|
|
8
|
+
EOS
|
|
9
|
+
) do |arguments|
|
|
10
|
+
|
|
11
|
+
raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
|
|
12
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
13
|
+
|
|
14
|
+
value = arguments[0]
|
|
15
|
+
klass = value.class
|
|
16
|
+
|
|
17
|
+
unless [Array, String].include?(klass)
|
|
18
|
+
raise(Puppet::ParseError, 'reverse(): Requires either ' +
|
|
19
|
+
'array or string to work with')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
result = value.reverse
|
|
23
|
+
|
|
24
|
+
return result
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#
|
|
2
|
+
# rstrip.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Strips leading spaces to the right of the string.
|
|
8
|
+
EOS
|
|
9
|
+
) do |arguments|
|
|
10
|
+
|
|
11
|
+
raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " +
|
|
12
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
13
|
+
|
|
14
|
+
value = arguments[0]
|
|
15
|
+
klass = value.class
|
|
16
|
+
|
|
17
|
+
unless [Array, String].include?(klass)
|
|
18
|
+
raise(Puppet::ParseError, 'rstrip(): Requires either ' +
|
|
19
|
+
'array or string to work with')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if value.is_a?(Array)
|
|
23
|
+
result = value.collect { |i| i.is_a?(String) ? i.rstrip : i }
|
|
24
|
+
else
|
|
25
|
+
result = value.rstrip
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
return result
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#
|
|
2
|
+
# shuffle.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Randomizes the order of a string or array elements.
|
|
8
|
+
EOS
|
|
9
|
+
) do |arguments|
|
|
10
|
+
|
|
11
|
+
raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " +
|
|
12
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
13
|
+
|
|
14
|
+
value = arguments[0]
|
|
15
|
+
klass = value.class
|
|
16
|
+
|
|
17
|
+
unless [Array, String].include?(klass)
|
|
18
|
+
raise(Puppet::ParseError, 'shuffle(): Requires either ' +
|
|
19
|
+
'array or string to work with')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
result = value.clone
|
|
23
|
+
|
|
24
|
+
string = value.is_a?(String) ? true : false
|
|
25
|
+
|
|
26
|
+
# Check whether it makes sense to shuffle ...
|
|
27
|
+
return result if result.size <= 1
|
|
28
|
+
|
|
29
|
+
# We turn any string value into an array to be able to shuffle ...
|
|
30
|
+
result = string ? result.split('') : result
|
|
31
|
+
|
|
32
|
+
elements = result.size
|
|
33
|
+
|
|
34
|
+
# Simple implementation of Fisher–Yates in-place shuffle ...
|
|
35
|
+
elements.times do |i|
|
|
36
|
+
j = rand(elements - i) + i
|
|
37
|
+
result[j], result[i] = result[i], result[j]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
result = string ? result.join : result
|
|
41
|
+
|
|
42
|
+
return result
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#
|
|
2
|
+
# size.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
|
|
6
|
+
|
|
7
|
+
module Puppet::Parser::Functions
|
|
8
|
+
newfunction(:size, :type => :rvalue, :doc => <<-EOS
|
|
9
|
+
Returns the number of elements in a string or array.
|
|
10
|
+
EOS
|
|
11
|
+
) do |arguments|
|
|
12
|
+
|
|
13
|
+
raise(Puppet::ParseError, "size(): Wrong number of arguments " +
|
|
14
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
15
|
+
|
|
16
|
+
item = arguments[0]
|
|
17
|
+
|
|
18
|
+
if item.is_a?(String)
|
|
19
|
+
|
|
20
|
+
begin
|
|
21
|
+
#
|
|
22
|
+
# Check whether your item is a numeric value or not ...
|
|
23
|
+
# This will take care about positive and/or negative numbers
|
|
24
|
+
# for both integer and floating-point values ...
|
|
25
|
+
#
|
|
26
|
+
# Please note that Puppet has no notion of hexadecimal
|
|
27
|
+
# nor octal numbers for its DSL at this point in time ...
|
|
28
|
+
#
|
|
29
|
+
Float(item)
|
|
30
|
+
|
|
31
|
+
raise(Puppet::ParseError, 'size(): Requires either ' +
|
|
32
|
+
'string or array to work with')
|
|
33
|
+
|
|
34
|
+
rescue ArgumentError
|
|
35
|
+
result = item.size
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
elsif item.is_a?(Array)
|
|
39
|
+
result = item.size
|
|
40
|
+
else
|
|
41
|
+
raise(Puppet::ParseError, 'size(): Unknown type given')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
return result
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#
|
|
2
|
+
# sort.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:sort, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Sorts strings and arrays lexically.
|
|
8
|
+
EOS
|
|
9
|
+
) do |arguments|
|
|
10
|
+
|
|
11
|
+
if (arguments.size != 1) then
|
|
12
|
+
raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
|
|
13
|
+
"given #{arguments.size} for 1")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
value = arguments[0]
|
|
17
|
+
|
|
18
|
+
if value.is_a?(Array) then
|
|
19
|
+
value.sort
|
|
20
|
+
elsif value.is_a?(String) then
|
|
21
|
+
value.split("").sort.join("")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#
|
|
2
|
+
# squeeze.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Returns a new string where runs of the same character that occur in this set are replaced by a single character.
|
|
8
|
+
EOS
|
|
9
|
+
) do |arguments|
|
|
10
|
+
|
|
11
|
+
if ((arguments.size != 2) and (arguments.size != 1)) then
|
|
12
|
+
raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
|
|
13
|
+
"given #{arguments.size} for 2 or 1")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
item = arguments[0]
|
|
17
|
+
squeezeval = arguments[1]
|
|
18
|
+
|
|
19
|
+
if item.is_a?(Array) then
|
|
20
|
+
if squeezeval then
|
|
21
|
+
item.collect { |i| i.squeeze(squeezeval) }
|
|
22
|
+
else
|
|
23
|
+
item.collect { |i| i.squeeze }
|
|
24
|
+
end
|
|
25
|
+
else
|
|
26
|
+
if squeezeval then
|
|
27
|
+
item.squeeze(squeezeval)
|
|
28
|
+
else
|
|
29
|
+
item.squeeze
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# vim: set ts=2 sw=2 et :
|