Skip to content
Snippets Groups Projects

WS-649: send CARTA URL to workspaces system

Merged Janet Goldstein requested to merge WS-649-send-carta-url-to-ws into main
All threads resolved!
2 files
+ 2
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -2,6 +2,8 @@ import logging
import socket
from typing import Dict
# pylint: disable=C0103, C0301, E0401, E0402, E1101, R0903, R0913, W0105, W1203
import redis
import requests
@@ -26,6 +28,11 @@ class RedisConnect:
@staticmethod
def generate_ids() -> dict:
"""
Generates IDs and system name required by Redis
:return: dict of settings
"""
return {
"front_end_id": generate_random_str(),
"back_end_id": generate_random_str(),
@@ -34,6 +41,11 @@ class RedisConnect:
}
def generate_carta_url(self) -> str:
"""
Generates CARTA URL for Redis
:return: URL of current CARTA session
"""
self.logger.info("Generating CARTA url...")
front_end_id = self.generated_ids["front_end_id"]
back_end_id = self.generated_ids["back_end_id"]
@@ -72,6 +84,11 @@ class RedisConnect:
return s.getsockname()[1]
def prepare_redis(self) -> dict:
"""
Gathers Redis server settings
:return: settings as key-value pairs
"""
self.logger.info("Preparing Redis server...")
front_end_port = self.get_available_port()
back_end_port = self.get_available_port()
@@ -218,9 +235,7 @@ class ArchiveConnect:
:param url: URL generated to allow user access to this running CARTA instance
"""
send_archive_msg_url = (
f"{self.settings['workflow_url']}/workflows/carta/requests/{self.settings['wf_request_id']}/send-url-to-aat"
)
send_archive_msg_url = f"{self.settings['workflow_url']}/workflows/carta/requests/{self.settings['wf_request_id']}/send-url-to-aat"
payload = {"carta_url": url}
self.logger.info("Sending REST call to workflow service for AAT messaging.")
requests.post(send_archive_msg_url, json=payload)
@@ -237,6 +252,12 @@ class NotificationConnect:
self.url = settings["notification_url"]
def send_session_ready(self, wrapper_url: str):
"""
Notifies of CARTA session that's been created
:param wrapper_url: CARTA session URL
:return:
"""
if "user_email" not in self.settings:
self.logger.info("Not sending notification because no user email supplied")
return
@@ -251,6 +272,11 @@ class NotificationConnect:
)
def send_session_expired(self):
"""
Notifies of expired CARTA session
:return:
"""
if "user_email" not in self.settings:
self.logger.info("Not sending notification because no user email supplied")
return
@@ -262,3 +288,25 @@ class NotificationConnect:
"destination_email": self.settings["user_email"],
},
)
class WorkflowConnect:
"""For sending CARTA URL to workspaces system"""
def __init__(self, settings):
self.logger = logging.getLogger("carta_envoy")
self.settings = settings
self.url = settings["workflow_url"]
def send_carta_url(self, wrapper_url: str):
"""
Makes REST call to send message containing CARTA URL to workspaces system
:return:
"""
send_url_message = (
f"{self.settings['workflow_url']}/workflows/carta/requests/{self.settings['wf_request_id']}/url"
)
payload = {"carta_url": wrapper_url}
self.logger.info("Sending REST call to workflow service for WS CARTA messaging.")
requests.post(send_url_message, json=payload)
Loading