Skip to content

Commit

Permalink
Merge pull request #466 from xchem/m2ms-1240-achristie
Browse files Browse the repository at this point in the history
Potential fix for ispyb service query
  • Loading branch information
alanbchristie authored Dec 11, 2023
2 parents 031e588 + 3c849d6 commit 65295ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 10 additions & 5 deletions api/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def get_conn() -> Optional[Connector]:
return conn


def get_configured_connector() -> Optional[Union[Connector, SSHConnector]]:
if connector == 'ispyb':
return get_conn()
elif connector == 'ssh_ispyb':
return get_remote_conn()
else:
return None


class ISpyBSafeQuerySet(viewsets.ReadOnlyModelViewSet):
def get_queryset(self):
"""
Expand Down Expand Up @@ -190,11 +199,7 @@ def get_proposals_for_user_from_ispyb(self, user):
logger.info("user=%s needs_updating=%s", user.username, needs_updating)

if needs_updating:
conn: Optional[Union[Connector, SSHConnector]] = None
if connector == 'ispyb':
conn = get_conn()
elif connector == 'ssh_ispyb':
conn = get_remote_conn()
conn: Optional[Union[Connector, SSHConnector]] = get_configured_connector()

# If there is no connection (ISPyB credentials may be missing)
# then there's nothing we can do except return an empty list.
Expand Down
12 changes: 5 additions & 7 deletions viewer/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import os
from concurrent import futures
from enum import Enum
from typing import Optional

import requests
from frag.utils.network_utils import get_driver
from ispyb.connector.mysqlsp.main import ISPyBMySQLSPConnector as Connector
from pydiscourse import DiscourseClient

from api import security
from api.security import get_configured_connector
from viewer.squonk2_agent import get_squonk2_agent

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -150,16 +148,16 @@ async def wrapper_service_query(*args, **kwargs):


@service_query
def ispyb(func_id, name, ispyb_host=None) -> Optional[Connector]:
def ispyb(func_id, name, ispyb_host=None) -> bool:
# Unused arguments
del func_id, name, ispyb_host

logger.debug("+ ispyb")
return security.get_conn()
return get_configured_connector() != None


@service_query
def discourse(func_id, name, key=None, url=None, user=None) -> DiscourseClient:
def discourse(func_id, name, key=None, url=None, user=None) -> bool:
# Unused arguments
del func_id, name

Expand All @@ -170,7 +168,7 @@ def discourse(func_id, name, key=None, url=None, user=None) -> DiscourseClient:
api_key=os.environ.get(key, None),
)
# TODO: some action on client?
return client
return client != None


@service_query
Expand Down

0 comments on commit 65295ef

Please sign in to comment.