Module: AwsPublicIps::Utils

Defined in:
lib/aws_public_ips/utils.rb

Class Method Summary collapse

Class Method Details

.has_service?(client) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/aws_public_ips/utils.rb', line 24

def self.has_service?(client)
  region_partition = ::Aws::Partitions.partitions.find do |partition|
    partition.regions.map(&:name).include?(client.config.region)
  end
  service_name = client.class.to_s.split('::')[-2]

  aws_service = region_partition.services.find { |service| service.name == service_name }
  !aws_service.regionalized? || aws_service.regions.include?(client.config.region)
end

.resolve_hostname(hostname) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/aws_public_ips/utils.rb', line 12

def self.resolve_hostname(hostname)
  # Default Resolv.getaddresses doesn't seem to return IPv6 results
  resources = ::Resolv::DNS.open do |dns|
    dns.getresources(hostname, ::Resolv::DNS::Resource::IN::A) +
      dns.getresources(hostname, ::Resolv::DNS::Resource::IN::AAAA)
  end

  resources.map do |resource|
    resource.address.to_s.downcase
  end
end

.resolve_hostnames(hostnames) ⇒ Object



8
9
10
# File 'lib/aws_public_ips/utils.rb', line 8

def self.resolve_hostnames(hostnames)
  hostnames.flat_map(&method(:resolve_hostname))
end