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

Add support for authenticated OXPO #169

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 8 additions & 5 deletions sdx_lc/jobs/pull_topo_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import sys
import threading
import time
import urllib.request

import requests

# append abspath, so this file can import other modules from parent directory
sys.path.append(
Expand All @@ -15,6 +16,8 @@
from messaging.rpc_queue_producer import RpcProducer
from utils.db_utils import DbUtils

OXPO_USER = os.environ.get("OXPO_USER", None)
OXPO_PASS = os.environ.get("OXPO_PASS", None)
OXP_PULL_URL = os.environ.get("OXP_PULL_URL")
OXP_PULL_INTERVAL = os.environ.get("OXP_PULL_INTERVAL")
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -50,18 +53,18 @@ def process_domain_controller_topo(db_instance):
logger.debug("Latest topology does not exist")

try:
pulled_topology = urllib.request.urlopen(OXP_PULL_URL).read()
except (urllib.request.URLError, ConnectionResetError):
pulled_topology = requests.get(OXP_PULL_URL, auth=(OXPO_USER, OXPO_PASS))
except (requests.ConnectionError, requests.HTTPError):
logger.debug("Error connecting to domain controller...")
continue

if not pulled_topology:
if not pulled_topology.ok:
continue

logger.debug("Pulled request from domain controller")

try:
json_pulled_topology = json.loads(pulled_topology)
json_pulled_topology = pulled_topology.json()
except ValueError:
logger.debug("Cannot parse pulled topology, invalid JSON")
continue
Expand Down
14 changes: 12 additions & 2 deletions sdx_lc/messaging/topic_queue_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
MQ_USER = os.environ.get("MQ_USER")
MQ_PASS = os.environ.get("MQ_PASS")

OXPO_USER = os.environ.get("OXPO_USER", None)
OXPO_PASS = os.environ.get("OXPO_PASS", None)
OXP_CONNECTION_URL = os.environ.get("OXP_CONNECTION_URL")


Expand Down Expand Up @@ -104,7 +106,11 @@ def handle_mq_msg(self, msg_body):
# send connection info to OXP
if msg_json.get("operation") == "post":
try:
r = requests.post(str(OXP_CONNECTION_URL), json=connection)
r = requests.post(
str(OXP_CONNECTION_URL),
json=connection,
auth=(OXPO_USER, OXPO_PASS),
)
self.logger.info(f"Status from OXP: {r}")
except Exception as e:
self.logger.error(f"Error on POST to {OXP_CONNECTION_URL}: {e}")
Expand All @@ -113,7 +119,11 @@ def handle_mq_msg(self, msg_body):
)
elif msg_json.get("operation") == "delete":
try:
r = requests.delete(str(OXP_CONNECTION_URL), json=connection)
r = requests.delete(
str(OXP_CONNECTION_URL),
json=connection,
auth=(OXPO_USER, OXPO_PASS),
)
self.logger.info(f"Status from OXP: {r}")
except Exception as e:
self.logger.error(f"Error on DELETE {OXP_CONNECTION_URL}: {e}")
Expand Down