Commit d7966968 authored by Francesco Pace's avatar Francesco Pace
Browse files

Add credentials to RabbitMQ connection


Signed-off-by: default avatarFrancesco Pace <pace.francesco.g@gmail.com>
parent bdb69a95
...@@ -198,7 +198,7 @@ def _storage_plugin_check(data): ...@@ -198,7 +198,7 @@ def _storage_plugin_check(data):
def _channel_check(data): def _channel_check(data):
required_keys = ['protocol', 'host'] required_keys = ['protocol', 'host', 'username', 'password']
for k in required_keys: for k in required_keys:
if k not in data: if k not in data:
raise InvalidApplicationDescription(msg="Missing required key: %s" % k) raise InvalidApplicationDescription(msg="Missing required key: %s" % k)
......
...@@ -17,12 +17,15 @@ import pika ...@@ -17,12 +17,15 @@ import pika
class RabbitMQ: class RabbitMQ:
def __init__(self, host): def __init__(self, username, password, host):
self.username = username
self.password = password
self.host = host self.host = host
self.channel = None self.channel = None
def open_connection(self): def open_connection(self):
connection = pika.BlockingConnection(pika.ConnectionParameters(self.host)) credentials = pika.PlainCredentials(self.username, self.password)
connection = pika.BlockingConnection(pika.ConnectionParameters(self.host, credentials=credentials))
self.channel = connection.channel() self.channel = connection.channel()
def send_message(self, queue, message): def send_message(self, queue, message):
......
...@@ -23,7 +23,7 @@ class Crystal: ...@@ -23,7 +23,7 @@ class Crystal:
def transmit_policy(self, tenant, policy): def transmit_policy(self, tenant, policy):
message = "{}:{}".format(tenant, policy) message = "{}:{}".format(tenant, policy)
if self.channel['protocol'] is 'rabbitmq': if self.channel['protocol'] is 'rabbitmq':
rmq = RabbitMQ(self.channel['host']) rmq = RabbitMQ(self.channel['username'], self.channel['password'], self.channel['host'])
rmq.open_connection() rmq.open_connection()
rmq.send_message(self.channel['queue'], message) rmq.send_message(self.channel['queue'], message)
rmq.close_connection() rmq.close_connection()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment