From 681a1c7971d78c53dc9a0747ae4d983ff6b0d670 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 5 Aug 2011 08:25:03 +0100 Subject: Prep for stdlib merge * Renamed load_yaml & load_json to parseyaml & parsejson * Renamed is_valid_* functions and remove the 'valid_' --- lib/puppet/parser/functions/is_domain_name.rb | 27 ++++++++++++++++++ lib/puppet/parser/functions/is_ip_address.rb | 32 ++++++++++++++++++++++ lib/puppet/parser/functions/is_mac_address.rb | 27 ++++++++++++++++++ .../parser/functions/is_valid_domain_name.rb | 27 ------------------ lib/puppet/parser/functions/is_valid_ip_address.rb | 32 ---------------------- .../parser/functions/is_valid_mac_address.rb | 27 ------------------ lib/puppet/parser/functions/load_json.rb | 26 ------------------ lib/puppet/parser/functions/load_yaml.rb | 24 ---------------- lib/puppet/parser/functions/parsejson.rb | 26 ++++++++++++++++++ lib/puppet/parser/functions/parseyaml.rb | 24 ++++++++++++++++ 10 files changed, 136 insertions(+), 136 deletions(-) create mode 100644 lib/puppet/parser/functions/is_domain_name.rb create mode 100644 lib/puppet/parser/functions/is_ip_address.rb create mode 100644 lib/puppet/parser/functions/is_mac_address.rb delete mode 100644 lib/puppet/parser/functions/is_valid_domain_name.rb delete mode 100644 lib/puppet/parser/functions/is_valid_ip_address.rb delete mode 100644 lib/puppet/parser/functions/is_valid_mac_address.rb delete mode 100644 lib/puppet/parser/functions/load_json.rb delete mode 100644 lib/puppet/parser/functions/load_yaml.rb create mode 100644 lib/puppet/parser/functions/parsejson.rb create mode 100644 lib/puppet/parser/functions/parseyaml.rb (limited to 'lib') diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb new file mode 100644 index 0000000..4e92939 --- /dev/null +++ b/lib/puppet/parser/functions/is_domain_name.rb @@ -0,0 +1,27 @@ +# +# is_domain_name.rb +# + +module Puppet::Parser::Functions + newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + domain = arguments[0] + + if domain =~ /^(([a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\.?$/ then + return true + else + return false + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb new file mode 100644 index 0000000..b4a9a15 --- /dev/null +++ b/lib/puppet/parser/functions/is_ip_address.rb @@ -0,0 +1,32 @@ +# +# is_ip_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid IP address. + EOS + ) do |arguments| + + require 'ipaddr' + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + begin + ip = IPAddr.new(arguments[0]) + rescue ArgumentError + return false + end + + if ip.ipv4? or ip.ipv6? then + return true + else + return false + end + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_mac_address.rb b/lib/puppet/parser/functions/is_mac_address.rb new file mode 100644 index 0000000..1b3088a --- /dev/null +++ b/lib/puppet/parser/functions/is_mac_address.rb @@ -0,0 +1,27 @@ +# +# is_mac_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid mac address. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + mac = arguments[0] + + if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then + return true + else + return false + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_domain_name.rb b/lib/puppet/parser/functions/is_valid_domain_name.rb deleted file mode 100644 index 7dd9c0b..0000000 --- a/lib/puppet/parser/functions/is_valid_domain_name.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# is_valid_domain_name.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS -Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included. - EOS - ) do |arguments| - - if (arguments.size != 1) then - raise(Puppet::ParseError, "is_valid_domain_name(): Wrong number of arguments "+ - "given #{arguments.size} for 1") - end - - domain = arguments[0] - - if domain =~ /^(([a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\.?$/ then - return true - else - return false - end - - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_ip_address.rb b/lib/puppet/parser/functions/is_valid_ip_address.rb deleted file mode 100644 index 604d938..0000000 --- a/lib/puppet/parser/functions/is_valid_ip_address.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# is_valid_ip_address.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS -Returns true if the string passed to this function is a valid IP address. - EOS - ) do |arguments| - - require 'ipaddr' - - if (arguments.size != 1) then - raise(Puppet::ParseError, "is_valid_ip_address(): Wrong number of arguments "+ - "given #{arguments.size} for 1") - end - - begin - ip = IPAddr.new(arguments[0]) - rescue ArgumentError - return false - end - - if ip.ipv4? or ip.ipv6? then - return true - else - return false - end - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_mac_address.rb b/lib/puppet/parser/functions/is_valid_mac_address.rb deleted file mode 100644 index 53199b6..0000000 --- a/lib/puppet/parser/functions/is_valid_mac_address.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# is_valid_mac_address.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS -Returns true if the string passed to this function is a valid mac address. - EOS - ) do |arguments| - - if (arguments.size != 1) then - raise(Puppet::ParseError, "is_valid_mac_address(): Wrong number of arguments "+ - "given #{arguments.size} for 1") - end - - mac = arguments[0] - - if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then - return true - else - return false - end - - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/load_json.rb b/lib/puppet/parser/functions/load_json.rb deleted file mode 100644 index 333cf11..0000000 --- a/lib/puppet/parser/functions/load_json.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -# load_json.rb -# - -module Puppet::Parser::Functions - newfunction(:load_json, :type => :rvalue, :doc => <<-EOS -This function accepts JSON as a string and converts into the correct Puppet -structure. - EOS - ) do |arguments| - - if (arguments.size != 1) then - raise(Puppet::ParseError, "load_json(): Wrong number of arguments "+ - "given #{arguments.size} for 1") - end - - json = arguments[0] - - require 'json' - - JSON.load(json) - - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/load_yaml.rb b/lib/puppet/parser/functions/load_yaml.rb deleted file mode 100644 index 2683277..0000000 --- a/lib/puppet/parser/functions/load_yaml.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -# load_yaml.rb -# - -module Puppet::Parser::Functions - newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS -This function accepts YAML as a string and converts it into the correct -Puppet structure. - EOS - ) do |arguments| - - if (arguments.size != 1) then - raise(Puppet::ParseError, "load_yaml(): Wrong number of arguments "+ - "given #{arguments.size} for 1") - end - - require 'yaml' - - YAML::load(arguments[0]) - - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/parsejson.rb b/lib/puppet/parser/functions/parsejson.rb new file mode 100644 index 0000000..cf3b12c --- /dev/null +++ b/lib/puppet/parser/functions/parsejson.rb @@ -0,0 +1,26 @@ +# +# parsejson.rb +# + +module Puppet::Parser::Functions + newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS +This function accepts JSON as a string and converts into the correct Puppet +structure. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + json = arguments[0] + + require 'json' + + JSON.load(json) + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/parseyaml.rb b/lib/puppet/parser/functions/parseyaml.rb new file mode 100644 index 0000000..e8ac8a4 --- /dev/null +++ b/lib/puppet/parser/functions/parseyaml.rb @@ -0,0 +1,24 @@ +# +# parseyaml.rb +# + +module Puppet::Parser::Functions + newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS +This function accepts YAML as a string and converts it into the correct +Puppet structure. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + require 'yaml' + + YAML::load(arguments[0]) + + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3