Skip to content

Commit

Permalink
[DM-41830] Add some sanity checking on siav2 labels
Browse files Browse the repository at this point in the history
  • Loading branch information
cbanek committed Dec 2, 2023
1 parent ca0ea29 commit 95d5e5f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/lsst/rsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
)
from .forwarder import Forwarder
from .log import IPythonHandler, forward_lsst_log
from .service import get_datalink_result, get_siav2_service
from .utils import (
format_bytes,
get_access_token,
get_digest,
get_hostname,
get_node,
get_pod,
get_pyvo_auth,
show_with_bokeh_server,
)

Expand Down Expand Up @@ -47,5 +49,6 @@
"get_obstap_service",
"retrieve_query",
"get_hostname",
"get_pyvo_auth",
"show_with_bokeh_server",
]
50 changes: 45 additions & 5 deletions src/lsst/rsp/service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
import os

import pyvo
from pyvo.dal import SIA2Service
from pyvo.dal.adhoc import DatalinkResults

from utils import get_pyvo_auth, get_service_url

LSST_CLOUD = [
"https://data.lsst.cloud",
"https://data-int.lsst.cloud",
"https://data-dev.lsst.cloud"
]

USDF = [
"https://usdf-rsp.slac.stanford.edu",
"https://usdf-rsp-dev.slac.stanford.edu"
]


from .utils import get_pyvo_auth, get_service_url
def get_datalink_result(result) -> DatalinkResults:
"""Helper function to return the datalink part of the result."""
return DatalinkResults.from_result_url(result.getdataurl(),session=get_pyvo_auth())


def get_siav2_service(*args: str) -> SIA2Service:
"""Return a configured SIA2Service object that is ready to use."""
fqdn = os.environ["EXTERNAL_INSTANCE_URL"]

def get_siav2_service(*args: str) -> pyvo.dal.SIA2Service:
if len(args) == 0:
ds = "dp0.2"
elif args == "latiss":
ds = "latiss"
# Use the default for each environment
if fqdn in LSST_CLOUD:
label = "dp0.2"
elif fqdn in USDF:
label = "latiss"
else:
raise Exception("Unknown environment " + fqdn)
else:
label = args[0]

# If a label is passed, check that.
if label not in ["dp0.2", "latiss"]:
raise Exception(label + " is not a valid siav2 label")

if label == "latiss" and fqdn not in USDF:
raise Exception(label + " data not available at your location")
if label == "dp0.2" and fqdn not in LSST_CLOUD:
raise Exception(label + " data not available at your location")

# No matter what, we've only got one sia server per environment
# so for now just do some checking.
return SIA2Service(get_service_url("siav2"), get_pyvo_auth())
2 changes: 1 addition & 1 deletion src/lsst/rsp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_service_url(name: str, env_name=None) -> str:
return url

fqdn = os.getenv("EXTERNAL_INSTANCE_URL") or ""
path = os.getenv(f"{env_name}_ROUTE") or f"/api/{name}"
path = os.getenv(f"{env_name}_ROUTE") or f"api/{name}"
return f"{fqdn}/{path}"


Expand Down

0 comments on commit 95d5e5f

Please sign in to comment.