module Fog::OpenStack::Auth::Catalog

Attributes

payload[R]

Public Class Methods

new(payload) click to toggle source
# File lib/fog/openstack/auth/catalog.rb, line 11
def initialize(payload)
  @payload = payload
end

Public Instance Methods

get_endpoint_url(names, interfaces, region = nil) click to toggle source
# File lib/fog/openstack/auth/catalog.rb, line 15
def get_endpoint_url(names, interfaces, region = nil)
  # TODO: Inject OpenStack Service Types Authority
  names_list = if names.kind_of?(String)
                 [names]
               else
                 names
               end
  entries = get_by_type(names_list)
  raise ServiceTypeError, 'No endpoint match' if entries.empty?

  interfaces_list = if interfaces.kind_of?(String)
                      [interfaces]
                    else
                      interfaces
                    end

  list = []
  interfaces_list.each do |interface|
    val = get_endpoint(entries, interface, region)
    list << val if val
  end

  raise EndpointError, 'No endpoint found' if list.empty?
  list[0]
end

Private Instance Methods

get_by_type(names) click to toggle source
# File lib/fog/openstack/auth/catalog.rb, line 43
def get_by_type(names)
  raise CatalogError, 'Empty content' unless @payload
  @payload.select do |e|
    names.include?(e['type'])
  end
end
get_endpoint(entries, interface, region) click to toggle source
# File lib/fog/openstack/auth/catalog.rb, line 50
def get_endpoint(entries, interface, region)
  list = []
  entries.each do |type|
    next unless type.key?('endpoints')
    type['endpoints'].each do |endpoint|
      list << endpoint_url(endpoint, interface) if endpoint_match?(endpoint, interface, region)
    end
  end
  raise EndpointError, 'Multiple endpoints found' if list.size > 1
  list[0]
end