Class to support Manifest Endpoint elements
# File lib/openshift-origin-common/models/manifest.rb, line 152 def self.build_name(tag, name) name ? "OPENSHIFT_#{tag}_#{name}" : nil end
Parse Endpoint element and instantiate Endpoint objects to hold information
Endpoint.parse('PHP', manifest) #=> [Endpoint]
# File lib/openshift-origin-common/models/manifest.rb, line 84 def self.parse(short_name, manifest, categories) return [] unless manifest['Endpoints'] tag = short_name.upcase errors = [] endpoint_index =0 endpoints = manifest['Endpoints'].each_with_object([]) do |entry, memo| unless entry.is_a? Hash errors << "Non-Hash endpoint entry: #{entry}" next end endpoint_index += 1 # TODO: validation begin endpoint = Endpoint.new endpoint.private_ip_name = build_name(tag, entry['Private-IP-Name']) endpoint.private_port_name = build_name(tag, entry['Private-Port-Name']) endpoint.private_port = entry['Private-Port'].to_i endpoint.public_port_name = build_name(tag, entry['Public-Port-Name']) endpoint.websocket_port_name = build_name(tag, entry['WebSocket-Port-Name']) endpoint.websocket_port = entry['WebSocket-Port'].to_i if entry['WebSocket-Port'] endpoint.options = entry['Options'] endpoint.description = entry['Description'] if entry['Protocols'] endpoint.protocols = entry['Protocols'] elsif entry['Mappings'] endpoint.protocols = ['http'] else endpoint.protocols = ['tcp'] end if entry['Mappings'].respond_to?(:each) endpoint.mappings = entry['Mappings'].each_with_object([]) do |mapping_entry, mapping_memo| mapping = Endpoint::Mapping.new if not (endpoint.protocols - [ 'http', 'https', 'ws', 'wss' ]).empty? mapping.frontend = mapping_entry['Frontend'] mapping.backend = mapping_entry['Backend'] else mapping.frontend = prepend_slash mapping_entry['Frontend'] mapping.backend = prepend_slash mapping_entry['Backend'] end mapping.options = mapping_entry['Options'] mapping_memo << mapping end else endpoint.mappings = [] end memo << endpoint rescue Exception => e errors << "Couldn't parse endpoint entry '#{entry}': #{e.message}" end end raise "Couldn't parse endpoints: #{errors.join("\n")}" if errors.length > 0 endpoints end
Generated with the Darkfish Rdoc Generator 2.