def host_name(self, host_name): if host_name: # Remove brackets around IPv6 address host = re.sub(r"[\[\]]", "", host_name) else: raise MalformedBrokerUriException("Invalid host name") self._host_name = host
def _parse(self, broker_string): """ Constructs a Broker object for the specified broker string in the format [UniqueId];[Port];[HostName];[IpAddress] :param broker_string: The broker definition as a string :return: None """ elements = [ a.strip() for a in broker_string.split(self._FIELD_SEPARATOR) ] len_elems = len(elements) attrs = {} if len_elems < 2: raise MalformedBrokerUriException("Missing elements") else: if Broker._is_port_number(elements[0]): attrs['port'] = elements[0] attrs['hostname'] = elements[1] if len_elems > 2: attrs['ip_address'] = elements[2] else: attrs['unique_id'] = elements[0] attrs['port'] = elements[1] attrs['hostname'] = elements[2] if len_elems > 3: attrs['ip_address'] = elements[3] # Sets broker attributes from the dictionary generated. self._set_attributes(attrs)
def _parse(self, broker_string): """ Constructs a Broker object for the specified broker string in the format [UniqueId];[Port];[HostName];[IpAddress] :param broker_string: The broker definition as a string :return: None """ elements = [ a.strip() for a in broker_string.split(self._FIELD_SEPARATOR) ] if len(elements) < 2: raise MalformedBrokerUriException("Missing elements") else: if Broker._is_port_number(elements[0]): self.unique_id = None self.port = elements[0] self.host_name = elements[1] self.ip_address = self._get_array_element_or_none(elements, 2) else: self.unique_id = elements[0] self.port = elements[1] self.host_name = self._get_array_element_or_none(elements, 2) self.ip_address = self._get_array_element_or_none(elements, 3)
def ip_address(self, ip_address): ip = ip_address if ip: # Remove brackets around IPv6 address ip = re.sub(r"[\[\]]", "", ip_address) if not ServerNameHelper.is_valid_ip_address(ip): raise MalformedBrokerUriException("Invalid IP address") self._ip_address = ip
def parse(broker_url): """ Returns a broker instance corresponding to the specified broker URL of the form: ``[ssl://]<hostname>[:port]`` Valid URLs include: - ``ssl://mybroker:8883`` - ``ssl://mybroker`` - ``mybroker:8883`` - ``mybroker`` If the port is omitted it will be defaulted to 8883. :param broker_url: A valid broker URL :return: A broker corresponding to the specified broker URL """ broker = Broker(host_name='none') elements = broker_url.split("://") host_name = broker_url protocol = Broker._SSL_PROTOCOL port = Broker._SSL_PORT if len(elements) == 2: protocol = elements[0] host_name = elements[1] if host_name[-1] != ']': host_name_left, _, host_name_right = host_name.rpartition(":") if host_name_left: host_name = host_name_left port = host_name_right broker.host_name = host_name broker.port = port broker.unique_id = UuidGenerator.generate_id_as_string() if protocol and protocol.lower() != Broker._SSL_PROTOCOL.lower(): raise MalformedBrokerUriException("Unknown protocol: " + protocol) return broker
def parse(broker_url): """ Returns a broker instance corresponding to the specified broker URL of the form: ``[ssl://]<hostname>[:port]`` Valid URLs include: - ``ssl://mybroker:8883`` - ``ssl://mybroker`` - ``mybroker:8883`` - ``mybroker`` If the port is omitted it will be defaulted to 8883. :param broker_url: A valid broker URL :return: A broker corresponding to the specified broker URL """ broker = Broker(host_name='none') elements = broker_url.split("://") host_name = broker_url protocol = Broker._SSL_PROTOCOL port = Broker._SSL_PORT if len(elements) == 2: protocol = elements[0] host_name = elements[1] elements = host_name.split(":") if len(elements) == 2: host_name = elements[0] port = elements[1] broker.host_name = host_name broker.port = port if protocol and not protocol.lower() == Broker._SSL_PROTOCOL.lower(): raise MalformedBrokerUriException("Unknown protocol: " + protocol) return broker
def host_name(self, host_name): # Remove brackets around IPv6 address host = re.sub(r"[\[\]]", "", host_name) if not ServerNameHelper.is_valid_hostname_or_ip_address(host): raise MalformedBrokerUriException("Invalid host name") self._host_name = host
def port(self, port): if Broker._is_port_number(port): self._port = int(port) else: raise MalformedBrokerUriException("Invalid port")