class Endpoint
Represents one upstream endpoint published to Envoy EDS.
Definitions
def self.wrap(value)
Wrap serialized endpoint state.
Signature
-
parameter
valueEndpoint | Hash The value to wrap.
-
returns
Endpoint The endpoint value.
Implementation
def self.wrap(value)
case value
when self
value
when Hash
new(**value)
else
raise ArgumentError, "Invalid Envoy endpoint: #{value.inspect}"
end
end
def self.normalize_address(value)
Normalize a concrete endpoint address.
Signature
-
parameter
valueHash The address value.
-
returns
Hash A normalized IP or Unix address.
Implementation
def self.normalize_address(value)
if path = value[:path]
raise ArgumentError, "A Unix endpoint cannot specify an IP address or port!" if value[:address] || value[:port]
{path: path.to_s}.freeze
elsif value[:address] && value[:port]
{address: value[:address].to_s, port: Integer(value[:port])}.freeze
else
raise ArgumentError, "An endpoint address requires either path, or address and port: #{value.inspect}"
end
end
def initialize(name:, scheme:, protocols:, addresses:)
Initialize an endpoint.
Signature
-
parameter
nameString The upstream cluster name.
-
parameter
schemeString | Symbol The upstream application scheme.
-
parameter
protocolsArray(String) The supported upstream HTTP protocol names.
-
parameter
addressesArray(Hash) The grouped concrete addresses.
Implementation
def initialize(name:, scheme:, protocols:, addresses:)
@name = name.to_s
@scheme = scheme.to_sym
@protocols = protocols.map(&:to_s).uniq.freeze
raise ArgumentError, "An endpoint requires at least one protocol!" if @protocols.empty?
@addresses = addresses.map{|value| self.class.normalize_address(value)}.freeze
raise ArgumentError, "An endpoint requires at least one address!" if @addresses.empty?
end
attr :name
Signature
-
attribute
String The upstream cluster name.
attr :scheme
Signature
-
attribute
Symbol The upstream application scheme.
attr :protocols
Signature
-
attribute
Array(String) The supported upstream HTTP protocol names.
attr :addresses
Signature
-
attribute
Array(Hash) The grouped concrete addresses.