Beispiel #1
0
 def test_is_ssl(self):
     # false
     url = URL('amqp://localhost')
     self.assertFalse(url.is_ssl())
     # true
     url = URL('amqps://localhost')
     self.assertTrue(url.is_ssl())
Beispiel #2
0
 def test_is_ssl(self):
     # false
     url = URL('amqp://localhost')
     self.assertFalse(url.is_ssl())
     # true
     url = URL('amqps://localhost')
     self.assertTrue(url.is_ssl())
Beispiel #3
0
class Connector(Model):
    """
    Represents an AMQP connector.
    :ivar url: The URL.
    :type url: URL
    :ivar heartbeat: The connection heartbeat in seconds.
    :type heartbeat: int|None
    :ivar ssl: The SSL configuration.
    :type ssl: SSL
    """

    @staticmethod
    def find(url):
        """
        Find a broker by URL.
        :param url: A broker URL.
        :type url: str
        :return: The broker.
        :rtype: Broker
        """
        domain_id = URL(url).canonical
        try:
            return Domain.connector.find(domain_id)
        except NotFound:
            return Connector(url)

    def __init__(self, url=None):
        """
        :param url: The connector url:
            <adapter>+<scheme>://<userid:password@<host>:<port>/<virtual-host>.
        :type url: str
        """
        self.url = URL(url or DEFAULT_URL)
        self.heartbeat = None
        self.ssl = SSL()

    @property
    def domain_id(self):
        """
        Get the domain ID.
        :return: The domain id.
        :rtype: str
        """
        return self.url.canonical

    @property
    def adapter(self):
        """
        Get the (gofer) adapter component of the url.
        :return: The adapter component.
        :rtype: str
        """
        return self.url.adapter

    @property
    def scheme(self):
        """
        Get the scheme component of the url.
        :return: The scheme component.
        :rtype: str
        """
        return self.url.scheme

    @property
    def host(self):
        """
        Get the host component of the url.
        :return: The host component.
        :rtype: str
        """
        return self.url.host

    @property
    def port(self):
        """
        Get the port component of the url.
        :return: The port component.
        :rtype: str
        """
        return self.url.port

    @property
    def userid(self):
        """
        Get the userid component of the url.
        :return: The userid component.
        :rtype: str
        """
        return self.url.userid

    @property
    def password(self):
        """
        Get the password component of the url.
        :return: The password component.
        :rtype: str
        """
        return self.url.password

    @property
    def virtual_host(self):
        """
        Get the virtual_host component of the url.
        :return: The virtual_host component.
        :rtype: str
        """
        return self.url.path

    def add(self):
        """
        Add this broker to the domain.
        """
        Domain.connector.add(self)

    def use_ssl(self):
        """
        Get whether SSL should be used.
        :return: True if SSL should be used.
        :rtype: bool
        """
        return self.url.is_ssl()

    def __unicode__(self):
        s = list()
        s.append('URL: %s' % self.url)
        s.append('SSL: %s' % self.ssl)
        return '|'.join(s)

    def __str__(self):
        return utf8(self)