diff options
author | Josh Cooper <josh@puppet.com> | 2018-07-09 19:50:03 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppet.com> | 2018-07-09 19:50:03 -0700 |
commit | 59f4a9e49d397556a60f060faffdc14b734856da (patch) | |
tree | 8b630a7d02fc4e6e207fc3d84b9d78c1f6637191 /lib/puppet/type | |
parent | 34e83e11a5fc344195217d9cd159d022b5d89ec1 (diff) | |
download | puppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.gz puppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.bz2 |
Automatic validation updates
Updated rubocop violations using `pdk validate -a`.
Diffstat (limited to 'lib/puppet/type')
-rw-r--r-- | lib/puppet/type/host.rb | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index 3bfcc7e..5e58e3a 100644 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -7,39 +7,39 @@ module Puppet newproperty(:ip) do desc "The host's IP address, IPv4 or IPv6." - def valid_v4?(addr) - if /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ =~ addr - return $~.captures.all? {|i| i = i.to_i; i >= 0 and i <= 255 } + if %r{^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$} =~ addr + return $LAST_MATCH_INFO.captures.all? { |i| i = i.to_i; i >= 0 && i <= 255 } end - return false + false end def valid_v6?(addr) # http://forums.dartware.com/viewtopic.php?t=452 # ...and, yes, it is this hard. Doing it programmatically is harder. - return true if addr =~ /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[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25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$} - return false + false end + def valid_newline?(addr) - return false if (addr =~ /\n/ || addr =~ /\r/) - return true + return false if addr =~ %r{\n} || addr =~ %r{\r} + true end validate do |value| - return true if ((valid_v4?(value) || valid_v6?(value)) && (valid_newline?(value))) - raise Puppet::Error, _("Invalid IP address %{value}") % { value: value.inspect } + return true if (valid_v4?(value) || valid_v6?(value)) && valid_newline?(value) + raise Puppet::Error, _('Invalid IP address %{value}') % { value: value.inspect } end end # for now we use OrderedList to indicate that the order does matter. - newproperty(:host_aliases, :parent => Puppet::Property::OrderedList) do + newproperty(:host_aliases, parent: Puppet::Property::OrderedList) do desc "Any aliases the host might have. Multiple values must be specified as an array." def delimiter - " " + ' ' end def inclusive? @@ -48,16 +48,15 @@ module Puppet validate do |value| # This regex already includes newline check. - raise Puppet::Error, _("Host aliases cannot include whitespace") if value =~ /\s/ - raise Puppet::Error, _("Host aliases cannot be an empty string. Use an empty array to delete all host_aliases ") if value =~ /^\s*$/ + raise Puppet::Error, _('Host aliases cannot include whitespace') if value =~ %r{\s} + raise Puppet::Error, _('Host aliases cannot be an empty string. Use an empty array to delete all host_aliases ') if value =~ %r{^\s*$} end - end newproperty(:comment) do - desc "A comment that will be attached to the line with a # character." + desc 'A comment that will be attached to the line with a # character.' validate do |value| - raise Puppet::Error, _("Comment cannot include newline") if (value =~ /\n/ || value =~ /\r/) + raise Puppet::Error, _('Comment cannot include newline') if value =~ %r{\n} || value =~ %r{\r} end end @@ -65,26 +64,27 @@ module Puppet desc "The file in which to store service information. Only used by those providers that write to disk. On most systems this defaults to `/etc/hosts`." - defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) - @resource.class.defaultprovider.default_target + defaultto do + if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) + @resource.class.defaultprovider.default_target else nil end - } + end end newparam(:name) do - desc "The host name." + desc 'The host name.' isnamevar validate do |value| value.split('.').each do |hostpart| - unless hostpart =~ /^([\w]+|[\w][\w\-]+[\w])$/ - raise Puppet::Error, _("Invalid host name") + unless hostpart =~ %r{^([\w]+|[\w][\w\-]+[\w])$} + raise Puppet::Error, _('Invalid host name') end end - raise Puppet::Error, _("Hostname cannot include newline") if (value =~ /\n/ || value =~ /\r/) + raise Puppet::Error, _('Hostname cannot include newline') if value =~ %r{\n} || value =~ %r{\r} end end |