Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for authentication on RabbitMQ #107

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ jobs:
SDXLC_VERSION: '1.0.0'
SDXLC_NAME: 'test-lc'
MQ_HOST: 'localhost'
MQ_PORT: '5672'
MQ_USER: 'guest'
MQ_PASS: 'guest'
MQ_NAME: 'hello'
MQ_EXCHANGE: ''
SUB_QUEUE: 'test-queue'
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ $ docker run -it --rm --name rabbitmq \
rabbitmq:latest
```

Then in `env` and `docker-compose.yml` files, change `MQ_HOST` host to
the corresponding IP address or hostname of the RabbitMQ server
Then in `env` and `docker-compose.yml` files, change the following vars:

- `MQ_HOST` host to the corresponding IP address or hostname of the RabbitMQ server
- `MQ_PORT` to the corresponding port where the server will listen (default 5672)
- `MQ_USER` to the corresponding username to authenticate (default guest)
- `MQ_PASS` to the corresponding password to authenticate (default guest)


## Running SDX Local Controller with Docker Compose
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ services:
- MQ_NAME=hello
- MQ_HOST=aw-sdx-monitor.renci.org
- MQ_PORT=5672
- MQ_USER=guest
- MQ_PASS=guest
- DB_NAME=test-db
- DB_CONFIG_TABLE_NAME=sdx-config-test-1
- DOMAIN_CONTROLLER_URL=http://192.168.201.205:8088/SDX-LC/1.0.0/provision
Expand Down
3 changes: 3 additions & 0 deletions env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export SDXLC_VERSION='1.0.0'
export SDXLC_NAME='lc2'
export MQ_NAME='hello'
export MQ_HOST='aw-sdx-monitor.renci.org'
export MQ_PORT=5672
export MQ_USER='guest'
export MQ_PASS='guest'
export MQ_EXCHANGE=''
export DB_NAME='test-db'
export DB_CONFIG_TABLE_NAME='test-1'
18 changes: 14 additions & 4 deletions swagger_server/messaging/rpc_queue_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import pika

MQ_HOST = os.environ.get("MQ_HOST")
MQ_PORT = os.environ.get("MQ_PORT")
MQ_USER = os.environ.get("MQ_USER")
MQ_PASS = os.environ.get("MQ_PASS")

# subscribe to the corresponding queue
SUB_QUEUE = os.environ.get("SUB_QUEUE")
SUB_TOPIC = os.environ.get("SUB_TOPIC")
SUB_EXCHANGE = os.environ.get("SUB_EXCHANGE")

# hardcode for testing
MQ_HOST = "aw-sdx-monitor.renci.org"
SUB_QUEUE = "connection"
SUB_TOPIC = "lc1_q1"
SUB_EXCHANGE = "connection"
Expand All @@ -23,7 +25,11 @@ class RpcConsumer(object):
def __init__(self, thread_queue, exchange_name):
self.logger = logging.getLogger(__name__)
self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=MQ_HOST)
pika.ConnectionParameters(
host=MQ_HOST,
port=MQ_PORT,
credentials=pika.PlainCredentials(username=MQ_USER, password=MQ_PASS),
)
)

self.channel = self.connection.channel()
Expand All @@ -44,7 +50,11 @@ def on_request(self, ch, method, props, message_body):
self._thread_queue.put(message_body)

self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=MQ_HOST)
pika.ConnectionParameters(
host=MQ_HOST,
port=MQ_PORT,
credentials=pika.PlainCredentials(username=MQ_USER, password=MQ_PASS),
)
)
self.channel = self.connection.channel()

Expand Down
9 changes: 8 additions & 1 deletion swagger_server/messaging/rpc_queue_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
import pika

MQ_HOST = os.environ.get("MQ_HOST")
MQ_PORT = os.environ.get("MQ_PORT")
MQ_USER = os.environ.get("MQ_USER")
MQ_PASS = os.environ.get("MQ_PASS")


class RpcProducer(object):
def __init__(self, timeout, exchange_name, routing_key):
self.logger = logging.getLogger(__name__)
self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=MQ_HOST)
pika.ConnectionParameters(
host=MQ_HOST,
port=MQ_PORT,
credentials=pika.PlainCredentials(username=MQ_USER, password=MQ_PASS),
)
)

self.channel = self.connection.channel()
Expand Down
15 changes: 13 additions & 2 deletions swagger_server/messaging/topic_queue_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from swagger_server.utils.db_utils import DbUtils

MQ_HOST = os.environ.get("MQ_HOST")
MQ_PORT = os.environ.get("MQ_PORT")
MQ_USER = os.environ.get("MQ_USER")
MQ_PASS = os.environ.get("MQ_PASS")
# subscribe to the corresponding queue
SUB_QUEUE = os.environ.get("SUB_QUEUE")
SUB_TOPIC = os.environ.get("SUB_TOPIC")
Expand All @@ -30,7 +33,11 @@ class TopicQueueConsumer(object):
def __init__(self, thread_queue, exchange_name):
self.logger = logging.getLogger(__name__)
self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=MQ_HOST)
pika.ConnectionParameters(
host=MQ_HOST,
port=MQ_PORT,
credentials=pika.PlainCredentials(username=MQ_USER, password=MQ_PASS),
)
)

self.channel = self.connection.channel()
Expand All @@ -54,7 +61,11 @@ def on_rpc_request(self, ch, method, props, message_body):
self._thread_queue.put(message_body)

self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=MQ_HOST)
pika.ConnectionParameters(
host=MQ_HOST,
port=MQ_PORT,
credentials=pika.PlainCredentials(username=MQ_USER, password=MQ_PASS),
)
)
self.channel = self.connection.channel()

Expand Down
12 changes: 8 additions & 4 deletions swagger_server/messaging/topic_queue_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
import pika

MQ_HOST = os.environ.get("MQ_HOST")

# hardcode for testing
MQ_HOST = "aw-sdx-monitor.renci.org"
MQ_PORT = os.environ.get("MQ_PORT")
MQ_USER = os.environ.get("MQ_USER")
MQ_PASS = os.environ.get("MQ_PASS")


class TopicQueueProducer(object):
def __init__(self, timeout, exchange_name, routing_key):
self.logger = logging.getLogger(__name__)
self.connection = pika.BlockingConnection(
pika.ConnectionParameters(host=MQ_HOST)
pika.ConnectionParameters(
host=MQ_HOST,
port=MQ_PORT,
credentials=pika.PlainCredentials(username=MQ_USER, password=MQ_PASS),
)
)

self.channel = self.connection.channel()
Expand Down
Loading