Puppet Function: validate_uri_list
- Defined in:
- lib/puppet/parser/functions/validate_uri_list.rb
- Function type:
- Ruby 3.x API
Overview
Usage: validate_uri_list(,[<VALID_SCHEMES>])
Validate that a passed list (Array
or single
String
) of URIs is valid according to Ruby's URI parser.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet/parser/functions/validate_uri_list.rb', line 2 newfunction(:validate_uri_list, :arity => -1, :doc => <<-'ENDHEREDOC') do |args| uri_list = Array(args.shift) Usage: validate_uri_list([LIST],[<VALID_SCHEMES>]) Validate that a passed list (`Array` or single `String`) of URIs is valid according to Ruby's URI parser. @example Passing $uris = ['http://foo.bar.baz:1234','ldap://my.ldap.server'] validate_uri_list($uris) $uris = ['ldap://my.ldap.server','ldaps://my.ldap.server'] validate_uri_list($uris,['ldap','ldaps']) @return [Nil] ENDHEREDOC scheme_list = Array(args.shift) uri_list.each do |uri| begin require 'uri' uri_obj = URI(uri) unless scheme_list.empty? unless scheme_list.include?(uri_obj.scheme) raise Puppet::ParseError, ("validate_uri_list(): Scheme '#{uri_obj.scheme}' must be one of '#{uri_list.join(',')}'") end end rescue URI::InvalidURIError raise Puppet::ParseError, ("validate_uri_list(): '#{uri}' is not a valid URI") end end end |