Puppet Function: simplib::strip_ports

Defined in:
lib/puppet/functions/simplib/strip_ports.rb
Function type:
Ruby 4.x API

Overview

simplib::strip_ports(Array[String[1],1] $hosts)Array[String]

Extract list of unique hostnames and/or IP addresses from an ‘Array` of hosts, each of which may may contain protocols and/or port numbers

Terminates catalog compilation if

  • A valid network or hostname cannot be extracted from all input items.

  • Any input item that contains a port specifies an invalid port.

Examples:


$foo = ['https://mysite.net:8443',
        'http://yoursite.net:8081',
        'https://theirsite.com']

$bar = simplib::strip_ports($foo)

$bar contains: ['mysite.net','yoursite.net','theirsite.com']

Parameters:

  • hosts (Array[String[1],1])

    List of hosts which may contain protocols and port numbers.

Returns:

  • (Array[String])

    Non-port portion of hostnames

Raises:

  • (RuntimeError)

    if any input item that contains a port specifies an invalid port



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
# File 'lib/puppet/functions/simplib/strip_ports.rb', line 9

Puppet::Functions.create_function(:'simplib::strip_ports') do

  # @param hosts List of hosts which may contain protocols and port numbers.
  #
  # @return [Array[String]] Non-port portion of hostnames
  # @raise [RuntimeError] if any input item that contains a port
  #   specifies an invalid port
  #
  # @example
  #
  #   $foo = ['https://mysite.net:8443',
  #           'http://yoursite.net:8081',
  #           'https://theirsite.com']
  #
  #   $bar = simplib::strip_ports($foo)
  #
  #   $bar contains: ['mysite.net','yoursite.net','theirsite.com']
  dispatch :strip_ports do
    required_param 'Array[String[1],1]', :hosts
  end

  def strip_ports(hosts)
    call_function('simplib::parse_hosts', hosts).keys.uniq
  end
end