How to use the pika.credentials.PlainCredentials function in pika

To help you get started, we’ve selected a few pika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pika / pika / tests / unit / credentials_tests.py View on Github external
def test_ne(self):
        self.assertNotEqual(
            credentials.PlainCredentials('uu', 'p', False),
            credentials.PlainCredentials('u', 'p', False))

        self.assertNotEqual(
            credentials.PlainCredentials('u', 'p', False),
            credentials.PlainCredentials('uu', 'p', False))

        self.assertNotEqual(
            credentials.PlainCredentials('u', 'pp', False),
            credentials.PlainCredentials('u', 'p', False))

        self.assertNotEqual(
            credentials.PlainCredentials('u', 'p', False),
            credentials.PlainCredentials('u', 'pp', False))

        self.assertNotEqual(
            credentials.PlainCredentials('u', 'p', True),
            credentials.PlainCredentials('u', 'p', False))

        self.assertNotEqual(
            credentials.PlainCredentials('u', 'p', False),
            credentials.PlainCredentials('u', 'p', True))
github ldv-klever / klever / klever / scheduler / schedulers / __init__.py View on Github external
def run(self):
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(
                host=self.conf["host"],
                credentials=pika.credentials.PlainCredentials(self.conf["username"], self.conf["password"]))
        )
        channel = connection.channel()
        channel.queue_declare(queue=self.conf["name"], durable=True)
        for method, properties, body in channel.consume(self.conf["name"], inactivity_timeout=1):
            if self._is_interrupted:
                break
            if not body or not method:
                continue

            # Just forward to main loop all data. This can be done faster but it will require additional locks and sync
            data = body.decode('utf-8').split(' ')
            if len(data) == 4:
                if (data[0] == 'job' and self.accept_jobs) or (data[0] == 'task' and data[-1] == self.accept_tag):
                    channel.basic_ack(method.delivery_tag)
                    self._queue.put(body)
                else:
github waggle-sensor / beehive-server / scripts / soft-node / soft-node.py View on Github external
# soft/virtual node node_id must be of the form (without spaces)
        #    00 00 02 00 00 00 xx xx
        bValidNodeId = False
        if node_id and len(node_id) == 16:
            if re.match('^000002000000[0-9a-f]{4}$', node_id):
                print('VALID node_id = {}'.format(node_id))
                bValidNodeId = True
                
        if not bValidNodeId:
            print('INVALID node_id = {}'.format(node_id))
            sys.exit(-1)
    
    # open a connection
    # URI:    amqps://node:waggle@beehive1.mcs.anl.gov:23181?cacertfile=/usr/lib/waggle/SSL/waggleca/cacert.pem&certfile=/usr/lib/waggle/SSL/node/cert.pem&keyfile=/usr/lib/waggle/SSL/node/key.pem&verify=verify_peer"
    
    credentials = pika.credentials.PlainCredentials('node', 'waggle')
    
    ssl_options={'ca_certs' : dir + "/cacert.pem",
                'certfile'  : dir + "/node/cert.pem",
                'keyfile'   : dir + "/node/key.pem"}
    logging.debug('ssl_options = ', ssl_options)
    
    params = pika.ConnectionParameters(
                    host=server_host, 
                    port=23181, 
                    credentials=credentials, 
                    ssl=True, 
                    ssl_options=ssl_options,
                    retry_delay=10,
                    socket_timeout=10)
    logging.debug('params = {}'.format(params))
github VOLTTRON / volttron / volttron / utils / rmq_mgmt.py View on Github external
cert_reqs=ssl.CERT_REQUIRED)
                conn_params = pika.ConnectionParameters(
                    host= parsed_addr.hostname,
                    port= parsed_addr.port,
                    virtual_host=virtual_host,
                    ssl=True,
                    connection_attempts=retry_attempt,
                    retry_delay=retry_delay,
                    ssl_options=ssl_options,
                    credentials=pika.credentials.ExternalCredentials())
            else:
                conn_params = pika.ConnectionParameters(
                    host=parsed_addr.hostname,
                    port=parsed_addr.port,
                    virtual_host=virtual_host,
                    credentials=pika.credentials.PlainCredentials(
                        rmq_user, rmq_user))
        except KeyError:
            return None
        return conn_params
github StackStorm-Exchange / stackstorm-rabbitmq / sensors / queues_sensor.py View on Github external
def setup(self):
        if self.username and self.password:
            credentials = PlainCredentials(username=self.username, password=self.password)
            connection_params = pika.ConnectionParameters(host=self.host, credentials=credentials)
        else:
            connection_params = pika.ConnectionParameters(host=self.host)

        self.conn = pika.BlockingConnection(connection_params)
        self.channel = self.conn.channel()
        self.channel.basic_qos(prefetch_count=1)

        # Setup Qs for listening
        for queue in self.queues:
            self.channel.queue_declare(queue=queue, durable=True)

            def callback(ch, method, properties, body, queue_copy=queue):
                self._dispatch_trigger(ch, method, properties, body, queue_copy)

            self.channel.basic_consume(queue, callback)
github StackStorm / st2 / tools / direct_queue_publisher.py View on Github external
def main(queue, payload):
    connection = pika.BlockingConnection(
        pika.ConnectionParameters(
            host='localhost',
            credentials=pika.credentials.PlainCredentials(username='guest', password='guest'),
        )
    )
    channel = connection.channel()

    channel.queue_declare(queue=queue, durable=True)

    channel.basic_publish(exchange='', routing_key=queue, body=payload)
    print("Sent %s" % payload)
    connection.close()